From cdcd4d48f2dcb168e4ffb54ba0da3e0f09976e8f Mon Sep 17 00:00:00 2001 From: Cameron Gutman Date: Wed, 24 Oct 2018 19:25:47 -0700 Subject: [PATCH] Always handle KEYCODE_BACK to prevent synthetic right-clicks on back. Possibly fixes #634 --- app/src/main/java/com/limelight/Game.java | 31 ++++++++++++++--------- 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/app/src/main/java/com/limelight/Game.java b/app/src/main/java/com/limelight/Game.java index 3621543f..9dee6686 100644 --- a/app/src/main/java/com/limelight/Game.java +++ b/app/src/main/java/com/limelight/Game.java @@ -840,11 +840,14 @@ public class Game extends Activity implements SurfaceHolder.Callback, // the right mouse button is held down, so we ignore those. if ((event.getSource() == InputDevice.SOURCE_MOUSE || event.getSource() == InputDevice.SOURCE_MOUSE_RELATIVE) && - event.getKeyCode() == KeyEvent.KEYCODE_BACK && - event.getRepeatCount() == 0 && - !gotBackPointerEvent) { - syntheticBackDown = true; - conn.sendMouseButtonDown(MouseButtonPacket.BUTTON_RIGHT); + event.getKeyCode() == KeyEvent.KEYCODE_BACK) { + // It appears this may get turned into a right-click pointer event + // if we don't return true to indicate that we handled it on + // some devices. https://github.com/moonlight-stream/moonlight-android/issues/634 + if (event.getRepeatCount() == 0 && !gotBackPointerEvent) { + syntheticBackDown = true; + conn.sendMouseButtonDown(MouseButtonPacket.BUTTON_RIGHT); + } return true; } @@ -895,13 +898,17 @@ 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 && - (!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); + event.getKeyCode() == KeyEvent.KEYCODE_BACK) { + // It appears this may get turned into a right-click pointer event + // if we don't return true to indicate that we handled it on + // some devices. https://github.com/moonlight-stream/moonlight-android/issues/634 + if (!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; }