From 87a9ca43183b02348714ea71f7642d8a67d6838a Mon Sep 17 00:00:00 2001 From: Cameron Gutman Date: Sat, 10 Oct 2015 19:17:19 -0700 Subject: [PATCH] Make touchscreen and stylus support more robust (supporting Bluetooth stylus in 6.0 and hopefully fixing broken touchscreen input on some devices) --- app/src/main/java/com/limelight/Game.java | 104 ++++++++++------------ 1 file changed, 49 insertions(+), 55 deletions(-) diff --git a/app/src/main/java/com/limelight/Game.java b/app/src/main/java/com/limelight/Game.java index cbacd327..4f1ef88d 100644 --- a/app/src/main/java/com/limelight/Game.java +++ b/app/src/main/java/com/limelight/Game.java @@ -520,9 +520,56 @@ public class Game extends Activity implements SurfaceHolder.Callback, } else if ((event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0) { + // This case is for mice + if (event.getSource() == InputDevice.SOURCE_MOUSE) + { + int changedButtons = event.getButtonState() ^ lastButtonState; + + if (event.getActionMasked() == MotionEvent.ACTION_SCROLL) { + // Send the vertical scroll packet + byte vScrollClicks = (byte) event.getAxisValue(MotionEvent.AXIS_VSCROLL); + conn.sendMouseScroll(vScrollClicks); + } + + if ((changedButtons & MotionEvent.BUTTON_PRIMARY) != 0) { + if ((event.getButtonState() & MotionEvent.BUTTON_PRIMARY) != 0) { + conn.sendMouseButtonDown(MouseButtonPacket.BUTTON_LEFT); + } + else { + conn.sendMouseButtonUp(MouseButtonPacket.BUTTON_LEFT); + } + } + + if ((changedButtons & MotionEvent.BUTTON_SECONDARY) != 0) { + if ((event.getButtonState() & MotionEvent.BUTTON_SECONDARY) != 0) { + conn.sendMouseButtonDown(MouseButtonPacket.BUTTON_RIGHT); + } + else { + conn.sendMouseButtonUp(MouseButtonPacket.BUTTON_RIGHT); + } + } + + if ((changedButtons & MotionEvent.BUTTON_TERTIARY) != 0) { + if ((event.getButtonState() & MotionEvent.BUTTON_TERTIARY) != 0) { + conn.sendMouseButtonDown(MouseButtonPacket.BUTTON_MIDDLE); + } + else { + conn.sendMouseButtonUp(MouseButtonPacket.BUTTON_MIDDLE); + } + } + + // First process the history + for (int i = 0; i < event.getHistorySize(); i++) { + updateMousePosition((int)event.getHistoricalX(i), (int)event.getHistoricalY(i)); + } + + // Now process the current values + updateMousePosition((int)event.getX(), (int)event.getY()); + + lastButtonState = event.getButtonState(); + } // This case is for touch-based input devices - if (event.getSource() == InputDevice.SOURCE_TOUCHSCREEN || - event.getSource() == InputDevice.SOURCE_STYLUS) + else { int actionIndex = event.getActionIndex(); @@ -601,59 +648,6 @@ public class Game extends Activity implements SurfaceHolder.Callback, return false; } } - // This case is for mice - else if (event.getSource() == InputDevice.SOURCE_MOUSE) - { - int changedButtons = event.getButtonState() ^ lastButtonState; - - if (event.getActionMasked() == MotionEvent.ACTION_SCROLL) { - // Send the vertical scroll packet - byte vScrollClicks = (byte) event.getAxisValue(MotionEvent.AXIS_VSCROLL); - conn.sendMouseScroll(vScrollClicks); - } - - if ((changedButtons & MotionEvent.BUTTON_PRIMARY) != 0) { - if ((event.getButtonState() & MotionEvent.BUTTON_PRIMARY) != 0) { - conn.sendMouseButtonDown(MouseButtonPacket.BUTTON_LEFT); - } - else { - conn.sendMouseButtonUp(MouseButtonPacket.BUTTON_LEFT); - } - } - - if ((changedButtons & MotionEvent.BUTTON_SECONDARY) != 0) { - if ((event.getButtonState() & MotionEvent.BUTTON_SECONDARY) != 0) { - conn.sendMouseButtonDown(MouseButtonPacket.BUTTON_RIGHT); - } - else { - conn.sendMouseButtonUp(MouseButtonPacket.BUTTON_RIGHT); - } - } - - if ((changedButtons & MotionEvent.BUTTON_TERTIARY) != 0) { - if ((event.getButtonState() & MotionEvent.BUTTON_TERTIARY) != 0) { - conn.sendMouseButtonDown(MouseButtonPacket.BUTTON_MIDDLE); - } - else { - conn.sendMouseButtonUp(MouseButtonPacket.BUTTON_MIDDLE); - } - } - - // First process the history - for (int i = 0; i < event.getHistorySize(); i++) { - updateMousePosition((int)event.getHistoricalX(i), (int)event.getHistoricalY(i)); - } - - // Now process the current values - updateMousePosition((int)event.getX(), (int)event.getY()); - - lastButtonState = event.getButtonState(); - } - else - { - // Unknown source - return false; - } // Handled a known source return true;