From: NeilBrown Date: Wed, 9 Dec 2015 23:54:56 +0000 (+1100) Subject: Use callback to return pane for call_pane() X-Git-Tag: lca2016~92 X-Git-Url: http://git.neil.brown.name/?a=commitdiff_plain;h=9e57277e895d8557d04d915af8d80a8cdc77b743;p=edlib.git Use callback to return pane for call_pane() Signed-off-by: NeilBrown --- diff --git a/core-pane.c b/core-pane.c index cf5bd456..22a7eedc 100644 --- a/core-pane.c +++ b/core-pane.c @@ -523,3 +523,29 @@ struct pane *pane_final_child(struct pane *p) p = c; return p; } + +DEF_CMD(take_pane) +{ + struct call_return *cr = container_of(ci->comm, struct call_return, c); + cr->p = ci->focus; + return 1; +} + +struct pane *call_pane(char *key, struct pane *focus, int numeric, + struct mark *m, int extra) +{ + struct cmd_info ci = {0}; + struct call_return cr; + + ci.key = key; + ci.focus = focus; + ci.numeric = numeric; + ci.extra = extra; + ci.mark = m; + cr.c = take_pane; + cr.p = NULL; + ci.comm2 = &cr.c; + if (!key_handle_focus(&ci)) + return NULL; + return cr.p; +} diff --git a/core.h b/core.h index 0dcee8d7..03db70d7 100644 --- a/core.h +++ b/core.h @@ -330,6 +330,8 @@ struct pane *pane_attach(struct pane *p, char *type, struct pane *dp, char *arg) void pane_clear(struct pane *p, char *attrs); void pane_text(struct pane *p, wchar_t ch, char *attrs, int x, int y); char *pane_attr_get(struct pane *p, char *key); +struct pane *call_pane(char *key, struct pane *focus, int numeric, + struct mark *m, int extra); static inline struct pane *pane_child(struct pane *p) { @@ -514,21 +516,6 @@ static inline int comm_call(struct command *comm, char *key, struct pane *focus, return comm->func(&ci); } -static inline struct pane *call_pane(char *key, struct pane *focus, int numeric, - struct mark *m, int extra) -{ - struct cmd_info ci = {0}; - - ci.key = key; - ci.focus = focus; - ci.numeric = numeric; - ci.extra = extra; - ci.mark = m; - if (!key_handle_focus(&ci)) - return NULL; - return ci.focus; -} - static inline int call_extra(char *key, struct pane *focus, int numeric, struct mark *m, int extra) { diff --git a/lib-popup.c b/lib-popup.c index 6f12e57d..83e85785 100644 --- a/lib-popup.c +++ b/lib-popup.c @@ -98,10 +98,10 @@ DEF_CMD(popup_handle) pane_close(ppi->popup); return 1; } - if (strcmp(ci->key, "popup:get-target") == 0) { - ci->focus = ppi->target; - return 1; - } + if (strcmp(ci->key, "popup:get-target") == 0) + return comm_call(ci->comm2, "callback:get-target", + ppi->target, 0, NULL, NULL, 0); + return 0; } diff --git a/lib-tile.c b/lib-tile.c index 038be78e..7deb7d4b 100644 --- a/lib-tile.c +++ b/lib-tile.c @@ -631,22 +631,23 @@ DEF_CMD(tile_other) if (!list_empty(&ti->tiles)) { struct tileinfo *ti2 = list_next_entry(ti, tiles); - ci->focus = ti2->p; - return 1; + return comm_call(ci->comm2, "callback:pane", ti2->p, 0, + NULL, NULL, 0); } /* Need to create a tile. If wider than 120 (FIXME configurable and * pixel sensitive), horiz-split else vert */ p2 = tile_split(p, p->w >= 120, 1); if (p2) - ci->focus = p2; - return 1; + return comm_call(ci->comm2, "callback:pane", p2, 0, + NULL, NULL, 0); + return -1; } DEF_CMD(tile_this) { - ci->focus = ci->home; - return 1; + return comm_call(ci->comm2, "callback:pane", ci->home, 0, + NULL, NULL, 0); } DEF_CMD(tile_root) @@ -657,8 +658,8 @@ DEF_CMD(tile_root) p = p->parent; ti = p->data; } - ci->focus = p; - return 1; + return comm_call(ci->comm2, "callback:pane", p, 0, + NULL, NULL, 0); } void edlib_init(struct editor *ed)