WaylandBackend: re-arm the forced pointer lock when focus returns - #2343
Open
vincent562 wants to merge 1 commit into
Open
WaylandBackend: re-arm the forced pointer lock when focus returns#2343vincent562 wants to merge 1 commit into
vincent562 wants to merge 1 commit into
Conversation
With --force-grab-cursor, the pointer lock is armed exactly once, from CWaylandConnector::Init(), because steamcompmgr's per-frame call to SetRelativeMouseMode is gated behind !g_bForceRelativeMouse. When the host compositor deactivates our LIFETIME_PERSISTENT constraint on focus loss (alt-tab, workspace switch) and does not reactivate it, nothing ever re-arms it: SetRelativeMouseMode's guard only compares bRelative against m_pLockedPointer, which is still non-null. The cursor then escapes the game window for good, and clicking back into it does not help. Track the host-side unlock and re-arm the constraint from the keyboard and pointer enter handlers, i.e. when focus actually comes back. Mutter never reactivates the constraint on its own; the same symptom has been reported under Hyprland. Refs: ValveSoftware#1285
vincent562
force-pushed
the
upstream-fix-1711
branch
from
August 21, 2026 22:31
6fdee88 to
9692072
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
With
--force-grab-cursor, the cursor is confined to the game correctly at first, but as soon as focus leaves the gamescope window (alt-tab, workspace switch) and comes back, the confinement is gone for good: the cursor moves freely out of the game and onto other monitors. Clicking back into the window does not restore it.Reproduced on GNOME 50 / Mutter, Wayland session, 3 monitors, NVIDIA 595.84. The same symptom is reported under Hyprland in #1285.
Cause
With
--force-grab-cursor,g_bForceRelativeMousearms the lock exactly once, fromCWaylandConnector::Init(). The per-frame call toSetRelativeMouseModeinsteamcompmgrthat would otherwise keep it in sync is explicitly gated behind!g_bForceRelativeMouse, so it never runs in this mode.When the host compositor deactivates our
LIFETIME_PERSISTENTconstraint on focus loss and does not reactivate it, nothing ever re-arms it:SetRelativeMouseMode's guard only comparesbRelativeagainstm_pLockedPointer, which is still non-null.Wayland_LockedPointer_Unlockedjust clearsm_bPointerLockedand leaves the object in place.Fix
Track the host-side unlock in
m_bPointerUnlockedByHost, allowSetRelativeMouseModeto recreate the constraint when that flag is set, and re-arm from the keyboard and pointerenterhandlers — i.e. when focus actually comes back. Both handlers are used because the order of the two events is not guaranteed; the flag is cleared on re-arm, so the constraint is recreated once per unlock rather than per event.Testing
Built and run against wlroots 0.19.2 (the Ubuntu 26.04 system library) and the vendored 0.20.2 on
master. With the patch, confinement survives repeated alt-tabs and workspace switches, and the cursor stays visible and usable in game menus. Verified in a Proton game over XWayland and with a plain X11 client.Behaviour without
--force-grab-cursoris unchanged:ReArmForcedPointerLock()returns immediately unlessg_bForceRelativeMouseis set.