Repository navigation
Improve Android mouse event handling, especially relative mode. - #16538
Merged
Merged
Conversation
slouken
reviewed
Oct 17, 2026
| default: | ||
| break; | ||
| } | ||
|
|
slouken
reviewed
Oct 17, 2026
| int action = event.getActionMasked(); | ||
|
|
||
| SDLActivity.onNativeMouse(buttonState, action, x, y, true); | ||
|
|
slouken
reviewed
Oct 17, 2026
| default: | ||
| break; | ||
| } | ||
|
|
slouken
reviewed
Oct 17, 2026
| SDL_SendMouseMotion(0, window, SDL_DEFAULT_MOUSE_ID, relative, x, y); | ||
|
|
||
| if (changes_press) { | ||
| button = TranslateButton(changes_press); |
Collaborator
There was a problem hiding this comment.
Do you need to potentially handle multiple button state changes here?
Contributor
Author
There was a problem hiding this comment.
Hypothetically, yes, but nothing I've tested on so far groups more than two button changes into a single event.
Still, probably not the worst idea to handle it just in case... I'll tweak that this weekend.
Contributor
Author
|
Okay. I have now tested this with four different mice, across every Android device I could get my hands on this weekend. At this point, mouse buttons now work consistently across every combination in that matrix, so I think we're good to go! |
Collaborator
|
Merged, thanks! |
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.
Description
So it turns out that Android has some interestingly varied ways of handling mouse events.
Some devices will send
ACTION_DOWNandACTION_UPfor clicks. Some will sendACTION_BUTTON_PRESSandACTION_BUTTON_RELEASE. Some will sendACTION_BUTTON_PRESSfor the click, and thenACTION_CANCELfor the release. Some will useACTION_HOVER_EXITfor the button press, andACTION_HOVER_ENTERfor the button release.Some will include a button release for one button and a button press for another in the same message, only changing the button state field. Switching from absolute to relative mouse on some Android variants generates a spurious
ACTION_CANCELevent for mouse via the onTouch handler. Etc.In an effort to make mouse behavior consistent everywhere, these changes:
ACTION_CANCELin onTouchAs a side benefit, now that we are handling all the messages, we can get rid of the block of logic throwing out fallback key events in the key dispatcher.
These have been tested on Samsung Galaxy S21 and Amazon Fire TV Stick 4K Max so far. I'm going to do some further testing at home (Nvidia Shield TV, Wacom Movinkpad Pro, etc.) over the weekend, but I'm throwing this pull request in so that @slouken has time to review/request any changes.