[plasma/kwin] /: wayland: Use explicit xdg window geometry as is

Vlad Zahorodnii <[email protected]>
Newsgroups gmane.comp.kde.cvs
Message-ID <[email protected]>
Git commit 17b2f8f865e9f3c0947c932ca3a4235afa9da228 by Vlad Zahorodnii.
Committed on 10/08/2026 at 12:30.
Pushed by vladz into branch 'master'.

wayland: Use explicit xdg window geometry as is

According to the spec, the compositor needs to intersect the bounding
rect of the wl_surface with the explicit window geometry to get the
effective window geometry. The compositor has to do it only for a commit
that includes the set_window_geometry request.

kwin deviates from that because some apps that we can't really
ignore work poorly with the window geometry calculation strategy
described in the xdg-shell spec. So kwin calculates the effective window
geometry for every commit.

It was also suggested that the compositor can use the explicit window
geometry as the effective geometry. We skip the sanitization step, but
even with the misbehaving apps, that shouldn't matter in practice. This
simplifies the code, and it reduces the chances of the compositor
picking up the wrong move resize geometry with chromium-based apps more.

M  +4    -4    autotests/integration/xdgshellwindow_test.cpp
M  +5    -7    src/wayland/xdgshell.cpp
M  +1    -1    src/wayland/xdgshell_p.h

https://invent.kde.org/plasma/kwin/-/commit/17b2f8f865e9f3c0947c932ca3a4235afa9da228

diff --git a/autotests/integration/xdgshellwindow_test.cpp b/autotests/integration/xdgshellwindow_test.cpp
index 2af28961f18..8ee6b9924be 100644
--- a/autotests/integration/xdgshellwindow_test.cpp
+++ b/autotests/integration/xdgshellwindow_test.cpp
@@ -1227,17 +1227,17 @@ void TestXdgShellWindow::testXdgWindowGeometryAttachBuffer()
     QCOMPARE(window->bufferGeometry().size(), QSize(200, 100));
 
     Test::render(surface.get(), QSize(100, 50), Qt::blue);
-    QVERIFY(frameGeometryChangedSpy.wait());
-    QCOMPARE(frameGeometryChangedSpy.count(), 2);
+    QVERIFY(Test::waylandSync());
+    QCOMPARE(frameGeometryChangedSpy.count(), 1);
     QCOMPARE(window->frameGeometry().topLeft(), oldPosition);
-    QCOMPARE(window->frameGeometry().size(), QSize(90, 40));
+    QCOMPARE(window->frameGeometry().size(), QSize(180, 80));
     QCOMPARE(window->bufferGeometry().topLeft(), oldPosition - QPoint(10, 10));
     QCOMPARE(window->bufferGeometry().size(), QSize(100, 50));
 
     shellSurface->xdgSurface()->set_window_geometry(0, 0, 100, 50);
     surface->commit(KWayland::Client::Surface::CommitFlag::None);
     QVERIFY(frameGeometryChangedSpy.wait());
-    QCOMPARE(frameGeometryChangedSpy.count(), 3);
+    QCOMPARE(frameGeometryChangedSpy.count(), 2);
     QCOMPARE(window->frameGeometry().topLeft(), oldPosition);
     QCOMPARE(window->frameGeometry().size(), QSize(100, 50));
     QCOMPARE(window->bufferGeometry().topLeft(), oldPosition);
diff --git a/src/wayland/xdgshell.cpp b/src/wayland/xdgshell.cpp
index 40343d5b6f4..e1b1d2555ed 100644
--- a/src/wayland/xdgshell.cpp
+++ b/src/wayland/xdgshell.cpp
@@ -158,19 +158,17 @@ void XdgSurfaceInterfacePrivate::apply(XdgSurfaceCommit *commit)
     }
 
     if (commit->windowGeometry.has_value()) {
-        explicitWindowGeometry = commit->windowGeometry;
-    }
-
-    effectiveWindowGeometry = surface->boundingRect();
-    if (explicitWindowGeometry) {
-        effectiveWindowGeometry &= *explicitWindowGeometry;
+        explicitWindowGeometryIsSet = true;
+        effectiveWindowGeometry = *commit->windowGeometry;
+    } else if (!explicitWindowGeometryIsSet) {
+        effectiveWindowGeometry = surface->boundingRect();
     }
 }
 
 void XdgSurfaceInterfacePrivate::reset()
 {
     effectiveWindowGeometry = RectF();
-    explicitWindowGeometry = std::nullopt;
+    explicitWindowGeometryIsSet = false;
     firstBufferAttached = false;
     isConfigured = false;
     isInitialized = false;
diff --git a/src/wayland/xdgshell_p.h b/src/wayland/xdgshell_p.h
index 6f47eba8b1b..b6179c292e5 100644
--- a/src/wayland/xdgshell_p.h
+++ b/src/wayland/xdgshell_p.h
@@ -124,7 +124,7 @@ public:
     QPointer<XXPipV1Interface> pip;
     QPointer<SurfaceInterface> surface;
     RectF effectiveWindowGeometry;
-    std::optional<RectF> explicitWindowGeometry;
+    bool explicitWindowGeometryIsSet = false;
     bool firstBufferAttached = false;
     bool isConfigured = false;
     bool isInitialized = false;
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.