From 44d1e21e4ca9227fa37c65ff26ab43d41ac22044 Mon Sep 17 00:00:00 2001 From: Xtr126 Date: Thu, 7 Mar 2024 22:23:26 +0530 Subject: [PATCH] fix: apply swipe delay when re-entering bounds Workaround for mouse aim lag issue #82 Swipe delay should be set to a non-zero value to be effective. --- .../java/xtr/keymapper/keymap/KeymapConfig.java | 2 +- .../java/xtr/keymapper/mouse/MouseAimHandler.java | 14 +++++++++++--- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/xtr/keymapper/keymap/KeymapConfig.java b/app/src/main/java/xtr/keymapper/keymap/KeymapConfig.java index 28b478df..3fe24143 100644 --- a/app/src/main/java/xtr/keymapper/keymap/KeymapConfig.java +++ b/app/src/main/java/xtr/keymapper/keymap/KeymapConfig.java @@ -108,7 +108,7 @@ private void loadSharedPrefs() { keyGraveMouseAim = sharedPref.getBoolean("key_grave_mouse_aim", true); rightClickMouseAim = sharedPref.getBoolean("right_click_mouse_aim", true); - swipeDelayMs = sharedPref.getInt("swipe_delay_ms", 0); + swipeDelayMs = sharedPref.getInt("swipe_delay_ms", 10); dpadRadiusMultiplier = sharedPref.getFloat("dpad_radius", 1f); touchpadInputMode = sharedPref.getString("touchpad_input_mode", TOUCHPAD_DISABLED); diff --git a/app/src/main/java/xtr/keymapper/mouse/MouseAimHandler.java b/app/src/main/java/xtr/keymapper/mouse/MouseAimHandler.java index d30c98ff..68c9a910 100644 --- a/app/src/main/java/xtr/keymapper/mouse/MouseAimHandler.java +++ b/app/src/main/java/xtr/keymapper/mouse/MouseAimHandler.java @@ -9,6 +9,8 @@ import static xtr.keymapper.server.InputService.UP; import android.graphics.RectF; +import android.os.Handler; +import android.os.Looper; import xtr.keymapper.server.IInputInterface; import xtr.keymapper.touchpointer.PointerId; @@ -21,11 +23,14 @@ public class MouseAimHandler { private IInputInterface service; private final int pointerIdMouse = PointerId.pid1.id; private final int pointerIdAim = PointerId.pid2.id; + private final Handler mHandler; + public MouseAimHandler(MouseAimConfig config){ currentX = config.xCenter; currentY = config.yCenter; this.config = config; + mHandler = new Handler(Looper.getMainLooper()); } public void setInterface(IInputInterface input) { @@ -47,10 +52,13 @@ public void setDimensions(int width, int height){ } public void resetPointer() { - currentY = config.yCenter; - currentX = config.xCenter; service.injectEvent(currentX, currentY, UP, pointerIdAim); - service.injectEvent(currentX, currentY, DOWN, pointerIdAim); + mHandler.postDelayed(() -> { + currentY = config.yCenter; + currentX = config.xCenter; + service.injectEvent(currentX, currentY, DOWN, pointerIdAim); + }, + service.getKeymapConfig().swipeDelayMs); } public void handleEvent(int code, int value, OnRightClick r) {