From 50a6c085aeaa8a9cd933de5fe2ddce99e9deff46 Mon Sep 17 00:00:00 2001 From: NeilBrown Date: Sat, 9 Sep 2023 10:07:16 +1000 Subject: [PATCH] Introduce Close:Notify Close:Notify is like Notify:Close, but can be called even after the home pane has DAMAGED_CLOSED. Functions that respond to this must be careful to not trust anything that "Close" might have freed. Signed-off-by: NeilBrown --- core-doc.c | 7 +++++-- core-pane.c | 5 +++++ core-pane.h | 8 +++++--- 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/core-doc.c b/core-doc.c index f11ac966..645d2825 100644 --- a/core-doc.c +++ b/core-doc.c @@ -731,7 +731,10 @@ DEF_CMD(doc_addview) if (d->views /* FIXME always true */) { points_attach(d, ret); d->views[ret].owner = ci->focus; - pane_add_notify(ci->home, ci->focus, "Notify:Close"); + /* Use Close:Notify because we need this even + * when the pane is closing + */ + pane_add_notify(ci->home, ci->focus, "Close:Notify"); } return 1 + ret; } @@ -1330,7 +1333,7 @@ static void init_doc_cmds(void) key_add(doc_default_cmd, "doc:add-view", &doc_addview); key_add(doc_default_cmd, "doc:del-view", &doc_delview); - key_add(doc_default_cmd, "Notify:Close", &doc_view_close); + key_add(doc_default_cmd, "Close:Notify", &doc_view_close); key_add(doc_default_cmd, "doc:vmark-get", &doc_vmarkget); key_add(doc_default_cmd, "doc:vmark-prev", &doc_vmarkprev); key_add(doc_default_cmd, "doc:vmark-new", &doc_vmarknew); diff --git a/core-pane.c b/core-pane.c index 8026b88d..1ba2bf14 100644 --- a/core-pane.c +++ b/core-pane.c @@ -485,6 +485,11 @@ static void pane_notify_close(struct pane *p safe) list_del_init(&n->notifier_link); if (strcmp(n->notification, "Notify:Close") == 0) pane_call(n->notifiee, n->notification, p); + /* Close:Notify can be delivered even to DAMAGED_CLOSED + * panes + */ + if (strcmp(n->notification, "Close:Notify") == 0) + pane_call(n->notifiee, n->notification, p); free(n->notification); free(n); } diff --git a/core-pane.h b/core-pane.h index ca24b0d9..6bdaead0 100644 --- a/core-pane.h +++ b/core-pane.h @@ -132,10 +132,12 @@ static inline int do_call_val(enum target_type type, struct pane *home, if (home) ci.home = home; if ((home->damaged & DAMAGED_CLOSED) && - strncmp(ci.key, "Close", 5) != 0 && - strcmp(ci.key, "Notify:Close") != 0) + ci.key[0] != 'C' && /* Compile will often optimise + * the strncmp away + */ + strncmp(ci.key, "Close", 5) != 0) /* This pane cannot accept anything but - * "Close" or "Close:mark" or "Notify:Close" + * "Close" or "Close:mark" or "Close:Notify" */ return Efail; ci.comm = home->handle; -- 2.39.5