1
0
mirror of https://github.com/godotengine/godot.git synced 2025-11-05 12:10:55 +00:00

Fix Android mouse capture issues

- Allow mouse capture to be enabled in `_ready`
- Update the input handler logic to avoid dropping mouse captured motion events

(cherry picked from commit bea6472ea4)
This commit is contained in:
Fredia Huya-Kouadio
2025-02-28 13:54:30 -08:00
committed by Rémi Verschelde
parent 69faae9b36
commit bdf4f38ac4
2 changed files with 7 additions and 5 deletions

View File

@@ -337,7 +337,7 @@ void AndroidInputHandler::process_mouse_event(int p_event_action, int p_event_an
} break;
case AMOTION_EVENT_ACTION_MOVE: {
if (!mouse_event_info.valid) {
if (!p_source_mouse_relative && !mouse_event_info.valid) {
return;
}

View File

@@ -59,6 +59,7 @@ import androidx.annotation.NonNull;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
import java.util.concurrent.atomic.AtomicInteger;
/**
* Handles input related events for the {@link GodotRenderView} view.
@@ -83,7 +84,7 @@ public class GodotInputHandler implements InputManager.InputDeviceListener, Sens
/**
* Used to decide whether mouse capture can be enabled.
*/
private int lastSeenToolType = MotionEvent.TOOL_TYPE_UNKNOWN;
private AtomicInteger lastSeenToolType = new AtomicInteger(MotionEvent.TOOL_TYPE_UNKNOWN);
private int rotaryInputAxis = ROTARY_INPUT_VERTICAL_AXIS;
@@ -149,7 +150,8 @@ public class GodotInputHandler implements InputManager.InputDeviceListener, Sens
}
public boolean canCapturePointer() {
return lastSeenToolType == MotionEvent.TOOL_TYPE_MOUSE;
return lastSeenToolType.get() == MotionEvent.TOOL_TYPE_MOUSE ||
lastSeenToolType.get() == MotionEvent.TOOL_TYPE_UNKNOWN;
}
public void onPointerCaptureChange(boolean hasCapture) {
@@ -210,7 +212,7 @@ public class GodotInputHandler implements InputManager.InputDeviceListener, Sens
}
public boolean onTouchEvent(final MotionEvent event) {
lastSeenToolType = getEventToolType(event);
lastSeenToolType.set(getEventToolType(event));
this.scaleGestureDetector.onTouchEvent(event);
if (this.gestureDetector.onTouchEvent(event)) {
@@ -236,7 +238,7 @@ public class GodotInputHandler implements InputManager.InputDeviceListener, Sens
}
public boolean onGenericMotionEvent(MotionEvent event) {
lastSeenToolType = getEventToolType(event);
lastSeenToolType.set(getEventToolType(event));
if (event.isFromSource(InputDevice.SOURCE_JOYSTICK) && event.getActionMasked() == MotionEvent.ACTION_MOVE) {
// Check if the device exists