]> git.neil.brown.name Git - edlib.git/commitdiff
server: add -x option
authorNeilBrown <neil@brown.name>
Tue, 17 Aug 2021 06:04:54 +0000 (16:04 +1000)
committerNeilBrown <neil@brown.name>
Tue, 17 Aug 2021 06:44:15 +0000 (16:44 +1000)
lib-server -x now starts and X11 window.  The script terminates
immediately if no file was given, even though the window stays open.

Signed-off-by: NeilBrown <neil@brown.name>
display-x11-xcb.c
python/lib-server.py

index 3fe0862669d4b43ec70bb38e18b7516e5e505102..b1840f34d61198586ea48cc350cee09e276752c8 100644 (file)
@@ -1827,7 +1827,10 @@ DEF_CMD(display_xcb)
 DEF_CMD(xcb_new_display)
 {
        struct pane *p;
-       char *d = pane_attr_get(ci->focus, "DISPLAY");
+       const char *d = ci->str;
+
+       if (!d)
+               d = pane_attr_get(ci->focus, "DISPLAY");
 
        if (!d)
                return Enoarg;
@@ -1835,7 +1838,9 @@ DEF_CMD(xcb_new_display)
        if (p)
                p = call_ret(pane, "editor:activate-display", p);
        if (p)
-               home_call(ci->focus, "doc:attach-view", p, 1);
+               home_call_ret(pane, ci->focus, "doc:attach-view", p, 1);
+       if (p)
+               comm_call(ci->comm2, "cb", p);
        return 1;
 }
 
index ff2ca6c1f1927a6a7865c1e0d09bc1cc6426b132..169f8afb31debb0d90f84bd2e0c0de785ea77c11 100755 (executable)
@@ -60,7 +60,8 @@ try:
                         self.sock.send(b"FAIL")
                         return 1
                     if self.term:
-                        p = d.call("doc:attach-view", self.term, 1, ret='pane')
+                        p = self.term.leaf.call("ThisPane", ret='pane')
+                        p = d.call("doc:attach-view", p, 1, ret='pane')
                         self.term.take_focus()
                         self.sock.send(b"OK")
                         if self.lineno != None:
@@ -113,7 +114,15 @@ try:
                     self.want_close = True
                     self.sock.send(b"OK")
                     return 1
-                if msg.startswith(b"term "):
+                if msg.startswith(b'x11window ') and not self.term:
+                    d = msg[10:].decode()
+                    p = editor.call("interactive-cmd-x11window", d, ret='pane')
+                    if p:
+                        p.call("Window:bury")
+                    self.term = p
+                    self.sock.send(b'OK')
+                    return 1
+                if msg.startswith(b"term ") and not self.term:
                     w = msg.split(b' ')
                     path = w[1].decode("utf-8")
                     p = editor
@@ -167,6 +176,7 @@ try:
                 self.doc = None
                 if self.term:
                     self.term.call("Display:set-noclose")
+                    self.term.call("Display:close")
                 self.sock.send(b"Done")
             return 1
 
@@ -175,6 +185,7 @@ try:
             if str != "test":
                 if self.term:
                     self.term.call("Display:set-noclose")
+                    self.term.call("Display:close")
                 self.sock.send(b"Done")
             return 1
 
@@ -203,9 +214,12 @@ if is_client:
     term = False
     file = None
     lineno = None
+    x11 = False
     for a in sys.argv[1:]:
         if a == "-t":
             term = True
+        elif a == "-x":
+            x11 = True
         elif a[0] == '+':
             lineno = a[1:]
         elif file is None:
@@ -213,8 +227,8 @@ if is_client:
         else:
             print("Usage: edlibclient [-t] filename")
             sys.exit(1)
-    if not term and not file:
-        print("edlibclient: must provide -t or filename (or both)")
+    if not term and not x11 and not file:
+        print("edlibclient: must provide -t, -x, or filename")
         sys.exit(1)
 
     s = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
@@ -226,6 +240,17 @@ if is_client:
 
     winch_ok = False
 
+    if x11:
+        if 'DISPLAY' in os.environ:
+            d = os.environ['DISPLAY']
+        else:
+            print("edlibclient: -x not supported unless $DISPLAY is set")
+            sys.exit(1)
+        s.send(b"x11window %s" % d.encode())
+        ret = s.recv(100)
+        if ret != b'OK':
+            print("Cannot start x11 display:" + ret.decode())
+
     if term:
         t = os.ttyname(0)
         if t:
@@ -262,8 +287,10 @@ if is_client:
             print("Cannot open: ", ret.decode("utf-8"))
             sys.exit(1)
         s.send(b"doc:request:doc:done:"+file.encode("utf-8"))
-    else:
+    elif term:
         s.send(b"Request:Notify:Close")
+    else:
+        sys.exit(0)
     ret = s.recv(100)
     if ret != b"OK":
         print("Cannot request notification: ", ret.decode('utf-8'))
@@ -277,12 +304,12 @@ if is_client:
             break
         # probably a reply to Sig:Winch
     winch_ok = False
-    if ret != b"Done" and ret != b"Close":
+    if ret and ret != b"Done" and ret != b"Close":
         print("Received unexpected notification: ", ret.decode('utf-8'))
         s.send(b"Close")
         s.recv(100)
         sys.exit(1)
-    if ret != b"Close":
+    if ret and ret != b"Close":
         s.send(b"Close")
         s.recv(100)
     s.close()