Skip to content

WaylandBackend: re-arm the forced pointer lock when focus returns - #2343

Open
vincent562 wants to merge 1 commit into
ValveSoftware:masterfrom
vincent562:upstream-fix-1711
Open

WaylandBackend: re-arm the forced pointer lock when focus returns#2343
vincent562 wants to merge 1 commit into
ValveSoftware:masterfrom
vincent562:upstream-fix-1711

Conversation

@vincent562

Copy link
Copy Markdown

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_bForceRelativeMouse arms the lock exactly once, from CWaylandConnector::Init(). The per-frame call to SetRelativeMouseMode in steamcompmgr that 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_PERSISTENT constraint on focus loss and does not reactivate it, nothing ever re-arms it: SetRelativeMouseMode's guard only compares bRelative against m_pLockedPointer, which is still non-null. Wayland_LockedPointer_Unlocked just clears m_bPointerLocked and leaves the object in place.

Fix

Track the host-side unlock in m_bPointerUnlockedByHost, allow SetRelativeMouseMode to recreate the constraint when that flag is set, and re-arm from the keyboard and pointer enter handlers — 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-cursor is unchanged: ReArmForcedPointerLock() returns immediately unless g_bForceRelativeMouse is set.

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant