From bccbb8f3a5f85de19f671dc14895593d4a810ada Mon Sep 17 00:00:00 2001 From: Vlad Zahorodnii Date: Thu, 12 Sep 2019 17:52:47 +0300 Subject: [PATCH] Pass area by const reference to placeFoo methods --- abstract_client.cpp | 2 +- manage.cpp | 2 ++ placement.cpp | 27 ++++++++++++--------------- placement.h | 18 +++++++++--------- shell_client.cpp | 4 ++-- shell_client.h | 3 +-- workspace.cpp | 4 ++-- 7 files changed, 29 insertions(+), 31 deletions(-) diff --git a/abstract_client.cpp b/abstract_client.cpp index 2370d4f5af..64e6cec193 100644 --- a/abstract_client.cpp +++ b/abstract_client.cpp @@ -88,7 +88,7 @@ AbstractClient::AbstractClient() Q_UNUSED(c) if (isOnScreenDisplay() && !geometry().isEmpty() && old.size() != geometry().size() && !isInitialPositionSet()) { GeometryUpdatesBlocker blocker(this); - QRect area = workspace()->clientArea(PlacementArea, Screens::self()->current(), desktop()); + const QRect area = workspace()->clientArea(PlacementArea, Screens::self()->current(), desktop()); Placement::self()->place(this, area); setGeometryRestore(geometry()); } diff --git a/manage.cpp b/manage.cpp index 78e12328bd..b801fe93bb 100644 --- a/manage.cpp +++ b/manage.cpp @@ -360,6 +360,8 @@ bool Client::manage(xcb_window_t w, bool isMapped) if (!placementDone) { // Placement needs to be after setting size Placement::self()->place(this, area); + // The client may have been moved to another screen, update placement area. + area = workspace()->clientArea(PlacementArea, this); dontKeepInArea = true; placementDone = true; } diff --git a/placement.cpp b/placement.cpp index aba2372c14..9fcf2d88b5 100644 --- a/placement.cpp +++ b/placement.cpp @@ -54,7 +54,7 @@ Placement::~Placement() /** * Places the client \a c according to the workspace's layout policy */ -void Placement::place(AbstractClient* c, QRect& area) +void Placement::place(AbstractClient *c, const QRect &area) { Policy policy = c->rules()->checkPlacement(Default); if (policy != Default) { @@ -78,7 +78,7 @@ void Placement::place(AbstractClient* c, QRect& area) place(c, area, options->placement()); } -void Placement::place(AbstractClient* c, QRect& area, Policy policy, Policy nextPlacement) +void Placement::place(AbstractClient *c, const QRect &area, Policy policy, Policy nextPlacement) { if (policy == Unknown) policy = Default; @@ -374,7 +374,7 @@ QPoint Workspace::cascadeOffset(const AbstractClient *c) const /** * Place windows in a cascading order, remembering positions for each desktop */ -void Placement::placeCascaded(AbstractClient* c, QRect& area, Policy nextPlacement) +void Placement::placeCascaded(AbstractClient *c, const QRect &area, Policy nextPlacement) { if (!c->size().isValid()) { return; @@ -481,7 +481,7 @@ void Placement::placeZeroCornered(AbstractClient* c, const QRect& area, Policy / c->move(checkArea(c, area).topLeft()); } -void Placement::placeUtility(AbstractClient* c, QRect& area, Policy /*next*/) +void Placement::placeUtility(AbstractClient *c, const QRect &area, Policy /*next*/) { // TODO kwin should try to place utility windows next to their mainwindow, // preferably at the right edge, and going down if there are more of them @@ -491,7 +491,7 @@ void Placement::placeUtility(AbstractClient* c, QRect& area, Policy /*next*/) place(c, area, Default); } -void Placement::placeOnScreenDisplay(AbstractClient* c, QRect& area) +void Placement::placeOnScreenDisplay(AbstractClient *c, const QRect &area) { // place at lower 1/3 of the screen const int x = area.left() + (area.width() - c->width()) / 2; @@ -519,27 +519,25 @@ void Placement::placeTransient(AbstractClient *c) } } -void Placement::placeDialog(AbstractClient* c, QRect& area, Policy nextPlacement) +void Placement::placeDialog(AbstractClient *c, const QRect &area, Policy nextPlacement) { placeOnMainWindow(c, area, nextPlacement); } -void Placement::placeUnderMouse(AbstractClient* c, QRect& area, Policy /*next*/) +void Placement::placeUnderMouse(AbstractClient *c, const QRect &area, Policy /*next*/) { - area = checkArea(c, area); QRect geom = c->geometry(); geom.moveCenter(Cursor::pos()); c->move(geom.topLeft()); c->keepInArea(area); // make sure it's kept inside workarea } -void Placement::placeOnMainWindow(AbstractClient* c, QRect& area, Policy nextPlacement) +void Placement::placeOnMainWindow(AbstractClient *c, const QRect &area, Policy nextPlacement) { if (nextPlacement == Unknown) nextPlacement = Centered; if (nextPlacement == Maximizing) // maximize if needed placeMaximizing(c, area, NoPlacement); - area = checkArea(c, area); auto mainwindows = c->mainClients(); AbstractClient* place_on = nullptr; AbstractClient* place_on2 = nullptr; @@ -582,11 +580,11 @@ void Placement::placeOnMainWindow(AbstractClient* c, QRect& area, Policy nextPla geom.moveCenter(place_on->geometry().center()); c->move(geom.topLeft()); // get area again, because the mainwindow may be on different xinerama screen - area = checkArea(c, QRect()); - c->keepInArea(area); // make sure it's kept inside workarea + const QRect placementArea = checkArea(c, QRect()); + c->keepInArea(placementArea); // make sure it's kept inside workarea } -void Placement::placeMaximizing(AbstractClient* c, QRect& area, Policy nextPlacement) +void Placement::placeMaximizing(AbstractClient *c, const QRect &area, Policy nextPlacement) { if (nextPlacement == Unknown) nextPlacement = Smart; @@ -609,8 +607,7 @@ void Placement::cascadeDesktop() Workspace *ws = Workspace::self(); const int desktop = VirtualDesktopManager::self()->current(); reinitCascading(desktop); - // TODO: make area const once placeFoo methods are fixed to take a const QRect& - QRect area = ws->clientArea(PlacementArea, QPoint(0, 0), desktop); + const QRect area = ws->clientArea(PlacementArea, QPoint(0, 0), desktop); foreach (Toplevel *toplevel, ws->stackingOrder()) { auto client = qobject_cast(toplevel); if (!client || diff --git a/placement.h b/placement.h index 91b1cf15c6..cfd0d3dc4c 100644 --- a/placement.h +++ b/placement.h @@ -62,17 +62,17 @@ public: Maximizing }; - void place(AbstractClient* c, QRect& area); + void place(AbstractClient *c, const QRect &area); void placeAtRandom(AbstractClient* c, const QRect& area, Policy next = Unknown); - void placeCascaded(AbstractClient* c, QRect& area, Policy next = Unknown); + void placeCascaded(AbstractClient* c, const QRect& area, Policy next = Unknown); void placeSmart(AbstractClient* c, const QRect& area, Policy next = Unknown); - void placeMaximizing(AbstractClient* c, QRect& area, Policy next = Unknown); + void placeMaximizing(AbstractClient* c, const QRect& area, Policy next = Unknown); void placeCentered(AbstractClient* c, const QRect& area, Policy next = Unknown); void placeZeroCornered(AbstractClient* c, const QRect& area, Policy next = Unknown); - void placeDialog(AbstractClient* c, QRect& area, Policy next = Unknown); - void placeUtility(AbstractClient* c, QRect& area, Policy next = Unknown); - void placeOnScreenDisplay(AbstractClient* c, QRect& area); + void placeDialog(AbstractClient* c, const QRect& area, Policy next = Unknown); + void placeUtility(AbstractClient* c, const QRect& area, Policy next = Unknown); + void placeOnScreenDisplay(AbstractClient* c, const QRect& area); void reinitCascading(int desktop); @@ -89,9 +89,9 @@ public: static const char* policyToString(Policy policy); private: - void place(AbstractClient* c, QRect& area, Policy policy, Policy nextPlacement = Unknown); - void placeUnderMouse(AbstractClient* c, QRect& area, Policy next = Unknown); - void placeOnMainWindow(AbstractClient* c, QRect& area, Policy next = Unknown); + void place(AbstractClient *c, const QRect &area, Policy policy, Policy nextPlacement = Unknown); + void placeUnderMouse(AbstractClient *c, const QRect &area, Policy next = Unknown); + void placeOnMainWindow(AbstractClient *c, const QRect &area, Policy next = Unknown); void placeTransient(AbstractClient *c); QRect checkArea(const AbstractClient*c, const QRect& area); diff --git a/shell_client.cpp b/shell_client.cpp index eab97ba74e..f08050363e 100644 --- a/shell_client.cpp +++ b/shell_client.cpp @@ -399,7 +399,7 @@ void ShellClient::finishInit() { } if (needsPlacement) { - QRect area = workspace()->clientArea(PlacementArea, Screens::self()->current(), desktop()); + const QRect area = workspace()->clientArea(PlacementArea, Screens::self()->current(), desktop()); placeIn(area); } @@ -1884,7 +1884,7 @@ void ShellClient::finishCompositing(ReleaseReason releaseReason) Toplevel::finishCompositing(releaseReason); } -void ShellClient::placeIn(QRect &area) +void ShellClient::placeIn(const QRect &area) { Placement::self()->place(this, area); setGeometryRestore(geometry()); diff --git a/shell_client.h b/shell_client.h index 920ef2b8b5..4e2aa31a64 100644 --- a/shell_client.h +++ b/shell_client.h @@ -148,8 +148,7 @@ public: void killWindow() override; - // TODO: const-ref - void placeIn(QRect &area); + void placeIn(const QRect &area); bool hasPopupGrab() const override; void popupDone() override; diff --git a/workspace.cpp b/workspace.cpp index ded62dd5a0..6d4309b447 100644 --- a/workspace.cpp +++ b/workspace.cpp @@ -294,7 +294,7 @@ void Workspace::init() c->updateDecoration(false); updateClientLayer(c); if (!c->isInternal()) { - QRect area = clientArea(PlacementArea, Screens::self()->current(), c->desktop()); + const QRect area = clientArea(PlacementArea, Screens::self()->current(), c->desktop()); bool placementDone = false; if (c->isInitialPositionSet()) { placementDone = true; @@ -329,7 +329,7 @@ void Workspace::init() updateClientLayer(c); // TODO: when else should we send the client through placement? if (c->hasTransientPlacementHint()) { - QRect area = clientArea(PlacementArea, Screens::self()->current(), c->desktop()); + const QRect area = clientArea(PlacementArea, Screens::self()->current(), c->desktop()); c->placeIn(area); } markXStackingOrderAsDirty();