From a90d3119be3030c35765a00d3cc149f61fd8f69e Mon Sep 17 00:00:00 2001 From: Kevin Lamonte Date: Fri, 20 Mar 2015 22:21:49 -0400 Subject: [PATCH] mouse support inside terminal --- README.md | 3 --- src/jexer/io/AWTTerminal.java | 17 +++++++++++++++++ src/jexer/tterminal/ECMA48.java | 25 ++++++++++--------------- 3 files changed, 27 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index 746b168..1a41908 100644 --- a/README.md +++ b/README.md @@ -136,14 +136,11 @@ Many tasks remain before calling this version 1.0: - TWindow - "Smart placement" for new windows -- ECMATerminal - - Mouse 1006 mode parsing Wishlist features (2.0): - TTerminal - Handle resize events (pass to child process) - - xterm mouse handling - Screen - Allow complex characters in putCharXY() and detect them in putStrXY(). - TComboBox diff --git a/src/jexer/io/AWTTerminal.java b/src/jexer/io/AWTTerminal.java index 783cffd..38f6734 100644 --- a/src/jexer/io/AWTTerminal.java +++ b/src/jexer/io/AWTTerminal.java @@ -96,6 +96,16 @@ public final class AWTTerminal implements ComponentListener, KeyListener, */ private Thread readerThread; + /** + * The last reported mouse X position. + */ + private int oldMouseX = -1; + + /** + * The last reported mouse Y position. + */ + private int oldMouseY = -1; + /** * true if mouse1 was down. Used to report mouse1 on the release event. */ @@ -566,6 +576,13 @@ public final class AWTTerminal implements ComponentListener, KeyListener, public void mouseMoved(final MouseEvent mouse) { int x = screen.textColumn(mouse.getX()); int y = screen.textRow(mouse.getY()); + if ((x == oldMouseX) && (y == oldMouseY)) { + // Bail out, we've moved some pixels but not a whole text cell. + return; + } + oldMouseX = x; + oldMouseY = y; + TMouseEvent mouseEvent = new TMouseEvent(TMouseEvent.Type.MOUSE_MOTION, x, y, x, y, mouse1, mouse2, mouse3, false, false); diff --git a/src/jexer/tterminal/ECMA48.java b/src/jexer/tterminal/ECMA48.java index df157cf..017c3c7 100644 --- a/src/jexer/tterminal/ECMA48.java +++ b/src/jexer/tterminal/ECMA48.java @@ -1096,25 +1096,18 @@ public class ECMA48 implements Runnable { * @param mouse mouse event received from the local user */ public void mouse(final TMouseEvent mouse) { + /* - * TODO: - * - * - Parse the mouse requests from the remote side regarding protocol - * + encoding - * - * - Send mouse events to the other side. - * - * - Handle the cursor (double invert). + System.err.printf("mouse(): protocol %s encoding %s mouse %s\n", + mouseProtocol, mouseEncoding, mouse); */ - // System.err.printf("Mouse: %s\n", mouse); - - /* if (mouseEncoding != MouseEncoding.UTF8) { - // We only support UTF8 encoding, bail out now. - return; + // We will support X10 but only for (160,94) and smaller. + if ((mouse.getX() >= 160) || (mouse.getY() >= 94)) { + return; + } } - */ switch (mouseProtocol) { @@ -1165,7 +1158,9 @@ public class ECMA48 implements Runnable { sb.append((char) 0x1B); sb.append('['); sb.append('M'); - if (mouse.getMouse1()) { + if (mouse.getType() == TMouseEvent.Type.MOUSE_UP) { + sb.append((char) (0x03 + 32)); + } else if (mouse.getMouse1()) { sb.append((char) (0x00 + 32)); } else if (mouse.getMouse2()) { sb.append((char) (0x01 + 32)); -- 2.27.0