Skip to content

Fix lost MouseButtonUp events when releasing mouse outside window (Linux/X11)#1018

Open
TheRedDeveloper wants to merge 1 commit into
not-fl3:masterfrom
TheRedDeveloper:releaseoutsidewindowfix
Open

Fix lost MouseButtonUp events when releasing mouse outside window (Linux/X11)#1018
TheRedDeveloper wants to merge 1 commit into
not-fl3:masterfrom
TheRedDeveloper:releaseoutsidewindowfix

Conversation

@TheRedDeveloper
Copy link
Copy Markdown

Problem

On Linux (X11), macroquad was unconditionally calling miniquad::window::set_cursor_grab(false) every frame in Stage::update when the cursor wasn't explicitly grabbed.

This is problematic because miniquad's X11 implementation calls XUngrabPointer whenever set_cursor_grab is called. This cancels X11's "implicit passive grab" where it automatically routes events to the window when a mouse button is held down, even if the cursor leaves the window.

As a result, dragging the mouse outside the window and releasing it would result in the application never receiving the MouseButtonUp event, getting stuck in a "pressed" state.

Solution

  • I modified Context to track previous_cursor_grabbed state.
  • If cursor_grabbed is true, we continue to call set_cursor_grab(true) every frame (maintaining existing functionality).
  • If cursor_grabbed is false, we only call set_cursor_grab(false) once, when the state transitions from true to false.

After all, the set_cursor_grab(true) needs to happen every frame to assert that the cursor is grabbed, but set_cursor_grab(false) needs to happen only once.

Hope this helps!

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