Skip to content

Commit 625b92e

Browse files
committed
Input logic cleanup:
- Fix invalid detection of mouse input. Prioritize using the event tool type to detect the type of the event, and only use the event source as fallback. - Ensure that pressure and tilt information is passed for touch drag events - Consolidate logic and remove redundant methods - Improve the logic to detect when external hardware keyboards are connected to the device
1 parent daa81bb commit 625b92e

File tree

6 files changed

+127
-120
lines changed

6 files changed

+127
-120
lines changed

platform/android/android_input_handler.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,8 @@ void AndroidInputHandler::process_touch_event(int p_event, int p_pointer, const
176176
for (int i = 0; i < p_points.size(); i++) {
177177
touch.write[i].id = p_points[i].id;
178178
touch.write[i].pos = p_points[i].pos;
179+
touch.write[i].pressure = p_points[i].pressure;
180+
touch.write[i].tilt = p_points[i].tilt;
179181
}
180182

181183
//send touch
@@ -208,6 +210,8 @@ void AndroidInputHandler::process_touch_event(int p_event, int p_pointer, const
208210
ev->set_position(p_points[idx].pos);
209211
ev->set_relative(p_points[idx].pos - touch[i].pos);
210212
ev->set_relative_screen_position(ev->get_relative());
213+
ev->set_pressure(p_points[idx].pressure);
214+
ev->set_tilt(p_points[idx].tilt);
211215
Input::get_singleton()->parse_input_event(ev);
212216
touch.write[i].pos = p_points[idx].pos;
213217
}

platform/android/android_input_handler.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ class AndroidInputHandler {
4242
struct TouchPos {
4343
int id = 0;
4444
Point2 pos;
45+
float pressure = 0;
46+
Vector2 tilt;
4547
};
4648

4749
struct MouseEventInfo {

platform/android/java/lib/src/org/godotengine/godot/input/GodotEditText.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,8 +266,13 @@ private boolean needHandlingInGodot(int keyCode, KeyEvent keyEvent) {
266266

267267
boolean hasHardwareKeyboard() {
268268
Configuration config = getResources().getConfiguration();
269-
return config.keyboard != Configuration.KEYBOARD_NOKEYS &&
269+
boolean hasHardwareKeyboardConfig = config.keyboard != Configuration.KEYBOARD_NOKEYS &&
270270
config.hardKeyboardHidden == Configuration.HARDKEYBOARDHIDDEN_NO;
271+
if (hasHardwareKeyboardConfig) {
272+
return true;
273+
}
274+
275+
return mRenderView.getInputHandler().hasHardwareKeyboard();
271276
}
272277

273278
// ===========================================================

platform/android/java/lib/src/org/godotengine/godot/input/GodotGestureHandler.kt

Lines changed: 9 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ internal class GodotGestureHandler : SimpleOnGestureListener(), OnScaleGestureLi
6262
private var pointerCaptureInProgress = false
6363

6464
override fun onDown(event: MotionEvent): Boolean {
65-
GodotInputHandler.handleMotionEvent(event.source, MotionEvent.ACTION_DOWN, event.buttonState, event.x, event.y, nextDownIsDoubleTap)
65+
GodotInputHandler.handleMotionEvent(event, MotionEvent.ACTION_DOWN, nextDownIsDoubleTap)
6666
nextDownIsDoubleTap = false
6767
return true
6868
}
@@ -82,20 +82,14 @@ internal class GodotGestureHandler : SimpleOnGestureListener(), OnScaleGestureLi
8282
}
8383

8484
// Cancel the previous down event
85-
GodotInputHandler.handleMotionEvent(
86-
event.source,
87-
MotionEvent.ACTION_CANCEL,
88-
event.buttonState,
89-
event.x,
90-
event.y
91-
)
85+
GodotInputHandler.handleMotionEvent(event, MotionEvent.ACTION_CANCEL)
9286

9387
// Turn a context click into a single tap right mouse button click.
9488
GodotInputHandler.handleMouseEvent(
89+
event,
9590
MotionEvent.ACTION_DOWN,
9691
MotionEvent.BUTTON_SECONDARY,
97-
event.x,
98-
event.y
92+
false
9993
)
10094
contextClickInProgress = true
10195
}
@@ -107,16 +101,7 @@ internal class GodotGestureHandler : SimpleOnGestureListener(), OnScaleGestureLi
107101

108102
if (!hasCapture) {
109103
// Dispatch a mouse relative ACTION_UP event to signal the end of the capture
110-
GodotInputHandler.handleMouseEvent(
111-
MotionEvent.ACTION_UP,
112-
0,
113-
0f,
114-
0f,
115-
0f,
116-
0f,
117-
false,
118-
true
119-
)
104+
GodotInputHandler.handleMouseEvent(MotionEvent.ACTION_UP, true)
120105
}
121106
pointerCaptureInProgress = hasCapture
122107
}
@@ -139,26 +124,11 @@ internal class GodotGestureHandler : SimpleOnGestureListener(), OnScaleGestureLi
139124
return true
140125
}
141126

142-
val sourceMouseRelative = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
143-
event.isFromSource(InputDevice.SOURCE_MOUSE_RELATIVE)
144-
} else {
145-
false
146-
}
147-
148127
if (pointerCaptureInProgress || dragInProgress || contextClickInProgress) {
149128
if (contextClickInProgress || GodotInputHandler.isMouseEvent(event)) {
150129
// This may be an ACTION_BUTTON_RELEASE event which we don't handle,
151130
// so we convert it to an ACTION_UP event.
152-
GodotInputHandler.handleMouseEvent(
153-
MotionEvent.ACTION_UP,
154-
event.buttonState,
155-
event.x,
156-
event.y,
157-
0f,
158-
0f,
159-
false,
160-
sourceMouseRelative
161-
)
131+
GodotInputHandler.handleMouseEvent(event, MotionEvent.ACTION_UP)
162132
} else {
163133
GodotInputHandler.handleTouchEvent(event)
164134
}
@@ -173,21 +143,7 @@ internal class GodotGestureHandler : SimpleOnGestureListener(), OnScaleGestureLi
173143

174144
private fun onActionMove(event: MotionEvent): Boolean {
175145
if (contextClickInProgress) {
176-
val sourceMouseRelative = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
177-
event.isFromSource(InputDevice.SOURCE_MOUSE_RELATIVE)
178-
} else {
179-
false
180-
}
181-
GodotInputHandler.handleMouseEvent(
182-
event.actionMasked,
183-
MotionEvent.BUTTON_SECONDARY,
184-
event.x,
185-
event.y,
186-
0f,
187-
0f,
188-
false,
189-
sourceMouseRelative
190-
)
146+
GodotInputHandler.handleMouseEvent(event, event.actionMasked, MotionEvent.BUTTON_SECONDARY, false)
191147
return true
192148
}
193149
return false
@@ -197,7 +153,7 @@ internal class GodotGestureHandler : SimpleOnGestureListener(), OnScaleGestureLi
197153
if (event.actionMasked == MotionEvent.ACTION_UP) {
198154
nextDownIsDoubleTap = false
199155
GodotInputHandler.handleMotionEvent(event)
200-
} else if (event.actionMasked == MotionEvent.ACTION_MOVE && panningAndScalingEnabled == false) {
156+
} else if (event.actionMasked == MotionEvent.ACTION_MOVE && !panningAndScalingEnabled) {
201157
GodotInputHandler.handleMotionEvent(event)
202158
}
203159

@@ -219,13 +175,7 @@ internal class GodotGestureHandler : SimpleOnGestureListener(), OnScaleGestureLi
219175
if (dragInProgress) {
220176
if (originEvent != null) {
221177
// Cancel the drag
222-
GodotInputHandler.handleMotionEvent(
223-
originEvent.source,
224-
MotionEvent.ACTION_CANCEL,
225-
originEvent.buttonState,
226-
originEvent.x,
227-
originEvent.y
228-
)
178+
GodotInputHandler.handleMotionEvent(originEvent, MotionEvent.ACTION_CANCEL)
229179
}
230180
dragInProgress = false
231181
}

0 commit comments

Comments
 (0)