You've already forked godot
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:
committed by
Rémi Verschelde
parent
69faae9b36
commit
bdf4f38ac4
@@ -337,7 +337,7 @@ void AndroidInputHandler::process_mouse_event(int p_event_action, int p_event_an
|
|||||||
} break;
|
} break;
|
||||||
|
|
||||||
case AMOTION_EVENT_ACTION_MOVE: {
|
case AMOTION_EVENT_ACTION_MOVE: {
|
||||||
if (!mouse_event_info.valid) {
|
if (!p_source_mouse_relative && !mouse_event_info.valid) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -59,6 +59,7 @@ import androidx.annotation.NonNull;
|
|||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handles input related events for the {@link GodotRenderView} view.
|
* 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.
|
* 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;
|
private int rotaryInputAxis = ROTARY_INPUT_VERTICAL_AXIS;
|
||||||
|
|
||||||
@@ -149,7 +150,8 @@ public class GodotInputHandler implements InputManager.InputDeviceListener, Sens
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean canCapturePointer() {
|
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) {
|
public void onPointerCaptureChange(boolean hasCapture) {
|
||||||
@@ -210,7 +212,7 @@ public class GodotInputHandler implements InputManager.InputDeviceListener, Sens
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean onTouchEvent(final MotionEvent event) {
|
public boolean onTouchEvent(final MotionEvent event) {
|
||||||
lastSeenToolType = getEventToolType(event);
|
lastSeenToolType.set(getEventToolType(event));
|
||||||
|
|
||||||
this.scaleGestureDetector.onTouchEvent(event);
|
this.scaleGestureDetector.onTouchEvent(event);
|
||||||
if (this.gestureDetector.onTouchEvent(event)) {
|
if (this.gestureDetector.onTouchEvent(event)) {
|
||||||
@@ -236,7 +238,7 @@ public class GodotInputHandler implements InputManager.InputDeviceListener, Sens
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean onGenericMotionEvent(MotionEvent event) {
|
public boolean onGenericMotionEvent(MotionEvent event) {
|
||||||
lastSeenToolType = getEventToolType(event);
|
lastSeenToolType.set(getEventToolType(event));
|
||||||
|
|
||||||
if (event.isFromSource(InputDevice.SOURCE_JOYSTICK) && event.getActionMasked() == MotionEvent.ACTION_MOVE) {
|
if (event.isFromSource(InputDevice.SOURCE_JOYSTICK) && event.getActionMasked() == MotionEvent.ACTION_MOVE) {
|
||||||
// Check if the device exists
|
// Check if the device exists
|
||||||
|
|||||||
Reference in New Issue
Block a user