Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

streamline cursor clipping logic on windows #11237

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

expikr
Copy link
Contributor

@expikr expikr commented Oct 16, 2024

Fixes #7890

This commit does the following:

  • move relative_mouse_center field from Windows-specific per-window SDL_WindowData to the global SDL_Mouse struct, and the corresponding hint callbacks to SDL_mouse.c instead of SDL_windowswindow.c
  • remove Windows-specific periodic refresh of cursor clipping and its SDL_HINT_MOUSE_RELATIVE_CLIP_INTERVAL hint, instead solve the root issue with Window Procedure based approach
  • add logic in the WM_MOUSEMOVE case of the Window to conditionally call WIN_UpdateClipCursor upon receiving cursor motion if SDL is expecting the mouse to be clipped in some way.
  • streamline the processing logic within WIN_UpdateClipCursor for better readability of each branch, and avoid calling the Platform API until it is absolutely necessary.

relevant commits:

e56f05b (apr 2024)
6c96217 (mar 2024)
ab5351f (mar 2024)
50203d5 (dec 2020)
44f50c6 (jun 2020)
55b24b9 (sep 2018)

@expikr expikr changed the title Update SDL_windowsevents.c fix ClipCursor contention from background programs Oct 16, 2024
@expikr expikr changed the title fix ClipCursor contention from background programs fix ClipCursor contention from background programs by replacing polling based clipping with callback based approach, and remove SDL_HINT_MOUSE_RELATIVE_CLIP_INTERVAL Oct 19, 2024
@expikr expikr changed the title fix ClipCursor contention from background programs by replacing polling based clipping with callback based approach, and remove SDL_HINT_MOUSE_RELATIVE_CLIP_INTERVAL Fix ClipCursor contention from background programs by refreshing on event instead of on poll, and remove SDL_HINT_MOUSE_RELATIVE_CLIP_INTERVAL Oct 19, 2024
@expikr expikr requested review from slouken and sezero November 2, 2024 10:16
@sezero sezero removed their request for review November 2, 2024 12:02
@expikr expikr marked this pull request as draft November 20, 2024 10:21
@expikr expikr force-pushed the patch-2 branch 4 times, most recently from 2c8c77b to e494782 Compare November 20, 2024 14:43
@expikr expikr changed the title Fix ClipCursor contention from background programs by refreshing on event instead of on poll, and remove SDL_HINT_MOUSE_RELATIVE_CLIP_INTERVAL streamline cursor clipping logic on windows Nov 20, 2024
@expikr expikr marked this pull request as ready for review November 20, 2024 19:52
@expikr expikr force-pushed the patch-2 branch 9 times, most recently from 785d0ac to 2414ed9 Compare November 23, 2024 07:55
Comment on lines +1576 to +1580
// This is verbatim translation of the old logic,
// but I don't quite get what it's trying to do.
// A clean-room implementation according to MSDN
// documentation of GetClipCursor is provided in
// a commented-out block below.
Copy link
Contributor Author

@expikr expikr Nov 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've traced the origin of this logic to this commit:

e56f05b#diff-f2ae5c36a8afc0a9a343a6664ab306da2963213e180af8cd97b12397dcbb9ae7R1572

but still couldn't quite reason about what condition it's trying to check exactly, if @slouken could clarify then that would be extremely helpful.

@expikr expikr force-pushed the patch-2 branch 3 times, most recently from c66107c to 0fbe530 Compare November 23, 2024 13:15
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.

Cursor not constrained to window when using SDL_SetRelativeMouseMode and another game is running
3 participants