From 795f0a013b7e24d4f5b927d2312ed165098aa51d Mon Sep 17 00:00:00 2001 From: Cameron Gutman Date: Fri, 30 Nov 2018 18:37:36 -0800 Subject: [PATCH] Create toggle for back and forward mouse support --- app/src/main/java/com/limelight/Game.java | 54 +++++-------------- .../preferences/PreferenceConfiguration.java | 4 ++ app/src/main/res/values/strings.xml | 4 +- app/src/main/res/xml/preferences.xml | 7 ++- 4 files changed, 27 insertions(+), 42 deletions(-) diff --git a/app/src/main/java/com/limelight/Game.java b/app/src/main/java/com/limelight/Game.java index e4554cf7..1d4b15eb 100644 --- a/app/src/main/java/com/limelight/Game.java +++ b/app/src/main/java/com/limelight/Game.java @@ -105,8 +105,6 @@ 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; @@ -836,16 +834,11 @@ public class Game extends Activity implements SurfaceHolder.Callback, // Handle a synthetic back button event that some Android OS versions // create as a result of a right-click. This event WILL repeat if // the right mouse button is held down, so we ignore those. - if ((event.getSource() == InputDevice.SOURCE_MOUSE || + if (!prefConfig.mouseNavButtons && + (event.getSource() == InputDevice.SOURCE_MOUSE || event.getSource() == InputDevice.SOURCE_MOUSE_RELATIVE) && 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); - } + conn.sendMouseButtonDown(MouseButtonPacket.BUTTON_RIGHT); return true; } @@ -894,19 +887,11 @@ public class Game extends Activity implements SurfaceHolder.Callback, // Handle a synthetic back button event that some Android OS versions // create as a result of a right-click. - if ((event.getSource() == InputDevice.SOURCE_MOUSE || + if (!prefConfig.mouseNavButtons && + (event.getSource() == InputDevice.SOURCE_MOUSE || event.getSource() == InputDevice.SOURCE_MOUSE_RELATIVE) && 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); - } + conn.sendMouseButtonUp(MouseButtonPacket.BUTTON_RIGHT); return true; } @@ -1013,11 +998,6 @@ 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) { @@ -1029,9 +1009,7 @@ public class Game extends Activity implements SurfaceHolder.Callback, } } - // HACK: Disable mouse back button press on Xiaomi due to reported - // issues with right clicks triggering it. - if (!("Xiaomi".equalsIgnoreCase(Build.MANUFACTURER))) { + if (prefConfig.mouseNavButtons) { if ((changedButtons & MotionEvent.BUTTON_BACK) != 0) { if ((event.getButtonState() & MotionEvent.BUTTON_BACK) != 0) { conn.sendMouseButtonDown(MouseButtonPacket.BUTTON_X1); @@ -1039,19 +1017,15 @@ 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) { - if ((event.getButtonState() & MotionEvent.BUTTON_FORWARD) != 0) { - conn.sendMouseButtonDown(MouseButtonPacket.BUTTON_X2); - } - else { - conn.sendMouseButtonUp(MouseButtonPacket.BUTTON_X2); + if ((changedButtons & MotionEvent.BUTTON_FORWARD) != 0) { + if ((event.getButtonState() & MotionEvent.BUTTON_FORWARD) != 0) { + conn.sendMouseButtonDown(MouseButtonPacket.BUTTON_X2); + } + else { + conn.sendMouseButtonUp(MouseButtonPacket.BUTTON_X2); + } } } diff --git a/app/src/main/java/com/limelight/preferences/PreferenceConfiguration.java b/app/src/main/java/com/limelight/preferences/PreferenceConfiguration.java index 8f56cab1..2907eb10 100644 --- a/app/src/main/java/com/limelight/preferences/PreferenceConfiguration.java +++ b/app/src/main/java/com/limelight/preferences/PreferenceConfiguration.java @@ -33,6 +33,7 @@ public class PreferenceConfiguration { private static final String ENABLE_PIP_PREF_STRING = "checkbox_enable_pip"; private static final String BIND_ALL_USB_STRING = "checkbox_usb_bind_all"; private static final String MOUSE_EMULATION_STRING = "checkbox_mouse_emulation"; + private static final String MOUSE_NAV_BUTTONS_STRING = "checkbox_mouse_nav_buttons"; static final String DEFAULT_RESOLUTION = "720p"; static final String DEFAULT_FPS = "60"; @@ -54,6 +55,7 @@ public class PreferenceConfiguration { private static final boolean DEFAULT_ENABLE_PIP = false; private static final boolean DEFAULT_BIND_ALL_USB = false; private static final boolean DEFAULT_MOUSE_EMULATION = true; + private static final boolean DEFAULT_MOUSE_NAV_BUTTONS = false; public static final int FORCE_H265_ON = -1; public static final int AUTOSELECT_H265 = 0; @@ -73,6 +75,7 @@ public class PreferenceConfiguration { public boolean enablePip; public boolean bindAllUsb; public boolean mouseEmulation; + public boolean mouseNavButtons; private static int getHeightFromResolutionString(String resString) { if (resString.equalsIgnoreCase("360p")) { @@ -305,6 +308,7 @@ public class PreferenceConfiguration { config.enablePip = prefs.getBoolean(ENABLE_PIP_PREF_STRING, DEFAULT_ENABLE_PIP); config.bindAllUsb = prefs.getBoolean(BIND_ALL_USB_STRING, DEFAULT_BIND_ALL_USB); config.mouseEmulation = prefs.getBoolean(MOUSE_EMULATION_STRING, DEFAULT_MOUSE_EMULATION); + config.mouseNavButtons = prefs.getBoolean(MOUSE_NAV_BUTTONS_STRING, DEFAULT_MOUSE_NAV_BUTTONS); return config; } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 5989293d..a01ed908 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -131,7 +131,7 @@ Enable 5.1 surround sound Uncheck if you experience audio issues. Requires GFE 2.7 or higher. - Gamepad Settings + Input Settings Automatic gamepad presence detection Unchecking this option forces a gamepad to always be present Adjust analog stick deadzone @@ -142,6 +142,8 @@ Forces Moonlight\'s USB driver to take over all supported Xbox gamepads Mouse emulation via gamepad Long pressing the Start button will switch the gamepad into mouse mode + Enable back and forward mouse buttons + Enabling this option may break right clicking on some buggy devices On-screen Controls Settings Show on-screen controls diff --git a/app/src/main/res/xml/preferences.xml b/app/src/main/res/xml/preferences.xml index 993c5048..1f450b80 100644 --- a/app/src/main/res/xml/preferences.xml +++ b/app/src/main/res/xml/preferences.xml @@ -44,7 +44,7 @@ android:summary="@string/summary_checkbox_51_surround" android:defaultValue="false" /> - +