diff src/com/five_ten_sg/connectbot/service/TerminalMonitor.java @ 229:594101a0876a

add why argument on cursor updates
author Carl Byington <carl@five-ten-sg.com>
date Wed, 09 Jul 2014 09:37:00 -0700
parents 2dd627df4dfb
children ea49747c5447
line wrap: on
line diff
--- a/src/com/five_ten_sg/connectbot/service/TerminalMonitor.java	Wed Jul 09 09:05:05 2014 -0700
+++ b/src/com/five_ten_sg/connectbot/service/TerminalMonitor.java	Wed Jul 09 09:37:00 2014 -0700
@@ -41,6 +41,10 @@
     public  static final char MONITOR_CMD_SWITCHSESSION = 10;
     public  static final char MONITOR_CMD_CURSORREQUEST = 11;
 
+    public  static final char CURSOR_REQUESTED      = 0;
+    public  static final char CURSOR_SCREEN_CHANGE  = 1;
+    public  static final char CURSOR_USER_KEY       = 2;
+
     private static final int    MONITORPORT       = 6000;
     private static final String LOCALHOST         = "127.0.0.1";
 
@@ -54,6 +58,7 @@
     private int                 start_column = 0;       // ""
     private int                 end_column   = 500;     // ""
     private boolean             modified     = false;   // used to delay screen change notifications
+    private boolean             moved        = false;   // used to delay cursor moved notifications
     private int                 to_line      = 0;       // ""
     private int                 to_column    = 0;       // ""
     private HashMap<Integer, Integer>  keymap = null;   // map MS VK_ keys to vt320 virtual keys
@@ -370,22 +375,32 @@
     }
 
     public synchronized void cursorMove(int l, int c) {
+        if ((to_line != l) || (to_column != c)) moved = true;
         to_line = l;
         to_column = c;
     }
 
-    public void cursorMoved() {
-        char[] arg = new char[4];
+    public void cursorMoved(char why) {
+        char[] arg = new char[5];
         arg[2] = (char)(to_line & 0x0000ffff);
         arg[3] = (char)(to_column & 0x0000ffff);
+        arg[4] = why;
         monitorWrite(MONITOR_CMD_CURSORMOVE, arg);
+        moved = false;
+    }
+
+    public void testMoved() {
+        if (moved) cursorMoved(CURSOR_USER_KEY);
     }
 
     public synchronized void testChanged() {
         if (modified) {
             modified = false;
             sendScreen(MONITOR_CMD_SCREENCHANGE);
-            cursorMoved();
+            cursorMoved(CURSOR_SCREEN_CHANGE);
+        }
+        else {
+            if (moved) cursorMoved(CURSOR_SCREEN_CHANGE);
         }
     }
 
@@ -452,7 +467,7 @@
 
     public synchronized void cursorRequest() {
         Log.i(TAG, "cursorRequest()");
-        cursorMoved();
+        cursorMoved(CURSOR_REQUESTED);
     }
 
 }