Bug 484963 - Incorrect client geometry reported via KWin scripting API for gtk4-demo running on XWayland
Summary: Incorrect client geometry reported via KWin scripting API for gtk4-demo runni...
Status: RESOLVED NOT A BUG
Alias: None
Product: kwin
Classification: Plasma
Component: scripting (show other bugs)
Version: 6.0.3
Platform: Fedora RPMs Linux
: NOR normal
Target Milestone: ---
Assignee: KWin default assignee
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2024-04-03 09:10 UTC by Michael Weghorn
Modified: 2024-04-03 17:04 UTC (History)
1 user (show)

See Also:
Latest Commit:
Version Fixed In:
Sentry Crash Report:


Attachments
Sample KWin script to print client geometry of all windows (241 bytes, application/x-javascript)
2024-04-03 09:10 UTC, Michael Weghorn
Details
Screenshot showing current result on Fedora Rawhide (541.27 KB, image/png)
2024-04-03 09:10 UTC, Michael Weghorn
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Michael Weghorn 2024-04-03 09:10:08 UTC
Created attachment 168082 [details]
Sample KWin script to print client geometry of all windows

SUMMARY

KWin commit https://invent.kde.org/plasma/kwin/-/commit/51642177e370f4cf902d15494f700c27a9961b9c added a Window.clientGeometry property that can be used to query the client geometry via the KWin scripting API, which is very useful.
The client geometry is incorrect however e.g. when querying it for the gtk4-demo app when running it on XWayland in a Plasma Wayland session.


STEPS TO REPRODUCE
1. run KDE Plasma Wayland
2. run gtk4-demo as a native Wayland application:
    gtk4-demo
3. run gtk4-demo on XWayland:
   GDK_BACKEND=x11 gtk4-demo
4. move both of the gtk4-demo windows to the top edge of the screen (y coordinate 0).
5. load the attached KWin script that prints window information:
    $ dbus-send --print-reply --dest=org.kde.KWin /Scripting org.kde.kwin.Scripting.loadScript string:$(readlink -f kwin6-print-window-infos.js)
    method return time=1712133458.716388 sender=:1.20 -> destination=:1.102 serial=2231 reply_serial=2
    int32 4
6. run the script loaded in the previous step (adjust script path according to the number in the output from step 5, here it's script number 4).
    dbus-send --print-reply --dest=org.kde.KWin /Scripting/Script4 org.kde.kwin.Script.run
7. Check the script output in systemd journal:
    sudo journalctl -e

Sample output: 

    Apr 03 10:37:43 fedora kwin_wayland[7262]: js: caption: , bufferGeometry: QRectF(0, 0, 1920, 1080), clientGeometry: QRectF(0, 0, 1920, 1080)
    Apr 03 10:37:43 fedora kwin_wayland[7262]: js: caption: , bufferGeometry: QRectF(1920, 0, 1920, 1032), clientGeometry: QRectF(1920, 0, 1920, 1032)
    Apr 03 10:37:43 fedora kwin_wayland[7262]: js: caption: Wayland to X Recording bridge — Xwayland Video Bridge, bufferGeometry: QRectF(-99, 0, 100, 100), clientGeometry: QRectF(-99, 0, 100, 100)
    Apr 03 10:37:43 fedora kwin_wayland[7262]: js: caption: , bufferGeometry: QRectF(0, 1036, 1920, 60), clientGeometry: QRectF(0, 1036, 1920, 60)
    Apr 03 10:37:43 fedora kwin_wayland[7262]: js: caption: ~ : bash — Konsole, bufferGeometry: QRectF(0, 28, 958, 1008), clientGeometry: QRectF(0, 28, 958, 1008)
    Apr 03 10:37:43 fedora kwin_wayland[7262]: js: caption: GTK Demo, bufferGeometry: QRectF(1029, -12, 828, 629), clientGeometry: QRectF(1043, 0, 800, 600)
    Apr 03 10:37:43 fedora kwin_wayland[7262]: js: caption: GTK Demo <2>‎, bufferGeometry: QRectF(1028, -12, 828, 629), clientGeometry: QRectF(1028, -12, 828, 629)
    Apr 03 10:37:43 fedora kwin_wayland[7262]: js: caption: kwin6-print-window-infos.js — Kate, bufferGeometry: QRectF(0, 28, 1920, 1008), clientGeometry: QRectF(0, 28, 1920, 1008)

OBSERVED RESULT

The client geometry for gtk4-demo running as a native Wayland app is correct: clientGeometry: QRectF(1043, 0, 800, 600)
However, the client geometry for gtk4-demo running on XWayland is incorrect: clientGeometry: QRectF(1028, -12, 828, 629)

EXPECTED RESULT

The client geometry for gtk4-demo running on XWayland should also have a y position of 0.

SOFTWARE/OS VERSIONS

Fedora Rawhide, up-to-date as of 2024-04-03

Operating System: Fedora Linux 41
KDE Plasma Version: 6.0.3
KDE Frameworks Version: 6.0.0
Qt Version: 6.6.2
Kernel Version: 6.9.0-0.rc1.20240326git928a87efa423.17.fc41.x86_64 (64-bit)
Graphics Platform: Wayland
Processors: 4 × Intel® Core™ i7-8850H CPU @ 2.60GHz
Memory: 15.6 GiB of RAM
Graphics Processor: llvmpipe
Manufacturer: QEMU
Product Name: Standard PC (Q35 + ICH9, 2009)
System Version: pc-q35-8.2

$ dnf info kwin-wayland
Last metadata expiration check: 0:00:06 ago on Wed 03 Apr 2024 10:48:23 AM CEST.
Installed Packages
Name         : kwin-wayland
Version      : 6.0.3.1
Release      : 2.fc41
Architecture : x86_64
Size         : 1.7 M
Source       : kwin-6.0.3.1-2.fc41.src.rpm
Repository   : @System
From repo    : rawhide
Summary      : KDE Window Manager with Wayland support
URL          : https://userbase.kde.org/KWin
License      : BSD-2-Clause AND BSD-3-Clause AND CC0-1.0 AND GPL-2.0-only AND GPL-2.0-or-later AND GPL-3.0-only AND GPL-3.0-or-later AND LGPL-2.0-only AND LGPL-2.0-or-later AND LGPL-2.1-only AND LGPL-2.1-or-later AND LGPL-3.0-only AND
             : (GPL-2.0-only OR GPL-3.0-only) AND (LGPL-2.1-only OR LGPL-3.0-only) AND MIT
Description  : KDE Window Manager with Wayland support.

$ dnf info gtk4
Waiting for process with pid 21562 to finish.
Last metadata expiration check: 0:00:02 ago on Wed 03 Apr 2024 10:49:52 AM CEST.
Installed Packages
Name         : gtk4
Version      : 4.14.1
Release      : 1.fc41
Architecture : x86_64
Size         : 26 M
Source       : gtk4-4.14.1-1.fc41.src.rpm
Repository   : @System
From repo    : rawhide
Summary      : GTK graphical user interface library
URL          : https://www.gtk.org
License      : LGPL-2.0-or-later
Description  : GTK is a multi-platform toolkit for creating graphical user
             : interfaces. Offering a complete set of widgets, GTK is suitable for
             : projects ranging from small one-off tools to complete application
             : suites.
             : 
             : This package contains version 4 of GTK.

ADDITIONAL INFORMATION

This is e.g. relevant for accessibility tools. (E.g. a magnifier that automatically follows the position of the text caret would might then result in the wrong part of the screen being in view.)
I ran into this while implementing support in Accerciser to retrieve window coordinates from KWin on Wayland.
Comment 1 Michael Weghorn 2024-04-03 09:10:31 UTC
Created attachment 168083 [details]
Screenshot showing current result on Fedora Rawhide
Comment 2 Michael Weghorn 2024-04-03 17:04:01 UTC
After discussion on a similar ticket for GNOME Shell (see https://gitlab.gnome.org/GNOME/gnome-shell/-/issues/7559 ), I think the returned values are fine and my expectations were wrong.
-> Closing as INVALID

> This is e.g. relevant for accessibility tools. (E.g. a magnifier that
> automatically follows the position of the text caret would might then result
> in the wrong part of the screen being in view.)
> I ran into this while implementing support in Accerciser to retrieve window
> coordinates from KWin on Wayland.

This works now with an updated MR taking into account the discussion from above-mentioned gnome-shell ticket:
https://gitlab.gnome.org/GNOME/accerciser/-/merge_requests/57