Wayland: wl_compositor and wl_data_device_manager are bound at version 3 whatever the offer, and a second xdg_wm_base or wl_seat global overwrites the first #195

Open
opened 2026-11-17 06:45:46 +00:00 by jorijnvdgraaf · 0 comments

Summary

Device::handle_global binds wl_compositor and wl_data_device_manager at version 3 whatever version the compositor offers. A bind above the offer is a protocol error that ends the connection, so on a compositor that offers either below 3 no window would open at all. And of all the globals only wl_compositor is bound once: a second xdg_wm_base or wl_seat advertisement binds again and overwrites the first proxy. Line numbers refer to c006519.

Details

  • implementations/Crafter.Graphics-Device.cpp:319: wl_registry_bind(registry, name, &wl_compositor_interface, 3). :339-340: the same for wl_data_device_manager_interface. Neither looks at the handler's version argument.
  • The comment at :335-338 expects a fallback for a compositor without version 3 ("the per-source listener simply not getting the v3-only callbacks"). There is none: libwayland's server answers such a bind with a protocol error, invalid version for global ...: expected at most %d, got %d (wayland 1.26.0, src/wayland-server.c:1086-1090), and a protocol error is fatal to the client's connection. tests/ToplevelState/main.cpp:24-27 says the same of xdg_wm_base.
  • :326, since c006519, is the one bind that respects the offer: std::min<std::uint32_t>(version, 6).
  • :318: compositor == nullptr && guards the wl_compositor branch. The xdg_wm_base branch (:320-327) and the wl_seat branch (:304-317) have no such guard, and handle_global_remove (:480-482) is empty. A second advertisement of either overwrites Device::xdgWmBase or Device::seat and adds a listener to the new proxy; the first proxy is leaked, and the windows made from the first xdg_wm_base go on using it.

On KWin 6.8.0 the offers are wl_compositor 6, wl_data_device_manager 3, wl_seat 11 and wl_shm 2 (read off a WAYLAND_DEBUG=1 run on 2026-11-17), so nothing goes wrong there. Latent.

Found by reading the code, in the pre-push review of 364d210..c006519. It is older than that range, which changed only the xdg_wm_base bind's version. Not reproduced: no compositor that offers either global below version 3, and none with two seats, was tried.

Suggested fix

Bind each at std::min(version, <the version the code is written for>), as the xdg_wm_base branch does, and stop relying on what the lower version lacks: for wl_data_device_manager below 3, the wl_data_source events of version 3. Give the xdg_wm_base and wl_seat branches the == nullptr guard wl_compositor has, or handle a second seat on purpose.

## Summary `Device::handle_global` binds `wl_compositor` and `wl_data_device_manager` at version 3 whatever version the compositor offers. A bind above the offer is a protocol error that ends the connection, so on a compositor that offers either below 3 no window would open at all. And of all the globals only `wl_compositor` is bound once: a second `xdg_wm_base` or `wl_seat` advertisement binds again and overwrites the first proxy. Line numbers refer to `c006519`. ## Details - `implementations/Crafter.Graphics-Device.cpp:319`: `wl_registry_bind(registry, name, &wl_compositor_interface, 3)`. `:339-340`: the same for `wl_data_device_manager_interface`. Neither looks at the handler's `version` argument. - The comment at `:335-338` expects a fallback for a compositor without version 3 ("the per-source listener simply not getting the v3-only callbacks"). There is none: libwayland's server answers such a bind with a protocol error, `invalid version for global ...: expected at most %d, got %d` (wayland 1.26.0, `src/wayland-server.c:1086-1090`), and a protocol error is fatal to the client's connection. `tests/ToplevelState/main.cpp:24-27` says the same of `xdg_wm_base`. - `:326`, since c006519, is the one bind that respects the offer: `std::min<std::uint32_t>(version, 6)`. - `:318`: `compositor == nullptr &&` guards the `wl_compositor` branch. The `xdg_wm_base` branch (`:320-327`) and the `wl_seat` branch (`:304-317`) have no such guard, and `handle_global_remove` (`:480-482`) is empty. A second advertisement of either overwrites `Device::xdgWmBase` or `Device::seat` and adds a listener to the new proxy; the first proxy is leaked, and the windows made from the first `xdg_wm_base` go on using it. On KWin 6.8.0 the offers are `wl_compositor` 6, `wl_data_device_manager` 3, `wl_seat` 11 and `wl_shm` 2 (read off a `WAYLAND_DEBUG=1` run on 2026-11-17), so nothing goes wrong there. Latent. Found by reading the code, in the pre-push review of 364d210..c006519. It is older than that range, which changed only the `xdg_wm_base` bind's version. Not reproduced: no compositor that offers either global below version 3, and none with two seats, was tried. ## Suggested fix Bind each at `std::min(version, <the version the code is written for>)`, as the `xdg_wm_base` branch does, and stop relying on what the lower version lacks: for `wl_data_device_manager` below 3, the `wl_data_source` events of version 3. Give the `xdg_wm_base` and `wl_seat` branches the `== nullptr` guard `wl_compositor` has, or handle a second seat on purpose.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
Catcrafts/Crafter.Graphics#195
No description provided.