-
-
Notifications
You must be signed in to change notification settings - Fork 155
Expand file tree
/
Copy pathandroidf13to24-qt5-krita.diff
More file actions
153 lines (143 loc) · 6.62 KB
/
Copy pathandroidf13to24-qt5-krita.diff
File metadata and controls
153 lines (143 loc) · 6.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
Description: OnePlus tablet handling: interpret F13 to F24 keys on Android and
add a hack to translate F21 to middle click.
--- a/src/corelib/kernel/qcoreapplication.h
+++ b/src/corelib/kernel/qcoreapplication.h
@@ -87,6 +87,13 @@ class QAbstractNativeEventFilter;
# define KRITA_QATTRIBUTE_ANDROID_IGNORE_HISTORIC_TABLET_EVENTS 1u
#endif
+// OnePlus workaround. The stylus inputs F21 for its button. Turn it into proper
+// middle clicks instead. This constant name is kept generic in case we need to
+// add additional function keys.
+#ifdef Q_OS_ANDROID
+# define KRITA_QATTRIBUTE_ANDROID_EMULATE_MOUSE_BUTTONS_FOR_HIGH_FUNCTION_KEYS 2u
+#endif
+
// End of Krita attributes.
class Q_CORE_EXPORT QCoreApplication
--- a/src/plugins/platforms/android/androidjniinput.cpp
+++ b/src/plugins/platforms/android/androidjniinput.cpp
@@ -87,6 +87,7 @@ namespace QtAndroidInput
static long m_lastTabletTime;
static bool m_emulatedPageUpPressed = false;
static bool m_emulatedPageDownPressed = false;
+ static bool m_emulatedF21Pressed = false;
void updateSelection(int selStart, int selEnd, int candidatesStart, int candidatesEnd)
{
@@ -417,17 +418,27 @@ namespace QtAndroidInput
case AMOTION_EVENT_ACTION_UP:
m_mouseGrabber = nullptr;
buttons = Qt::NoButton;
+ m_emulatedPageUpPressed = false;
+ m_emulatedPageDownPressed = false;
+ m_emulatedF21Pressed = false;
break;
case AMOTION_EVENT_ACTION_DOWN:
m_mouseGrabber = tlw;
checkAndSetTopLevelWindow(m_mouseGrabber);
+ m_emulatedPageUpPressed = false;
+ m_emulatedPageDownPressed = false;
+ m_emulatedF21Pressed = false;
// fall through
case AMOTION_EVENT_ACTION_MOVE:
if (!buttonState)
buttons = Qt::LeftButton;
case AMOTION_EVENT_ACTION_HOVER_MOVE:
default:
- if (buttonState == AMOTION_EVENT_BUTTON_STYLUS_PRIMARY)
+ if (m_emulatedPageUpPressed)
+ buttons = Qt::RightButton;
+ else if (m_emulatedPageDownPressed || m_emulatedF21Pressed)
+ buttons = Qt::MiddleButton;
+ else if (buttonState == AMOTION_EVENT_BUTTON_STYLUS_PRIMARY)
buttons = Qt::MiddleButton;
else if (buttonState == AMOTION_EVENT_BUTTON_STYLUS_SECONDARY)
buttons = Qt::RightButton;
@@ -640,6 +651,10 @@ namespace QtAndroidInput
if (key >= 0x00000083 && key <= 0x0000008e)
return Qt::Key_F1 + key - 0x00000083;
+ // F13--F24 0x00000146 -- 0x00000151
+ if (key >= 0x00000146 && key <= 0x00000151)
+ return Qt::Key_F13 + key - 0x00000146;
+
// NUMPAD_0--NUMPAD_9 0x00000090 -- 0x00000099
if (key >= 0x00000090 && key <= 0x00000099)
return Qt::KeypadModifier + Qt::Key_0 + key - 0x00000090;
@@ -1052,14 +1067,11 @@ namespace QtAndroidInput
}
// Xiaomi insanity, their stylus buttons input page up and down key presses.
- static bool emulateTabletButtonsFromPageUpAndPageDown(
+ // And also OnePlus, their stylus button inputs F21.
+ static bool emulateTabletButtonsFromKeyboard(
int key, jint modifier, jboolean autoRepeat, bool down)
{
- if (!QCoreApplication::testKritaAttribute(KRITA_QATTRIBUTE_ANDROID_EMULATE_MOUSE_BUTTONS_FOR_PAGE_UP_DOWN)) {
- return false;
- }
-
- if ((m_emulatedPageUpPressed || m_emulatedPageDownPressed) && autoRepeat) {
+ if ((m_emulatedPageUpPressed || m_emulatedPageDownPressed || m_emulatedF21Pressed) && autoRepeat) {
return true;
}
@@ -1068,15 +1080,32 @@ namespace QtAndroidInput
}
int buttonState;
+ bool *emulatedButtonPressed;
switch (key) {
case 0x0000005c: // KEYCODE_PAGE_UP
- buttonState = AMOTION_EVENT_BUTTON_STYLUS_SECONDARY;
- m_emulatedPageUpPressed = down;
- break;
+ if (QCoreApplication::testKritaAttribute(KRITA_QATTRIBUTE_ANDROID_EMULATE_MOUSE_BUTTONS_FOR_PAGE_UP_DOWN)) {
+ buttonState = AMOTION_EVENT_BUTTON_STYLUS_SECONDARY;
+ emulatedButtonPressed = &m_emulatedPageUpPressed;
+ break;
+ } else {
+ return false;
+ }
case 0x0000005d: // KEYCODE_PAGE_DOWN
- buttonState = AMOTION_EVENT_BUTTON_STYLUS_PRIMARY;
- m_emulatedPageDownPressed = down;
- break;
+ if (QCoreApplication::testKritaAttribute(KRITA_QATTRIBUTE_ANDROID_EMULATE_MOUSE_BUTTONS_FOR_PAGE_UP_DOWN)) {
+ buttonState = AMOTION_EVENT_BUTTON_STYLUS_PRIMARY;
+ emulatedButtonPressed = &m_emulatedPageDownPressed;
+ break;
+ } else {
+ return false;
+ }
+ case 0x0000014e: // KEYCODE_F21
+ if (QCoreApplication::testKritaAttribute(KRITA_QATTRIBUTE_ANDROID_EMULATE_MOUSE_BUTTONS_FOR_HIGH_FUNCTION_KEYS)) {
+ buttonState = AMOTION_EVENT_BUTTON_STYLUS_PRIMARY;
+ emulatedButtonPressed = &m_emulatedF21Pressed;
+ break;
+ } else {
+ return false;
+ }
default:
return false;
}
@@ -1094,12 +1123,16 @@ namespace QtAndroidInput
m_lastTabletTiltY,
m_lastTabletRotation,
modifier);
+ // Must come *after* the tabletEvent call, it resets these emulated
+ // press values down and up actions!
+ *emulatedButtonPressed = down;
+
return true;
}
static void keyDown(JNIEnv */*env*/, jobject /*thiz*/, jint key, jint unicode, jint modifier, jboolean autoRepeat)
{
- if (!emulateTabletButtonsFromPageUpAndPageDown(key, modifier, autoRepeat, true)) {
+ if (!emulateTabletButtonsFromKeyboard(key, modifier, autoRepeat, true)) {
QWindowSystemInterface::handleKeyEvent(0,
QEvent::KeyPress,
mapAndroidKey(key),
@@ -1111,7 +1144,7 @@ namespace QtAndroidInput
static void keyUp(JNIEnv */*env*/, jobject /*thiz*/, jint key, jint unicode, jint modifier, jboolean autoRepeat)
{
- if (!emulateTabletButtonsFromPageUpAndPageDown(key, modifier, autoRepeat, false)) {
+ if (!emulateTabletButtonsFromKeyboard(key, modifier, autoRepeat, false)) {
QWindowSystemInterface::handleKeyEvent(0,
QEvent::KeyRelease,
mapAndroidKey(key),