Skip to content

Commit a6ef250

Browse files
authored
Merge pull request #92133 from m4gr3d/fix_touch_input
Fix invalid detection of mouse input
2 parents ebe7377 + 625b92e commit a6ef250

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
@@ -65,7 +65,7 @@ internal class GodotGestureHandler : SimpleOnGestureListener(), OnScaleGestureLi
6565
private var lastDragY: Float = 0.0f
6666

6767
override fun onDown(event: MotionEvent): Boolean {
68-
GodotInputHandler.handleMotionEvent(event.source, MotionEvent.ACTION_DOWN, event.buttonState, event.x, event.y, nextDownIsDoubleTap)
68+
GodotInputHandler.handleMotionEvent(event, MotionEvent.ACTION_DOWN, nextDownIsDoubleTap)
6969
nextDownIsDoubleTap = false
7070
return true
7171
}
@@ -85,20 +85,14 @@ internal class GodotGestureHandler : SimpleOnGestureListener(), OnScaleGestureLi
8585
}
8686

8787
// Cancel the previous down event
88-
GodotInputHandler.handleMotionEvent(
89-
event.source,
90-
MotionEvent.ACTION_CANCEL,
91-
event.buttonState,
92-
event.x,
93-
event.y
94-
)
88+
GodotInputHandler.handleMotionEvent(event, MotionEvent.ACTION_CANCEL)
9589

9690
// Turn a context click into a single tap right mouse button click.
9791
GodotInputHandler.handleMouseEvent(
92+
event,
9893
MotionEvent.ACTION_DOWN,
9994
MotionEvent.BUTTON_SECONDARY,
100-
event.x,
101-
event.y
95+
false
10296
)
10397
contextClickInProgress = true
10498
}
@@ -110,16 +104,7 @@ internal class GodotGestureHandler : SimpleOnGestureListener(), OnScaleGestureLi
110104

111105
if (!hasCapture) {
112106
// Dispatch a mouse relative ACTION_UP event to signal the end of the capture
113-
GodotInputHandler.handleMouseEvent(
114-
MotionEvent.ACTION_UP,
115-
0,
116-
0f,
117-
0f,
118-
0f,
119-
0f,
120-
false,
121-
true
122-
)
107+
GodotInputHandler.handleMouseEvent(MotionEvent.ACTION_UP, true)
123108
}
124109
pointerCaptureInProgress = hasCapture
125110
}
@@ -142,26 +127,11 @@ internal class GodotGestureHandler : SimpleOnGestureListener(), OnScaleGestureLi
142127
return true
143128
}
144129

145-
val sourceMouseRelative = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
146-
event.isFromSource(InputDevice.SOURCE_MOUSE_RELATIVE)
147-
} else {
148-
false
149-
}
150-
151130
if (pointerCaptureInProgress || dragInProgress || contextClickInProgress) {
152131
if (contextClickInProgress || GodotInputHandler.isMouseEvent(event)) {
153132
// This may be an ACTION_BUTTON_RELEASE event which we don't handle,
154133
// so we convert it to an ACTION_UP event.
155-
GodotInputHandler.handleMouseEvent(
156-
MotionEvent.ACTION_UP,
157-
event.buttonState,
158-
event.x,
159-
event.y,
160-
0f,
161-
0f,
162-
false,
163-
sourceMouseRelative
164-
)
134+
GodotInputHandler.handleMouseEvent(event, MotionEvent.ACTION_UP)
165135
} else {
166136
GodotInputHandler.handleTouchEvent(event)
167137
}
@@ -178,21 +148,7 @@ internal class GodotGestureHandler : SimpleOnGestureListener(), OnScaleGestureLi
178148

179149
private fun onActionMove(event: MotionEvent): Boolean {
180150
if (contextClickInProgress) {
181-
val sourceMouseRelative = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
182-
event.isFromSource(InputDevice.SOURCE_MOUSE_RELATIVE)
183-
} else {
184-
false
185-
}
186-
GodotInputHandler.handleMouseEvent(
187-
event.actionMasked,
188-
MotionEvent.BUTTON_SECONDARY,
189-
event.x,
190-
event.y,
191-
0f,
192-
0f,
193-
false,
194-
sourceMouseRelative
195-
)
151+
GodotInputHandler.handleMouseEvent(event, event.actionMasked, MotionEvent.BUTTON_SECONDARY, false)
196152
return true
197153
} else if (!scaleInProgress) {
198154
// The 'onScroll' event is triggered with a long delay.
@@ -213,7 +169,7 @@ internal class GodotGestureHandler : SimpleOnGestureListener(), OnScaleGestureLi
213169
if (event.actionMasked == MotionEvent.ACTION_UP) {
214170
nextDownIsDoubleTap = false
215171
GodotInputHandler.handleMotionEvent(event)
216-
} else if (event.actionMasked == MotionEvent.ACTION_MOVE && panningAndScalingEnabled == false) {
172+
} else if (event.actionMasked == MotionEvent.ACTION_MOVE && !panningAndScalingEnabled) {
217173
GodotInputHandler.handleMotionEvent(event)
218174
}
219175

@@ -235,13 +191,7 @@ internal class GodotGestureHandler : SimpleOnGestureListener(), OnScaleGestureLi
235191
if (dragInProgress || lastDragX != 0.0f || lastDragY != 0.0f) {
236192
if (originEvent != null) {
237193
// Cancel the drag
238-
GodotInputHandler.handleMotionEvent(
239-
originEvent.source,
240-
MotionEvent.ACTION_CANCEL,
241-
originEvent.buttonState,
242-
originEvent.x,
243-
originEvent.y
244-
)
194+
GodotInputHandler.handleMotionEvent(originEvent, MotionEvent.ACTION_CANCEL)
245195
}
246196
dragInProgress = false
247197
lastDragX = 0.0f

0 commit comments

Comments
 (0)