From: NeilBrown Date: Wed, 28 Jun 2023 08:08:15 +0000 (+1000) Subject: handle Display:close in window-core X-Git-Url: http://git.neil.brown.name/?a=commitdiff_plain;h=49a7b31e384904cf2530ab751abd40f7decd717e;p=edlib.git handle Display:close in window-core When a display/window is closed, the whole stack needs to go including the window-core pane. So let the Display:close request get down to there, and close everything. Signed-off-by: NeilBrown --- diff --git a/DOC/TODO.md b/DOC/TODO.md index 3578c0cc..08a20033 100644 --- a/DOC/TODO.md +++ b/DOC/TODO.md @@ -73,6 +73,8 @@ Requirements for a v1.0 release Core features ------------- +- [ ] Do I want "Display" as in "Display:close", or "window" as in + "window:notify". Decide, and make everything consistent. - [ ] Do I really need global-multicall- or can I just use notifications. It would mean more modules would need a private pane, but might diff --git a/core-window.c b/core-window.c index 058b36ce..31c02dcd 100644 --- a/core-window.c +++ b/core-window.c @@ -151,6 +151,12 @@ DEF_CMD(window_attach) return 1; } +DEF_CMD(window_close) +{ + pane_close(ci->home); + return 1; +} + void window_setup(struct pane *ed safe) { window_map = key_alloc(); @@ -158,6 +164,8 @@ void window_setup(struct pane *ed safe) key_add_prefix(window_map, "window:request:", &request_notify); key_add_prefix(window_map, "window:notify:", &send_notify); + key_add(window_map, "Display:close", &window_close); + key_add(window_map, "selection:claim", &selection_claim); key_add(window_map, "selection:commit", &selection_commit); key_add(window_map, "selection:discard", &selection_discard); diff --git a/display-ncurses.c b/display-ncurses.c index fd4d48d5..77df7fe9 100644 --- a/display-ncurses.c +++ b/display-ncurses.c @@ -452,10 +452,10 @@ DEF_CMD(nc_close_display) call_comm("editor:notify:all-displays", ci->focus, &cr.c); if (cr.i > 1) { /* Need to call ncurses_end() before we send a Notify:Close - * notification, else server exists too early + * notification, else server exits too early */ ncurses_end(ci->home); - pane_close(ci->home); + return Efallthrough; } else call("Message", ci->focus, 0, NULL, "Cannot close only window."); diff --git a/display-x11-xcb.c b/display-x11-xcb.c index 35a36a4d..b0c82da7 100644 --- a/display-x11-xcb.c +++ b/display-x11-xcb.c @@ -438,6 +438,7 @@ DEF_CMD(xcb_close_display) /* If this is only display, then refuse to close this one */ struct call_return cr; struct xcb_data *xd = ci->home->data; + if (xd->noclose) { call("Message", ci->focus, 0, NULL, xd->noclose); return 1; @@ -446,7 +447,7 @@ DEF_CMD(xcb_close_display) cr.i = 0; call_comm("editor:notify:all-displays", ci->focus, &cr.c); if (cr.i > 1) - pane_close(ci->home); + return Efallthrough; else call("Message", ci->focus, 0, NULL, "Cannot close only window."); @@ -1593,7 +1594,7 @@ static void handle_client_message(struct pane *home safe, cme->format == 32 && cme->window == xd->win && cme->data.data32[0] == xd->atoms[a_WM_DELETE_WINDOW]) { - pane_call(home, "Display:close", pane_leaf(home)); + call("Display:close", pane_leaf(home)); return; } @@ -1692,8 +1693,10 @@ DEF_CMD(xcb_input) } xcb_flush(xd->conn); } - if (xcb_connection_has_error(xd->conn)) + if (xcb_connection_has_error(xd->conn)) { + call("Display:close", ci->home->parent); pane_close(ci->home); + } return ret; } diff --git a/python/display-pygtk.py b/python/display-pygtk.py index bc1d84b3..ae5a4c74 100644 --- a/python/display-pygtk.py +++ b/python/display-pygtk.py @@ -50,7 +50,8 @@ class EdDisplay(edlib.Pane): self.panes = {} self.bg = {} self.win.set_title("EDLIB") - self.win.connect('destroy', self.close_win) + self.win.connect('destroy', self.destroy_win) + self.win.connect('delete-event', self.close_win) self.create_ui() # report approximate size of an "M" self["scale:M"] = "%dx%d" % (self.charwidth, self.lineheight) @@ -79,7 +80,7 @@ class EdDisplay(edlib.Pane): x = [] focus.call("editor:notify:all-displays", lambda key,**a:x.append(1)) if len(x) > 1: - self.close_win() + return edlib.Efallthrough else: focus.call("Message", "Cannot close only window.") return 1 @@ -497,7 +498,12 @@ class EdDisplay(edlib.Pane): # This must not happen. What should I do? def close_win(self, *a): - self.close() + self.call("Display:close") + return True + + def destroy_win(self, *a): + self.parent("Display:close") + return False def create_ui(self): text = Gtk.DrawingArea()