fix(rage-input-five): release the cursor clip when the window loses focus - #4092
Open
Github-Samuel wants to merge 1 commit into
Open
fix(rage-input-five): release the cursor clip when the window loses focus#4092Github-Samuel wants to merge 1 commit into
Github-Samuel wants to merge 1 commit into
Conversation
…ocus `ClipHostCursor` keeps the last rect it applied and skips the call when it is asked for the same one again, to avoid the repeated `ClipCursor` calls that load DWM. Windows drops the clip by itself when the window stops being the foreground one, but that cache does not know about it, so when the game asks for the same rect again after alt tabbing back the call is treated as a duplicate and never reaches `ClipCursor`. The cursor is then free to leave the window during gameplay. Clear the cache on `WM_ACTIVATEAPP` when focus is lost so the game's own request goes through on the way back in. `rage-input-rdr3` already does this, from pr-3637. Signed-off-by: Samuel Nicol <99494967+Github-Samuel@users.noreply.github.com>
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.
Goal of this PR
Stop the mouse escaping the game window after alt tabbing back in. This is the FiveM side of #3637, which fixed the same thing for RedM.
How is this PR achieving the goal
ClipCursoris hooked so repeated identical calls don't hit DWM, andClipHostCursorholds the last rect for that:Windows releases the clip itself once the window is no longer in the foreground, and nothing tells the cache. So after an alt tab the OS is not clipping anything while
lastRectPtrstill points at the old rect. When the game asks for that same rect again on the way back in, all three conditions are false, the call is treated as a duplicate, and the realClipCursoris never reached. The cursor stays loose for the rest of the session.rage-input-fivealready tracks focus for key messages, it just doesn't do anything with it here:rage-input-rdr3clears the cache in the same spot, and itsClipHostCursoris identical to this one, so this is the same change:ClipHostCursor(NULL)setslastRectPtrback to null, so the next request from the game is seen as a change and actually applied.Only the focus-lost path is touched, and the game re-requests the clip when it wants one, so nothing changes for a session that never loses focus.
This PR applies to the following area(s)
FiveM
Successfully tested on
Game builds: n/a, this does not depend on a game build
Platforms: Windows
Checklist
I could not do a full client build locally so I left the first box unchecked. What I did check is the cache behaviour, by running
ClipHostCursoras it is written against a model ofClipCursorthrough clip, lose focus, clip again with the same rect. As it stands the second clip does not reachClipCursorat all and the cursor is left unclipped, with the change it does and the cursor is clipped again. Since I can't alt tab a real client here it would be worth someone confirming on an actual install before this goes in.