Commit graph Crafter.Graphics/tests/ToplevelState/main.cpp
Author SHA1 Message Date
c006519fa0
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.
2026-11-17 06:57:46 +01:00