From a11834b6021b2d943efeee73b1af38179dcea5a4 Mon Sep 17 00:00:00 2001 From: Jeremy Klein Date: Tue, 29 Sep 2015 16:48:05 -0700 Subject: Add support for mouse move event forwarding. --- app/src/main/java/de/mud/terminal/vt320.java | 67 +++++++++++++++++----- .../main/java/org/connectbot/ConsoleActivity.java | 40 ++++++++----- 2 files changed, 79 insertions(+), 28 deletions(-) (limited to 'app/src/main') diff --git a/app/src/main/java/de/mud/terminal/vt320.java b/app/src/main/java/de/mud/terminal/vt320.java index 90c7403..ab4a90d 100644 --- a/app/src/main/java/de/mud/terminal/vt320.java +++ b/app/src/main/java/de/mud/terminal/vt320.java @@ -385,26 +385,63 @@ public void setScreenSize(int c, int r, boolean broadcast) { * @param meta */ public void mouseWheel(boolean down, int x, int y, boolean ctrl, boolean shift, boolean meta) { - if (mouserpt == 0 || mouserpt == 9) - return; + if (mouserpt == 0 || mouserpt == 9) + return; + + int mods = 0; + if (ctrl) mods |= 16; + if (shift) mods |= 4; + if (meta) mods |= 8; + + int mousecode = ((down ? 0 : 1) + 96) | 0x20 | mods; + + byte b[] = new byte[6]; + + b[0] = 27; + b[1] = (byte) '['; + b[2] = (byte) 'M'; + b[3] = (byte) mousecode; + b[4] = (byte) (0x20 + x + 1); + b[5] = (byte) (0x20 + y + 1); + + write(b); // FIXME: writeSpecial here + } + + /** + * Passes mouse move events to the terminal. + * @param button The mouse button pressed. 3 indicates no button is pressed. + * @param x + * @param y + * @param ctrl + * @param shift + * @param meta + */ + public void mouseMoved(int button, int x, int y, boolean ctrl, boolean shift, boolean meta) { + if (mouserpt != 1002 && mouserpt != 1003) + return; - int mods = 0; - if (ctrl) mods |= 2; - if (shift) mods |= 1; - if (meta) mods |= 4; + // 1002 only reports drags. 1003 reports any movement. + if (mouserpt == 1002 && button == 3) + return; - int mousecode = ((down ? 0 : 1) + 96) | 0x20 | ((mods & 7) << 2); + int mods = 0; + if (ctrl) mods |= 16; + if (shift) mods |= 4; + if (meta) mods |= 8; - byte b[] = new byte[6]; + // Normal mouse code plus additional 32 to indicate movement. + int mousecode = (button + 0x40) | mods; - b[0] = 27; - b[1] = (byte) '['; - b[2] = (byte) 'M'; - b[3] = (byte) mousecode; - b[4] = (byte) (0x20 + x + 1); - b[5] = (byte) (0x20 + y + 1); + byte b[] = new byte[6]; - write(b); // FIXME: writeSpecial here + b[0] = 27; + b[1] = (byte) '['; + b[2] = (byte) 'M'; + b[3] = (byte) mousecode; + b[4] = (byte) (0x20 + x + 1); + b[5] = (byte) (0x20 + y + 1); + + write(b); // FIXME: writeSpecial here } /** diff --git a/app/src/main/java/org/connectbot/ConsoleActivity.java b/app/src/main/java/org/connectbot/ConsoleActivity.java index 0ee6a5a..66617f2 100644 --- a/app/src/main/java/org/connectbot/ConsoleActivity.java +++ b/app/src/main/java/org/connectbot/ConsoleActivity.java @@ -756,25 +756,39 @@ public class ConsoleActivity extends AppCompatActivity implements BridgeDisconne boolean mouseReport = ((vt320) bridge.buffer).isMouseReportEnabled(); // MouseReport can be "defeated" using the shift key. - if ((!mouseReport || shiftOn) && event.getAction() == MotionEvent.ACTION_DOWN) { - switch (event.getButtonState()) { - case MotionEvent.BUTTON_PRIMARY: - // Automatically start copy mode if using a mouse. - startCopyMode(); - break; - case MotionEvent.BUTTON_SECONDARY: - openContextMenu(pager); - return true; - case MotionEvent.BUTTON_TERTIARY: - // Middle click pastes. - pasteIntoTerminal(); - return true; + if ((!mouseReport || shiftOn)) { + if (event.getAction() == MotionEvent.ACTION_DOWN) { + switch (event.getButtonState()) { + case MotionEvent.BUTTON_PRIMARY: + // Automatically start copy mode if using a mouse. + startCopyMode(); + break; + case MotionEvent.BUTTON_SECONDARY: + openContextMenu(pager); + return true; + case MotionEvent.BUTTON_TERTIARY: + // Middle click pastes. + pasteIntoTerminal(); + return true; + } } } else if (event.getAction() == MotionEvent.ACTION_DOWN) { ((vt320) bridge.buffer).mousePressed( col, row, mouseEventToJavaModifiers(event)); } else if (event.getAction() == MotionEvent.ACTION_UP) { ((vt320) bridge.buffer).mouseReleased(col, row); + } else if (event.getAction() == MotionEvent.ACTION_MOVE) { + int buttonState = event.getButtonState(); + int button = (buttonState & MotionEvent.BUTTON_PRIMARY) != 0 ? 0 : + (buttonState & MotionEvent.BUTTON_SECONDARY) != 0 ? 1 : + (buttonState & MotionEvent.BUTTON_TERTIARY) != 0 ? 2 : 3; + ((vt320) bridge.buffer).mouseMoved( + button, + col, + row, + (event.getMetaState() & KeyEvent.META_CTRL_ON) != 0, + (event.getMetaState() & KeyEvent.META_SHIFT_ON) != 0, + (event.getMetaState() & KeyEvent.META_META_ON) != 0); } } -- cgit v1.2.3