-
-
Notifications
You must be signed in to change notification settings - Fork 21.4k
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
[android] Added pressure support for stylus. #49609
Conversation
We don't have an Android test suite yet, but I don't know how such a test suite would work anyway. |
I just noticed that this does not trigger "MouseButton" events for the stylus and no InputEventScreenTouch either. |
CC @HEAVYPOLY if you can test. |
I investigated that a little bit, and it seams like it dosn't fire any other event except move for my stylus (Samsung Note 10 lite) so a MouseButton event would need to be emulated. But I'm very new to the codebase so maybe I overlooked something: |
@thebestnom For additional review. @ModProg In order to debug why no other events are fired, it may be easier to write a sample android app that just logs all the input from the stylus. Using that app, once you figure out how to properly identify stylus input events, then you can replicate the logic in the Godot codebase. |
Interesting, sounds like the same bug I had with mouse that I had to hack around, Ill test that later today maybe I was a complete fool, or we need the same hack for stylus too |
@m4gr3d Looks good! The only thing Im trying to understand is in that case why we need special case for stylus in |
@thebestnom Yea I agree, in theory we shouldn't need special casing. |
So I created a test app (https://github.com/ModProg/PenTest)
|
@ModProg The We may instead need to start using Note: You can use |
@m4gr3d this doesn't change anything still get 211,212,213. Those may be proprietary from Samsung: Samsung/ChromiumGStreamerBackend We should still support those tho. |
@ModProg I would like to test the 3.2 version but I'm still a beginner with github. I have my own branch that is modified and based on 3.x godot branch. Should I clone your branch, rebase on 3.x godot, then rebase my branch ontop of that? |
@HEAVYPOLY yes you can do that, use this branch: https://github.com/ModProg/godot/tree/android-stylus-support that is the 3.2 version of my fix, currently using this as well. |
@ModProg semi success, I'm getting the InputEventMouseMotion events with pressure! But not getting InputEventMouseButton events. (No mouse button pressed events) |
Sounds correct, Im pretty sure you forgot to change |
is it this section? case AMOTION_EVENT_ACTION_BUTTON_PRESS:
|
No, I meant on the Java side, the native side should be ok |
In |
looks like it fires godotlib.hover. should it just be lumped in with mouse in this case since it should behave same as mouse( hover is just mousemovement )? |
@@ -170,7 +170,7 @@ public void run() { | |||
|
|||
public boolean onTouchEvent(final MotionEvent event) { | |||
// Mouse drag (mouse pressed and move) doesn't fire onGenericMotionEvent so this is needed | |||
if (event.isFromSource(InputDevice.SOURCE_MOUSE)) { | |||
if (event.isFromSource(InputDevice.SOURCE_MOUSE) || event.isFromSource(InputDevice.SOURCE_STYLUS)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This means that now onGenericMotionEvent
need to do a the work except for ACTION_MOVE, and because you didn't implemented touch there only move works for now
#49609 (comment) |
That's really weird and it makes bo sense to me 😅 |
Maybe try printing |
got it working! Sortof. The issue was button mask defaulting to 0 for pen. Made the default of _button_index_from_mask() return BUTTON_LEFT instead of 0, now it works as left mouse. void OS_Android::process_mouse_event(int event_action, int event_android_buttons_mask, Point2 event_pos, float event_vertical_factor, float event_horizontal_factor, float pressure) {
int event_buttons_mask = _android_button_mask_to_godot_button_mask(event_android_buttons_mask);
switch (event_action) {
case AMOTION_EVENT_ACTION_DOWN:
case AMOTION_EVENT_ACTION_UP:
case AMOTION_EVENT_ACTION_POINTER_DOWN:
case AMOTION_EVENT_ACTION_POINTER_UP:
case AMOTION_EVENT_ACTION_BUTTON_PRESS:
case AMOTION_EVENT_ACTION_BUTTON_RELEASE: {
Ref<InputEventMouseButton> ev;
ev.instance();
_set_key_modifier_state(ev);
ev->set_position(event_pos);
ev->set_global_position(event_pos);
ev->set_pressed(event_action == AMOTION_EVENT_ACTION_BUTTON_PRESS || event_action == AMOTION_EVENT_ACTION_DOWN || event_action == AMOTION_EVENT_ACTION_POINTER_DOWN);
int changed_button_mask = buttons_state ^ event_buttons_mask;
buttons_state = event_buttons_mask;
ev->set_button_index(_button_index_from_mask(changed_button_mask));
ev->set_button_mask(event_buttons_mask);
input->parse_input_event(ev);
hover_prev_pos = event_pos;
} break; |
Well, in android it does count as nothing in the mouse is clicked, I suggest changing this in the java side in an if source stylus statement |
what do you think of this? int OS_Android::_button_index_from_mask(int button_mask) {
switch (button_mask) {
case BUTTON_MASK_LEFT:
return BUTTON_LEFT;
case BUTTON_MASK_RIGHT:
return BUTTON_RIGHT;
case BUTTON_MASK_MIDDLE:
return BUTTON_MIDDLE;
case BUTTON_MASK_XBUTTON1:
return BUTTON_XBUTTON1;
case BUTTON_MASK_XBUTTON2:
return BUTTON_XBUTTON2;
default:
return BUTTON_LEFT; //Changed from return 0 <---
} |
@HEAVYPOLY do you have your version on Github? Then I would merge that here and try with my phone as well. |
@ModProg https://github.com/HEAVYPOLY/godot/tree/ui_scale_3x |
How is it going? |
@thebestnom currently a little busy with live stuff, but I tried experimenting with @HEAVYPOLY's changes. should be possible to get this in a mergable state soon, but I probably need to get the mouse down events in here first. |
Need any help? Got time to burn |
@thebestnom If you want to finish this up I think it's mostly getting Mouse-down events working and supporting these strange Samsung codes: #49609 (comment) |
I just noticed something, is it correct that godot/platform/android/java/lib/src/org/godotengine/godot/input/GodotInputHandler.java Lines 425 to 433 in 437b0dd
|
@thebestnom I'll map the Stylus events to Left and Right click for now? I do think that we should add actual stylus buttons in the future to differentiate mouse and stylus not only on android. |
I usually test on windows to see the event are identical 😅 |
@thebestnom currently don't have a Windowstablet availible. I have a working version with the sidebutton mapped to rightclick on here https://github.com/ModProg/godot/pull/1/files it is compared to the 3.3 branch as that is where I was able to actually test it. If that lookes ok to you I'll rebase it on master and get it in here. Due to #51737 right click will map to 0. |
I've been trying to refactor this for 3.x branch for the past week and have run up against a wall. I'm getting the Log prints from ACTION_MOVE with correct pressure, but I'm not seeing the pressure in Godot engine (returns pressure of 1) and also not seeing the pen down and pen up events. Does anyone know what is wrong here? https://github.com/HEAVYPOLY/godot/tree/android-pen-modprog
|
@HEAVYPOLY did it work at some point? And did https://github.com/ModProg/godot/tree/android-stylus-support work for you? Does your current version build? I got
|
@HEAVYPOLY You are parsing and |
@ModProg should it be like this instead?
I'm trying to match this:
I had this all working for a while but must have forgotten to commit...now trying to get back to where I was. I tried your android-stylus-support but was getting some with queue_event |
Ahh nevermind, I see in your branch the solution of 2 placeholder ints for vertical and horizontal factor. It worked! Getting the pressure mousemotion events again finally! |
Ended up using your handlesylusevent function, removing queue event and it worked for me, thanks @ModProg |
No problem, I really want this to happen, but sadly don't have the time currently to finalize this. If there is anything I can help with to make this a thing let me know. |
Thanks for the contribution nonetheless 🙂 |
Fixes godotengine/godot-proposals#735 for android.
I verified that this works on 3.2.2 and builds for master,
as I was not able to run the master godot engine.
There are no tests as I didn't find anything about tests for android.