]> git.neil.brown.name Git - edlib.git/commitdiff
handle Display:close in window-core
authorNeilBrown <neil@brown.name>
Wed, 28 Jun 2023 08:08:15 +0000 (18:08 +1000)
committerNeilBrown <neil@brown.name>
Wed, 28 Jun 2023 21:03:28 +0000 (07:03 +1000)
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 <neil@brown.name>
DOC/TODO.md
core-window.c
display-ncurses.c
display-x11-xcb.c
python/display-pygtk.py

index 3578c0cc711a01902f967ae9fc6e81b7651dc986..08a20033d511f1857c47afa45de579b5af12554f 100644 (file)
@@ -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
index 058b36ceb22312255c64f6cf8fccbc4a488ec608..31c02dcdae6b55cf7d74b0740e0dbba0f3d4e25d 100644 (file)
@@ -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);
index fd4d48d587d7b5b81c5ce176ad978eb5711b168d..77df7fe95c080cd8e87d1c096bfea72bd9d1df7b 100644 (file)
@@ -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.");
index 35a36a4d9970158f9696abf10925886980bd2e63..b0c82da754efffacfff16434668d476da127db39 100644 (file)
@@ -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;
 }
 
index bc1d84b375adfd578d51b7516021c033af776c2c..ae5a4c7413e7e1f43027737e5101d092f98b1456 100644 (file)
@@ -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()