Bug 486464

Summary: X11 applications that use _NET_WM_SYNC_REQUEST do not resize correctly on Wayland
Product: [Plasma] kwin Reporter: Eduardo Sánchez Muñoz <eduardosanchezmunoz>
Component: xwaylandAssignee: KWin default assignee <kwin-bugs-null>
Status: RESOLVED FIXED    
Severity: normal CC: nate, vlad.zahorodnii, xaver.hugl, yanexbug
Priority: NOR    
Version: 6.0.4   
Target Milestone: ---   
Platform: Fedora RPMs   
OS: Linux   
Latest Commit: Version Fixed In: 6.3.0
Sentry Crash Report:

Description Eduardo Sánchez Muñoz 2024-05-02 16:07:26 UTC
SUMMARY

On Wayland, X11 applications that use _NET_WM_SYNC_REQUEST exhibit incorrect behavior during resizing:

* Window decoration painting is not synchronized with window content painting.
* At some point, the it will not be possible to resize or move the window for a few seconds.

Only happens with kwin_wayland, kwin_x11 works correctly.

STEPS TO REPRODUCE
1. Log in to a Wayland KDE session-
1. Open a X11 application that use _NET_WM_SYNC_REQUEST (or force it to use X11).
    For example: QT_QPA_PLATFORM=xcb dolphin
2. Resize the window multiple times.

OBSERVED RESULT

The dimensions of the decorations are not synchronized to the dimensions of the window contents. At some point, the window will stop resizing for a few seconds. During that period, it will not be possible to move the window.

EXPECTED RESULT

The window should resize as expected and the decorations are not synchronized with the contents.

SOFTWARE/OS VERSIONS
Linux/KDE Plasma: Fedora Linux 40
KDE Plasma Version: 6.0.4
KDE Frameworks Version: 6.1.0
Qt Version: 6.7.0

ADDITIONAL INFORMATION

Reproducible with Qt and GTK applications (when forced to use the X11 backend)
Comment 1 Vlad Zahorodnii 2024-10-01 09:10:24 UTC
*** Bug 490574 has been marked as a duplicate of this bug. ***
Comment 2 Vlad Zahorodnii 2024-10-28 15:29:08 UTC
Git commit 63932229d7fbc8345f1ea9246bd0587162839b77 by Vlad Zahorodnii.
Committed on 28/10/2024 at 15:15.
Pushed by vladz into branch 'master'.

Make Xwayland resizing less glitchy

XSYNC requests and wl_surface commits are unsynchronized. This results
in the window bouncing when it's being resized.

Let's consider a concrete example. Assume that there is a window with 0,0
100x100 geometry and it is being resized by dragging the left edge. If
the left edge is dragged by 10px, the following will occur:

- wl_surface commits will be blocked (it is needed to ensure the
  consistent order of XSync acknowledgements and wl_surface commits)
- an XSync request will be sent
- a ConfigureNotify event will be sent
- a client processes the ConfigureNotify by repainting the window and
  acknowledges the XSync request
- kwin notices that the XSync request has been acked and updates the
  window position to 10,0 and unblocks surface commits

The problem is that it can take a while for Xwayland to attach a new
buffer to the surface with a size of 90x100. If kwin composes a frame in
meanwhile, the effective geometry of the window will be 10,0 100x100,
i.e. the right window edge will stick by 10px. Some time later, Xwayland
would attach a buffer with the right size (90x100), and the right window
edge will be put back in the right place.

In order to address the bouncing, this change reworks how the
synchronization is performed:

- when a window is asked to resize, kwin will freeze wl_surface commits,
  send a sync request, and configure the window
- after the client repaints the window, it acks the sync request
- when kwin sees that the sync request has been acked, it will unfreeze
  the wl_surface commits. And here's the most important part: it will NOT
  update the window position until Xwayland commits something
- when Xwayland commits the wl_surface, kwin will update the window geometry

It's important to wait until Xwayland commits the wl_surface because, as
it was said previously, it can take a while until Xwayland commits the
wl_surface and kwin could compose a frame with the new position but old
surface size in meanwhile.

M  +30   -10   src/x11window.cpp
M  +2    -0    src/x11window.h

https://invent.kde.org/plasma/kwin/-/commit/63932229d7fbc8345f1ea9246bd0587162839b77