From 64de13ab50fb02184452dbe50707f5acccb40c37 Mon Sep 17 00:00:00 2001 From: Cameron Gutman Date: Fri, 5 Oct 2018 01:29:18 -0700 Subject: [PATCH] Try to disambiguate right clicks from back presses --- app/src/main/java/com/limelight/Game.java | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/com/limelight/Game.java b/app/src/main/java/com/limelight/Game.java index 7a356dbe..3621543f 100644 --- a/app/src/main/java/com/limelight/Game.java +++ b/app/src/main/java/com/limelight/Game.java @@ -105,6 +105,8 @@ public class Game extends Activity implements SurfaceHolder.Callback, private boolean grabbedInput = true; private boolean grabComboDown = false; private StreamView streamView; + private boolean gotBackPointerEvent = false; + private boolean syntheticBackDown = false; private ShortcutHelper shortcutHelper; @@ -839,7 +841,9 @@ public class Game extends Activity implements SurfaceHolder.Callback, if ((event.getSource() == InputDevice.SOURCE_MOUSE || event.getSource() == InputDevice.SOURCE_MOUSE_RELATIVE) && event.getKeyCode() == KeyEvent.KEYCODE_BACK && - event.getRepeatCount() == 0) { + event.getRepeatCount() == 0 && + !gotBackPointerEvent) { + syntheticBackDown = true; conn.sendMouseButtonDown(MouseButtonPacket.BUTTON_RIGHT); return true; } @@ -891,7 +895,12 @@ public class Game extends Activity implements SurfaceHolder.Callback, // create as a result of a right-click. if ((event.getSource() == InputDevice.SOURCE_MOUSE || event.getSource() == InputDevice.SOURCE_MOUSE_RELATIVE) && - event.getKeyCode() == KeyEvent.KEYCODE_BACK) { + event.getKeyCode() == KeyEvent.KEYCODE_BACK && + (!gotBackPointerEvent || syntheticBackDown)) { + // We need to raise the button if gotBackPointerEvent is true + // in the case where it transitioned to true after we already + // sent the right click down event. + syntheticBackDown = false; conn.sendMouseButtonUp(MouseButtonPacket.BUTTON_RIGHT); return true; } @@ -999,6 +1008,11 @@ public class Game extends Activity implements SurfaceHolder.Callback, else { conn.sendMouseButtonUp(MouseButtonPacket.BUTTON_RIGHT); } + + // Don't use the KEYCODE_BACK hack (which interferes with mice + // with actual back buttons) since we're getting right clicks + // using this callback. + gotBackPointerEvent = true; } if ((changedButtons & MotionEvent.BUTTON_TERTIARY) != 0) { @@ -1017,6 +1031,10 @@ public class Game extends Activity implements SurfaceHolder.Callback, else { conn.sendMouseButtonUp(MouseButtonPacket.BUTTON_X1); } + + // Don't use the KEYCODE_BACK hack. That will cause this + // button press to trigger a right-click. + gotBackPointerEvent = true; } if ((changedButtons & MotionEvent.BUTTON_FORWARD) != 0) {