]> git.neil.brown.name Git - edlib.git/commitdiff
Split display creation into two separate steps.
authorNeilBrown <neil@brown.name>
Sun, 8 Oct 2023 08:17:21 +0000 (19:17 +1100)
committerNeilBrown <neil@brown.name>
Mon, 9 Oct 2023 22:15:33 +0000 (09:15 +1100)
This effectively reverts an earlier patch.
That patch caused x11 selection to stop working because
the relevant pane was attached before DISPLAY had been set.
So now we create the display first, then have the opportunity to set
attributes, then call window-active-display which adds all the extra
panes and attaches a document.

Signed-off-by: NeilBrown <neil@brown.name>
DOC/TODO.md
core-editor.c
core-window.c
data/edlib.ini
display-ncurses.c
display-x11-xcb.c
edlib.c
python/display-pygtk.py
python/lib-server.py

index 8543d8198098bcd752ac4691c60e0c18091ee2ad..8a07acfadb329a514269a3d7f7a103585a6df204 100644 (file)
@@ -9,6 +9,8 @@ the file.
 
 ### Triage
 
+- [ ] in filename competion, TAB might add a '/' to a partial name and
+      then get confused.
 - [X] when search succeeds on final line then trying again loops back to
       there, redraw is strange
 - [ ] There is a "window:close" and a "Window:close" and they are
index 9743689a0009b0b248e63568246faa6dc3ad2447..2971d5e682dc87107a0a124fce2a1348eabd2360 100644 (file)
@@ -232,49 +232,6 @@ DEF_CMD(editor_auto_event)
        return key_lookup_prefix(map, ci, False);
 }
 
-DEF_CMD(editor_activate_display)
-{
-       /* Given a display attached to the root, integrate it
-        * into a full initial stack of panes.
-        */
-       struct pane *disp = ci->focus;
-       struct pane *p, *p2;
-       char *ip = attr_find(ci->home->attrs, "editor-initial-panes");
-       char *save, *t, *m;
-
-       if (!ip)
-               return Efail;
-       ip = strsave(ci->home, ip);
-       p = pane_root(ci->focus);
-
-       p2 = call_ret(pane, "attach-window-core", p);
-       if (!p2)
-               return Efail;
-       p = p2;
-
-       for (t = strtok_r(ip, " \t\n", &save);
-            t;
-            t = strtok_r(NULL, " \t\n", &save)) {
-               if (!*t)
-                       continue;
-               if (strcmp(t, "DISPLAY") == 0) {
-                       if (disp) {
-                               pane_reparent(disp, p);
-                               p = disp;
-                               disp = NULL;
-                       }
-                       continue;
-               }
-               m = strconcat(NULL, "attach-", t);
-               p2 = call_ret(pane, m, p);
-               free(m);
-               if (p2)
-                       p = p2;
-       }
-       comm_call(ci->comm2, "cb", p);
-       return 1;
-}
-
 DEF_CMD(editor_multicall)
 {
        struct ed_info *ei = ci->home->data;
@@ -737,8 +694,6 @@ struct pane *editor_new(const char *comm_name)
                               &editor_request_notify);
                key_add_prefix(ed_map, "editor:notify:",
                               &editor_send_notify);
-               key_add(ed_map, "editor:activate-display",
-                       &editor_activate_display);
                key_add(ed_map, "Close", &editor_close);
        }
        ed = pane_register_root(&ed_handle.c, NULL, sizeof(*ei));
index 54c7ec25fd8e83726fa5e5b12f4ea95e4e86d43d..36c8d90a5e1a380f2b054b610143488635a11011 100644 (file)
@@ -271,6 +271,54 @@ DEF_CMD(scale_image)
        return 1;
 }
 
+DEF_CMD(window_activate_display)
+{
+       /* Given a display attached to the root, integrate it
+        * into a full initial stack of panes.
+        * The display is the focus of this pane.  This doc to
+        * attach there is the focus in the command.
+        */
+       struct pane *disp = ci->home->focus;
+       struct pane *p, *p2;
+       bool display_added = False;
+       char *ip;
+       char *save, *t, *m;
+
+       if (!disp || !list_empty(&disp->children))
+               return Efail;
+       ip = pane_attr_get(disp, "window-initial-panes");
+       if (!ip)
+               return Efail;
+       ip = strdup(ip);
+       p = ci->home;
+
+       for (t = strtok_r(ip, " \t\n", &save);
+            t;
+            t = strtok_r(NULL, " \t\n", &save)) {
+               if (!*t)
+                       continue;
+               if (strcmp(t, "DISPLAY") == 0) {
+                       if (!display_added) {
+                               pane_reparent(disp, p);
+                               p = disp;
+                               display_added = True;
+                       }
+               } else {
+                       m = strconcat(NULL, "attach-", t);
+                       p2 = call_ret(pane, m, p);
+                       free(m);
+                       if (p2)
+                               p = p2;
+               }
+       }
+       free(ip);
+       if (p && ci->focus != disp)
+               p = home_call_ret(pane, ci->focus, "doc:attach-view", p, 1);
+       if (p)
+               comm_call(ci->comm2, "cb", p);
+       return 1;
+}
+
 DEF_CMD(close_notify)
 {
        struct window_data *wd = ci->home->data;
@@ -290,7 +338,7 @@ DEF_CMD(window_attach)
 {
        struct pane *p;
 
-       p = pane_register(ci->focus, 0, &window_handle.c);
+       p = pane_register(pane_root(ci->focus), 0, &window_handle.c);
        if (!p)
                return Efail;
        comm_call(ci->comm2, "cb", p);
@@ -320,6 +368,8 @@ void window_setup(struct pane *ed safe)
        key_add(window_map, "Notify:Close", &close_notify);
 
        key_add(window_map, "Draw:scale-image", &scale_image);
+       key_add(window_map, "window:activate-display",
+               &window_activate_display);
 
        call_comm("global-set-command", ed, &window_attach, 0, NULL,
                  "attach-window-core");
index 6ec0143bf586ff52dbffc6ecaf7bc2b0a81da0cb..ea84a5b8f66d28828e1afc7e0c4bbfe33d322fa0 100644 (file)
@@ -3,7 +3,7 @@ include = modules.ini
 
 [global]
 
-editor-initial-panes = input DISPLAY
+window-initial-panes = input DISPLAY
        " x11selection"
        " messageline"
        " mode-basic"
index f402be61e39d7e5a1a5c73afec05e38547bc8ace..40012043cd5ea007a03ee912969206f9e560885a 100644 (file)
@@ -1803,12 +1803,11 @@ DEF_CMD(display_ncurses)
        if (!term)
                term = "xterm-256color";
 
-       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);
+       p = call_ret(pane, "attach-window-core", ed);
+       if (!p)
+               return Efail;
+
+       p = ncurses_init(p, tty, term);
        if (p)
                return comm_call(ci->comm2, "callback:display", p);
 
index 1d21e5907f2f85ae9051ee5747066aeae11e5fa8..5772df9331f2b6b38e539277caf946fc26a6fa4b 100644 (file)
@@ -1829,7 +1829,10 @@ static struct pane *xcb_display_init(const char *d safe,
        if (xcb_connection_has_error(conn))
                return NULL;
 
-       p = pane_register(pane_root(focus), 1, &xcb_handle.c);
+       p = call_ret(pane, "attach-window-core", focus);
+       if (!p)
+               return NULL;
+       p = pane_register(p, 1, &xcb_handle.c);
        if (!p)
                return NULL;
        xd = p->data;
@@ -1965,7 +1968,6 @@ static struct pane *xcb_display_init(const char *d safe,
        attr_set_str(&p->attrs, "scale:M", scale);
        xd->last_event = time(NULL);
        call("editor:request:all-displays", p);
-       p = call_ret(pane, "editor:activate-display", p);
        return p;
 abort:
        kbd_free(xd);
@@ -1993,8 +1995,9 @@ DEF_CMD(xcb_new_display)
        if (!d)
                return Enoarg;
        p = xcb_display_init(d, disp_auth, ci->focus);
-       if (p)
-               home_call_ret(pane, ci->focus, "doc:attach-view", p, 1);
+       if (strcmp(ci->key, "interactive-cmd-x11window") == 0)
+               p = home_call_ret(pane, p,
+                                 "window:activate-display", ci->focus);
        if (p)
                comm_call(ci->comm2, "cb", p);
        return 1;
diff --git a/edlib.c b/edlib.c
index 0cae4d16bcff360606f8f34b45980af9d18ddc1a..bac2c5f2726cb94a1dc54d0aec4a9667de0da0a3 100644 (file)
--- a/edlib.c
+++ b/edlib.c
@@ -111,7 +111,7 @@ int main(int argc, char *argv[])
        if (term) {
                char *TERM = getenv("TERM");
 
-               p = call_ret(pane, "attach-display-ncurses", doc,
+               p = call_ret(pane, "attach-display-ncurses", ed,
                             0, NULL, "-", 0, NULL, TERM);
                if (p) {
                        char *e;
@@ -128,20 +128,23 @@ int main(int argc, char *argv[])
                                first_window = p;
                        call("window:set:no-close", p, 1, NULL,
                             "Cannot close primary display");
+                       home_call(p, "window:activate-display", doc);
                }
        }
 
        if (gtk) {
                p = call_ret(pane, "attach-display-gtk",
-                            doc, 0, NULL, getenv("DISPLAY"));
+                            ed, 0, NULL, getenv("DISPLAY"));
+               home_call(p, "window:activate-display", doc);
                if (!first_window)
                        first_window = p;
        }
 
        if (x11) {
                p = call_ret(pane, "attach-display-x11",
-                            doc, 0, NULL, getenv("DISPLAY"),
+                            ed, 0, NULL, getenv("DISPLAY"),
                             0, NULL, getenv("XAUTHORITY"));
+               home_call(p, "window:activate-display", doc);
                if (!first_window)
                        first_window = p;
        }
index a9882c3b75be8dc61e220be343a62483aeac0c6b..392169eb0aea0503ef9de59e2aa4bf98542e7056 100644 (file)
@@ -95,10 +95,11 @@ class EdDisplay(edlib.Pane):
 
     def handle_new(self, key, focus, **a):
         "handle:window:new"
-        newdisp = EdDisplay(edlib.editor, self['DISPLAY'])
-        p = newdisp.call("editor:activate-display", ret='pane')
-        if p:
-            focus.call("doc:attach-view", p, 1)
+        p = focus.call("attach-window-core", ret='pane')
+        if not p:
+            return edlib.Efail
+        newdisp = EdDisplay(p, self['DISPLAY'])
+        newdisp.call("window:activate-display", focus)
         return 1
 
     def handle_external(self, key, str, **a):
@@ -634,8 +635,11 @@ class EdDisplay(edlib.Pane):
         self.im.focus_out()
         self.in_focus = False
         f = self.final_focus
-        pt = f.call("doc:point", ret='mark')
-        f.call("view:changed", pt)
+        try:
+            pt = f.call("doc:point", ret='mark')
+            f.call("view:changed", pt)
+        except edlib.commandfailed:
+            pass
         edlib.time_stop(edlib.TIME_WINDOW)
 
     def reconfigure(self, w, ev):
@@ -790,17 +794,18 @@ def new_display(key, focus, comm2, str1, **a):
             return None
 
     focus.call("attach-glibevents")
-    ed = focus.root
 
     if 'SCALE' in os.environ:
         sc = int(os.environ['SCALE'])
         s = Gtk.settings_get_default()
         s.set_long_property("Gtk-xft-dpi",sc*Pango.SCALE, "code")
 
-    disp = EdDisplay(ed, display)
-    p = disp.call("editor:activate-display", ret='pane')
-    if p and focus != ed:
-        p = focus.call("doc:attach-view", p, 1, ret='pane')
+    p = focus.call("attach-window-core", ret='pane')
+    if not p:
+        return edlib.Efail;
+    disp = EdDisplay(p, display)
+    if key == "interactive-cmd-gtkwindow":
+        p = disp.call("window:activate-display", focus, ret='pane')
     if comm2:
         comm2('callback', p)
     return 1
index 41438a05bbf45984ad60f78fca8a6d1e9a5e0b40..686b9d86b7df92aeb3168d5c523adcbe5127beec 100755 (executable)
@@ -150,9 +150,10 @@ if sys.argv[0] == "":
                     p = edlib.editor
                     p = p.call("attach-display-ncurses", path, env['TERM'],
                                ret='pane')
-                    self.term = p
                     for v in env:
-                        self.term.call("window:set:", env[v], v)
+                        p.call("window:set:", env[v], v)
+                    p = p.call("window:activate-display", ret='pane')
+                    self.term = p
                     self.disp = self.term
                     self.add_notify(self.disp, "Notify:Close")
                     self.sock.send(b"OK")