Always handle KEYCODE_BACK to prevent synthetic right-clicks on back. Possibly fixes #634

This commit is contained in:
Cameron Gutman 2018-10-24 19:25:47 -07:00
parent a9af4e54a9
commit cdcd4d48f2

View File

@ -840,11 +840,14 @@ public class Game extends Activity implements SurfaceHolder.Callback,
// 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 ((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) {
event.getRepeatCount() == 0 && // It appears this may get turned into a right-click pointer event
!gotBackPointerEvent) { // if we don't return true to indicate that we handled it on
syntheticBackDown = true; // some devices. https://github.com/moonlight-stream/moonlight-android/issues/634
conn.sendMouseButtonDown(MouseButtonPacket.BUTTON_RIGHT); if (event.getRepeatCount() == 0 && !gotBackPointerEvent) {
syntheticBackDown = true;
conn.sendMouseButtonDown(MouseButtonPacket.BUTTON_RIGHT);
}
return true; return true;
} }
@ -895,13 +898,17 @@ public class Game extends Activity implements SurfaceHolder.Callback,
// create as a result of a right-click. // create as a result of a right-click.
if ((event.getSource() == InputDevice.SOURCE_MOUSE || if ((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) {
(!gotBackPointerEvent || syntheticBackDown)) { // It appears this may get turned into a right-click pointer event
// We need to raise the button if gotBackPointerEvent is true // if we don't return true to indicate that we handled it on
// in the case where it transitioned to true after we already // some devices. https://github.com/moonlight-stream/moonlight-android/issues/634
// sent the right click down event. if (!gotBackPointerEvent || syntheticBackDown) {
syntheticBackDown = false; // We need to raise the button if gotBackPointerEvent is true
conn.sendMouseButtonUp(MouseButtonPacket.BUTTON_RIGHT); // 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;
} }