diff options
author | Jeremy Klein <jklein24@gmail.com> | 2015-10-01 15:25:59 -0700 |
---|---|---|
committer | Jeremy Klein <jklein24@gmail.com> | 2015-10-01 15:25:59 -0700 |
commit | 4c0ca79b464af40b5a41e39bcd3d7968abde5c9a (patch) | |
tree | 4b4d219d6b53c62492580c9aa27ca8fd5b7501a1 /app/src/main/java/de/mud/terminal/vt320.java | |
parent | f5ff9f7bda5d05434471050533d404452275a38e (diff) | |
parent | d531902ab57cdca8f4b40ecc4bbf290b56562649 (diff) | |
download | connectbot-4c0ca79b464af40b5a41e39bcd3d7968abde5c9a.tar.gz connectbot-4c0ca79b464af40b5a41e39bcd3d7968abde5c9a.tar.bz2 connectbot-4c0ca79b464af40b5a41e39bcd3d7968abde5c9a.zip |
Merge pull request #267 from jklein24/mouseevents
Forward mouseevents to the terminal when appropriate.
Diffstat (limited to 'app/src/main/java/de/mud/terminal/vt320.java')
-rw-r--r-- | app/src/main/java/de/mud/terminal/vt320.java | 76 |
1 files changed, 74 insertions, 2 deletions
diff --git a/app/src/main/java/de/mud/terminal/vt320.java b/app/src/main/java/de/mud/terminal/vt320.java index 73369af..ab4a90d 100644 --- a/app/src/main/java/de/mud/terminal/vt320.java +++ b/app/src/main/java/de/mud/terminal/vt320.java @@ -336,6 +336,10 @@ public void setScreenSize(int c, int r, boolean broadcast) { this(80, 24); } + public boolean isMouseReportEnabled() { + return mouserpt != 0; + } + /** * Terminal is mouse-aware and requires (x,y) coordinates of * on the terminal (character coordinates) and the button clicked. @@ -372,13 +376,81 @@ public void setScreenSize(int c, int r, boolean broadcast) { } /** + * Passes mouse wheel events to the terminal. + * @param down True if scrolling down the page. False if scrolling up. + * @param x + * @param y + * @param ctrl + * @param shift + * @param meta + */ + public void mouseWheel(boolean down, int x, int y, boolean ctrl, boolean shift, boolean meta) { + 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; + + // 1002 only reports drags. 1003 reports any movement. + if (mouserpt == 1002 && button == 3) + return; + + int mods = 0; + if (ctrl) mods |= 16; + if (shift) mods |= 4; + if (meta) mods |= 8; + + // Normal mouse code plus additional 32 to indicate movement. + int mousecode = (button + 0x40) | 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 + } + + /** * Terminal is mouse-aware and requires the coordinates and button * of the release. * @param x * @param y - * @param modifiers */ - public void mouseReleased(int x, int y, int modifiers) { + public void mouseReleased(int x, int y) { if (mouserpt == 0) return; |