From b674b458df709c7a6b8d194f78c017f76ea68c27 Mon Sep 17 00:00:00 2001 From: Vlad Zahorodnii Date: Wed, 6 Mar 2024 12:09:27 +0200 Subject: [PATCH] Rename Workspace::updateClientArea as Workspace::rearrange We need to re-arrange layer shell surfaces, compute new struts and adjust the windows in a single step. Workspace::updateClientArea() is the best candidate for that, so this change repurposes that function from computing work areas to a generic relayouting function. CCBUG: 482361 --- src/activities.cpp | 2 +- src/events.cpp | 2 +- src/layershellv1integration.cpp | 2 +- src/layershellv1window.cpp | 2 +- src/window.cpp | 4 +-- src/workspace.cpp | 49 ++++++++++++++------------------- src/workspace.h | 33 ++++++++++++++++------ src/x11window.cpp | 5 ++-- 8 files changed, 52 insertions(+), 47 deletions(-) diff --git a/src/activities.cpp b/src/activities.cpp index 59f4cbdae7..9f03dbd211 100644 --- a/src/activities.cpp +++ b/src/activities.cpp @@ -122,7 +122,7 @@ void Activities::toggleWindowOnActivity(Window *window, const QString &activity, } toggleWindowOnActivity(window, activity, dont_activate); } - ws->updateClientArea(); + ws->rearrange(); } bool Activities::start(const QString &id) diff --git a/src/events.cpp b/src/events.cpp index 7a40441af5..cf3ebf5249 100644 --- a/src/events.cpp +++ b/src/events.cpp @@ -396,7 +396,7 @@ bool X11Window::windowEvent(xcb_generic_event_t *e) } if ((dirtyProperties & NET::WMStrut) != 0 || (dirtyProperties2 & NET::WM2ExtendedStrut) != 0) { - workspace()->updateClientArea(); + workspace()->rearrange(); } if ((dirtyProperties & NET::WMIcon) != 0) { getIcons(); diff --git a/src/layershellv1integration.cpp b/src/layershellv1integration.cpp index 11fb99556c..d343b69f5f 100644 --- a/src/layershellv1integration.cpp +++ b/src/layershellv1integration.cpp @@ -26,7 +26,7 @@ LayerShellV1Integration::LayerShellV1Integration(QObject *parent) connect(shell, &LayerShellV1Interface::surfaceCreated, this, &LayerShellV1Integration::createWindow); - connect(workspace(), &Workspace::aboutToUpdateClientArea, this, &LayerShellV1Integration::rearrange); + connect(workspace(), &Workspace::aboutToRearrange, this, &LayerShellV1Integration::rearrange); } void LayerShellV1Integration::createWindow(LayerSurfaceV1Interface *shellSurface) diff --git a/src/layershellv1window.cpp b/src/layershellv1window.cpp index 2a9b43213d..a450e66352 100644 --- a/src/layershellv1window.cpp +++ b/src/layershellv1window.cpp @@ -88,7 +88,7 @@ Output *LayerShellV1Window::desiredOutput() const void LayerShellV1Window::scheduleRearrange() { - workspace()->scheduleUpdateClientArea(); + workspace()->scheduleRearrange(); } WindowType LayerShellV1Window::windowType() const diff --git a/src/window.cpp b/src/window.cpp index 6ff6335b18..97fdeebe62 100644 --- a/src/window.cpp +++ b/src/window.cpp @@ -3736,7 +3736,7 @@ void Window::checkWorkspacePosition(QRectF oldGeometry, const VirtualDesktop *ol // edge will move when a new strut is placed on the edge. QRect oldScreenArea; QRect screenArea; - if (workspace()->inUpdateClientArea()) { + if (workspace()->inRearrange()) { // check if the window is on an about to be destroyed output Output *newOutput = moveResizeOutput(); if (!workspace()->outputs().contains(newOutput)) { @@ -3777,7 +3777,7 @@ void Window::checkWorkspacePosition(QRectF oldGeometry, const VirtualDesktop *ol // the bottom struts bounded by the window's left and right sides). // These 4 compute old bounds ... - auto moveAreaFunc = workspace()->inUpdateClientArea() ? &Workspace::previousRestrictedMoveArea : //... the restricted areas changed + auto moveAreaFunc = workspace()->inRearrange() ? &Workspace::previousRestrictedMoveArea : //... the restricted areas changed &Workspace::restrictedMoveArea; //... when e.g. active desktop or screen changes for (const QRect &r : (workspace()->*moveAreaFunc)(oldDesktop, StrutAreaTop)) { diff --git a/src/workspace.cpp b/src/workspace.cpp index 8dac5a1536..97e400c21a 100644 --- a/src/workspace.cpp +++ b/src/workspace.cpp @@ -205,11 +205,11 @@ void Workspace::init() vds->setCurrent(m_initialDesktop); reconfigureTimer.setSingleShot(true); - m_updateClientAreaTimer.setSingleShot(true); + m_rearrangeTimer.setSingleShot(true); updateToolWindowsTimer.setSingleShot(true); connect(&reconfigureTimer, &QTimer::timeout, this, &Workspace::slotReconfigure); - connect(&m_updateClientAreaTimer, &QTimer::timeout, this, &Workspace::updateClientArea); + connect(&m_rearrangeTimer, &QTimer::timeout, this, &Workspace::rearrange); connect(&updateToolWindowsTimer, &QTimer::timeout, this, &Workspace::slotUpdateToolWindows); // TODO: do we really need to reconfigure everything when fonts change? @@ -380,7 +380,7 @@ void Workspace::initializeX11() // Propagate windows, will really happen at the end of the updates blocker block updateStackingOrder(true); - updateClientArea(); + rearrange(); // NETWM spec says we have to set it to (0,0) if we don't support it NETPoint *viewports = new NETPoint[VirtualDesktopManager::self()->count()]; @@ -722,7 +722,7 @@ void Workspace::addX11Window(X11Window *window) m_windows.append(window); addToStack(window); if (window->hasStrut()) { - updateClientArea(); // This cannot be in manage(), because the window got added only now + rearrange(); // This cannot be in manage(), because the window got added only now } window->updateLayer(); if (window->isDesktop()) { @@ -818,7 +818,7 @@ void Workspace::addWaylandWindow(Window *window) updateStackingOrder(true); if (window->hasStrut()) { - updateClientArea(); + rearrange(); } if (window->wantsInput() && !window->isMinimized()) { // Never activate a window on its own in "Extreme" mode. @@ -861,7 +861,7 @@ void Workspace::removeWindow(Window *window) setupWindowShortcutDone(false); } if (window->hasStrut()) { - updateClientArea(); + rearrange(); } Q_EMIT windowRemoved(window); @@ -1454,7 +1454,7 @@ void Workspace::slotDesktopAdded(VirtualDesktop *desktop) { m_focusChain->addDesktop(desktop); m_placement->reinitCascading(); - updateClientArea(); + rearrange(); } void Workspace::slotDesktopRemoved(VirtualDesktop *desktop) @@ -1477,7 +1477,7 @@ void Workspace::slotDesktopRemoved(VirtualDesktop *desktop) } } - updateClientArea(); + rearrange(); m_placement->reinitCascading(); m_focusChain->removeDesktop(desktop); } @@ -1534,7 +1534,7 @@ void Workspace::sendWindowToDesktops(Window *window, const QListdesktops(), dont_activate); } - updateClientArea(); + rearrange(); } void Workspace::sendWindowToOutput(Window *window, Output *output) @@ -2221,7 +2221,7 @@ void Workspace::desktopResized() } #endif - updateClientArea(); + rearrange(); const auto stack = stackingOrder(); for (Window *window : stack) { @@ -2244,7 +2244,7 @@ void Workspace::desktopResized() } } - saveOldScreenSizes(); // after updateClientArea(), so that one still uses the previous one + saveOldScreenSizes(); // after rearrange(), so that one still uses the previous one // TODO: emit a signal instead and remove the deep function calls into edges and effects m_screenEdges->recreateEdges(); @@ -2349,24 +2349,15 @@ QRectF Workspace::adjustClientArea(Window *window, const QRectF &area) const return adjustedArea; } -void Workspace::scheduleUpdateClientArea() +void Workspace::scheduleRearrange() { - m_updateClientAreaTimer.start(0); + m_rearrangeTimer.start(0); } -/** - * Updates the current client areas according to the current windows. - * - * The client area is the area that is available for windows (that - * which is not taken by windows like panels, the top-of-screen menu - * etc). - * - * @see clientArea() - */ -void Workspace::updateClientArea() +void Workspace::rearrange() { - Q_EMIT aboutToUpdateClientArea(); - m_updateClientAreaTimer.stop(); + Q_EMIT aboutToRearrange(); + m_rearrangeTimer.stop(); const QList desktops = VirtualDesktopManager::self()->desktops(); @@ -2444,7 +2435,7 @@ void Workspace::updateClientArea() m_workAreas = workAreas; m_screenAreas = screenAreas; - m_inUpdateClientArea = true; + m_inRearrange = true; m_oldRestrictedAreas = m_restrictedAreas; m_restrictedAreas = restrictedAreas; @@ -2465,7 +2456,7 @@ void Workspace::updateClientArea() } m_oldRestrictedAreas.clear(); // reset, no longer valid or needed - m_inUpdateClientArea = false; + m_inRearrange = false; } } @@ -2542,9 +2533,9 @@ StrutRects Workspace::restrictedMoveArea(const VirtualDesktop *desktop, StrutAre return ret; } -bool Workspace::inUpdateClientArea() const +bool Workspace::inRearrange() const { - return m_inUpdateClientArea; + return m_inRearrange; } StrutRects Workspace::previousRestrictedMoveArea(const VirtualDesktop *desktop, StrutAreas areas) const diff --git a/src/workspace.h b/src/workspace.h index a9d41f047e..6356d82035 100644 --- a/src/workspace.h +++ b/src/workspace.h @@ -277,12 +277,30 @@ private: // Unsorted public: - // True when performing Workspace::updateClientArea(). - // The calls below are valid only in that case. - bool inUpdateClientArea() const; StrutRects previousRestrictedMoveArea(const VirtualDesktop *desktop, StrutAreas areas = StrutAreaAll) const; QHash previousScreenSizes() const; + /** + * Returns @c true if the workspace is currently being rearranged; otherwise returns @c false. + */ + bool inRearrange() const; + + /** + * Re-arranges the workspace, it includes computing restricted areas, moving windows out of the + * restricted areas, and so on. + * + * The client area is the area that is available for windows (that which is not taken by windows + * like panels, the top-of-screen menu etc). + * + * @see clientArea() + */ + void rearrange(); + + /** + * Schedules the workspace to be re-arranged at the next available opportunity. + */ + void scheduleRearrange(); + /** * Returns the list of windows sorted in stacking order, with topmost window * at the last position @@ -529,9 +547,6 @@ public Q_SLOTS: void slotSetupWindowShortcut(); void setupWindowShortcutDone(bool); - void updateClientArea(); - void scheduleUpdateClientArea(); - private Q_SLOTS: void desktopResized(); #if KWIN_BUILD_X11 @@ -581,7 +596,7 @@ Q_SIGNALS: * or lowered */ void stackingOrderChanged(); - void aboutToUpdateClientArea(); + void aboutToRearrange(); private: void init(); @@ -708,7 +723,6 @@ private: // Timer to collect requests for 'reconfigure' QTimer reconfigureTimer; - QTimer m_updateClientAreaTimer; QTimer updateToolWindowsTimer; @@ -723,7 +737,8 @@ private: QHash m_oldScreenGeometries; QHash m_oldRestrictedAreas; - bool m_inUpdateClientArea = false; + QTimer m_rearrangeTimer; + bool m_inRearrange = false; int m_setActiveWindowRecursion = 0; int m_blockStackingUpdates = 0; // When > 0, stacking updates are temporarily disabled diff --git a/src/x11window.cpp b/src/x11window.cpp index 74e0485842..260fb41454 100644 --- a/src/x11window.cpp +++ b/src/x11window.cpp @@ -4078,10 +4078,9 @@ void X11Window::configureRequest(int value_mask, qreal rx, qreal ry, qreal rw, q // this is part of the kicker-xinerama-hack... it should be // safe to remove when kicker gets proper ExtendedStrut support; - // see Workspace::updateClientArea() and - // X11Window::adjustedClientArea() + // see Workspace::rearrange() and X11Window::adjustedClientArea() if (hasStrut()) { - workspace()->updateClientArea(); + workspace()->rearrange(); } }