diff --git a/abstract_client.cpp b/abstract_client.cpp --- a/abstract_client.cpp +++ b/abstract_client.cpp @@ -89,7 +89,7 @@ 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 --- a/manage.cpp +++ b/manage.cpp @@ -405,6 +405,8 @@ 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.h b/placement.h --- a/placement.h +++ b/placement.h @@ -62,17 +62,17 @@ 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 @@ 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/placement.cpp b/placement.cpp --- a/placement.cpp +++ b/placement.cpp @@ -54,7 +54,7 @@ /** * 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 @@ 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; @@ -376,7 +376,7 @@ /** * 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; @@ -483,7 +483,7 @@ 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 @@ -493,7 +493,7 @@ 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; @@ -521,27 +521,25 @@ } } -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; @@ -584,11 +582,11 @@ 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; @@ -611,8 +609,7 @@ 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/shell_client.h b/shell_client.h --- a/shell_client.h +++ b/shell_client.h @@ -148,8 +148,7 @@ 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/shell_client.cpp b/shell_client.cpp --- a/shell_client.cpp +++ b/shell_client.cpp @@ -399,7 +399,7 @@ } if (needsPlacement) { - QRect area = workspace()->clientArea(PlacementArea, Screens::self()->current(), desktop()); + const QRect area = workspace()->clientArea(PlacementArea, Screens::self()->current(), desktop()); placeIn(area); } @@ -1885,7 +1885,7 @@ Toplevel::finishCompositing(releaseReason); } -void ShellClient::placeIn(QRect &area) +void ShellClient::placeIn(const QRect &area) { Placement::self()->place(this, area); setGeometryRestore(geometry()); diff --git a/workspace.cpp b/workspace.cpp --- a/workspace.cpp +++ b/workspace.cpp @@ -294,7 +294,7 @@ 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 @@ 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();