diff --git a/screenedge.cpp b/screenedge.cpp index baa442cc4e..fb6209c199 100644 --- a/screenedge.cpp +++ b/screenedge.cpp @@ -49,6 +49,8 @@ ScreenEdge::ScreenEdge() : QObject(NULL) , m_screenEdgeWindows(ELECTRIC_COUNT, None) , m_screenEdgeReserved(ELECTRIC_COUNT, 0) + , m_virtualDesktopSwitching(Options::ElectricDisabled) + , m_virtualDesktopLayout(0) { } @@ -130,6 +132,52 @@ void ScreenEdge::restoreSize(ElectricBorder border) xywh[border][0], xywh[border][1], xywh[border][2], xywh[border][3]); } +void ScreenEdge::reconfigureVirtualDesktopSwitching() +{ + const int newMode = options->electricBorders(); + if (m_virtualDesktopSwitching == newMode) { + return; + } + if (m_virtualDesktopSwitching == Options::ElectricAlways) { + reserveDesktopSwitching(false, m_virtualDesktopLayout); + } + m_virtualDesktopSwitching = newMode; + if (m_virtualDesktopSwitching == Options::ElectricAlways) { + reserveDesktopSwitching(true, m_virtualDesktopLayout); + } + update(); +} + +void ScreenEdge::reconfigure() +{ + reserveActions(true); + reconfigureVirtualDesktopSwitching(); + updateLayout(); + update(); +} + +void ScreenEdge::updateLayout() +{ + const QSize desktopMatrix = VirtualDesktopManager::self()->grid().size(); + Qt::Orientations newLayout = 0; + if (desktopMatrix.width() > 1) { + newLayout |= Qt::Horizontal; + } + if (desktopMatrix.height() > 1) { + newLayout |= Qt::Vertical; + } + if (newLayout == m_virtualDesktopLayout) { + return; + } + if (m_virtualDesktopSwitching == Options::ElectricAlways) { + reserveDesktopSwitching(false, m_virtualDesktopLayout); + } + m_virtualDesktopLayout = newLayout; + if (m_virtualDesktopSwitching == Options::ElectricAlways) { + reserveDesktopSwitching(true, m_virtualDesktopLayout); + } +} + void ScreenEdge::reserveActions(bool isToReserve) { for (int pos = 0; pos < ELECTRIC_COUNT; ++pos) @@ -255,11 +303,11 @@ void ScreenEdge::check(const QPoint& pos, Time now, bool forceNoPushback) m_screenEdgeTimeLastTrigger = now; if (Workspace::self()->getMovingClient()) { // If moving a client or have force doing the desktop switch - if (options->electricBorders() != Options::ElectricDisabled) + if (m_virtualDesktopSwitching != Options::ElectricDisabled) switchDesktop(border, pos); return; // Don't reset cursor position } else { - if (options->electricBorders() == Options::ElectricAlways && + if (m_virtualDesktopSwitching == Options::ElectricAlways && (border == ElectricTop || border == ElectricRight || border == ElectricBottom || border == ElectricLeft)) { // If desktop switching is always enabled don't apply it to the corners if @@ -290,7 +338,7 @@ void ScreenEdge::check(const QPoint& pos, Time now, bool forceNoPushback) if (effects && static_cast(effects)->borderActivated(border)) {} // Handled by effects else { - if (options->electricBorders() == Options::ElectricAlways) { + if (m_virtualDesktopSwitching == Options::ElectricAlways) { switchDesktop(border, pos); return; // Don't reset cursor position } diff --git a/screenedge.h b/screenedge.h index b2cda7b545..6dd1956332 100644 --- a/screenedge.h +++ b/screenedge.h @@ -114,6 +114,18 @@ public Q_SLOTS: * actions or disabled desktop switching. */ void update(bool force=false); + /** + * Reconfigures the screen edges. That is reserves required borders. + **/ + void reconfigure(); + /** + * Reconfigures for virtual desktop switching, that is updates m_virtualDesktopSwitching. + **/ + void reconfigureVirtualDesktopSwitching(); + /** + * Updates the layout of virtual desktops, that is updates m_virtualDesktopLayout. + **/ + void updateLayout(); Q_SIGNALS: /** * Emitted when the @p border got activated and there is neither an effect nor a global @@ -139,6 +151,18 @@ private: Time m_screenEdgeTimeLast; Time m_screenEdgeTimeLastTrigger; QPoint m_screenEdgePushPoint; + /** + * The virtual desktop switching mode when hitting screen edges. Either: + * @li never enabled + * @li enabled when moving windows + * @li always enabled + **/ + int m_virtualDesktopSwitching; + /** + * Used to know whether desktop switching at top/bottom or left/right borders is supported + * by the layout of virtual desktops. + **/ + Qt::Orientations m_virtualDesktopLayout; }; } #endif // KWIN_SCREENEDGE_H diff --git a/workspace.cpp b/workspace.cpp index f60720d545..07e65ae495 100644 --- a/workspace.cpp +++ b/workspace.cpp @@ -93,9 +93,6 @@ Workspace* Workspace::_self = 0; Workspace::Workspace(bool restore) : QObject(0) -#ifdef KWIN_BUILD_SCREENEDGES - , m_screenEdgeOrientation(0) -#endif , m_compositor(NULL) // Unsorted , active_popup(NULL) @@ -255,6 +252,9 @@ void Workspace::init() { #ifdef KWIN_BUILD_SCREENEDGES m_screenEdge.init(); + connect(options, SIGNAL(configChanged()), &m_screenEdge, SLOT(reconfigure())); + connect(options, SIGNAL(electricBordersChanged()), &m_screenEdge, SLOT(reconfigureVirtualDesktopSwitching())); + connect(VirtualDesktopManager::self(), SIGNAL(layoutChanged(int,int)), &m_screenEdge, SLOT(updateLayout())); #endif supportWindow = new QWidget(NULL, Qt::X11BypassWindowManagerHint); @@ -997,8 +997,6 @@ void Workspace::slotReconfigure() #ifdef KWIN_BUILD_SCREENEDGES m_screenEdge.reserveActions(false); - if (options->electricBorders() == Options::ElectricAlways) - m_screenEdge.reserveDesktopSwitching(false, m_screenEdgeOrientation); #endif bool borderlessMaximizedWindows = options->borderlessMaximizedWindows(); @@ -1033,19 +1031,6 @@ void Workspace::slotReconfigure() c->triggerDecorationRepaint(); } -#ifdef KWIN_BUILD_SCREENEDGES - m_screenEdge.reserveActions(true); - if (options->electricBorders() == Options::ElectricAlways) { - QSize desktopMatrix = rootInfo->desktopLayoutColumnsRows(); - m_screenEdgeOrientation = 0; - if (desktopMatrix.width() > 1) - m_screenEdgeOrientation |= Qt::Horizontal; - if (desktopMatrix.height() > 1) - m_screenEdgeOrientation |= Qt::Vertical; - m_screenEdge.reserveDesktopSwitching(true, m_screenEdgeOrientation); - } - m_screenEdge.update(); -#endif loadWindowRules(); for (ClientList::Iterator it = clients.begin(); it != clients.end(); diff --git a/workspace.h b/workspace.h index abf2642089..252a959e89 100644 --- a/workspace.h +++ b/workspace.h @@ -218,7 +218,6 @@ private: Outline* m_outline; #ifdef KWIN_BUILD_SCREENEDGES ScreenEdge m_screenEdge; - Qt::Orientations m_screenEdgeOrientation; #endif Compositor *m_compositor;