mirror of
https://github.com/moonlight-stream/moonlight-android.git
synced 2026-06-17 14:21:08 +00:00
Fix unmapped paddle and share button presses
This commit is contained in:
@@ -1052,13 +1052,25 @@ public class ControllerHandler implements InputManager.InputDeviceListener, UsbD
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return a valid keycode, 0 to consume, or -1 to not consume the event
|
private final int REMAP_IGNORE = -1;
|
||||||
|
private final int REMAP_CONSUME = -2;
|
||||||
|
|
||||||
|
// Return a valid keycode, -2 to consume, or -1 to not consume the event
|
||||||
// Device MAY BE NULL
|
// Device MAY BE NULL
|
||||||
private int handleRemapping(InputDeviceContext context, KeyEvent event) {
|
private int handleRemapping(InputDeviceContext context, KeyEvent event) {
|
||||||
// Don't capture the back button if configured
|
// Don't capture the back button if configured
|
||||||
if (context.ignoreBack) {
|
if (context.ignoreBack) {
|
||||||
if (event.getKeyCode() == KeyEvent.KEYCODE_BACK) {
|
if (event.getKeyCode() == KeyEvent.KEYCODE_BACK) {
|
||||||
return -1;
|
return REMAP_IGNORE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// If we know this gamepad has a share button and receive an unmapped
|
||||||
|
// KEY_RECORD event, report that as a share button press.
|
||||||
|
if (context.hasShare) {
|
||||||
|
if (event.getKeyCode() == KeyEvent.KEYCODE_UNKNOWN &&
|
||||||
|
event.getScanCode() == 167) {
|
||||||
|
return KeyEvent.KEYCODE_MEDIA_RECORD;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1148,7 +1160,7 @@ public class ControllerHandler implements InputManager.InputDeviceListener, UsbD
|
|||||||
case 316:
|
case 316:
|
||||||
return KeyEvent.KEYCODE_BUTTON_MODE;
|
return KeyEvent.KEYCODE_BUTTON_MODE;
|
||||||
default:
|
default:
|
||||||
return 0;
|
return REMAP_CONSUME;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// If this is a Serval controller sending an unknown key code, it's probably
|
// If this is a Serval controller sending an unknown key code, it's probably
|
||||||
@@ -1904,15 +1916,14 @@ public class ControllerHandler implements InputManager.InputDeviceListener, UsbD
|
|||||||
}
|
}
|
||||||
|
|
||||||
int keyCode = handleRemapping(context, event);
|
int keyCode = handleRemapping(context, event);
|
||||||
|
if (keyCode < 0) {
|
||||||
|
return (keyCode == REMAP_CONSUME);
|
||||||
|
}
|
||||||
|
|
||||||
if (prefConfig.flipFaceButtons) {
|
if (prefConfig.flipFaceButtons) {
|
||||||
keyCode = handleFlipFaceButtons(keyCode);
|
keyCode = handleFlipFaceButtons(keyCode);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (keyCode == 0) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// If the button hasn't been down long enough, sleep for a bit before sending the up event
|
// If the button hasn't been down long enough, sleep for a bit before sending the up event
|
||||||
// This allows "instant" button presses (like OUYA's virtual menu button) to work. This
|
// This allows "instant" button presses (like OUYA's virtual menu button) to work. This
|
||||||
// path should not be triggered during normal usage.
|
// path should not be triggered during normal usage.
|
||||||
@@ -2056,9 +2067,10 @@ public class ControllerHandler implements InputManager.InputDeviceListener, UsbD
|
|||||||
}
|
}
|
||||||
context.rightTrigger = 0;
|
context.rightTrigger = 0;
|
||||||
break;
|
break;
|
||||||
default:
|
case KeyEvent.KEYCODE_UNKNOWN:
|
||||||
// Paddles aren't mapped in any of the Android key layout files,
|
// Paddles aren't mapped in any of the Android key layout files,
|
||||||
// so we need to handle the evdev key codes directly.
|
// so we need to handle the evdev key codes directly.
|
||||||
|
if (context.hasPaddles) {
|
||||||
switch (event.getScanCode()) {
|
switch (event.getScanCode()) {
|
||||||
case 0x2c4: // BTN_TRIGGER_HAPPY5
|
case 0x2c4: // BTN_TRIGGER_HAPPY5
|
||||||
context.inputMap &= ~ControllerPacket.PADDLE1_FLAG;
|
context.inputMap &= ~ControllerPacket.PADDLE1_FLAG;
|
||||||
@@ -2076,6 +2088,13 @@ public class ControllerHandler implements InputManager.InputDeviceListener, UsbD
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
// Check if we're emulating the select button
|
// Check if we're emulating the select button
|
||||||
if ((context.emulatingButtonFlags & ControllerHandler.EMULATING_SELECT) != 0)
|
if ((context.emulatingButtonFlags & ControllerHandler.EMULATING_SELECT) != 0)
|
||||||
@@ -2121,15 +2140,14 @@ public class ControllerHandler implements InputManager.InputDeviceListener, UsbD
|
|||||||
}
|
}
|
||||||
|
|
||||||
int keyCode = handleRemapping(context, event);
|
int keyCode = handleRemapping(context, event);
|
||||||
|
if (keyCode < 0) {
|
||||||
|
return (keyCode == REMAP_CONSUME);
|
||||||
|
}
|
||||||
|
|
||||||
if (prefConfig.flipFaceButtons) {
|
if (prefConfig.flipFaceButtons) {
|
||||||
keyCode = handleFlipFaceButtons(keyCode);
|
keyCode = handleFlipFaceButtons(keyCode);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (keyCode == 0) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
switch (keyCode) {
|
switch (keyCode) {
|
||||||
case KeyEvent.KEYCODE_BUTTON_MODE:
|
case KeyEvent.KEYCODE_BUTTON_MODE:
|
||||||
context.hasMode = true;
|
context.hasMode = true;
|
||||||
@@ -2248,9 +2266,10 @@ public class ControllerHandler implements InputManager.InputDeviceListener, UsbD
|
|||||||
}
|
}
|
||||||
context.rightTrigger = (byte)0xFF;
|
context.rightTrigger = (byte)0xFF;
|
||||||
break;
|
break;
|
||||||
default:
|
case KeyEvent.KEYCODE_UNKNOWN:
|
||||||
// Paddles aren't mapped in any of the Android key layout files,
|
// Paddles aren't mapped in any of the Android key layout files,
|
||||||
// so we need to handle the evdev key codes directly.
|
// so we need to handle the evdev key codes directly.
|
||||||
|
if (context.hasPaddles) {
|
||||||
switch (event.getScanCode()) {
|
switch (event.getScanCode()) {
|
||||||
case 0x2c4: // BTN_TRIGGER_HAPPY5
|
case 0x2c4: // BTN_TRIGGER_HAPPY5
|
||||||
context.inputMap |= ControllerPacket.PADDLE1_FLAG;
|
context.inputMap |= ControllerPacket.PADDLE1_FLAG;
|
||||||
@@ -2268,6 +2287,13 @@ public class ControllerHandler implements InputManager.InputDeviceListener, UsbD
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
// Start+Back+LB+RB is the quit combo
|
// Start+Back+LB+RB is the quit combo
|
||||||
if (context.inputMap == (ControllerPacket.BACK_FLAG | ControllerPacket.PLAY_FLAG |
|
if (context.inputMap == (ControllerPacket.BACK_FLAG | ControllerPacket.PLAY_FLAG |
|
||||||
|
|||||||
Reference in New Issue
Block a user