From 988e9ee567108bb05a7fd3a1ceeb506907a4dd94 Mon Sep 17 00:00:00 2001 From: NeilBrown Date: Fri, 8 Sep 2023 20:31:13 +1000 Subject: [PATCH] popup: switch to embedded-data pattern. Signed-off-by: NeilBrown --- lib-popup.c | 36 ++++++++++++++++-------------------- lib-tile.c | 3 +++ 2 files changed, 19 insertions(+), 20 deletions(-) diff --git a/lib-popup.c b/lib-popup.c index 6cbb6673..e0f4067a 100644 --- a/lib-popup.c +++ b/lib-popup.c @@ -49,17 +49,19 @@ #include #include +#define PANE_DATA_TYPE struct popup_info #include "core.h" -static struct map *popup_map; -DEF_LOOKUP_CMD(popup_handle, popup_map); - struct popup_info { struct pane *target safe; struct pane *parent_popup; char *style safe; struct command *done; }; +#include "core-pane.h" + +static struct map *popup_map; +DEF_LOOKUP_CMD(popup_handle, popup_map); static int line_height(struct pane *p safe, int scale) { @@ -139,15 +141,8 @@ DEF_CMD(popup_close) pane_focus(ppi->target); command_put(ppi->done); ppi->done = NULL; - return 1; -} - -DEF_CMD(popup_free) -{ - struct popup_info *ppi = ci->home->data; - free(ppi->style); - unalloc(ppi, pane); + ppi->style = ""; return 1; } @@ -468,7 +463,7 @@ DEF_CMD(popup_attach) * r - allow recursive popup * t - temp pane, disappears when it loses focus */ - struct pane *root, *p; + struct pane *root, *p, *parent; struct popup_info *ppi; const char *style = ci->str; char *in_popup; @@ -494,24 +489,26 @@ DEF_CMD(popup_attach) if (!root) return Efallthrough; - alloc(ppi, pane); - ppi->done = NULL; - ppi->target = ci->focus; - /* If focus is already a popup, make this popup higher */ p = pane_my_child(root, ci->focus); if (p && p->z > 0) z = p->z + 1; - ppi->parent_popup = NULL; + parent = NULL; if (strchr(style, 'P')) { - ppi->parent_popup = root; + parent = root; root = root->parent; } - p = pane_register(root, z + 1, &popup_handle.c, ppi); + p = pane_register(root, z + 1, &popup_handle.c); if (!p) return Efail; + ppi = p->data; + ppi->done = NULL; + ppi->target = ci->focus; + + ppi->parent_popup = parent; + ppi->style = strdup(style); popup_set_style(p); xy = pane_mapxy(ci->focus, root, ci->x, ci->y, True); @@ -550,7 +547,6 @@ void edlib_init(struct pane *ed safe) popup_map = key_alloc(); key_add(popup_map, "Close", &popup_close); - key_add(popup_map, "Free", &popup_free); key_add(popup_map, "Notify:Close", &popup_notify_close); key_add(popup_map, "Abort", &popup_abort); key_add(popup_map, "popup:style", &popup_style); diff --git a/lib-tile.c b/lib-tile.c index ed5a6aa9..683c0665 100644 --- a/lib-tile.c +++ b/lib-tile.c @@ -19,6 +19,9 @@ #include #include +/* Note that we don't use PANE_DATA_TYPE because the tileinfo + * moves between panes sometimes. + */ #include "core.h" struct tileinfo { -- 2.43.0