From 4d382ae8e6c71c5414dc41053223c05400d923f8 Mon Sep 17 00:00:00 2001 From: Nicholas Marriott Date: Sun, 10 Feb 2013 17:32:58 +0000 Subject: 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. this means 1 ref for each item but what of it :-) - also add a ref to tree_session - not sure if this is needed? - 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 --- cmd-choose-client.c | 42 ++++++++++++++---------------------------- 1 file changed, 14 insertions(+), 28 deletions(-) (limited to 'cmd-choose-client.c') diff --git a/cmd-choose-client.c b/cmd-choose-client.c index 75ef8f2c..0748072d 100644 --- a/cmd-choose-client.c +++ b/cmd-choose-client.c @@ -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); } -- cgit