]> git.neil.brown.name Git - edlib.git/commitdiff
Use callback to return pane for call_pane()
authorNeilBrown <neil@brown.name>
Wed, 9 Dec 2015 23:54:56 +0000 (10:54 +1100)
committerNeilBrown <neil@brown.name>
Thu, 10 Dec 2015 02:54:09 +0000 (13:54 +1100)
Signed-off-by: NeilBrown <neil@brown.name>
core-pane.c
core.h
lib-popup.c
lib-tile.c

index cf5bd456b6f6e04f26992f4906ffb01e9075eeb8..22a7eedcf548927395addf3c0b9efe61544a1d02 100644 (file)
@@ -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 0dcee8d76cbdea3ca33b454d46772c88f2965a6d..03db70d70043fb05c33170f78118a4eb9ca430d5 100644 (file)
--- 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)
 {
index 6f12e57ddceaafe701a8935212b67e8d0d6d7044..83e85785bb64443bff9eb4560febf8ced7acb397 100644 (file)
@@ -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;
 }
 
index 038be78e132c883e423316160b957cfdab44798d..7deb7d4b1da9170422c882b59c9f0a4a1d26d870 100644 (file)
@@ -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)