From 773c23fda298fd3dace4ded5a89e8716d3c0fc76 Mon Sep 17 00:00:00 2001 From: Romain Vimont Date: Fri, 2 Aug 2024 20:20:12 +0200 Subject: [PATCH] Inject finger input whenever possible Even if the pointer is a mouse, inject it as a finger unless it is required to be a mouse, that is: - when it is a HOVER_MOUSE event, or - when a secondary button is pressed. Some apps/games only accept events from a finger/touchscreen, so using a mouse by default does not work for them. For simplicity, make this change on the server side just before event injection (so that the client does not need to know about this hacky behavior). Refs 6808288823239b0f3a76f9be377e4de82e91b35a Refs c7b1d0ea9af8bb9603ec8f713f1a5fbf3f628b6a Fixes #5162 Fixes #5163 --- .../main/java/com/genymobile/scrcpy/control/Controller.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/server/src/main/java/com/genymobile/scrcpy/control/Controller.java b/server/src/main/java/com/genymobile/scrcpy/control/Controller.java index 85425113a8..1494c10af3 100644 --- a/server/src/main/java/com/genymobile/scrcpy/control/Controller.java +++ b/server/src/main/java/com/genymobile/scrcpy/control/Controller.java @@ -278,8 +278,9 @@ private boolean injectTouch(int action, long pointerId, Position position, float pointer.setPressure(pressure); int source; - if (pointerId == POINTER_ID_MOUSE) { - // real mouse event + boolean activeSecondaryButtons = ((actionButton | buttons) & ~MotionEvent.BUTTON_PRIMARY) != 0; + if (pointerId == POINTER_ID_MOUSE && (action == MotionEvent.ACTION_HOVER_MOVE || activeSecondaryButtons)) { + // real mouse event, or event incompatible with a finger pointerProperties[pointerIndex].toolType = MotionEvent.TOOL_TYPE_MOUSE; source = InputDevice.SOURCE_MOUSE; pointer.setUp(buttons == 0);