Skip to content

Feature - Mouse devices on android#2597

Open
joliver82 wants to merge 4 commits intojMonkeyEngine:masterfrom
joliver82:feature_mouse_devices_on_android
Open

Feature - Mouse devices on android#2597
joliver82 wants to merge 4 commits intojMonkeyEngine:masterfrom
joliver82:feature_mouse_devices_on_android

Conversation

@joliver82
Copy link
Contributor

This pull request adds mouse device support to android. (Issue #2173 )

In addition to specific android code, I had to add a new method "setMouseGrab" to both InputManager and MouseInput (and classes implemeting it).

This changed was done because when Android changes to grab/capture mode while dragging all events after mouse down are ignored till mouse up is received. FlyByCamera and ChaseCamera changes visibility while dragging if set dragToRotate=true. So changing grab state in setVisibility method avoids being able to move the camera in this mode. Also I wanted to be able to properly capture the mouse if the game requires it like jme3 works on desktop when running setVisibility(false)

Jesus Oliver added 3 commits February 6, 2026 01:15
Added setMouseGrab method to both MouseInput and InputManager. Android cannot change to grab/capture mode while dragging, all events after mouse down are ignored till mouse up is received
@riccardobl
Copy link
Member

Looks solid, but i am not sure about the new setMouseGrab method, usually in jme we consider setCursorVisible(false) = mouse grab, isn't there a way to make this behavior work in the new android input handler?

@joliver82
Copy link
Contributor Author

Thanks for reviewing.

I know jme3 uses setVisibility as grab method but in Android it's not possible to do it this way unless we accept that drag to rotate functionality won't work when using a mouse.

As I wrote in the first comment, if changed grab state after a mouse down event, the following events (move events) are not sent by the OS till mouse up (checked in all my devices and the behavior is the same).

Notice that I updated all existing mouse handlers to include the set grab method as wrapper for setVisibility(!grab) and also updated all classes using mouse handler setVisibility to use it or setGrab (only three classes)

I don't see much issue in adding this method, in fact I feel it's a more meaningful name. Also I don't know if there're lots of users using setVisibility directly or just through current existing jme3 classes (like FlyByCamera).

@riccardobl
Copy link
Member

riccardobl commented Feb 7, 2026

My goal would be to make this behave exactly like in desktop without any api change.
I did some debugging and in my device calling requestPointerCapture() normally hides the mouse pointer automatically, however i think the problem in this implementation is that ACTION_CANCEL are handled like RELEASE, this causes a button up event to be triggered when android cancels the click action in favor of a drag action, and in turn it breaks the chasecamera use case and shows the cursor again

@riccardobl
Copy link
Member

riccardobl commented Feb 7, 2026

I've pushed the changes that fixed it for me, without the setMouseGrab, here on this branch.
Could you please review it and test on your devices? Thanks

(feel free to revert the commit or to force push, if it is conflicting with your local branch)

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.

2 participants