From 8ef07b8cb3a398f14489592a7255ea4cbaab8227 Mon Sep 17 00:00:00 2001 From: NeilBrown Date: Fri, 25 Aug 2023 14:56:48 +1000 Subject: [PATCH] Change Display:set-noclose to Display:set:no-close and store in attribute. Using an attribute to store the no-close string simplifies code, and using "Display:set:" is similar to "doc:set:" and will soon be used to set any attribute at the display level. Signed-off-by: NeilBrown --- DOC/Calls | 2 +- DOC/Developer/07-displays.md | 2 +- display-ncurses.c | 16 +++++----------- display-x11-xcb.c | 17 +++++------------ edlib.c | 2 +- python/display-pygtk.py | 12 ++++++------ python/lib-server.py | 8 ++++---- 7 files changed, 23 insertions(+), 36 deletions(-) diff --git a/DOC/Calls b/DOC/Calls index 1295ac8a..84c20e82 100644 --- a/DOC/Calls +++ b/DOC/Calls @@ -152,7 +152,7 @@ display can be awkward. This is a request for the display to close - may be rejected if it is the only display left. -## Display:set-noclose +## Display:set:no-close This comes with a reason in str1. If a Display:close request arrives when the most recent set-noclose request contained a non-empty string, diff --git a/DOC/Developer/07-displays.md b/DOC/Developer/07-displays.md index 77304a70..606eb0ac 100644 --- a/DOC/Developer/07-displays.md +++ b/DOC/Developer/07-displays.md @@ -98,7 +98,7 @@ Draw:image ## Display management commands Display:close -Display:set-noclose +Display:set:no-close Display:external-viewer Display:fullscreen Display:new diff --git a/display-ncurses.c b/display-ncurses.c index 1e854f42..167048cd 100644 --- a/display-ncurses.c +++ b/display-ncurses.c @@ -64,7 +64,6 @@ struct display_data { SCREEN *scr; FILE *scr_file; int is_xterm; - char *noclose; struct col_hash *col_hash; int report_position; long last_event; @@ -442,10 +441,10 @@ DEF_CMD(nc_close_display) { /* If this is only display, then refuse to close this one */ struct call_return cr; - struct display_data *dd = &ci->home->data; + char *nc = attr_find(ci->home->attrs, "no-close"); - if (dd->noclose) { - call("Message", ci->focus, 0, NULL, dd->noclose); + if (nc) { + call("Message", ci->focus, 0, NULL, nc); return 1; } @@ -466,12 +465,7 @@ DEF_CMD(nc_close_display) DEF_CMD(nc_set_noclose) { - struct display_data *dd = &ci->home->data; - - free(dd->noclose); - dd->noclose = NULL; - if (ci->str) - dd->noclose = strdup(ci->str); + attr_set_str(&ci->home->attrs, "no-close", ci->str); return 1; } @@ -1824,7 +1818,7 @@ void edlib_init(struct pane *ed safe) nc_map = key_alloc(); key_add(nc_map, "Display:refresh", &force_redraw); key_add(nc_map, "Display:close", &nc_close_display); - key_add(nc_map, "Display:set-noclose", &nc_set_noclose); + key_add(nc_map, "Display:set:no-close", &nc_set_noclose); key_add(nc_map, "Display:external-viewer", &nc_external_viewer); key_add(nc_map, "Close", &nc_close); key_add(nc_map, "Draw:clear", &nc_clear); diff --git a/display-x11-xcb.c b/display-x11-xcb.c index b5bd7aa8..63c0e875 100644 --- a/display-x11-xcb.c +++ b/display-x11-xcb.c @@ -195,7 +195,6 @@ struct xcb_data { cairo_t *cairo safe; cairo_surface_t *surface safe; PangoFontDescription *fd safe; - char *noclose; int charwidth, lineheight; cairo_region_t *need_update; @@ -447,10 +446,10 @@ 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; + char *nc = attr_find(ci->home->attrs, "no-close"); - if (xd->noclose) { - call("Message", ci->focus, 0, NULL, xd->noclose); + if (nc) { + call("Message", ci->focus, 0, NULL, nc); return 1; } cr.c = cnt_disp; @@ -466,12 +465,7 @@ DEF_CMD(xcb_close_display) DEF_CMD(xcb_set_noclose) { - struct xcb_data *xd = &ci->home->data; - - free(xd->noclose); - xd->noclose = NULL; - if (ci->str) - xd->noclose = strdup(ci->str); + attr_set_str(&ci->home->attrs, "no-close", ci->str); return 1; } @@ -589,7 +583,6 @@ DEF_CMD(xcb_free) cairo_surface_destroy(xd->surface); free(xd->display); free(xd->disp_auth); - free(xd->noclose); xcb_disconnect(xd->conn); if (xd->need_update) cairo_region_destroy(xd->need_update); @@ -2010,7 +2003,7 @@ void edlib_init(struct pane *ed safe) xcb_map = key_alloc(); key_add(xcb_map, "Display:close", &xcb_close_display); - key_add(xcb_map, "Display:set-noclose", &xcb_set_noclose); + key_add(xcb_map, "Display:set:no-close", &xcb_set_noclose); key_add(xcb_map, "Display:external-viewer", &xcb_external_viewer); key_add(xcb_map, "Display:fullscreen", &xcb_fullscreen); key_add(xcb_map, "Display:new", &xcb_new_display); diff --git a/edlib.c b/edlib.c index c4e8d47c..ee70bab5 100644 --- a/edlib.c +++ b/edlib.c @@ -126,7 +126,7 @@ int main(int argc, char *argv[]) 0, NULL, getenv("XAUTHORITY")); if (!first_window) first_window = p; - call("Display:set-noclose", p, 1, NULL, + call("Display:set:no-close", p, 1, NULL, "Cannot close primary display"); } } diff --git a/python/display-pygtk.py b/python/display-pygtk.py index 6d2367b5..7d2c9954 100644 --- a/python/display-pygtk.py +++ b/python/display-pygtk.py @@ -58,7 +58,6 @@ class EdDisplay(edlib.Pane): self.w = int(self.charwidth * 80.0) self.h = int(self.lineheight * 24.0) self.call("editor:request:all-displays") - self.noclose = None self.last_event = 0 self.win.show() @@ -74,8 +73,9 @@ class EdDisplay(edlib.Pane): def handle_close_window(self, key, focus, **a): "handle:Display:close" - if self.noclose: - focus.call("Message", self.noclose) + nc = self['no-close'] + if nc: + focus.call("Message", nc) return 1 x = [] focus.call("editor:notify:all-displays", lambda key,**a:x.append(1)) @@ -85,9 +85,9 @@ class EdDisplay(edlib.Pane): focus.call("Message", "Cannot close only window.") return 1 - def handle_set_noclose(self, key, str, **a): - "handle:Display:set-noclose" - self.noclose = str + def handle_set_noclose(self, key, str1, **a): + "handle:Display:set:no-close" + self['no-close'] = str1 return 1 def handle_fullscreen(self, key, num, **a): diff --git a/python/lib-server.py b/python/lib-server.py index 49714c29..c1f9294d 100755 --- a/python/lib-server.py +++ b/python/lib-server.py @@ -123,7 +123,7 @@ if sys.argv[0] == "": self.add_notify(d, "Notify:Close") self.doc = d if self.term: - self.term.call("Display:set-noclose", + self.term.call("Display:set:no-close", "Cannot close display until document done - use 'C-x #'") self.sock.send(b"OK") return 1 @@ -166,7 +166,7 @@ if sys.argv[0] == "": return 1 if cmd == "close": if self.disp: - self.disp.call("Display:set-noclose") + self.disp.call("Display:set:no-close") self.disp.call("Display:close") self.disp = None self.call("event:free", self.read) @@ -200,7 +200,7 @@ if sys.argv[0] == "": # same as doc:done self.doc = None if self.term: - self.term.call("Display:set-noclose") + self.term.call("Display:set:no-close") self.term.call("Display:close") self.sock.send(b"Done") return 1 @@ -209,7 +209,7 @@ if sys.argv[0] == "": "handle:doc:done" if str != "test": if self.term: - self.term.call("Display:set-noclose") + self.term.call("Display:set:no-close") self.term.call("Display:close") self.sock.send(b"Done") return 1 -- 2.39.5