-
-
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 Stylus pressure and tilt support. #80644
Conversation
Have verified that this works on my Galaxy Tab S7. |
platform/android/java/lib/src/org/godotengine/godot/input/GodotInputHandler.java
Outdated
Show resolved
Hide resolved
platform/android/java/lib/src/org/godotengine/godot/input/GodotInputHandler.java
Outdated
Show resolved
Hide resolved
platform/android/java/lib/src/org/godotengine/godot/input/GodotInputHandler.java
Outdated
Show resolved
Hide resolved
platform/android/java/lib/src/org/godotengine/godot/input/GodotInputHandler.java
Outdated
Show resolved
Hide resolved
Thanks for the contribution! Did you check if this solves any existing bug report or feature proposal? Please make changes to the PR by amending the commit and force pushing the branch, so style fixes for example become part of the main commit, instead of follow up fixup commits. See PR workflow for details. |
I believe it satisfies the Android half of godotengine/godot-proposals#735. |
Thanks! Please also have a look at #49609 for comparison - it looks like your PR is more feature complete as it also implements tilt and not just pressure. The discussion in the PR might still be useful to make this one fully ready to merge. |
Had a look at #49609, seem's like they had a couple of issues with getting the stylus to register up and down events. From what I can see testing right now, my PR does emit these events. |
Did some testing to get another data point, before remembering that my device is also a Galaxy Tab S7 :P Anyway, I can confirm it seems to work well on that device, with a generic stylus I got with it. Screenshot of received events while writing my name with the stylus. |
Good to know its not a fluke haha |
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.
Tested functionality, works fine for a basic test (didn't try it on a real app that would make use of pressure and tilt). Code style looks good.
I'll let @godotengine/android review the actual implementation for Android.
Do we have a testing project that features pen drawing somewhere? (If not, this could be worth adding to godot-demo-projects.) |
I've got a project I've been using to test this that displays the pressure (in both text and colour background) alongside the tilt, can post that here if needed. |
Please upload it here 🙂 |
Here you are. Hopefully it isn't too sloppy code-wise. |
I'll probably not be able to experiment with this before the beginning of September, unless someone builds the APK for me 😬. My devicd would be a Note 10 lite, i.e. a smart phone. |
@ModProg I am able to give you the APK, but GitHub only allows max 25mb as attachments. Any way to send it to you? |
Won't a zipped apk fit under the limit? |
Mine is 37mb at max compression (for reference, the raw APK is 40mb), although there might be a way to shrink it in Godot that I don't know about? |
It can be shrunk by only including a single architecture. Here's the release export template APK I built from this PR ( Exported project APK: Android Pressure Test.apk.zip |
Legendary, @ModProg this is for you 👍 |
I've tested the project locally. Both pressure and tilt reporting work as expected (Samsung Galaxy Z Fold4, Android 13, S Pen Fold Edition). Note that if the pen appears to do nothing, make sure it's enabled in the system settings. |
I think I ran into a similar problem I had when implementing this IIRC. There is only an output when I start moving, simply pressing down doesn't do anything independent from how hard I press down. Screen_Recording_20230815_193156_Android.Pressure.Test.mp4 |
Slow movements also don't trigger it. Thou I haven't looked at the Testprojekt, might be it is written to behave this way? |
Only InputEventMouseMotion has a pressure field, so the InputEventMouseButton events don't have any pressure information. I think there must be some sort of threshold (for displacement from the beginning position) built-in for triggering the motion events. The test project I supplied only displays motion events |
One thing I noticed in my testing, was that pen touching without moving wasn't detected at all, because Samsung introduced custom actions: ModProg@cbce6a1 Edit: This could also have been related to the eraser thinking about it now. 2 years is a long time and I'm not 100% sure, but would be good if we supported the action button an s-pen has on the side as well. |
I think supporting the stylus buttons is a different issue and should probably be in its own PR. If we do support the Samsung codes, could that potentially cause issues relating to duplicate events? |
IIRC they just didn't send the nornal codes. But it would also be interesting whether e.g. Huawei sends the same or different codes. I don't think I ever researched that. |
But I agree, this is not necessarily a blocker for this PR. When I hopefully continue the project I wanted pen support for, I'll revisit this and can add those then. |
I see, thank you for the clarification! |
@@ -433,7 +433,7 @@ static boolean isMouseEvent(MotionEvent event) { | |||
} | |||
|
|||
private static boolean isMouseEvent(int eventSource) { | |||
boolean mouseSource = ((eventSource & InputDevice.SOURCE_MOUSE) == InputDevice.SOURCE_MOUSE) || ((eventSource & (InputDevice.SOURCE_TOUCHSCREEN | InputDevice.SOURCE_STYLUS)) == 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.
What's the reason for removing the SOURCE_TOUCHSCREEN
check?
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.
I couldn't get it to work without removing that. I think SOURCE_TOUCHSCREEN
is used for fingers also?
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.
Should we try it like this, or investigate further?
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.
From what I can test, there seems to be no regression in touch handling when removing that SOURCE_TOUCHSCREEN
, I think it should be fine to try it like this.
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.
It looks like this change has introduced the following regression: #88621
Asides from the comment above the logic looks good!
@Distantz Thoughts? |
I think that could definitely be a good change, but I think it would require some conversation with the other platforms. For Android specifically, it should be easy to implement. |
To be clear, the inheritance tree is like this:
So indeed the This is IMO outside the scope of this PR though, and we'd need to evaluate whether moving properties to a parent class like this will break API or ABI compatibility. |
Let's proceed and merge, if @m4gr3d still has concerns on the change to |
Thanks! And congrats for your first merged Godot contribution 🎉 |
Modified the Android input code to send pressure and tilt information.
Bugsquad edit: