From c6fe3c3de5cbda3e729884dccce2b5a15110fcb9 Mon Sep 17 00:00:00 2001 From: Mathias-Boulay Date: Fri, 29 Nov 2024 21:17:29 +0100 Subject: [PATCH] QoL(gesture): decouple gyroscope from long press gesture --- .../mouse/InGameEventProcessor.java | 8 +++++-- .../mouse/LeftClickGesture.java | 22 +++++++++++++++---- .../mouse/RightClickGesture.java | 9 ++++++-- 3 files changed, 31 insertions(+), 8 deletions(-) diff --git a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/customcontrols/mouse/InGameEventProcessor.java b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/customcontrols/mouse/InGameEventProcessor.java index f4e5fe7639..bc05007002 100644 --- a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/customcontrols/mouse/InGameEventProcessor.java +++ b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/customcontrols/mouse/InGameEventProcessor.java @@ -33,8 +33,12 @@ public boolean processTouchEvent(MotionEvent motionEvent) { case MotionEvent.ACTION_MOVE: mTracker.trackEvent(motionEvent); float[] motionVector = mTracker.getMotionVector(); - CallbackBridge.mouseX += (float) (motionVector[0] * mSensitivity); - CallbackBridge.mouseY += (float) (motionVector[1] * mSensitivity); + float deltaX = (float) (motionVector[0] * mSensitivity); + float deltaY = (float) (motionVector[1] * mSensitivity); + mLeftClickGesture.setMotion(deltaX, deltaY); + mRightClickGesture.setMotion(deltaX, deltaY); + CallbackBridge.mouseX += deltaX; + CallbackBridge.mouseY += deltaY; CallbackBridge.sendCursorPos(CallbackBridge.mouseX, CallbackBridge.mouseY); if(LauncherPreferences.PREF_DISABLE_GESTURES) break; checkGestures(); diff --git a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/customcontrols/mouse/LeftClickGesture.java b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/customcontrols/mouse/LeftClickGesture.java index d422ed6838..38ffef803b 100644 --- a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/customcontrols/mouse/LeftClickGesture.java +++ b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/customcontrols/mouse/LeftClickGesture.java @@ -13,7 +13,7 @@ public class LeftClickGesture extends ValidatorGesture { public static final int FINGER_STILL_THRESHOLD = (int) Tools.dpToPx(9); - private float mGestureStartX, mGestureStartY; + private float mGestureStartX, mGestureStartY, mGestureEndX, mGestureEndY; private boolean mMouseActivated; public LeftClickGesture(Handler handler) { @@ -22,14 +22,14 @@ public LeftClickGesture(Handler handler) { public final void inputEvent() { if(submit()) { - mGestureStartX = CallbackBridge.mouseX; - mGestureStartY = CallbackBridge.mouseY; + mGestureStartX = mGestureEndX = CallbackBridge.mouseX; + mGestureStartY = mGestureEndY = CallbackBridge.mouseY; } } @Override public boolean checkAndTrigger() { - boolean fingerStill = LeftClickGesture.isFingerStill(mGestureStartX, mGestureStartY, FINGER_STILL_THRESHOLD); + boolean fingerStill = LeftClickGesture.isFingerStill(mGestureStartX, mGestureStartY, mGestureEndX, mGestureEndY, FINGER_STILL_THRESHOLD); // If the finger is still, fire the gesture. if(fingerStill) { sendMouseButton(LwjglGlfwKeycode.GLFW_MOUSE_BUTTON_LEFT, true); @@ -47,6 +47,11 @@ public void onGestureCancelled(boolean isSwitching) { } } + public void setMotion(float deltaX, float deltaY) { + mGestureEndX += deltaX; + mGestureEndY += deltaY; + } + /** * Check if the finger is still when compared to mouseX/mouseY in CallbackBridge. * @param startX the starting X of the gesture @@ -61,4 +66,13 @@ public static boolean isFingerStill(float startX, float startY, float threshold) startY ) <= threshold; } + + public static boolean isFingerStill(float startX, float startY, float endX, float endY, float threshold) { + return MathUtils.dist( + endX, + endY, + startX, + startY + ) <= threshold; + } } diff --git a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/customcontrols/mouse/RightClickGesture.java b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/customcontrols/mouse/RightClickGesture.java index 75ccbba6c7..d24874f7ed 100644 --- a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/customcontrols/mouse/RightClickGesture.java +++ b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/customcontrols/mouse/RightClickGesture.java @@ -9,7 +9,7 @@ public class RightClickGesture extends ValidatorGesture{ private boolean mGestureEnabled = true; private boolean mGestureValid = true; - private float mGestureStartX, mGestureStartY; + private float mGestureStartX, mGestureStartY, mGestureEndX, mGestureEndY; public RightClickGesture(Handler mHandler) { super(mHandler, 150); } @@ -24,6 +24,11 @@ public final void inputEvent() { } } + public void setMotion(float deltaX, float deltaY) { + mGestureEndX += deltaX; + mGestureEndY += deltaY; + } + @Override public boolean checkAndTrigger() { // If the validate() method was called, it means that the user held on for too long. The cancellation should be ignored. @@ -38,7 +43,7 @@ public boolean checkAndTrigger() { public void onGestureCancelled(boolean isSwitching) { mGestureEnabled = true; if(!mGestureValid || isSwitching) return; - boolean fingerStill = LeftClickGesture.isFingerStill(mGestureStartX, mGestureStartY, LeftClickGesture.FINGER_STILL_THRESHOLD); + boolean fingerStill = LeftClickGesture.isFingerStill(mGestureStartX, mGestureStartY, mGestureEndX, mGestureEndY, LeftClickGesture.FINGER_STILL_THRESHOLD); if(!fingerStill) return; CallbackBridge.sendMouseButton(LwjglGlfwKeycode.GLFW_MOUSE_BUTTON_RIGHT, true); CallbackBridge.sendMouseButton(LwjglGlfwKeycode.GLFW_MOUSE_BUTTON_RIGHT, false);