From e4e3047bd5e9c8e010041aec196a77797e420332 Mon Sep 17 00:00:00 2001 From: Jeremy Klein Date: Fri, 25 Sep 2015 15:32:12 -0700 Subject: Add support for mouse wheel forwarding. --- app/src/main/java/de/mud/terminal/VDUInput.java | 11 ++++++++ app/src/main/java/de/mud/terminal/vt320.java | 32 ++++++++++++++++++++++ app/src/main/java/org/connectbot/TerminalView.java | 16 ++++++++++- 3 files changed, 58 insertions(+), 1 deletion(-) (limited to 'app/src/main') diff --git a/app/src/main/java/de/mud/terminal/VDUInput.java b/app/src/main/java/de/mud/terminal/VDUInput.java index abaa70f..e1bce90 100644 --- a/app/src/main/java/de/mud/terminal/VDUInput.java +++ b/app/src/main/java/de/mud/terminal/VDUInput.java @@ -56,6 +56,17 @@ public interface VDUInput { */ void mousePressed(int x, int y, int modifiers); + /** + * 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); + /** * Terminal is mouse-aware and requires the coordinates and button * of the release. diff --git a/app/src/main/java/de/mud/terminal/vt320.java b/app/src/main/java/de/mud/terminal/vt320.java index 4f36f28..90c7403 100644 --- a/app/src/main/java/de/mud/terminal/vt320.java +++ b/app/src/main/java/de/mud/terminal/vt320.java @@ -375,6 +375,38 @@ public void setScreenSize(int c, int r, boolean broadcast) { write(b); // FIXME: writeSpecial here } + /** + * 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 |= 2; + if (shift) mods |= 1; + if (meta) mods |= 4; + + int mousecode = ((down ? 0 : 1) + 96) | 0x20 | ((mods & 7) << 2); + + 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. diff --git a/app/src/main/java/org/connectbot/TerminalView.java b/app/src/main/java/org/connectbot/TerminalView.java index 261407c..ffe8d8b 100644 --- a/app/src/main/java/org/connectbot/TerminalView.java +++ b/app/src/main/java/org/connectbot/TerminalView.java @@ -52,6 +52,7 @@ import android.view.inputmethod.EditorInfo; import android.view.inputmethod.InputConnection; import android.widget.Toast; import de.mud.terminal.VDUBuffer; +import de.mud.terminal.vt320; /** * User interface {@link View} for showing a TerminalBridge in an @@ -329,7 +330,20 @@ public class TerminalView extends View implements FontSizeChangedListener { case MotionEvent.ACTION_SCROLL: // Process scroll wheel movement: float yDistance = MotionEventCompat.getAxisValue(event, MotionEvent.AXIS_VSCROLL); - if (yDistance != 0) { + boolean mouseReport = ((vt320) bridge.buffer).isMouseReportEnabled(); + if (mouseReport) { + int row = (int) Math.floor(event.getY() / bridge.charHeight); + int col = (int) Math.floor(event.getX() / bridge.charWidth); + + ((vt320) bridge.buffer).mouseWheel( + yDistance > 0, + col, + row, + (event.getMetaState() & KeyEvent.META_CTRL_ON) != 0, + (event.getMetaState() & KeyEvent.META_SHIFT_ON) != 0, + (event.getMetaState() & KeyEvent.META_META_ON) != 0); + return true; + } else if (yDistance != 0) { int base = bridge.buffer.getWindowBase(); bridge.buffer.setWindowBase(base - Math.round(yDistance)); return true; -- cgit v1.2.3