From: NeilBrown Date: Sun, 8 Oct 2023 08:17:21 +0000 (+1100) Subject: Split display creation into two separate steps. X-Git-Url: http://git.neil.brown.name/?a=commitdiff_plain;h=8fba1fc3efc3b91dbad9971a51ff3e0eeae3faf3;p=edlib.git Split display creation into two separate steps. 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 --- diff --git a/DOC/TODO.md b/DOC/TODO.md index 8543d819..8a07acfa 100644 --- a/DOC/TODO.md +++ b/DOC/TODO.md @@ -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 diff --git a/core-editor.c b/core-editor.c index 9743689a..2971d5e6 100644 --- a/core-editor.c +++ b/core-editor.c @@ -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)); diff --git a/core-window.c b/core-window.c index 54c7ec25..36c8d90a 100644 --- a/core-window.c +++ b/core-window.c @@ -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"); diff --git a/data/edlib.ini b/data/edlib.ini index 6ec0143b..ea84a5b8 100644 --- a/data/edlib.ini +++ b/data/edlib.ini @@ -3,7 +3,7 @@ include = modules.ini [global] -editor-initial-panes = input DISPLAY +window-initial-panes = input DISPLAY " x11selection" " messageline" " mode-basic" diff --git a/display-ncurses.c b/display-ncurses.c index f402be61..40012043 100644 --- a/display-ncurses.c +++ b/display-ncurses.c @@ -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); diff --git a/display-x11-xcb.c b/display-x11-xcb.c index 1d21e590..5772df93 100644 --- a/display-x11-xcb.c +++ b/display-x11-xcb.c @@ -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 0cae4d16..bac2c5f2 100644 --- 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; } diff --git a/python/display-pygtk.py b/python/display-pygtk.py index a9882c3b..392169eb 100644 --- a/python/display-pygtk.py +++ b/python/display-pygtk.py @@ -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 diff --git a/python/lib-server.py b/python/lib-server.py index 41438a05..686b9d86 100755 --- a/python/lib-server.py +++ b/python/lib-server.py @@ -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")