]> git.neil.brown.name Git - edlib.git/commitdiff
Finish attach-display-foo commands with doc:attach-view
authorNeilBrown <neil@brown.name>
Wed, 28 Jun 2023 20:40:20 +0000 (06:40 +1000)
committerNeilBrown <neil@brown.name>
Wed, 28 Jun 2023 21:03:47 +0000 (07:03 +1000)
And attach-display-* command must now be called on a document or on the
root.
If it was on a document, that document is viewed in the created display
using doc:attach-view.
This makes it easier for a caller to create a useful window in a single
command.

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

index e3162453c1584f99f5d552be983ef9e92335ec28..1577ae0af2ed9e8d9c24a408087fe1bc3af4bc3b 100644 (file)
@@ -1796,15 +1796,19 @@ REDEF_CMD(input_handle)
 DEF_CMD(display_ncurses)
 {
        struct pane *p;
+       struct pane *ed = pane_root(ci->focus);
        const char *tty = ci->str;
        const char *term = ci->str2;
 
        if (!term)
                term = "xterm-256color";
 
-       p = ncurses_init(ci->focus, tty, term);
+       p = ncurses_init(ed, tty, term);
        if (p)
                p = call_ret(pane, "editor:activate-display", p);
+       if (p && ci->focus != ed)
+               /* Assume ci->focus is a document */
+               p = home_call_ret(pane, ci->focus, "doc:attach-view", p, 1);
        if (p)
                return comm_call(ci->comm2, "callback:display", p);
 
index 6248ab5fc045b575d37ed4d88f3e4fdd6c5c4d56..497ae3f1942aa8d15540221894bbce4a3d8bd115 100644 (file)
@@ -1918,11 +1918,15 @@ abort:
 DEF_CMD(display_xcb)
 {
        struct pane *p;
+       struct pane *ed = pane_root(ci->focus);
        const char *d = ci->str;
 
        if (!d)
                return Enoarg;
-       p = xcb_display_init(d, ci->str2, ci->focus);
+       p = xcb_display_init(d, ci->str2, ed);
+       if (p && ci->focus != ed)
+               /* Assume ci->focus is a document */
+               p = home_call_ret(pane, ci->focus, "doc:attach-view", p, 1);
        if (p)
                return comm_call(ci->comm2, "cb", p);
        return Efail;
diff --git a/edlib.c b/edlib.c
index be6b596b703316d38b006823240b99c5451b41d4..c7c210070719467a06acd7bf487650856e3ab582 100644 (file)
--- a/edlib.c
+++ b/edlib.c
@@ -105,7 +105,7 @@ int main(int argc, char *argv[])
        if (term) {
                char *TERM = getenv("TERM");
 
-               p = call_ret(pane, "attach-display-ncurses", ed,
+               p = call_ret(pane, "attach-display-ncurses", doc,
                             0, NULL, "-", 0, NULL, TERM);
                if (p) {
                        char *e;
@@ -118,34 +118,24 @@ int main(int argc, char *argv[])
                             0, NULL, getenv("DISPLAY"));
                        call("window:set:XAUTHORITY", p,
                             0, NULL, getenv("XAUTHORITY"));
-               }
-               if (p)
-                       p = home_call_ret(pane, doc, "doc:attach-view",
-                                         p, 1);
-               if (!first_window)
-                       first_window = p;
-               if (p)
+                       if (!first_window)
+                               first_window = p;
                        call("Display:set-noclose", p, 1, NULL,
                             "Cannot close primary display");
+               }
        }
 
        if (gtk) {
                p = call_ret(pane, "attach-display-gtk",
-                            ed, 0, NULL, getenv("DISPLAY"));
-               if (p)
-                       p = home_call_ret(pane, doc, "doc:attach-view",
-                                         p, 1);
+                            doc, 0, NULL, getenv("DISPLAY"));
                if (!first_window)
                        first_window = p;
        }
 
        if (x11) {
                p = call_ret(pane, "attach-display-x11",
-                            ed, 0, NULL, getenv("DISPLAY"),
+                            doc, 0, NULL, getenv("DISPLAY"),
                             0, NULL, getenv("XAUTHORITY"));
-               if (p)
-                       p = home_call_ret(pane, doc, "doc:attach-view",
-                                         p, 1);
                if (!first_window)
                        first_window = p;
        }
index efa699f49e7504e4efb114091a1bf001dcfb7edc..6638c2c46d606aee4ef470a047842b4bb25ba444 100644 (file)
@@ -740,6 +740,7 @@ def new_display(key, focus, comm2, str1, **a):
     if not str1:
         return None
     focus.call("attach-glibevents")
+    ed = focus.root
 
     if 'SCALE' in os.environ:
         sc = int(os.environ['SCALE'])
@@ -748,6 +749,8 @@ def new_display(key, focus, comm2, str1, **a):
 
     disp = EdDisplay(focus, str1)
     p = disp.call("editor:activate-display", ret='pane')
+    if p and focus != ed:
+        p = focus.call("doc:attach-view", p, 1)
     comm2('callback', p)
     return 1