diff options
author | Nicholas Marriott <nicm@cvs.openbsd.org> | 2013-03-21 16:08:26 +0000 |
---|---|---|
committer | Nicholas Marriott <nicm@cvs.openbsd.org> | 2013-03-21 16:08:26 +0000 |
commit | 11acb26f8ba0d9cfe239c44002ea5d6c27c39250 (patch) | |
tree | 2c3169ec5d71b660a35fd878796d7aa6eaf17726 /usr.bin | |
parent | ff9aa3a975061758e959ffc2d5802e8608155f69 (diff) |
Miscellaneous tidying of choose API, including:
- rename client and session to start_client and start_session in
window_choose_data struct. also add TREE_OTHER define and reorder
the struct
- rename window_choose_ctx to window_choose_data_run
- don't pass a cmd_ctx into window_choose_create (will let it use a
different client later). instead take type, session, client
- add window_choose_data_free and use it to dispose of wcd rather than
each cmd-*.c doing it individually
- change so ref counting is done by wcd_add and wcd_free rather than
callers
- also add a ref to tree_session
- all the callbacks except choose-client and find-window are the same so
remove them and add window_choose_default_callback
- reorder/rename some other bits and pieces for tidyness
Diffstat (limited to 'usr.bin')
-rw-r--r-- | usr.bin/tmux/cmd-choose-buffer.c | 39 | ||||
-rw-r--r-- | usr.bin/tmux/cmd-choose-client.c | 44 | ||||
-rw-r--r-- | usr.bin/tmux/cmd-choose-list.c | 30 | ||||
-rw-r--r-- | usr.bin/tmux/cmd-choose-tree.c | 32 | ||||
-rw-r--r-- | usr.bin/tmux/cmd-find-window.c | 29 | ||||
-rw-r--r-- | usr.bin/tmux/tmux.h | 28 | ||||
-rw-r--r-- | usr.bin/tmux/window-choose.c | 185 |
7 files changed, 163 insertions, 224 deletions
diff --git a/usr.bin/tmux/cmd-choose-buffer.c b/usr.bin/tmux/cmd-choose-buffer.c index 026a77fe520..305e8e6d8e2 100644 --- a/usr.bin/tmux/cmd-choose-buffer.c +++ b/usr.bin/tmux/cmd-choose-buffer.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cmd-choose-buffer.c,v 1.10 2012/08/14 08:51:53 nicm Exp $ */ +/* $OpenBSD: cmd-choose-buffer.c,v 1.11 2013/03/21 16:08:24 nicm Exp $ */ /* * Copyright (c) 2010 Nicholas Marriott <nicm@users.sourceforge.net> @@ -29,9 +29,6 @@ enum cmd_retval cmd_choose_buffer_exec(struct cmd *, struct cmd_ctx *); -void cmd_choose_buffer_callback(struct window_choose_data *); -void cmd_choose_buffer_free(struct window_choose_data *); - const struct cmd_entry cmd_choose_buffer_entry = { "choose-buffer", NULL, "F:t:", 0, 1, @@ -46,6 +43,7 @@ enum cmd_retval cmd_choose_buffer_exec(struct cmd *self, struct cmd_ctx *ctx) { struct args *args = self->args; + struct client *c; struct window_choose_data *cdata; struct winlink *wl; struct paste_buffer *pb; @@ -57,6 +55,7 @@ cmd_choose_buffer_exec(struct cmd *self, struct cmd_ctx *ctx) ctx->error(ctx, "must be run interactively"); return (CMD_RETURN_ERROR); } + c = ctx->curclient; if ((template = args_get(args, 'F')) == NULL) template = CHOOSE_BUFFER_TEMPLATE; @@ -77,9 +76,8 @@ cmd_choose_buffer_exec(struct cmd *self, struct cmd_ctx *ctx) idx = 0; while ((pb = paste_walk_stack(&global_buffers, &idx)) != NULL) { - cdata = window_choose_data_create(ctx); + cdata = window_choose_data_create(TREE_OTHER, c, c->session); cdata->idx = idx - 1; - cdata->client->references++; cdata->ft_template = xstrdup(template); format_add(cdata->ft, "line", "%u", idx - 1); @@ -93,34 +91,7 @@ cmd_choose_buffer_exec(struct cmd *self, struct cmd_ctx *ctx) } free(action); - window_choose_ready(wl->window->active, - 0, cmd_choose_buffer_callback, cmd_choose_buffer_free); + window_choose_ready(wl->window->active, 0, NULL, NULL); return (CMD_RETURN_NORMAL); } - -void -cmd_choose_buffer_callback(struct window_choose_data *cdata) -{ - if (cdata == NULL) - return; - if (cdata->client->flags & CLIENT_DEAD) - return; - - window_choose_ctx(cdata); -} - -void -cmd_choose_buffer_free(struct window_choose_data *data) -{ - struct window_choose_data *cdata = data; - - if (cdata == NULL) - return; - - cdata->client->references--; - - free(cdata->command); - free(cdata->ft_template); - free(cdata); -} diff --git a/usr.bin/tmux/cmd-choose-client.c b/usr.bin/tmux/cmd-choose-client.c index 0590cba3589..ed8f8bde6fa 100644 --- a/usr.bin/tmux/cmd-choose-client.c +++ b/usr.bin/tmux/cmd-choose-client.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cmd-choose-client.c,v 1.13 2013/01/17 20:30:43 nicm Exp $ */ +/* $OpenBSD: cmd-choose-client.c,v 1.14 2013/03/21 16:08:24 nicm Exp $ */ /* * Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net> @@ -30,7 +30,6 @@ enum cmd_retval cmd_choose_client_exec(struct cmd *, struct cmd_ctx *); void cmd_choose_client_callback(struct window_choose_data *); -void cmd_choose_client_free(struct window_choose_data *); const struct cmd_entry cmd_choose_client_entry = { "choose-client", NULL, @@ -50,9 +49,10 @@ enum cmd_retval cmd_choose_client_exec(struct cmd *self, struct cmd_ctx *ctx) { struct args *args = self->args; + struct client *c; + struct client *c1; struct window_choose_data *cdata; struct winlink *wl; - struct client *c; const char *template; char *action; u_int i, idx, cur; @@ -61,6 +61,7 @@ cmd_choose_client_exec(struct cmd *self, struct cmd_ctx *ctx) ctx->error(ctx, "must be run interactively"); return (CMD_RETURN_ERROR); } + c = ctx->curclient; if ((wl = cmd_find_window(ctx, args_get(args, 't'), NULL)) == NULL) return (CMD_RETURN_ERROR); @@ -78,30 +79,29 @@ cmd_choose_client_exec(struct cmd *self, struct cmd_ctx *ctx) cur = idx = 0; for (i = 0; i < ARRAY_LENGTH(&clients); i++) { - c = ARRAY_ITEM(&clients, i); - if (c == NULL || c->session == NULL) + c1 = ARRAY_ITEM(&clients, i); + if (c1 == NULL || c1->session == NULL) continue; - if (c == ctx->curclient) + if (c1 == ctx->curclient) cur = idx; idx++; - cdata = window_choose_data_create(ctx); + cdata = window_choose_data_create(TREE_OTHER, c, c->session); cdata->idx = i; - cdata->client->references++; cdata->ft_template = xstrdup(template); format_add(cdata->ft, "line", "%u", i); - format_session(cdata->ft, c->session); - format_client(cdata->ft, c); + format_session(cdata->ft, c1->session); + format_client(cdata->ft, c1); - cdata->command = cmd_template_replace(action, c->tty.path, 1); + cdata->command = cmd_template_replace(action, c1->tty.path, 1); window_choose_add(wl->window->active, cdata); } free(action); - window_choose_ready(wl->window->active, - cur, cmd_choose_client_callback, cmd_choose_client_free); + window_choose_ready(wl->window->active, cur, + cmd_choose_client_callback, NULL); return (CMD_RETURN_NORMAL); } @@ -113,7 +113,7 @@ cmd_choose_client_callback(struct window_choose_data *cdata) if (cdata == NULL) return; - if (cdata->client->flags & CLIENT_DEAD) + if (cdata->start_client->flags & CLIENT_DEAD) return; if (cdata->idx > ARRAY_LENGTH(&clients) - 1) @@ -122,19 +122,5 @@ cmd_choose_client_callback(struct window_choose_data *cdata) if (c == NULL || c->session == NULL) return; - window_choose_ctx(cdata); -} - -void -cmd_choose_client_free(struct window_choose_data *cdata) -{ - if (cdata == NULL) - return; - - cdata->client->references--; - - free(cdata->ft_template); - free(cdata->command); - format_free(cdata->ft); - free(cdata); + window_choose_data_run(cdata); } diff --git a/usr.bin/tmux/cmd-choose-list.c b/usr.bin/tmux/cmd-choose-list.c index febbd0e41b1..2bb0aa31ab2 100644 --- a/usr.bin/tmux/cmd-choose-list.c +++ b/usr.bin/tmux/cmd-choose-list.c @@ -1,4 +1,4 @@ -/* $Id: cmd-choose-list.c,v 1.3 2012/09/05 10:14:21 nicm Exp $ */ +/* $Id: cmd-choose-list.c,v 1.4 2013/03/21 16:08:24 nicm Exp $ */ /* * Copyright (c) 2012 Thomas Adam <thomas@xteddy.org> @@ -33,9 +33,6 @@ enum cmd_retval cmd_choose_list_exec(struct cmd *, struct cmd_ctx *); -void cmd_choose_list_callback(struct window_choose_data *); -void cmd_choose_list_free(struct window_choose_data *); - const struct cmd_entry cmd_choose_list_entry = { "choose-list", NULL, "l:t:", 0, 1, @@ -92,32 +89,9 @@ cmd_choose_list_exec(struct cmd *self, struct cmd_ctx *ctx) return (CMD_RETURN_ERROR); } - window_choose_ready(wl->window->active, 0, cmd_choose_list_callback, - cmd_choose_list_free); + window_choose_ready(wl->window->active, 0, NULL, NULL); free(template); return (CMD_RETURN_NORMAL); } - -void -cmd_choose_list_callback(struct window_choose_data *cdata) -{ - if (cdata == NULL || (cdata->client->flags & CLIENT_DEAD)) - return; - - window_choose_ctx(cdata); -} - -void -cmd_choose_list_free(struct window_choose_data *cdata) -{ - cdata->session->references--; - cdata->client->references--; - - free(cdata->ft_template); - free(cdata->command); - format_free(cdata->ft); - free(cdata); - -} diff --git a/usr.bin/tmux/cmd-choose-tree.c b/usr.bin/tmux/cmd-choose-tree.c index de4dff1f6eb..93480b21389 100644 --- a/usr.bin/tmux/cmd-choose-tree.c +++ b/usr.bin/tmux/cmd-choose-tree.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cmd-choose-tree.c,v 1.13 2013/01/17 03:51:21 nicm Exp $ */ +/* $OpenBSD: cmd-choose-tree.c,v 1.14 2013/03/21 16:08:24 nicm Exp $ */ /* * Copyright (c) 2012 Thomas Adam <thomas@xteddy.org> @@ -34,9 +34,6 @@ enum cmd_retval cmd_choose_tree_exec(struct cmd *, struct cmd_ctx *); -void cmd_choose_tree_callback(struct window_choose_data *); -void cmd_choose_tree_free(struct window_choose_data *); - const struct cmd_entry cmd_choose_tree_entry = { "choose-tree", NULL, "S:W:swub:c:t:", 0, 1, @@ -230,35 +227,10 @@ windows_only: free(final_win_template_middle); free(final_win_template_last); - window_choose_ready(wl->window->active, cur_win, - cmd_choose_tree_callback, cmd_choose_tree_free); + window_choose_ready(wl->window->active, cur_win, NULL, NULL); if (args_has(args, 'u')) window_choose_expand_all(wl->window->active); return (CMD_RETURN_NORMAL); } - -void -cmd_choose_tree_callback(struct window_choose_data *cdata) -{ - if (cdata == NULL) - return; - - if (cdata->client->flags & CLIENT_DEAD) - return; - - window_choose_ctx(cdata); -} - -void -cmd_choose_tree_free(struct window_choose_data *cdata) -{ - cdata->session->references--; - cdata->client->references--; - - free(cdata->ft_template); - free(cdata->command); - format_free(cdata->ft); - free(cdata); -} diff --git a/usr.bin/tmux/cmd-find-window.c b/usr.bin/tmux/cmd-find-window.c index 2c73753cda5..0d47fdc8009 100644 --- a/usr.bin/tmux/cmd-find-window.c +++ b/usr.bin/tmux/cmd-find-window.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cmd-find-window.c,v 1.20 2012/10/25 11:26:47 nicm Exp $ */ +/* $OpenBSD: cmd-find-window.c,v 1.21 2013/03/21 16:08:24 nicm Exp $ */ /* * Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net> @@ -31,7 +31,6 @@ enum cmd_retval cmd_find_window_exec(struct cmd *, struct cmd_ctx *); void cmd_find_window_callback(struct window_choose_data *); -void cmd_find_window_free(struct window_choose_data *); /* Flags for determining matching behavior. */ #define CMD_FIND_WINDOW_BY_TITLE 0x1 @@ -131,6 +130,7 @@ enum cmd_retval cmd_find_window_exec(struct cmd *self, struct cmd_ctx *ctx) { struct args *args = self->args; + struct client *c; struct window_choose_data *cdata; struct session *s; struct winlink *wl, *wm; @@ -143,7 +143,8 @@ cmd_find_window_exec(struct cmd *self, struct cmd_ctx *ctx) ctx->error(ctx, "must be run interactively"); return (CMD_RETURN_ERROR); } - s = ctx->curclient->session; + c = ctx->curclient; + s = c->session; if ((wl = cmd_find_window(ctx, args_get(args, 't'), NULL)) == NULL) return (CMD_RETURN_ERROR); @@ -180,9 +181,8 @@ cmd_find_window_exec(struct cmd *self, struct cmd_ctx *ctx) for (i = 0; i < ARRAY_LENGTH(&find_list); i++) { wm = ARRAY_ITEM(&find_list, i).wl; - cdata = window_choose_data_create(ctx); + cdata = window_choose_data_create(TREE_OTHER, c, c->session); cdata->idx = wm->idx; - cdata->client->references++; cdata->wl = wm; cdata->ft_template = xstrdup(template); @@ -198,8 +198,8 @@ cmd_find_window_exec(struct cmd *self, struct cmd_ctx *ctx) window_choose_add(wl->window->active, cdata); } - window_choose_ready(wl->window->active, - 0, cmd_find_window_callback, cmd_find_window_free); + window_choose_ready(wl->window->active, 0, cmd_find_window_callback, + NULL); out: ARRAY_FREE(&find_list); @@ -215,7 +215,7 @@ cmd_find_window_callback(struct window_choose_data *cdata) if (cdata == NULL) return; - s = cdata->session; + s = cdata->start_session; if (!session_alive(s)) return; @@ -228,16 +228,3 @@ cmd_find_window_callback(struct window_choose_data *cdata) recalculate_sizes(); } } - -void -cmd_find_window_free(struct window_choose_data *cdata) -{ - if (cdata == NULL) - return; - - cdata->session->references--; - - free(cdata->ft_template); - format_free(cdata->ft); - free(cdata); -} diff --git a/usr.bin/tmux/tmux.h b/usr.bin/tmux/tmux.h index 6c36c88443b..47aad442008 100644 --- a/usr.bin/tmux/tmux.h +++ b/usr.bin/tmux/tmux.h @@ -1,4 +1,4 @@ -/* $OpenBSD: tmux.h,v 1.374 2013/02/05 11:08:59 nicm Exp $ */ +/* $OpenBSD: tmux.h,v 1.375 2013/03/21 16:08:24 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> @@ -883,18 +883,24 @@ struct window_mode { /* Structures for choose mode. */ struct window_choose_data { - struct client *client; - struct session *session; /* Session of current client. */ - struct session *tree_session; /* Session of items in tree. */ - struct format_tree *ft; - struct winlink *wl; - char *ft_template; - char *command; + struct client *start_client; + struct session *start_session; + u_int idx; int type; +#define TREE_OTHER 0x0 #define TREE_WINDOW 0x1 #define TREE_SESSION 0x2 + + struct session *tree_session; /* session of items in tree */ + + struct winlink *wl; int pane_id; + + char *ft_template; + struct format_tree *ft; + + char *command; }; struct window_choose_mode_item { @@ -2198,8 +2204,10 @@ void window_choose_add(struct window_pane *, void window_choose_ready(struct window_pane *, u_int, void (*)(struct window_choose_data *), void (*)(struct window_choose_data *)); -struct window_choose_data *window_choose_data_create(struct cmd_ctx *); -void window_choose_ctx(struct window_choose_data *); +struct window_choose_data *window_choose_data_create (int, + struct client *, struct session *); +void window_choose_data_free(struct window_choose_data *); +void window_choose_data_run(struct window_choose_data *); struct window_choose_data *window_choose_add_window(struct window_pane *, struct cmd_ctx *, struct session *, struct winlink *, const char *, char *, u_int); diff --git a/usr.bin/tmux/window-choose.c b/usr.bin/tmux/window-choose.c index 0ef949582a7..2e947670453 100644 --- a/usr.bin/tmux/window-choose.c +++ b/usr.bin/tmux/window-choose.c @@ -1,4 +1,4 @@ -/* $OpenBSD: window-choose.c,v 1.32 2013/02/05 11:08:59 nicm Exp $ */ +/* $OpenBSD: window-choose.c,v 1.33 2013/03/21 16:08:25 nicm Exp $ */ /* * Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net> @@ -31,6 +31,8 @@ void window_choose_key(struct window_pane *, struct session *, int); void window_choose_mouse( struct window_pane *, struct session *, struct mouse_event *); +void window_choose_default_callback(struct window_choose_data *); + void window_choose_fire_callback( struct window_pane *, struct window_choose_data *); void window_choose_redraw_screen(struct window_pane *); @@ -112,6 +114,8 @@ window_choose_ready(struct window_pane *wp, u_int cur, data->top = ARRAY_LENGTH(&data->list) - screen_size_y(s); data->callbackfn = callbackfn; + if (data->callbackfn == NULL) + data->callbackfn = window_choose_default_callback; data->freefn = freefn; ARRAY_CONCAT(&data->old_list, &data->list); @@ -154,25 +158,96 @@ window_choose_init(struct window_pane *wp) } struct window_choose_data * -window_choose_data_create(struct cmd_ctx *ctx) +window_choose_data_create(int type, struct client *c, struct session *s) { struct window_choose_data *wcd; wcd = xmalloc(sizeof *wcd); + wcd->type = type; + wcd->ft = format_create(); wcd->ft_template = NULL; + wcd->command = NULL; + wcd->wl = NULL; - wcd->tree_session = NULL; - wcd->client = ctx->curclient; - wcd->session = ctx->curclient->session; + wcd->pane_id = -1; wcd->idx = -1; - wcd->type = 0; + + wcd->tree_session = NULL; + + wcd->start_client = c; + wcd->start_client->references++; + wcd->start_session = s; + wcd->start_session->references++; return (wcd); } void +window_choose_data_free(struct window_choose_data *wcd) +{ + wcd->start_client->references--; + wcd->start_session->references--; + + if (wcd->tree_session != NULL) + wcd->tree_session->references--; + + free(wcd->ft_template); + format_free(wcd->ft); + + free(wcd->command); + free(wcd); +} + +void +window_choose_data_run(struct window_choose_data *cdata) +{ + struct cmd_ctx ctx; + struct cmd_list *cmdlist; + char *cause; + + /* + * The command template will have already been replaced. But if it's + * NULL, bail here. + */ + if (cdata->command == NULL) + return; + + if (cmd_string_parse(cdata->command, &cmdlist, &cause) != 0) { + if (cause != NULL) { + *cause = toupper((u_char) *cause); + status_message_set(cdata->start_client, "%s", cause); + free(cause); + } + return; + } + + ctx.msgdata = NULL; + ctx.curclient = cdata->start_client; + + ctx.error = key_bindings_error; + ctx.print = key_bindings_print; + ctx.info = key_bindings_info; + + ctx.cmdclient = NULL; + + cmd_list_exec(cmdlist, &ctx); + cmd_list_free(cmdlist); +} + +void +window_choose_default_callback(struct window_choose_data *wcd) +{ + if (wcd == NULL) + return; + if (wcd->start_client->flags & CLIENT_DEAD) + return; + + window_choose_data_run(wcd); +} + +void window_choose_free(struct window_pane *wp) { struct window_choose_mode_data *data = wp->modedata; @@ -183,6 +258,7 @@ window_choose_free(struct window_pane *wp) item = &ARRAY_ITEM(&data->old_list, i); if (data->freefn != NULL && item->wcd != NULL) data->freefn(item->wcd); + window_choose_data_free(item->wcd); free(item->name); } ARRAY_FREE(&data->list); @@ -209,7 +285,7 @@ window_choose_resize(struct window_pane *wp, u_int sx, u_int sy) void window_choose_fire_callback( - struct window_pane *wp, struct window_choose_data *wcd) + struct window_pane *wp, struct window_choose_data *wcd) { struct window_choose_mode_data *data = wp->modedata; const struct window_mode *oldmode; @@ -299,7 +375,7 @@ window_choose_collapse_all(struct window_pane *wp) struct session *s, *chosen; u_int i; - chosen = ARRAY_ITEM(&data->list, data->selected).wcd->session; + chosen = ARRAY_ITEM(&data->list, data->selected).wcd->start_session; RB_FOREACH(s, sessions, &sessions) window_choose_collapse(wp, s); @@ -790,58 +866,24 @@ window_choose_scroll_down(struct window_pane *wp) screen_write_stop(&ctx); } -void -window_choose_ctx(struct window_choose_data *cdata) -{ - struct cmd_ctx ctx; - struct cmd_list *cmdlist; - char *cause; - - /* The command template will have already been replaced. But if it's - * NULL, bail here. - */ - if (cdata->command == NULL) - return; - - if (cmd_string_parse(cdata->command, &cmdlist, &cause) != 0) { - if (cause != NULL) { - *cause = toupper((u_char) *cause); - status_message_set(cdata->client, "%s", cause); - free(cause); - } - return; - } - - ctx.msgdata = NULL; - ctx.curclient = cdata->client; - - ctx.error = key_bindings_error; - ctx.print = key_bindings_print; - ctx.info = key_bindings_info; - - ctx.cmdclient = NULL; - - cmd_list_exec(cmdlist, &ctx); - cmd_list_free(cmdlist); -} - struct window_choose_data * window_choose_add_session(struct window_pane *wp, struct cmd_ctx *ctx, struct session *s, const char *template, char *action, u_int idx) { struct window_choose_data *wcd; + struct client *c = ctx->curclient; - wcd = window_choose_data_create(ctx); + wcd = window_choose_data_create(TREE_SESSION, c, c->session); wcd->idx = s->idx; + wcd->tree_session = s; - wcd->type = TREE_SESSION; - wcd->command = cmd_template_replace(action, s->name, 1); + wcd->tree_session->references++; + wcd->ft_template = xstrdup(template); format_add(wcd->ft, "line", "%u", idx); format_session(wcd->ft, s); - wcd->client->references++; - wcd->session->references++; + wcd->command = cmd_template_replace(action, s->name, 1); window_choose_add(wp, wcd); @@ -853,28 +895,27 @@ window_choose_add_item(struct window_pane *wp, struct cmd_ctx *ctx, struct winlink *wl, const char *template, char *action, u_int idx) { struct window_choose_data *wcd; - char *action_data; + struct client *c = ctx->curclient; + char *expanded; - wcd = window_choose_data_create(ctx); + wcd = window_choose_data_create(TREE_OTHER, c, c->session); wcd->idx = wl->idx; + wcd->ft_template = xstrdup(template); format_add(wcd->ft, "line", "%u", idx); - format_session(wcd->ft, wcd->session); - format_winlink(wcd->ft, wcd->session, wl); + format_session(wcd->ft, wcd->start_session); + format_winlink(wcd->ft, wcd->start_session, wl); format_window_pane(wcd->ft, wl->window->active); - wcd->client->references++; - wcd->session->references++; - - window_choose_add(wp, wcd); - /* - * Interpolate action_data here, since the data we pass back is the - * expanded template itself. + * Interpolate action here, since the data we pass back is the expanded + * template itself. */ - xasprintf(&action_data, "%s", format_expand(wcd->ft, wcd->ft_template)); - wcd->command = cmd_template_replace(action, action_data, 1); - free(action_data); + xasprintf(&expanded, "%s", format_expand(wcd->ft, wcd->ft_template)); + wcd->command = cmd_template_replace(action, expanded, 1); + free(expanded); + + window_choose_add(wp, wcd); return (wcd); @@ -886,26 +927,26 @@ window_choose_add_window(struct window_pane *wp, struct cmd_ctx *ctx, char *action, u_int idx) { struct window_choose_data *wcd; - char *action_data; - - wcd = window_choose_data_create(ctx); - - xasprintf(&action_data, "%s:%d", s->name, wl->idx); - wcd->command = cmd_template_replace(action, action_data, 1); - free(action_data); + struct client *c = ctx->curclient; + char *expanded; + wcd = window_choose_data_create(TREE_WINDOW, c, c->session); wcd->idx = wl->idx; + wcd->wl = wl; + wcd->tree_session = s; - wcd->type = TREE_WINDOW; + wcd->tree_session->references++; + wcd->ft_template = xstrdup(template); format_add(wcd->ft, "line", "%u", idx); format_session(wcd->ft, s); format_winlink(wcd->ft, s, wl); format_window_pane(wcd->ft, wl->window->active); - wcd->client->references++; - wcd->session->references++; + xasprintf(&expanded, "%s:%d", s->name, wl->idx); + wcd->command = cmd_template_replace(action, expanded, 1); + free(expanded); window_choose_add(wp, wcd); |