gamescope icon indicating copy to clipboard operation
gamescope copied to clipboard

With Wayland backend app_id and title are not re-sent after a NULL-buffer unmap

Open nilsenist opened this issue 2 months ago • 0 comments

Is there an existing issue for this?

  • [x] I have searched the existing issues

Are you using any gamescope patches or a forked version of gamescope?

  • [x] The issue occurs on upstream gamescope without any modifications

Current Behavior

With --backend wayland, gamescope commits a NULL buffer on its main xdg_toplevel ~40 ms after first mapping it, then maps it again. Per xdg-shell, a NULL-buffer commit unmaps the toplevel and resets it to its initial state, which clears title and app_id. gamescope does not re-send set_app_id / set_title before remapping, so the remapped window has no app_id, and no title until the game sets one.

As a result, compositor window rules matching app_id gamescope don't apply to the remapped window, and it lands wherever an unmatched window goes.

Expected behavior: after a NULL-buffer unmap, gamescope re-sends set_app_id("gamescope") and the current title before attaching a buffer again. The unmap case is already tracked via m_bUnmappedAwaitingConfigure in CWaylandPlane (src/Backends/WaylandBackend.cpp), which looks like the natural place to do it.

In all four traces I captured (two Proton, two native), the unmap happened only when gamescope's first presented frame came before the nested app had a window (toplevel title still the default "gamescope"); when the app's window existed first (title already set), no unmap occurred.

Steps To Reproduce

  1. On a wlroots-based compositor, set a window rule matching app_id gamescope (e.g. move to a specific workspace/tag).
  2. Launch a Proton title from Steam with: gamescope -W 2560 -H 1440 -r 75 --backend wayland --expose-wayland -- %command% (reproduces with and without -f).
  3. The window briefly appears on the rule's workspace (app_id still set), is unmapped via a NULL-buffer commit ~40 ms later, then remaps with no app_id and lands on the current workspace instead.

Reproduced with two Proton titles: RuneScape (1343400, with -f) and RuneScape: Dragonwilds (1374490, without -f). Not reproduced with two native Linux titles, Dota 2 (570) and Crusader Kings III (1158310): the toplevel is mapped once and keeps its app_id. For CK3 this includes the Paradox Launcher → game handoff, which reuses the same mapped toplevel.

To observe: prefix the launch command with WAYLAND_DEBUG=client and redirect stderr to a file.

Hardware information

- Distro: Arch Linux (kernel 7.2.8-1-cachyos)
- CPU: Intel Core i5-14400
- GPU: NVIDIA GeForce RTX 3070 Ti (GA104) [10de:2482]
- Driver Version: NVIDIA 615.71.09 (nvidia-open)

Software information

- Desktop environment: dwl 0.8 (wlroots 0.19.3)
- Session type: wayland
- Gamescope version: 3.16.25 (gcc 16.2.1)
- Gamescope launch command(s): gamescope -W 2560 -H 1440 -r 75 -f --backend wayland --expose-wayland -- %command%

Which gamescope backends have the issue you are reporting?

  • [x] Wayland (default for nested gamescope)
  • [ ] DRM (default for embedded gamescope, i.e. gamescope-session)
  • [ ] SDL
  • [ ] OpenVR

Logging, screenshots, or anything else

Protocol trace (WAYLAND_DEBUG=client, main toplevel only, timestamps in seconds), RuneScape with -f:

35.037  xdg_toplevel#53.set_title("Gamescope")
35.037  xdg_toplevel#53.set_app_id("gamescope")
35.037  xdg_toplevel#53.set_fullscreen(nil)
37.315  xdg_toplevel#53.set_title("gamescope")
37.326  wl_surface#49.attach(wl_buffer#78) + commit   <- mapped (app_id "gamescope")
37.339  xdg_toplevel#53.configure(2560, 1440, ...)
37.366  wl_surface#49.attach(nil) + commit           <- unmapped: toplevel state reset
37.406  xdg_toplevel#53.configure(0, 0, ...)
37.819  xdg_toplevel#53.set_fullscreen(nil)
37.821  xdg_toplevel#53.configure(2560, 1440, ...)
        ... buffer attached again                    <- remapped, no set_app_id / set_title
49.645  xdg_toplevel#53.set_title("RuneScape")       <- title only, 12 s later; app_id never re-sent

Same pattern without -f (RuneScape: Dragonwilds):

07.830  xdg_toplevel#53.set_title("Gamescope")
07.830  xdg_toplevel#53.set_app_id("gamescope")
09.914  xdg_toplevel#53.set_title("gamescope")
09.920  wl_surface#49.attach(wl_buffer#78) + commit   <- mapped
09.960  wl_surface#49.attach(nil) + commit           <- unmapped (toplevel reset)
11.773  wl_surface#49.attach(wl_buffer#78) + commit   <- remapped, no set_app_id
12.831  xdg_toplevel#53.set_title("Runescape: Dragonwilds  ")

For contrast, the native titles: Dota 2 sets title "Dota 2" before the first buffer (32.024) and never commits a NULL buffer. CK3 sets title "Paradox Launcher" before the first buffer, and the only NULL commit is at exit.

Compositor side: in wlroots 0.19.3 a NULL-buffer commit leads to reset_xdg_surface() → reset_xdg_toplevel(), which frees title and app_id (types/xdg_shell/wlr_xdg_surface.c, wlr_xdg_toplevel.c). After the remap, toplevel->app_id is NULL.

I've worked around it locally by caching the last non-NULL app_id in the compositor, but the fix belongs in the client. Not related to #1456 (different Wayland-backend bug, a crash rather than lost toplevel state).

nilsenist avatar Sep 29 '26 19:09 nilsenist