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
This commit is contained in:
Nicholas Marriott
2013-02-10 17:32:58 +00:00
parent 418ba99078
commit 4d382ae8e6
7 changed files with 156 additions and 217 deletions

View File

@ -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);
}