diff --git a/autotests/integration/effects/scripts/effectsHandler.js b/autotests/integration/effects/scripts/effectsHandler.js index 5db80636b8..a2e47461e5 100644 --- a/autotests/integration/effects/scripts/effectsHandler.js +++ b/autotests/integration/effects/scripts/effectsHandler.js @@ -13,5 +13,5 @@ effects.windowClosed.connect(function(window) { sendTestResponse("windowClosed - " + window.caption); }); effects.desktopChanged.connect(function(old, current) { - sendTestResponse("desktopChanged - " + old + " " + current); + sendTestResponse("desktopChanged - " + old.x11DesktopNumber + " " + current.x11DesktopNumber); }); diff --git a/src/effects.cpp b/src/effects.cpp index c2e43f1af3..0e068e7bd1 100644 --- a/src/effects.cpp +++ b/src/effects.cpp @@ -150,11 +150,11 @@ EffectsHandlerImpl::EffectsHandlerImpl(Compositor *compositor, WorkspaceScene *s } }); connect(ws, &Workspace::currentDesktopChanged, this, [this](VirtualDesktop *old, Window *window) { - const VirtualDesktop *newDesktop = VirtualDesktopManager::self()->currentDesktop(); - Q_EMIT desktopChanged(old->x11DesktopNumber(), newDesktop->x11DesktopNumber(), window ? window->effectWindow() : nullptr); + VirtualDesktop *newDesktop = VirtualDesktopManager::self()->currentDesktop(); + Q_EMIT desktopChanged(old, newDesktop, window ? window->effectWindow() : nullptr); }); connect(ws, &Workspace::currentDesktopChanging, this, [this](VirtualDesktop *currentDesktop, QPointF offset, KWin::Window *window) { - Q_EMIT desktopChanging(currentDesktop->x11DesktopNumber(), offset, window ? window->effectWindow() : nullptr); + Q_EMIT desktopChanging(currentDesktop, offset, window ? window->effectWindow() : nullptr); }); connect(ws, &Workspace::currentDesktopChangingCancelled, this, [this]() { Q_EMIT desktopChangingCancelled(); @@ -170,12 +170,13 @@ EffectsHandlerImpl::EffectsHandlerImpl(Compositor *compositor, WorkspaceScene *s Q_EMIT windowDeleted(d->effectWindow()); }); connect(ws->sessionManager(), &SessionManager::stateChanged, this, &KWin::EffectsHandler::sessionStateChanged); - connect(vds, &VirtualDesktopManager::countChanged, this, &EffectsHandler::numberDesktopsChanged); connect(vds, &VirtualDesktopManager::layoutChanged, this, [this](int width, int height) { Q_EMIT desktopGridSizeChanged(QSize(width, height)); Q_EMIT desktopGridWidthChanged(width); Q_EMIT desktopGridHeightChanged(height); }); + connect(vds, &VirtualDesktopManager::desktopCreated, this, &EffectsHandler::desktopAdded); + connect(vds, &VirtualDesktopManager::desktopRemoved, this, &EffectsHandler::desktopRemoved); connect(Cursors::self()->mouse(), &Cursor::mouseChanged, this, &EffectsHandler::mouseChanged); connect(ws, &Workspace::geometryChanged, this, &EffectsHandler::virtualScreenSizeChanged); connect(ws, &Workspace::geometryChanged, this, &EffectsHandler::virtualScreenGeometryChanged); @@ -715,25 +716,12 @@ void EffectsHandlerImpl::moveWindow(EffectWindow *w, const QPoint &pos, bool sna } } -void EffectsHandlerImpl::windowToDesktops(EffectWindow *w, const QList &desktopIds) +void EffectsHandlerImpl::windowToDesktops(EffectWindow *w, const QList &desktops) { auto window = static_cast(w)->window(); if (!window->isClient() || window->isDesktop() || window->isDock()) { return; } - QList desktops; - desktops.reserve(desktopIds.count()); - for (uint x11Id : desktopIds) { - if (x11Id > VirtualDesktopManager::self()->count()) { - continue; - } - VirtualDesktop *d = VirtualDesktopManager::self()->desktopForX11Id(x11Id); - Q_ASSERT(d); - if (desktops.contains(d)) { - continue; - } - desktops << d; - } window->setDesktops(desktops); } @@ -762,26 +750,21 @@ QString EffectsHandlerImpl::currentActivity() const #endif } -int EffectsHandlerImpl::currentDesktop() const +VirtualDesktop *EffectsHandlerImpl::currentDesktop() const { - return VirtualDesktopManager::self()->current(); + return VirtualDesktopManager::self()->currentDesktop(); } -int EffectsHandlerImpl::numberOfDesktops() const +QList EffectsHandlerImpl::desktops() const { - return VirtualDesktopManager::self()->count(); + return VirtualDesktopManager::self()->desktops(); } -void EffectsHandlerImpl::setCurrentDesktop(int desktop) +void EffectsHandlerImpl::setCurrentDesktop(VirtualDesktop *desktop) { VirtualDesktopManager::self()->setCurrent(desktop); } -void EffectsHandlerImpl::setNumberOfDesktops(int desktops) -{ - VirtualDesktopManager::self()->setCount(desktops); -} - QSize EffectsHandlerImpl::desktopGridSize() const { return VirtualDesktopManager::self()->grid().size(); @@ -807,22 +790,19 @@ int EffectsHandlerImpl::workspaceHeight() const return desktopGridHeight() * Workspace::self()->geometry().height(); } -int EffectsHandlerImpl::desktopAtCoords(QPoint coords) const +VirtualDesktop *EffectsHandlerImpl::desktopAtCoords(QPoint coords) const { - if (auto vd = VirtualDesktopManager::self()->grid().at(coords)) { - return vd->x11DesktopNumber(); - } - return 0; + return VirtualDesktopManager::self()->grid().at(coords); } -QPoint EffectsHandlerImpl::desktopGridCoords(int id) const +QPoint EffectsHandlerImpl::desktopGridCoords(VirtualDesktop *desktop) const { - return VirtualDesktopManager::self()->grid().gridCoords(id); + return VirtualDesktopManager::self()->grid().gridCoords(desktop); } -QPoint EffectsHandlerImpl::desktopCoords(int id) const +QPoint EffectsHandlerImpl::desktopCoords(VirtualDesktop *desktop) const { - QPoint coords = VirtualDesktopManager::self()->grid().gridCoords(id); + QPoint coords = VirtualDesktopManager::self()->grid().gridCoords(desktop); if (coords.x() == -1) { return QPoint(-1, -1); } @@ -830,30 +810,29 @@ QPoint EffectsHandlerImpl::desktopCoords(int id) const return QPoint(coords.x() * displaySize.width(), coords.y() * displaySize.height()); } -int EffectsHandlerImpl::desktopAbove(int desktop, bool wrap) const +VirtualDesktop *EffectsHandlerImpl::desktopAbove(VirtualDesktop *desktop, bool wrap) const { return VirtualDesktopManager::self()->inDirection(desktop, VirtualDesktopManager::Direction::Up, wrap); } -int EffectsHandlerImpl::desktopToRight(int desktop, bool wrap) const +VirtualDesktop *EffectsHandlerImpl::desktopToRight(VirtualDesktop *desktop, bool wrap) const { return VirtualDesktopManager::self()->inDirection(desktop, VirtualDesktopManager::Direction::Right, wrap); } -int EffectsHandlerImpl::desktopBelow(int desktop, bool wrap) const +VirtualDesktop *EffectsHandlerImpl::desktopBelow(VirtualDesktop *desktop, bool wrap) const { return VirtualDesktopManager::self()->inDirection(desktop, VirtualDesktopManager::Direction::Down, wrap); } -int EffectsHandlerImpl::desktopToLeft(int desktop, bool wrap) const +VirtualDesktop *EffectsHandlerImpl::desktopToLeft(VirtualDesktop *desktop, bool wrap) const { return VirtualDesktopManager::self()->inDirection(desktop, VirtualDesktopManager::Direction::Left, wrap); } -QString EffectsHandlerImpl::desktopName(int desktop) const +QString EffectsHandlerImpl::desktopName(VirtualDesktop *desktop) const { - const VirtualDesktop *vd = VirtualDesktopManager::self()->desktopForX11Id(desktop); - return vd ? vd->name() : QString(); + return desktop->name(); } bool EffectsHandlerImpl::optionRollOverDesktops() const @@ -1014,18 +993,9 @@ Output *EffectsHandlerImpl::activeScreen() const return workspace()->activeOutput(); } -static VirtualDesktop *resolveVirtualDesktop(int desktopId) +QRectF EffectsHandlerImpl::clientArea(clientAreaOption opt, const Output *screen, const VirtualDesktop *desktop) const { - if (desktopId == 0 || desktopId == -1) { - return VirtualDesktopManager::self()->currentDesktop(); - } else { - return VirtualDesktopManager::self()->desktopForX11Id(desktopId); - } -} - -QRectF EffectsHandlerImpl::clientArea(clientAreaOption opt, const Output *screen, int desktop) const -{ - return Workspace::self()->clientArea(opt, screen, resolveVirtualDesktop(desktop)); + return Workspace::self()->clientArea(opt, screen, desktop); } QRectF EffectsHandlerImpl::clientArea(clientAreaOption opt, const EffectWindow *effectWindow) const @@ -1034,11 +1004,10 @@ QRectF EffectsHandlerImpl::clientArea(clientAreaOption opt, const EffectWindow * return Workspace::self()->clientArea(opt, window); } -QRectF EffectsHandlerImpl::clientArea(clientAreaOption opt, const QPoint &p, int desktop) const +QRectF EffectsHandlerImpl::clientArea(clientAreaOption opt, const QPoint &p, const VirtualDesktop *desktop) const { const Output *output = Workspace::self()->outputAt(p); - const VirtualDesktop *virtualDesktop = resolveVirtualDesktop(desktop); - return Workspace::self()->clientArea(opt, output, virtualDesktop); + return Workspace::self()->clientArea(opt, output, desktop); } QRect EffectsHandlerImpl::virtualScreenGeometry() const @@ -1845,6 +1814,7 @@ WINDOW_HELPER(QIcon, icon, icon) WINDOW_HELPER(bool, isSkipSwitcher, skipSwitcher) WINDOW_HELPER(bool, decorationHasAlpha, decorationHasAlpha) WINDOW_HELPER(bool, isUnresponsive, unresponsive) +WINDOW_HELPER(QList, desktops, desktops) #undef WINDOW_HELPER @@ -1856,17 +1826,6 @@ qlonglong EffectWindowImpl::windowId() const return 0; } -QList EffectWindowImpl::desktops() const -{ - const auto desks = m_window->desktops(); - QList ids; - ids.reserve(desks.count()); - std::transform(desks.constBegin(), desks.constEnd(), std::back_inserter(ids), [](const VirtualDesktop *vd) { - return vd->x11DesktopNumber(); - }); - return ids; -} - QString EffectWindowImpl::windowClass() const { return m_window->resourceName() + QLatin1Char(' ') + m_window->resourceClass(); diff --git a/src/effects.h b/src/effects.h index 5c315794f9..056a9ae390 100644 --- a/src/effects.h +++ b/src/effects.h @@ -68,23 +68,22 @@ public: void setShowingDesktop(bool showing) override; QString currentActivity() const override; - int currentDesktop() const override; - int numberOfDesktops() const override; - void setCurrentDesktop(int desktop) override; - void setNumberOfDesktops(int desktops) override; + VirtualDesktop *currentDesktop() const override; + QList desktops() const override; + void setCurrentDesktop(VirtualDesktop *desktop) override; QSize desktopGridSize() const override; int desktopGridWidth() const override; int desktopGridHeight() const override; int workspaceWidth() const override; int workspaceHeight() const override; - int desktopAtCoords(QPoint coords) const override; - QPoint desktopGridCoords(int id) const override; - QPoint desktopCoords(int id) const override; - int desktopAbove(int desktop = 0, bool wrap = true) const override; - int desktopToRight(int desktop = 0, bool wrap = true) const override; - int desktopBelow(int desktop = 0, bool wrap = true) const override; - int desktopToLeft(int desktop = 0, bool wrap = true) const override; - QString desktopName(int desktop) const override; + VirtualDesktop *desktopAtCoords(QPoint coords) const override; + QPoint desktopGridCoords(VirtualDesktop *desktop) const override; + QPoint desktopCoords(VirtualDesktop *desktop) const override; + VirtualDesktop *desktopAbove(VirtualDesktop *desktop = nullptr, bool wrap = true) const override; + VirtualDesktop *desktopToRight(VirtualDesktop *desktop = nullptr, bool wrap = true) const override; + VirtualDesktop *desktopBelow(VirtualDesktop *desktop = nullptr, bool wrap = true) const override; + VirtualDesktop *desktopToLeft(VirtualDesktop *desktop = nullptr, bool wrap = true) const override; + QString desktopName(VirtualDesktop *desktop) const override; bool optionRollOverDesktops() const override; QPointF cursorPos() const override; @@ -126,9 +125,9 @@ public: void addRepaint(const QRegion &r) override; void addRepaint(int x, int y, int w, int h) override; Output *activeScreen() const override; - QRectF clientArea(clientAreaOption, const Output *screen, int desktop) const override; + QRectF clientArea(clientAreaOption, const Output *screen, const VirtualDesktop *desktop) const override; QRectF clientArea(clientAreaOption, const EffectWindow *c) const override; - QRectF clientArea(clientAreaOption, const QPoint &p, int desktop) const override; + QRectF clientArea(clientAreaOption, const QPoint &p, const VirtualDesktop *desktop) const override; QSize virtualScreenSize() const override; QRect virtualScreenGeometry() const override; double animationTimeFactor() const override; @@ -223,7 +222,7 @@ public: return registered_atoms.contains(atom); } - void windowToDesktops(EffectWindow *w, const QList &desktops) override; + void windowToDesktops(EffectWindow *w, const QList &desktops) override; /** * Finds an effect with the given name. @@ -341,7 +340,7 @@ public: double opacity() const override; QStringList activities() const override; - QList desktops() const override; + QList desktops() const override; qreal x() const override; qreal y() const override; qreal width() const override; diff --git a/src/libkwineffects/kwineffects.cpp b/src/libkwineffects/kwineffects.cpp index 81b2105265..72f6e6a189 100644 --- a/src/libkwineffects/kwineffects.cpp +++ b/src/libkwineffects/kwineffects.cpp @@ -11,6 +11,7 @@ #include "libkwineffects/kwineffects.h" #include "core/output.h" +#include "virtualdesktops.h" #include "config-kwin.h" @@ -684,10 +685,10 @@ bool EffectWindow::isOnCurrentDesktop() const return isOnDesktop(effects->currentDesktop()); } -bool EffectWindow::isOnDesktop(int d) const +bool EffectWindow::isOnDesktop(VirtualDesktop *desktop) const { - const QList ds = desktops(); - return ds.isEmpty() || ds.contains(d); + const QList ds = desktops(); + return ds.isEmpty() || ds.contains(desktop); } bool EffectWindow::isOnAllDesktops() const diff --git a/src/libkwineffects/kwineffects.h b/src/libkwineffects/kwineffects.h index bb69aad355..b429271847 100644 --- a/src/libkwineffects/kwineffects.h +++ b/src/libkwineffects/kwineffects.h @@ -82,6 +82,7 @@ class WindowPaintData; class ScreenPrePaintData; class RenderTarget; class RenderViewport; +class VirtualDesktop; typedef QPair EffectPair; typedef QList EffectWindowList; @@ -788,7 +789,7 @@ public: class KWIN_EXPORT EffectsHandler : public QObject { Q_OBJECT - Q_PROPERTY(int currentDesktop READ currentDesktop WRITE setCurrentDesktop NOTIFY desktopChanged) + Q_PROPERTY(KWin::VirtualDesktop *currentDesktop READ currentDesktop WRITE setCurrentDesktop NOTIFY desktopChanged) Q_PROPERTY(QString currentActivity READ currentActivity NOTIFY currentActivityChanged) Q_PROPERTY(KWin::EffectWindow *activeWindow READ activeWindow WRITE activateWindow NOTIFY windowActivated) Q_PROPERTY(QSize desktopGridSize READ desktopGridSize NOTIFY desktopGridSizeChanged) @@ -796,10 +797,7 @@ class KWIN_EXPORT EffectsHandler : public QObject Q_PROPERTY(int desktopGridHeight READ desktopGridHeight NOTIFY desktopGridHeightChanged) Q_PROPERTY(int workspaceWidth READ workspaceWidth) Q_PROPERTY(int workspaceHeight READ workspaceHeight) - /** - * The number of desktops currently used. Minimum number of desktops is 1, maximum 20. - */ - Q_PROPERTY(int desktops READ numberOfDesktops WRITE setNumberOfDesktops NOTIFY numberDesktopsChanged) + Q_PROPERTY(QList desktops READ desktops) Q_PROPERTY(bool optionRollOverDesktops READ optionRollOverDesktops) Q_PROPERTY(KWin::Output *activeScreen READ activeScreen) /** @@ -971,10 +969,8 @@ public: * Moves a window to the given desktops * On X11, the window will end up on the last window in the list * Setting this to an empty list will set the window on all desktops - * - * @arg desktopIds a list of desktops the window should be placed on. NET::OnAllDesktops is not a valid desktop X11Id */ - Q_SCRIPTABLE virtual void windowToDesktops(KWin::EffectWindow *w, const QList &desktopIds) = 0; + Q_SCRIPTABLE virtual void windowToDesktops(KWin::EffectWindow *w, const QList &desktops) = 0; Q_SCRIPTABLE virtual void windowToScreen(KWin::EffectWindow *w, Output *screen) = 0; virtual void setShowingDesktop(bool showing) = 0; @@ -986,21 +982,17 @@ public: virtual QString currentActivity() const = 0; // Desktops /** - * @returns The ID of the current desktop. + * @returns The current desktop. */ - virtual int currentDesktop() const = 0; + virtual VirtualDesktop *currentDesktop() const = 0; /** * @returns Total number of desktops currently in existence. */ - virtual int numberOfDesktops() const = 0; + virtual QList desktops() const = 0; /** * Set the current desktop to @a desktop. */ - virtual void setCurrentDesktop(int desktop) = 0; - /** - * Sets the total number of desktops to @a desktops. - */ - virtual void setNumberOfDesktops(int desktops) = 0; + virtual void setCurrentDesktop(KWin::VirtualDesktop *desktop) = 0; /** * @returns The size of desktop layout in grid units. */ @@ -1022,45 +1014,45 @@ public: */ virtual int workspaceHeight() const = 0; /** - * @returns The ID of the desktop at the point @a coords or 0 if no desktop exists at that + * @returns The desktop at the point @a coords or 0 if no desktop exists at that * point. @a coords is to be in grid units. */ - virtual int desktopAtCoords(QPoint coords) const = 0; + virtual VirtualDesktop *desktopAtCoords(QPoint coords) const = 0; /** - * @returns The coords of desktop @a id in grid units. + * @returns The coords of the specified @a desktop in grid units. */ - virtual QPoint desktopGridCoords(int id) const = 0; + virtual QPoint desktopGridCoords(VirtualDesktop *desktop) const = 0; /** - * @returns The coords of the top-left corner of desktop @a id in pixels. + * @returns The coords of the top-left corner of @a desktop in pixels. */ - virtual QPoint desktopCoords(int id) const = 0; + virtual QPoint desktopCoords(VirtualDesktop *desktop) const = 0; /** - * @returns The ID of the desktop above desktop @a id. Wraps around to the bottom of + * @returns The desktop above the given @a desktop. Wraps around to the bottom of * the layout if @a wrap is set. If @a id is not set use the current one. */ - Q_SCRIPTABLE virtual int desktopAbove(int desktop = 0, bool wrap = true) const = 0; + Q_SCRIPTABLE virtual KWin::VirtualDesktop *desktopAbove(KWin::VirtualDesktop *desktop = nullptr, bool wrap = true) const = 0; /** - * @returns The ID of the desktop to the right of desktop @a id. Wraps around to the + * @returns The desktop to the right of the given @a desktop. Wraps around to the * left of the layout if @a wrap is set. If @a id is not set use the current one. */ - Q_SCRIPTABLE virtual int desktopToRight(int desktop = 0, bool wrap = true) const = 0; + Q_SCRIPTABLE virtual KWin::VirtualDesktop *desktopToRight(KWin::VirtualDesktop *desktop = nullptr, bool wrap = true) const = 0; /** - * @returns The ID of the desktop below desktop @a id. Wraps around to the top of the + * @returns The desktop below the given @a desktop. Wraps around to the top of the * layout if @a wrap is set. If @a id is not set use the current one. */ - Q_SCRIPTABLE virtual int desktopBelow(int desktop = 0, bool wrap = true) const = 0; + Q_SCRIPTABLE virtual KWin::VirtualDesktop *desktopBelow(KWin::VirtualDesktop *desktop = nullptr, bool wrap = true) const = 0; /** - * @returns The ID of the desktop to the left of desktop @a id. Wraps around to the + * @returns The desktop to the left of the given @a desktop. Wraps around to the * right of the layout if @a wrap is set. If @a id is not set use the current one. */ - Q_SCRIPTABLE virtual int desktopToLeft(int desktop = 0, bool wrap = true) const = 0; - Q_SCRIPTABLE virtual QString desktopName(int desktop) const = 0; + Q_SCRIPTABLE virtual KWin::VirtualDesktop *desktopToLeft(KWin::VirtualDesktop *desktop = nullptr, bool wrap = true) const = 0; + Q_SCRIPTABLE virtual QString desktopName(KWin::VirtualDesktop *desktop) const = 0; virtual bool optionRollOverDesktops() const = 0; virtual Output *activeScreen() const = 0; // Xinerama - virtual QRectF clientArea(clientAreaOption, const Output *screen, int desktop) const = 0; + virtual QRectF clientArea(clientAreaOption, const Output *screen, const VirtualDesktop *desktop) const = 0; virtual QRectF clientArea(clientAreaOption, const EffectWindow *c) const = 0; - virtual QRectF clientArea(clientAreaOption, const QPoint &p, int desktop) const = 0; + virtual QRectF clientArea(clientAreaOption, const QPoint &p, const VirtualDesktop *desktop) const = 0; /** * The bounding size of all screens combined. Overlapping areas @@ -1417,7 +1409,7 @@ Q_SIGNALS: * @param with The window which is taken over to the new desktop, can be NULL * @since 4.9 */ - void desktopChanged(int oldDesktop, int newDesktop, KWin::EffectWindow *with); + void desktopChanged(KWin::VirtualDesktop *oldDesktop, KWin::VirtualDesktop *newDesktop, KWin::EffectWindow *with); /** * Signal emmitted while desktop is changing for animation. @@ -1426,8 +1418,10 @@ Q_SIGNALS: * offset.x() = .6 means 60% of the way to the desktop to the right. * Positive Values means Up and Right. */ - void desktopChanging(uint currentDesktop, QPointF offset, KWin::EffectWindow *with); + void desktopChanging(KWin::VirtualDesktop *currentDesktop, QPointF offset, KWin::EffectWindow *with); void desktopChangingCancelled(); + void desktopAdded(KWin::VirtualDesktop *desktop); + void desktopRemoved(KWin::VirtualDesktop *desktop); /** * Emitted when the virtual desktop grid layout changes @@ -1447,13 +1441,6 @@ Q_SIGNALS: * @since 5.25 */ void desktopGridHeightChanged(int height); - /** - * Signal emitted when the number of currently existing desktops is changed. - * @param old The previous number of desktops in used. - * @see EffectsHandler::numberOfDesktops. - * @since 4.7 - */ - void numberDesktopsChanged(uint old); /** * Signal emitted when the desktop showing ("dashboard") state changed * The desktop is risen to the keepAbove layer, you may want to elevate @@ -1716,7 +1703,7 @@ class KWIN_EXPORT EffectWindow : public QObject Q_PROPERTY(qreal width READ width) Q_PROPERTY(qreal x READ x) Q_PROPERTY(qreal y READ y) - Q_PROPERTY(QList desktops READ desktops) + Q_PROPERTY(QList desktops READ desktops) Q_PROPERTY(bool onAllDesktops READ isOnAllDesktops) Q_PROPERTY(bool onCurrentDesktop READ isOnCurrentDesktop) Q_PROPERTY(QRectF rect READ rect) @@ -2026,7 +2013,7 @@ public: bool isOnAllActivities() const; virtual QStringList activities() const = 0; - Q_SCRIPTABLE bool isOnDesktop(int d) const; + Q_SCRIPTABLE bool isOnDesktop(KWin::VirtualDesktop *desktop) const; bool isOnCurrentDesktop() const; bool isOnAllDesktops() const; /** @@ -2034,7 +2021,7 @@ public: * a length of 1, on Wayland can be any subset. * If the list is empty it means the window is on all desktops */ - virtual QList desktops() const = 0; + virtual QList desktops() const = 0; virtual qreal x() const = 0; virtual qreal y() const = 0; diff --git a/src/plugins/overview/overvieweffect.cpp b/src/plugins/overview/overvieweffect.cpp index 33fc0df2d5..23318f6685 100644 --- a/src/plugins/overview/overvieweffect.cpp +++ b/src/plugins/overview/overvieweffect.cpp @@ -101,11 +101,11 @@ OverviewEffect::OverviewEffect() connect(m_gridState, &EffectTogglableState::inProgressChanged, this, &OverviewEffect::gridGestureInProgressChanged); connect(m_gridState, &EffectTogglableState::partialActivationFactorChanged, this, &OverviewEffect::gridPartialActivationFactorChanged); - connect(effects, &EffectsHandler::desktopChanging, this, [this](uint old, QPointF desktopOffset, EffectWindow *with) { + connect(effects, &EffectsHandler::desktopChanging, this, [this](VirtualDesktop *old, QPointF desktopOffset, EffectWindow *with) { m_desktopOffset = desktopOffset; Q_EMIT desktopOffsetChanged(); }); - connect(effects, &EffectsHandler::desktopChanged, this, [this](int old, int current, EffectWindow *with) { + connect(effects, &EffectsHandler::desktopChanged, this, [this](VirtualDesktop *old, VirtualDesktop *current, EffectWindow *with) { m_desktopOffset = QPointF(0, 0); Q_EMIT desktopOffsetChanged(); }); @@ -362,7 +362,7 @@ void OverviewEffect::grabbedKeyboardEvent(QKeyEvent *keyEvent) QuickSceneEffect::grabbedKeyboardEvent(keyEvent); } -void OverviewEffect::swapDesktops(uint from, uint to) +void OverviewEffect::swapDesktops(VirtualDesktop *from, VirtualDesktop *to) { QList fromList; QList toList; diff --git a/src/plugins/overview/overvieweffect.h b/src/plugins/overview/overvieweffect.h index 176003e8b9..ab6907db64 100644 --- a/src/plugins/overview/overvieweffect.h +++ b/src/plugins/overview/overvieweffect.h @@ -59,7 +59,7 @@ public: void reconfigure(ReconfigureFlags flags) override; void grabbedKeyboardEvent(QKeyEvent *keyEvent) override; - Q_INVOKABLE void swapDesktops(uint from, uint to); + Q_INVOKABLE void swapDesktops(KWin::VirtualDesktop *from, KWin::VirtualDesktop *to); Q_SIGNALS: void animationDurationChanged(); diff --git a/src/plugins/overview/qml/main.qml b/src/plugins/overview/qml/main.qml index 1feccd97aa..88129fe924 100644 --- a/src/plugins/overview/qml/main.qml +++ b/src/plugins/overview/qml/main.qml @@ -485,7 +485,7 @@ FocusScope { drop.action = Qt.IgnoreAction; return; } - effect.swapDesktops(drag.source.desktop.x11DesktopNumber, desktop.x11DesktopNumber); + effect.swapDesktops(drag.source.desktop, desktop); } else { // dragging a KWin::Window if (drag.source.desktops.length === 0 || drag.source.desktops.indexOf(mainBackground.desktop) !== -1) { diff --git a/src/plugins/slide/slide.cpp b/src/plugins/slide/slide.cpp index e58405e909..9ea1482eeb 100644 --- a/src/plugins/slide/slide.cpp +++ b/src/plugins/slide/slide.cpp @@ -36,7 +36,9 @@ SlideEffect::SlideEffect() this, &SlideEffect::windowAdded); connect(effects, &EffectsHandler::windowDeleted, this, &SlideEffect::windowDeleted); - connect(effects, &EffectsHandler::numberDesktopsChanged, + connect(effects, &EffectsHandler::desktopAdded, + this, &SlideEffect::finishedSwitching); + connect(effects, &EffectsHandler::desktopRemoved, this, &SlideEffect::finishedSwitching); connect(effects, &EffectsHandler::screenAdded, this, &SlideEffect::finishedSwitching); @@ -106,6 +108,7 @@ void SlideEffect::prePaintScreen(ScreenPrePaintData &data, std::chrono::millisec m_currentPosition.setY(m_motionY.position() / virtualSpaceSize.height()); } + const QList desktops = effects->desktops(); const int w = effects->desktopGridWidth(); const int h = effects->desktopGridHeight(); @@ -113,20 +116,21 @@ void SlideEffect::prePaintScreen(ScreenPrePaintData &data, std::chrono::millisec m_paintCtx.visibleDesktops.clear(); m_paintCtx.visibleDesktops.reserve(4); // 4 - maximum number of visible desktops bool includedX = false, includedY = false; - for (int i = 1; i <= effects->numberOfDesktops(); i++) { - if (effects->desktopGridCoords(i).x() % w == (int)(m_currentPosition.x()) % w) { + for (VirtualDesktop *desktop : desktops) { + const QPoint coords = effects->desktopGridCoords(desktop); + if (coords.x() % w == (int)(m_currentPosition.x()) % w) { includedX = true; - } else if (effects->desktopGridCoords(i).x() % w == ((int)(m_currentPosition.x()) + 1) % w) { + } else if (coords.x() % w == ((int)(m_currentPosition.x()) + 1) % w) { includedX = true; } - if (effects->desktopGridCoords(i).y() % h == (int)(m_currentPosition.y()) % h) { + if (coords.y() % h == (int)(m_currentPosition.y()) % h) { includedY = true; - } else if (effects->desktopGridCoords(i).y() % h == ((int)(m_currentPosition.y()) + 1) % h) { + } else if (coords.y() % h == ((int)(m_currentPosition.y()) + 1) % h) { includedY = true; } if (includedX && includedY) { - m_paintCtx.visibleDesktops << i; + m_paintCtx.visibleDesktops << desktop; } } @@ -177,8 +181,8 @@ bool SlideEffect::willBePainted(const EffectWindow *w) const if (w == m_movingWindow) { return true; } - for (const int &id : std::as_const(m_paintCtx.visibleDesktops)) { - if (w->isOnDesktop(id)) { + for (VirtualDesktop *desktop : std::as_const(m_paintCtx.visibleDesktops)) { + if (w->isOnDesktop(desktop)) { return true; } } @@ -214,7 +218,7 @@ void SlideEffect::paintWindow(const RenderTarget &renderTarget, const RenderView const auto screens = effects->screens(); - for (int desktop : std::as_const(m_paintCtx.visibleDesktops)) { + for (VirtualDesktop *desktop : std::as_const(m_paintCtx.visibleDesktops)) { if (!w->isOnDesktop(desktop)) { continue; } @@ -283,7 +287,7 @@ bool SlideEffect::shouldElevate(const EffectWindow *w) const * Called AFTER the gesture is released. * Sets up animation to round off to the new current desktop. */ -void SlideEffect::startAnimation(int old, int current, EffectWindow *movingWindow) +void SlideEffect::startAnimation(VirtualDesktop *old, VirtualDesktop *current, EffectWindow *movingWindow) { if (m_state == State::Inactive) { prepareSwitching(); @@ -351,7 +355,7 @@ void SlideEffect::finishedSwitching() m_currentPosition = effects->desktopGridCoords(effects->currentDesktop()); } -void SlideEffect::desktopChanged(int old, int current, EffectWindow *with) +void SlideEffect::desktopChanged(VirtualDesktop *old, VirtualDesktop *current, EffectWindow *with) { if (effects->hasActiveFullScreenEffect() && effects->activeFullScreenEffect() != this) { m_currentPosition = effects->desktopGridCoords(effects->currentDesktop()); @@ -361,7 +365,7 @@ void SlideEffect::desktopChanged(int old, int current, EffectWindow *with) startAnimation(old, current, with); } -void SlideEffect::desktopChanging(uint old, QPointF desktopOffset, EffectWindow *with) +void SlideEffect::desktopChanging(VirtualDesktop *old, QPointF desktopOffset, EffectWindow *with) { if (effects->hasActiveFullScreenEffect() && effects->activeFullScreenEffect() != this) { return; diff --git a/src/plugins/slide/slide.h b/src/plugins/slide/slide.h index 795b83b7e1..99626e0d1e 100644 --- a/src/plugins/slide/slide.h +++ b/src/plugins/slide/slide.h @@ -73,8 +73,8 @@ public: bool slideBackground() const; private Q_SLOTS: - void desktopChanged(int old, int current, EffectWindow *with); - void desktopChanging(uint old, QPointF desktopOffset, EffectWindow *with); + void desktopChanged(VirtualDesktop *old, VirtualDesktop *current, EffectWindow *with); + void desktopChanging(VirtualDesktop *old, QPointF desktopOffset, EffectWindow *with); void desktopChangingCancelled(); void windowAdded(EffectWindow *w); void windowDeleted(EffectWindow *w); @@ -89,7 +89,7 @@ private: QPointF forcePositivePosition(QPointF p) const; void optimizePath(); // Find the best path to target desktop - void startAnimation(int old, int current, EffectWindow *movingWindow = nullptr); + void startAnimation(VirtualDesktop *old, VirtualDesktop *current, EffectWindow *movingWindow = nullptr); void prepareSwitching(); void finishedSwitching(); @@ -120,7 +120,7 @@ private: struct { bool wrap; - QList visibleDesktops; + QList visibleDesktops; } m_paintCtx; struct WindowData