Skip to content

Commit

Permalink
Implement tilt support on Android
Browse files Browse the repository at this point in the history
With a patch to Qt to interpret those axis values.
  • Loading branch information
askmeaboutlo0m committed Dec 1, 2024
1 parent 52ce966 commit 288ea4d
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 0 deletions.
1 change: 1 addition & 0 deletions .github/scripts/build-qt.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,7 @@ if(BASE)
patches/windows_clipboard_sadness.diff
patches/qt5androidsupport_params.diff
patches/android_backtrace.diff
patches/androidtilt-qt5.diff
6.7.2
patches/qtbug-113394.diff
patches/cancel_touch_on_pen.diff
Expand Down
72 changes: 72 additions & 0 deletions .github/scripts/patches/androidtilt-qt5.diff
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
Description: Tilt support for QTabletEvent on Android.

--- a/src/android/jar/src/org/qtproject/qt5/android/QtNative.java
+++ b/src/android/jar/src/org/qtproject/qt5/android/QtNative.java
@@ -563,8 +563,20 @@
if (event.getToolType(0) == MotionEvent.TOOL_TYPE_MOUSE) {
sendMouseEvent(event, id);
} else if (m_tabletEventSupported && pointerType != 0) {
+ int xtilt, ytilt;
+ double tilt = event.getAxisValue(MotionEvent.AXIS_TILT);
+ if (tilt == 0.0) {
+ xtilt = 0;
+ ytilt = 0;
+ } else {
+ double orientation = ((double)event.getOrientation()) - Math.PI / 2.0;
+ double tiltDegrees = Math.toDegrees(tilt);
+ xtilt = (int)Math.round(Math.cos(orientation) * tiltDegrees);
+ ytilt = (int)Math.round(-Math.sin(orientation) * tiltDegrees);
+ }
tabletEvent(id, event.getDeviceId(), event.getEventTime(), event.getAction(), pointerType,
- event.getButtonState(), event.getX(), event.getY(), event.getPressure());
+ event.getButtonState(), event.getX(), event.getY(), event.getPressure(),
+ xtilt, ytilt);
} else {
touchBegin(id);
for (int i = 0; i < event.getPointerCount(); ++i) {
@@ -1219,7 +1231,7 @@

// tablet methods
public static native boolean isTabletEventSupported();
- public static native void tabletEvent(int winId, int deviceId, long time, int action, int pointerType, int buttonState, float x, float y, float pressure);
+ public static native void tabletEvent(int winId, int deviceId, long time, int action, int pointerType, int buttonState, float x, float y, float pressure, int xtilt, int ytilt);
// tablet methods

// keyboard methods
--- a/src/plugins/platforms/android/androidjniinput.cpp
+++ b/src/plugins/platforms/android/androidjniinput.cpp
@@ -327,7 +327,8 @@
}

static void tabletEvent(JNIEnv */*env*/, jobject /*thiz*/, jint /*winId*/, jint deviceId, jlong time, jint action,
- jint pointerType, jint buttonState, jfloat x, jfloat y, jfloat pressure)
+ jint pointerType, jint buttonState, jfloat x, jfloat y, jfloat pressure,
+ jint xtilt, jint ytilt)
{
#if QT_CONFIG(tabletevent)
QPointF globalPosF(x, y);
@@ -365,12 +366,13 @@
}

#ifdef QT_DEBUG_ANDROID_STYLUS
- qDebug() << action << pointerType << buttonState << '@' << x << y << "pressure" << pressure << ": buttons" << buttons;
+ qDebug() << action << pointerType << buttonState << '@' << x << y << "pressure" << pressure << "tilt" << xtilt << ytilt << ": buttons" << buttons;
#endif

QWindowSystemInterface::handleTabletEvent(tlw, ulong(time),
localPos, globalPosF, QTabletEvent::Stylus, pointerType,
- buttons, pressure, 0, 0, 0., 0., 0, deviceId, Qt::NoModifier);
+ buttons, pressure, qBound(-60, xtilt, 60), qBound(-60, ytilt, 60),
+ 0., 0., 0, deviceId, Qt::NoModifier);
#endif // QT_CONFIG(tabletevent)
}

@@ -875,7 +877,7 @@
{"mouseWheel", "(IIIFF)V", (void *)mouseWheel},
{"longPress", "(III)V", (void *)longPress},
{"isTabletEventSupported", "()Z", (void *)isTabletEventSupported},
- {"tabletEvent", "(IIJIIIFFF)V", (void *)tabletEvent},
+ {"tabletEvent", "(IIJIIIFFFII)V", (void *)tabletEvent},
{"keyDown", "(IIIZ)V", (void *)keyDown},
{"keyUp", "(IIIZ)V", (void *)keyUp},
{"keyboardVisibilityChanged", "(Z)V", (void *)keyboardVisibilityChanged},
1 change: 1 addition & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ Unreleased Version 2.2.2-pre
* Feature: Replace "hold shift to arrange" with View > Docks > Arrange Docks, which doesn't require a keyboard. Thanks 3rd_EFNO for suggesting.
* Feature: Allow configuring temporary tool switch hold time. Thanks 3rd_EFNO and pachuco for suggesting.
* Fix: Properly pass tilt and barrel rotation values to MyPaint brushes. Thanks MorrowShore for reporting.
* Feature: Tilt support on Android. Thanks MorrowShore and Verdrusk for suggesting.

2024-11-06 Version 2.2.2-beta.4
* Fix: Solve rendering glitches with selection outlines that happen on some systems. Thanks xxxx for reporting.
Expand Down

0 comments on commit 288ea4d

Please sign in to comment.