feat(wayland): keep xdg_toplevel's activated and suspended states on the window

A consumer could not tell a window somebody is looking at from one that
merely exists. The compositor's word on it comes with every
xdg_toplevel configure — the `activated` state, and since version 6 of
xdg_wm_base `suspended`, "not ordinarily being repainted", for example
for a content covered by another window or outputs switched off for a
screen lock — and the window dropped the states array. A messenger
built on it took a conversation left open behind a lock screen or
another application for one that was being read: its texts were marked
read and never notified.

Window: `activated` and `suspended` hold the two states, and
onToplevelState fires after a configure changed either, with both
already set. They are batched as the size is: xdg_toplevel.configure
leaves them pending and the xdg_surface.configure that ends the batch
applies them (ApplyToplevelState) last, so the handler does nothing
with the window after its listeners. The constructor takes the first
configure before a listener can be added, so a consumer reads the two
once after it. Both are reported and the library combines nothing:
which of the two a lock screen or another window in front changes is
the compositor's choice, so a consumer that asks whether the user is
looking at the window wants `activated && !suspended`, and the consumer
notes say so. The members are the Wayland backend's; the Win32 and DOM
backends keep no such state.

Device: xdg_wm_base is bound at the version the compositor offers, up
to 6, where it was bound at 1: `suspended` does not exist below 6
(`activated` is version 1's). Every request the windows make is version
1's. Besides `suspended`, the higher versions bring the window state
values it passes over (the tiled ones, 2) and two events,
xdg_toplevel's configure_bounds (4) and wm_capabilities (5), which the
toplevel's listener takes and drops, since libwayland aborts a client
at an event whose handler is null.

Tests: ToplevelState feeds the two configure callbacks of a window
whose surfaces are proxies on a wl_display over a socketpair, as
TitleWayland makes them, and reads the bind off the wire: the states
pending until the surface's configure, the last toplevel configure of a
batch applied, one event for a batch that changes both, none for a
repeat or for other states, an empty array clearing both; an offer of
7, 6, 5 and 1 bound at 6, 6, 5 and 1; a handler in the xdg_wm_base,
xdg_surface and xdg_toplevel listeners for every event of the bundled
protocol.
This commit is contained in:
Jorijn van der Graaf 2026-11-17 00:49:53 +01:00
commit c006519fa0
Signed by: jorijnvdgraaf
GPG key ID: 2937E59CDCC1BCFB
7 changed files with 310 additions and 4 deletions

View file

@ -318,7 +318,12 @@ void Device::handle_global(void *data, wl_registry *registry, std::uint32_t name
} else if (compositor == nullptr && strcmp(interface, wl_compositor_interface.name) == 0) {
compositor = reinterpret_cast<wl_compositor*>(wl_registry_bind(registry, name, &wl_compositor_interface, 3));
} else if (strcmp(interface, xdg_wm_base_interface.name) == 0) {
xdgWmBase = reinterpret_cast<xdg_wm_base*>(wl_registry_bind(registry, name, &xdg_wm_base_interface, 1));
// Up to version 6, for xdg_toplevel's `suspended` state
// (Window::suspended); `activated` is there from version 1. The
// requests the windows make are all version 1's. On the way come
// xdg_toplevel's configure_bounds (4) and wm_capabilities (5), which
// Window's listener takes and drops.
xdgWmBase = reinterpret_cast<xdg_wm_base*>(wl_registry_bind(registry, name, &xdg_wm_base_interface, std::min<std::uint32_t>(version, 6)));
xdg_wm_base_add_listener(xdgWmBase, &xdgWmBaseListener, nullptr);
} else if (strcmp(interface, zxdg_decoration_manager_v1_interface.name) == 0) {
manager = reinterpret_cast<zxdg_decoration_manager_v1*>(wl_registry_bind(registry, name, &zxdg_decoration_manager_v1_interface, 1));