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
This commit is contained in:
Vlad Zahorodnii 2024-03-06 12:09:27 +02:00
parent a489bfa12c
commit b674b458df
8 changed files with 52 additions and 47 deletions

View file

@ -122,7 +122,7 @@ void Activities::toggleWindowOnActivity(Window *window, const QString &activity,
} }
toggleWindowOnActivity(window, activity, dont_activate); toggleWindowOnActivity(window, activity, dont_activate);
} }
ws->updateClientArea(); ws->rearrange();
} }
bool Activities::start(const QString &id) bool Activities::start(const QString &id)

View file

@ -396,7 +396,7 @@ bool X11Window::windowEvent(xcb_generic_event_t *e)
} }
if ((dirtyProperties & NET::WMStrut) != 0 if ((dirtyProperties & NET::WMStrut) != 0
|| (dirtyProperties2 & NET::WM2ExtendedStrut) != 0) { || (dirtyProperties2 & NET::WM2ExtendedStrut) != 0) {
workspace()->updateClientArea(); workspace()->rearrange();
} }
if ((dirtyProperties & NET::WMIcon) != 0) { if ((dirtyProperties & NET::WMIcon) != 0) {
getIcons(); getIcons();

View file

@ -26,7 +26,7 @@ LayerShellV1Integration::LayerShellV1Integration(QObject *parent)
connect(shell, &LayerShellV1Interface::surfaceCreated, connect(shell, &LayerShellV1Interface::surfaceCreated,
this, &LayerShellV1Integration::createWindow); this, &LayerShellV1Integration::createWindow);
connect(workspace(), &Workspace::aboutToUpdateClientArea, this, &LayerShellV1Integration::rearrange); connect(workspace(), &Workspace::aboutToRearrange, this, &LayerShellV1Integration::rearrange);
} }
void LayerShellV1Integration::createWindow(LayerSurfaceV1Interface *shellSurface) void LayerShellV1Integration::createWindow(LayerSurfaceV1Interface *shellSurface)

View file

@ -88,7 +88,7 @@ Output *LayerShellV1Window::desiredOutput() const
void LayerShellV1Window::scheduleRearrange() void LayerShellV1Window::scheduleRearrange()
{ {
workspace()->scheduleUpdateClientArea(); workspace()->scheduleRearrange();
} }
WindowType LayerShellV1Window::windowType() const WindowType LayerShellV1Window::windowType() const

View file

@ -3736,7 +3736,7 @@ void Window::checkWorkspacePosition(QRectF oldGeometry, const VirtualDesktop *ol
// edge will move when a new strut is placed on the edge. // edge will move when a new strut is placed on the edge.
QRect oldScreenArea; QRect oldScreenArea;
QRect screenArea; QRect screenArea;
if (workspace()->inUpdateClientArea()) { if (workspace()->inRearrange()) {
// check if the window is on an about to be destroyed output // check if the window is on an about to be destroyed output
Output *newOutput = moveResizeOutput(); Output *newOutput = moveResizeOutput();
if (!workspace()->outputs().contains(newOutput)) { 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). // the bottom struts bounded by the window's left and right sides).
// These 4 compute old bounds ... // 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 &Workspace::restrictedMoveArea; //... when e.g. active desktop or screen changes
for (const QRect &r : (workspace()->*moveAreaFunc)(oldDesktop, StrutAreaTop)) { for (const QRect &r : (workspace()->*moveAreaFunc)(oldDesktop, StrutAreaTop)) {

View file

@ -205,11 +205,11 @@ void Workspace::init()
vds->setCurrent(m_initialDesktop); vds->setCurrent(m_initialDesktop);
reconfigureTimer.setSingleShot(true); reconfigureTimer.setSingleShot(true);
m_updateClientAreaTimer.setSingleShot(true); m_rearrangeTimer.setSingleShot(true);
updateToolWindowsTimer.setSingleShot(true); updateToolWindowsTimer.setSingleShot(true);
connect(&reconfigureTimer, &QTimer::timeout, this, &Workspace::slotReconfigure); 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); connect(&updateToolWindowsTimer, &QTimer::timeout, this, &Workspace::slotUpdateToolWindows);
// TODO: do we really need to reconfigure everything when fonts change? // 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 // Propagate windows, will really happen at the end of the updates blocker block
updateStackingOrder(true); updateStackingOrder(true);
updateClientArea(); rearrange();
// NETWM spec says we have to set it to (0,0) if we don't support it // NETWM spec says we have to set it to (0,0) if we don't support it
NETPoint *viewports = new NETPoint[VirtualDesktopManager::self()->count()]; NETPoint *viewports = new NETPoint[VirtualDesktopManager::self()->count()];
@ -722,7 +722,7 @@ void Workspace::addX11Window(X11Window *window)
m_windows.append(window); m_windows.append(window);
addToStack(window); addToStack(window);
if (window->hasStrut()) { 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(); window->updateLayer();
if (window->isDesktop()) { if (window->isDesktop()) {
@ -818,7 +818,7 @@ void Workspace::addWaylandWindow(Window *window)
updateStackingOrder(true); updateStackingOrder(true);
if (window->hasStrut()) { if (window->hasStrut()) {
updateClientArea(); rearrange();
} }
if (window->wantsInput() && !window->isMinimized()) { if (window->wantsInput() && !window->isMinimized()) {
// Never activate a window on its own in "Extreme" mode. // Never activate a window on its own in "Extreme" mode.
@ -861,7 +861,7 @@ void Workspace::removeWindow(Window *window)
setupWindowShortcutDone(false); setupWindowShortcutDone(false);
} }
if (window->hasStrut()) { if (window->hasStrut()) {
updateClientArea(); rearrange();
} }
Q_EMIT windowRemoved(window); Q_EMIT windowRemoved(window);
@ -1454,7 +1454,7 @@ void Workspace::slotDesktopAdded(VirtualDesktop *desktop)
{ {
m_focusChain->addDesktop(desktop); m_focusChain->addDesktop(desktop);
m_placement->reinitCascading(); m_placement->reinitCascading();
updateClientArea(); rearrange();
} }
void Workspace::slotDesktopRemoved(VirtualDesktop *desktop) void Workspace::slotDesktopRemoved(VirtualDesktop *desktop)
@ -1477,7 +1477,7 @@ void Workspace::slotDesktopRemoved(VirtualDesktop *desktop)
} }
} }
updateClientArea(); rearrange();
m_placement->reinitCascading(); m_placement->reinitCascading();
m_focusChain->removeDesktop(desktop); m_focusChain->removeDesktop(desktop);
} }
@ -1534,7 +1534,7 @@ void Workspace::sendWindowToDesktops(Window *window, const QList<VirtualDesktop
for (auto it = transients_stacking_order.constBegin(); it != transients_stacking_order.constEnd(); ++it) { for (auto it = transients_stacking_order.constBegin(); it != transients_stacking_order.constEnd(); ++it) {
sendWindowToDesktops(*it, window->desktops(), dont_activate); sendWindowToDesktops(*it, window->desktops(), dont_activate);
} }
updateClientArea(); rearrange();
} }
void Workspace::sendWindowToOutput(Window *window, Output *output) void Workspace::sendWindowToOutput(Window *window, Output *output)
@ -2221,7 +2221,7 @@ void Workspace::desktopResized()
} }
#endif #endif
updateClientArea(); rearrange();
const auto stack = stackingOrder(); const auto stack = stackingOrder();
for (Window *window : stack) { 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 // TODO: emit a signal instead and remove the deep function calls into edges and effects
m_screenEdges->recreateEdges(); m_screenEdges->recreateEdges();
@ -2349,24 +2349,15 @@ QRectF Workspace::adjustClientArea(Window *window, const QRectF &area) const
return adjustedArea; return adjustedArea;
} }
void Workspace::scheduleUpdateClientArea() void Workspace::scheduleRearrange()
{ {
m_updateClientAreaTimer.start(0); m_rearrangeTimer.start(0);
} }
/** void Workspace::rearrange()
* 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()
{ {
Q_EMIT aboutToUpdateClientArea(); Q_EMIT aboutToRearrange();
m_updateClientAreaTimer.stop(); m_rearrangeTimer.stop();
const QList<VirtualDesktop *> desktops = VirtualDesktopManager::self()->desktops(); const QList<VirtualDesktop *> desktops = VirtualDesktopManager::self()->desktops();
@ -2444,7 +2435,7 @@ void Workspace::updateClientArea()
m_workAreas = workAreas; m_workAreas = workAreas;
m_screenAreas = screenAreas; m_screenAreas = screenAreas;
m_inUpdateClientArea = true; m_inRearrange = true;
m_oldRestrictedAreas = m_restrictedAreas; m_oldRestrictedAreas = m_restrictedAreas;
m_restrictedAreas = restrictedAreas; m_restrictedAreas = restrictedAreas;
@ -2465,7 +2456,7 @@ void Workspace::updateClientArea()
} }
m_oldRestrictedAreas.clear(); // reset, no longer valid or needed 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; 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 StrutRects Workspace::previousRestrictedMoveArea(const VirtualDesktop *desktop, StrutAreas areas) const

View file

@ -277,12 +277,30 @@ private:
// Unsorted // Unsorted
public: 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; StrutRects previousRestrictedMoveArea(const VirtualDesktop *desktop, StrutAreas areas = StrutAreaAll) const;
QHash<const Output *, QRect> previousScreenSizes() const; QHash<const Output *, QRect> 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 * Returns the list of windows sorted in stacking order, with topmost window
* at the last position * at the last position
@ -529,9 +547,6 @@ public Q_SLOTS:
void slotSetupWindowShortcut(); void slotSetupWindowShortcut();
void setupWindowShortcutDone(bool); void setupWindowShortcutDone(bool);
void updateClientArea();
void scheduleUpdateClientArea();
private Q_SLOTS: private Q_SLOTS:
void desktopResized(); void desktopResized();
#if KWIN_BUILD_X11 #if KWIN_BUILD_X11
@ -581,7 +596,7 @@ Q_SIGNALS:
* or lowered * or lowered
*/ */
void stackingOrderChanged(); void stackingOrderChanged();
void aboutToUpdateClientArea(); void aboutToRearrange();
private: private:
void init(); void init();
@ -708,7 +723,6 @@ private:
// Timer to collect requests for 'reconfigure' // Timer to collect requests for 'reconfigure'
QTimer reconfigureTimer; QTimer reconfigureTimer;
QTimer m_updateClientAreaTimer;
QTimer updateToolWindowsTimer; QTimer updateToolWindowsTimer;
@ -723,7 +737,8 @@ private:
QHash<const Output *, QRect> m_oldScreenGeometries; QHash<const Output *, QRect> m_oldScreenGeometries;
QHash<const VirtualDesktop *, StrutRects> m_oldRestrictedAreas; QHash<const VirtualDesktop *, StrutRects> m_oldRestrictedAreas;
bool m_inUpdateClientArea = false; QTimer m_rearrangeTimer;
bool m_inRearrange = false;
int m_setActiveWindowRecursion = 0; int m_setActiveWindowRecursion = 0;
int m_blockStackingUpdates = 0; // When > 0, stacking updates are temporarily disabled int m_blockStackingUpdates = 0; // When > 0, stacking updates are temporarily disabled

View file

@ -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 // this is part of the kicker-xinerama-hack... it should be
// safe to remove when kicker gets proper ExtendedStrut support; // safe to remove when kicker gets proper ExtendedStrut support;
// see Workspace::updateClientArea() and // see Workspace::rearrange() and X11Window::adjustedClientArea()
// X11Window::adjustedClientArea()
if (hasStrut()) { if (hasStrut()) {
workspace()->updateClientArea(); workspace()->rearrange();
} }
} }