Port Workspace::cascadeOffset() away from Window::frameGeometry()

Workspace::cascadeOffset() can be called by placement code before the
frame geometry has a valid position. That is wrong. In order to avoid
that, use the placement area that we are given.
This commit is contained in:
Vlad Zahorodnii 2024-08-22 20:55:08 +03:00
parent 428c4c4fd1
commit 4258797402
3 changed files with 8 additions and 9 deletions

View file

@ -310,14 +310,14 @@ void TestPlacement::testPlaceZeroCornered()
std::unique_ptr<Test::XdgToplevel> shellSurface2(Test::createXdgToplevelSurface(surface2.get())); std::unique_ptr<Test::XdgToplevel> shellSurface2(Test::createXdgToplevelSurface(surface2.get()));
Window *window2 = Test::renderAndWaitForShown(surface2.get(), QSize(100, 50), Qt::blue); Window *window2 = Test::renderAndWaitForShown(surface2.get(), QSize(100, 50), Qt::blue);
QVERIFY(window2); QVERIFY(window2);
QCOMPARE(window2->pos(), window1->pos() + workspace()->cascadeOffset(window2)); QCOMPARE(window2->pos(), window1->pos() + workspace()->cascadeOffset(workspace()->clientArea(PlacementArea, window2)));
QCOMPARE(window2->size(), QSize(100, 50)); QCOMPARE(window2->size(), QSize(100, 50));
std::unique_ptr<KWayland::Client::Surface> surface3(Test::createSurface()); std::unique_ptr<KWayland::Client::Surface> surface3(Test::createSurface());
std::unique_ptr<Test::XdgToplevel> shellSurface3(Test::createXdgToplevelSurface(surface3.get())); std::unique_ptr<Test::XdgToplevel> shellSurface3(Test::createXdgToplevelSurface(surface3.get()));
Window *window3 = Test::renderAndWaitForShown(surface3.get(), QSize(100, 50), Qt::green); Window *window3 = Test::renderAndWaitForShown(surface3.get(), QSize(100, 50), Qt::green);
QVERIFY(window3); QVERIFY(window3);
QCOMPARE(window3->pos(), window2->pos() + workspace()->cascadeOffset(window3)); QCOMPARE(window3->pos(), window2->pos() + workspace()->cascadeOffset(workspace()->clientArea(PlacementArea, window3)));
QCOMPARE(window3->size(), QSize(100, 50)); QCOMPARE(window3->size(), QSize(100, 50));
shellSurface3.reset(); shellSurface3.reset();
@ -421,7 +421,7 @@ void TestPlacement::testCascadeIfCovering()
std::unique_ptr<Test::XdgToplevel> shellSurface2(Test::createXdgToplevelSurface(surface2.get())); std::unique_ptr<Test::XdgToplevel> shellSurface2(Test::createXdgToplevelSurface(surface2.get()));
Window *window2 = Test::renderAndWaitForShown(surface2.get(), QSize(100, 50), Qt::blue); Window *window2 = Test::renderAndWaitForShown(surface2.get(), QSize(100, 50), Qt::blue);
QVERIFY(window2); QVERIFY(window2);
QCOMPARE(window2->pos(), window1->pos() + workspace()->cascadeOffset(window2)); QCOMPARE(window2->pos(), window1->pos() + workspace()->cascadeOffset(workspace()->clientArea(PlacementArea, window2)));
QCOMPARE(window2->size(), QSize(100, 50)); QCOMPARE(window2->size(), QSize(100, 50));
// window should be cascaded to avoid overlapping window 1 and 2 // window should be cascaded to avoid overlapping window 1 and 2
@ -429,7 +429,7 @@ void TestPlacement::testCascadeIfCovering()
std::unique_ptr<Test::XdgToplevel> shellSurface3(Test::createXdgToplevelSurface(surface3.get())); std::unique_ptr<Test::XdgToplevel> shellSurface3(Test::createXdgToplevelSurface(surface3.get()));
Window *window3 = Test::renderAndWaitForShown(surface3.get(), QSize(100, 50), Qt::green); Window *window3 = Test::renderAndWaitForShown(surface3.get(), QSize(100, 50), Qt::green);
QVERIFY(window3); QVERIFY(window3);
QCOMPARE(window3->pos(), window2->pos() + workspace()->cascadeOffset(window3)); QCOMPARE(window3->pos(), window2->pos() + workspace()->cascadeOffset(workspace()->clientArea(PlacementArea, window3)));
QCOMPARE(window3->size(), QSize(100, 50)); QCOMPARE(window3->size(), QSize(100, 50));
shellSurface3.reset(); shellSurface3.reset();

View file

@ -361,9 +361,8 @@ void Placement::reinitCascading(VirtualDesktop *desktop)
}; };
} }
QPoint Workspace::cascadeOffset(const Window *c) const QPoint Workspace::cascadeOffset(const QRectF &area) const
{ {
QRect area = clientArea(PlacementArea, c, c->frameGeometry().center()).toRect();
return QPoint(area.width() / 48, area.height() / 48); return QPoint(area.width() / 48, area.height() / 48);
} }
@ -379,7 +378,7 @@ void Placement::placeCascaded(Window *c, const QRect &area, PlacementPolicy next
} }
// CT how do I get from the 'Client' class the size that NW squarish "handle" // CT how do I get from the 'Client' class the size that NW squarish "handle"
const QPoint delta = workspace()->cascadeOffset(c); const QPoint delta = workspace()->cascadeOffset(area);
VirtualDesktop *dn = c->isOnCurrentDesktop() ? VirtualDesktopManager::self()->currentDesktop() : c->desktops().constLast(); VirtualDesktop *dn = c->isOnCurrentDesktop() ? VirtualDesktopManager::self()->currentDesktop() : c->desktops().constLast();
@ -581,7 +580,7 @@ void Placement::placeMaximizing(Window *c, const QRect &area, PlacementPolicy ne
*/ */
void Placement::cascadeIfCovering(Window *window, const QRectF &area) void Placement::cascadeIfCovering(Window *window, const QRectF &area)
{ {
const QPoint offset = workspace()->cascadeOffset(window); const QPoint offset = workspace()->cascadeOffset(area);
VirtualDesktop *const desktop = window->isOnCurrentDesktop() ? VirtualDesktopManager::self()->currentDesktop() : window->desktops().front(); VirtualDesktop *const desktop = window->isOnCurrentDesktop() ? VirtualDesktopManager::self()->currentDesktop() : window->desktops().front();

View file

@ -265,7 +265,7 @@ public:
TileManager *tileManager(Output *output); TileManager *tileManager(Output *output);
public: public:
QPoint cascadeOffset(const Window *c) const; QPoint cascadeOffset(const QRectF &area) const;
private: private:
QTimer *m_quickTileCombineTimer; QTimer *m_quickTileCombineTimer;