changeset 506:b8cc360e1550 stable-1.9.4-5

allow multiple screen watch areas
author Carl Byington <carl@five-ten-sg.com>
date Wed, 16 Nov 2022 12:05:29 -0700
parents bd87ca9eb4b8
children f7498bd7621b
files app/src/main/AndroidManifest.xml app/src/main/java/com/five_ten_sg/connectbot/service/TerminalMonitor.java
diffstat 2 files changed, 43 insertions(+), 24 deletions(-) [+]
line wrap: on
line diff
--- a/app/src/main/AndroidManifest.xml	Sun Jun 26 12:35:37 2022 -0700
+++ b/app/src/main/AndroidManifest.xml	Wed Nov 16 12:05:29 2022 -0700
@@ -17,10 +17,10 @@
 -->
 <manifest xmlns:android="http://schemas.android.com/apk/res/android"
     package="com.five_ten_sg.connectbot"
-    android:versionName="1.9.4-4"
-    android:versionCode="1944"
+    android:versionName="1.9.4-5"
+    android:versionCode="1945"
     android:installLocation="auto">
-   <queries>
+    <queries>
         <package android:name="com.five_ten_sg.connectbot.monitor" />
     </queries>
 
--- a/app/src/main/java/com/five_ten_sg/connectbot/service/TerminalMonitor.java	Sun Jun 26 12:35:37 2022 -0700
+++ b/app/src/main/java/com/five_ten_sg/connectbot/service/TerminalMonitor.java	Wed Nov 16 12:05:29 2022 -0700
@@ -26,7 +26,6 @@
 import com.five_ten_sg.connectbot.ConsoleActivity;
 import com.five_ten_sg.connectbot.bean.HostBean;
 
-
 public class TerminalMonitor {
     public final static String TAG = "ConnectBot.TermMonitor";
 
@@ -84,10 +83,7 @@
     private int                 port         = 0;
     private String              target       = null;
     private String              init         = null;
-    private int                 start_line   = 0;       // monitor part of the screen for changes
-    private int                 end_line     = 500;     // ""
-    private int                 start_column = 0;       // ""
-    private int                 end_column   = 500;     // ""
+    private Watch[]             watches      = null;
     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;       // ""
@@ -101,6 +97,28 @@
     private BlockingQueue<char[]> pending_commands = new ArrayBlockingQueue<char[]>(100);
     private MyServiceConnection monitor_connection = new MyServiceConnection();
 
+
+    private class Watch {
+        // monitor part of the screen for changes
+        private int  start_line;
+        private int  end_line;
+        private int  start_column;
+        private int  end_column;
+        public Watch(int l, int c, int len) {
+            Log.i(TAG, String.format("screenWatch(line %d, col %d, len %d)", l, c, len));
+            this.start_line   = l;
+            this.end_line     = l;
+            this.start_column = c;
+            this.end_column   = c + len - 1;
+        }
+        public boolean screenChanged(int llow, int lhigh, int clow, int chigh) {
+            return ((start_line <= lhigh)   &&
+                    (llow <= end_line)      &&
+                    (start_column <= chigh) &&
+                    (clow <= end_column));
+        }
+    }
+
     class MyReader extends Thread {
         private InputStream monitor_in;
         private byte[] b;
@@ -155,9 +173,14 @@
                             break;
 
                         case MONITOR_CMD_SCREENWATCH:
-                            if (packet.length == 4)
-                                screenWatch(packet[1], packet[2], packet[3]);
-
+                            if (packet.length >= 4) {
+                                int n = (packet.length - 1) / 3;
+                                watches = new Watch[n];
+                                for (int i=0; i<n; i++) {
+                                    int j = 1 + i*3;
+                                    watches[i] = new Watch(packet[j], packet[j+1], packet[j+2]);
+                                }
+                            }
                             break;
 
                         case MONITOR_CMD_DEPRESS:
@@ -421,10 +444,7 @@
     };
 
     public void resetWatch() {
-        start_line   = 0;
-        end_line     = 500;
-        start_column = 0;
-        end_column   = 500;
+        watches = null;
     };
 
     public void sendScreen(char cmd) {
@@ -487,8 +507,15 @@
     }
 
     public synchronized void screenChanged(int llow, int lhigh, int clow, int chigh) {
-        if ((start_line <= lhigh) && (llow <= end_line) && (start_column <= chigh) && (clow <= end_column)) {
+        if (watches == null) {
             modified = true;
+            return;
+        }
+        for (Watch w : watches) {
+            if (w.screenChanged(llow, lhigh, clow, chigh)) {
+                modified = true;
+                return;
+            }
         }
     }
 
@@ -543,14 +570,6 @@
         monitorWrite(MONITOR_CMD_FIELDVALUE, arg2);
     }
 
-    public synchronized void screenWatch(int l, int c, int len) {
-        Log.i(TAG, String.format("screenWatch(line %d, col %d, len %d)", l, c, len));
-        start_line   = l;
-        end_line     = l;
-        start_column = c;
-        end_column   = c + len - 1;
-    }
-
     public synchronized void depress(int vk_key) {
         Log.i(TAG, String.format("depress(%04x)", vk_key));
         Integer x = keymap.get(new Integer(vk_key));