Create toggle for back and forward mouse support

This commit is contained in:
Cameron Gutman 2018-11-30 18:37:36 -08:00
parent 213414778e
commit 795f0a013b
4 changed files with 27 additions and 42 deletions

View File

@ -105,8 +105,6 @@ public class Game extends Activity implements SurfaceHolder.Callback,
private boolean grabbedInput = true; private boolean grabbedInput = true;
private boolean grabComboDown = false; private boolean grabComboDown = false;
private StreamView streamView; private StreamView streamView;
private boolean gotBackPointerEvent = false;
private boolean syntheticBackDown = false;
private ShortcutHelper shortcutHelper; 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 // Handle a synthetic back button event that some Android OS versions
// create as a result of a right-click. This event WILL repeat if // create as a result of a right-click. This event WILL repeat if
// the right mouse button is held down, so we ignore those. // 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.getSource() == InputDevice.SOURCE_MOUSE_RELATIVE) &&
event.getKeyCode() == KeyEvent.KEYCODE_BACK) { event.getKeyCode() == KeyEvent.KEYCODE_BACK) {
// It appears this may get turned into a right-click pointer event conn.sendMouseButtonDown(MouseButtonPacket.BUTTON_RIGHT);
// 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; 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 // Handle a synthetic back button event that some Android OS versions
// create as a result of a right-click. // 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.getSource() == InputDevice.SOURCE_MOUSE_RELATIVE) &&
event.getKeyCode() == KeyEvent.KEYCODE_BACK) { event.getKeyCode() == KeyEvent.KEYCODE_BACK) {
// It appears this may get turned into a right-click pointer event conn.sendMouseButtonUp(MouseButtonPacket.BUTTON_RIGHT);
// 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; return true;
} }
@ -1013,11 +998,6 @@ public class Game extends Activity implements SurfaceHolder.Callback,
else { else {
conn.sendMouseButtonUp(MouseButtonPacket.BUTTON_RIGHT); 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) { 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 if (prefConfig.mouseNavButtons) {
// issues with right clicks triggering it.
if (!("Xiaomi".equalsIgnoreCase(Build.MANUFACTURER))) {
if ((changedButtons & MotionEvent.BUTTON_BACK) != 0) { if ((changedButtons & MotionEvent.BUTTON_BACK) != 0) {
if ((event.getButtonState() & MotionEvent.BUTTON_BACK) != 0) { if ((event.getButtonState() & MotionEvent.BUTTON_BACK) != 0) {
conn.sendMouseButtonDown(MouseButtonPacket.BUTTON_X1); conn.sendMouseButtonDown(MouseButtonPacket.BUTTON_X1);
@ -1039,19 +1017,15 @@ public class Game extends Activity implements SurfaceHolder.Callback,
else { else {
conn.sendMouseButtonUp(MouseButtonPacket.BUTTON_X1); 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 ((changedButtons & MotionEvent.BUTTON_FORWARD) != 0) {
if ((event.getButtonState() & MotionEvent.BUTTON_FORWARD) != 0) { if ((event.getButtonState() & MotionEvent.BUTTON_FORWARD) != 0) {
conn.sendMouseButtonDown(MouseButtonPacket.BUTTON_X2); conn.sendMouseButtonDown(MouseButtonPacket.BUTTON_X2);
} }
else { else {
conn.sendMouseButtonUp(MouseButtonPacket.BUTTON_X2); conn.sendMouseButtonUp(MouseButtonPacket.BUTTON_X2);
}
} }
} }

View File

@ -33,6 +33,7 @@ public class PreferenceConfiguration {
private static final String ENABLE_PIP_PREF_STRING = "checkbox_enable_pip"; 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 BIND_ALL_USB_STRING = "checkbox_usb_bind_all";
private static final String MOUSE_EMULATION_STRING = "checkbox_mouse_emulation"; 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_RESOLUTION = "720p";
static final String DEFAULT_FPS = "60"; 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_ENABLE_PIP = false;
private static final boolean DEFAULT_BIND_ALL_USB = false; private static final boolean DEFAULT_BIND_ALL_USB = false;
private static final boolean DEFAULT_MOUSE_EMULATION = true; 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 FORCE_H265_ON = -1;
public static final int AUTOSELECT_H265 = 0; public static final int AUTOSELECT_H265 = 0;
@ -73,6 +75,7 @@ public class PreferenceConfiguration {
public boolean enablePip; public boolean enablePip;
public boolean bindAllUsb; public boolean bindAllUsb;
public boolean mouseEmulation; public boolean mouseEmulation;
public boolean mouseNavButtons;
private static int getHeightFromResolutionString(String resString) { private static int getHeightFromResolutionString(String resString) {
if (resString.equalsIgnoreCase("360p")) { if (resString.equalsIgnoreCase("360p")) {
@ -305,6 +308,7 @@ public class PreferenceConfiguration {
config.enablePip = prefs.getBoolean(ENABLE_PIP_PREF_STRING, DEFAULT_ENABLE_PIP); config.enablePip = prefs.getBoolean(ENABLE_PIP_PREF_STRING, DEFAULT_ENABLE_PIP);
config.bindAllUsb = prefs.getBoolean(BIND_ALL_USB_STRING, DEFAULT_BIND_ALL_USB); config.bindAllUsb = prefs.getBoolean(BIND_ALL_USB_STRING, DEFAULT_BIND_ALL_USB);
config.mouseEmulation = prefs.getBoolean(MOUSE_EMULATION_STRING, DEFAULT_MOUSE_EMULATION); config.mouseEmulation = prefs.getBoolean(MOUSE_EMULATION_STRING, DEFAULT_MOUSE_EMULATION);
config.mouseNavButtons = prefs.getBoolean(MOUSE_NAV_BUTTONS_STRING, DEFAULT_MOUSE_NAV_BUTTONS);
return config; return config;
} }

View File

@ -131,7 +131,7 @@
<string name="title_checkbox_51_surround">Enable 5.1 surround sound</string> <string name="title_checkbox_51_surround">Enable 5.1 surround sound</string>
<string name="summary_checkbox_51_surround">Uncheck if you experience audio issues. Requires GFE 2.7 or higher.</string> <string name="summary_checkbox_51_surround">Uncheck if you experience audio issues. Requires GFE 2.7 or higher.</string>
<string name="category_gamepad_settings">Gamepad Settings</string> <string name="category_input_settings">Input Settings</string>
<string name="title_checkbox_multi_controller">Automatic gamepad presence detection</string> <string name="title_checkbox_multi_controller">Automatic gamepad presence detection</string>
<string name="summary_checkbox_multi_controller">Unchecking this option forces a gamepad to always be present</string> <string name="summary_checkbox_multi_controller">Unchecking this option forces a gamepad to always be present</string>
<string name="title_seekbar_deadzone">Adjust analog stick deadzone</string> <string name="title_seekbar_deadzone">Adjust analog stick deadzone</string>
@ -142,6 +142,8 @@
<string name="summary_checkbox_usb_bind_all">Forces Moonlight\'s USB driver to take over all supported Xbox gamepads</string> <string name="summary_checkbox_usb_bind_all">Forces Moonlight\'s USB driver to take over all supported Xbox gamepads</string>
<string name="title_checkbox_mouse_emulation">Mouse emulation via gamepad</string> <string name="title_checkbox_mouse_emulation">Mouse emulation via gamepad</string>
<string name="summary_checkbox_mouse_emulation">Long pressing the Start button will switch the gamepad into mouse mode</string> <string name="summary_checkbox_mouse_emulation">Long pressing the Start button will switch the gamepad into mouse mode</string>
<string name="title_checkbox_mouse_nav_buttons">Enable back and forward mouse buttons</string>
<string name="summary_checkbox_mouse_nav_buttons">Enabling this option may break right clicking on some buggy devices</string>
<string name="category_on_screen_controls_settings">On-screen Controls Settings</string> <string name="category_on_screen_controls_settings">On-screen Controls Settings</string>
<string name="title_checkbox_show_onscreen_controls">Show on-screen controls</string> <string name="title_checkbox_show_onscreen_controls">Show on-screen controls</string>

View File

@ -44,7 +44,7 @@
android:summary="@string/summary_checkbox_51_surround" android:summary="@string/summary_checkbox_51_surround"
android:defaultValue="false" /> android:defaultValue="false" />
</PreferenceCategory> </PreferenceCategory>
<PreferenceCategory android:title="@string/category_gamepad_settings"> <PreferenceCategory android:title="@string/category_input_settings">
<!--com.limelight.preferences.SeekBarPreference <!--com.limelight.preferences.SeekBarPreference
android:key="seekbar_deadzone" android:key="seekbar_deadzone"
android:defaultValue="15" android:defaultValue="15"
@ -56,6 +56,11 @@
android:title="@string/title_checkbox_multi_controller" android:title="@string/title_checkbox_multi_controller"
android:summary="@string/summary_checkbox_multi_controller" android:summary="@string/summary_checkbox_multi_controller"
android:defaultValue="true" /> android:defaultValue="true" />
<CheckBoxPreference
android:key="checkbox_mouse_nav_buttons"
android:title="@string/title_checkbox_mouse_nav_buttons"
android:summary="@string/summary_checkbox_mouse_nav_buttons"
android:defaultValue="false" />
<CheckBoxPreference <CheckBoxPreference
android:key="checkbox_usb_driver" android:key="checkbox_usb_driver"
android:title="@string/title_checkbox_xb1_driver" android:title="@string/title_checkbox_xb1_driver"