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.
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;
}