diff options
author | Nicholas Marriott <nicm@cvs.openbsd.org> | 2020-04-13 11:00:00 +0000 |
---|---|---|
committer | Nicholas Marriott <nicm@cvs.openbsd.org> | 2020-04-13 11:00:00 +0000 |
commit | 56530d4d9e327bc4c76b8b02290102a1fadfffb9 (patch) | |
tree | c902ce5f812b38436dec697a5fa08bf3615c0ed4 /usr.bin/tmux | |
parent | 9947eee19da9830a3c591d7fb4574df8cdd144e6 (diff) |
Also move cmdq_item and cmdq_list into cmd-queue.c (this is to make its
use more clearly defined and preparation for some future work).
Diffstat (limited to 'usr.bin/tmux')
62 files changed, 532 insertions, 398 deletions
diff --git a/usr.bin/tmux/cmd-attach-session.c b/usr.bin/tmux/cmd-attach-session.c index 0c1de1c8177..c31adab30cb 100644 --- a/usr.bin/tmux/cmd-attach-session.c +++ b/usr.bin/tmux/cmd-attach-session.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cmd-attach-session.c,v 1.80 2020/04/13 08:26:27 nicm Exp $ */ +/* $OpenBSD: cmd-attach-session.c,v 1.81 2020/04/13 10:59:58 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com> @@ -50,10 +50,12 @@ enum cmd_retval cmd_attach_session(struct cmdq_item *item, const char *tflag, int dflag, int xflag, int rflag, const char *cflag, int Eflag) { - struct cmd_find_state *current = &item->shared->current; + struct cmdq_shared *shared = cmdq_get_shared(item); + struct cmd_find_state *current = &shared->current; + struct cmd_find_state target; enum cmd_find_type type; int flags; - struct client *c = item->client, *c_loop; + struct client *c = cmdq_get_client(item), *c_loop; struct session *s; struct winlink *wl; struct window_pane *wp; @@ -80,11 +82,11 @@ cmd_attach_session(struct cmdq_item *item, const char *tflag, int dflag, type = CMD_FIND_SESSION; flags = CMD_FIND_PREFER_UNATTACHED; } - if (cmd_find_target(&item->target, item, tflag, type, flags) != 0) + if (cmd_find_target(&target, item, tflag, type, flags) != 0) return (CMD_RETURN_ERROR); - s = item->target.s; - wl = item->target.wl; - wp = item->target.wp; + s = target.s; + wl = target.wl; + wp = target.wp; if (wl != NULL) { if (wp != NULL) @@ -118,7 +120,7 @@ cmd_attach_session(struct cmdq_item *item, const char *tflag, int dflag, environ_update(s->options, c->environ, s->environ); c->session = s; - if (~item->shared->flags & CMDQ_SHARED_REPEAT) + if (~shared->flags & CMDQ_SHARED_REPEAT) server_client_set_key_table(c, NULL); tty_update_client_offset(c); status_timer_start(c); diff --git a/usr.bin/tmux/cmd-break-pane.c b/usr.bin/tmux/cmd-break-pane.c index 8725bcac189..96a9029e966 100644 --- a/usr.bin/tmux/cmd-break-pane.c +++ b/usr.bin/tmux/cmd-break-pane.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cmd-break-pane.c,v 1.51 2020/04/13 08:26:27 nicm Exp $ */ +/* $OpenBSD: cmd-break-pane.c,v 1.52 2020/04/13 10:59:58 nicm Exp $ */ /* * Copyright (c) 2009 Nicholas Marriott <nicholas.marriott@gmail.com> @@ -49,15 +49,18 @@ static enum cmd_retval cmd_break_pane_exec(struct cmd *self, struct cmdq_item *item) { struct args *args = cmd_get_args(self); - struct cmd_find_state *current = &item->shared->current; + struct cmdq_shared *shared = cmdq_get_shared(item); + struct cmd_find_state *current = &shared->current; + struct cmd_find_state *target = cmdq_get_target(item); + struct cmd_find_state *source = cmdq_get_source(item); struct client *c = cmd_find_client(item, NULL, 1); - struct winlink *wl = item->source.wl; - struct session *src_s = item->source.s; - struct session *dst_s = item->target.s; - struct window_pane *wp = item->source.wp; + struct winlink *wl = source->wl; + struct session *src_s = source->s; + struct session *dst_s = target->s; + struct window_pane *wp = source->wp; struct window *w = wl->window; char *name, *cause; - int idx = item->target.idx; + int idx = target->idx; const char *template; char *cp; diff --git a/usr.bin/tmux/cmd-capture-pane.c b/usr.bin/tmux/cmd-capture-pane.c index 1542d0be134..a250b5b980f 100644 --- a/usr.bin/tmux/cmd-capture-pane.c +++ b/usr.bin/tmux/cmd-capture-pane.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cmd-capture-pane.c,v 1.52 2020/04/13 08:26:27 nicm Exp $ */ +/* $OpenBSD: cmd-capture-pane.c,v 1.53 2020/04/13 10:59:58 nicm Exp $ */ /* * Copyright (c) 2009 Jonathan Alvarado <radobobo@users.sourceforge.net> @@ -193,8 +193,8 @@ static enum cmd_retval cmd_capture_pane_exec(struct cmd *self, struct cmdq_item *item) { struct args *args = cmd_get_args(self); - struct client *c = item->client; - struct window_pane *wp = item->target.wp; + struct client *c = cmdq_get_client(item); + struct window_pane *wp = cmdq_get_target(item)->wp; char *buf, *cause; const char *bufname; size_t len; diff --git a/usr.bin/tmux/cmd-choose-tree.c b/usr.bin/tmux/cmd-choose-tree.c index 9ef2ed589e3..e9c9115bdda 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.45 2020/04/13 08:26:27 nicm Exp $ */ +/* $OpenBSD: cmd-choose-tree.c,v 1.46 2020/04/13 10:59:58 nicm Exp $ */ /* * Copyright (c) 2012 Thomas Adam <thomas@xteddy.org> @@ -72,7 +72,8 @@ static enum cmd_retval cmd_choose_tree_exec(struct cmd *self, struct cmdq_item *item) { struct args *args = cmd_get_args(self); - struct window_pane *wp = item->target.wp; + struct cmd_find_state *target = cmdq_get_target(item); + struct window_pane *wp = target->wp; const struct window_mode *mode; if (cmd_get_entry(self) == &cmd_choose_buffer_entry) { @@ -86,6 +87,6 @@ cmd_choose_tree_exec(struct cmd *self, struct cmdq_item *item) } else mode = &window_tree_mode; - window_pane_set_mode(wp, NULL, mode, &item->target, args); + window_pane_set_mode(wp, NULL, mode, target, args); return (CMD_RETURN_NORMAL); } diff --git a/usr.bin/tmux/cmd-copy-mode.c b/usr.bin/tmux/cmd-copy-mode.c index 911fedbbca5..2e9eaa54bf1 100644 --- a/usr.bin/tmux/cmd-copy-mode.c +++ b/usr.bin/tmux/cmd-copy-mode.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cmd-copy-mode.c,v 1.42 2020/04/13 08:26:27 nicm Exp $ */ +/* $OpenBSD: cmd-copy-mode.c,v 1.43 2020/04/13 10:59:58 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com> @@ -57,10 +57,12 @@ static enum cmd_retval cmd_copy_mode_exec(struct cmd *self, struct cmdq_item *item) { struct args *args = cmd_get_args(self); - struct cmdq_shared *shared = item->shared; - struct client *c = item->client; + struct cmdq_shared *shared = cmdq_get_shared(item); + struct cmd_find_state *source = cmdq_get_source(item); + struct cmd_find_state *target = cmdq_get_target(item); + struct client *c = cmdq_get_client(item); struct session *s; - struct window_pane *wp = item->target.wp, *swp; + struct window_pane *wp = target->wp, *swp; if (args_has(args, 'q')) { window_pane_reset_mode_all(wp); @@ -80,7 +82,7 @@ cmd_copy_mode_exec(struct cmd *self, struct cmdq_item *item) } if (args_has(args, 's')) - swp = item->source.wp; + swp = source->wp; else swp = wp; if (!window_pane_set_mode(wp, swp, &window_copy_mode, NULL, args)) { diff --git a/usr.bin/tmux/cmd-detach-client.c b/usr.bin/tmux/cmd-detach-client.c index d2afb64c11b..f329e211237 100644 --- a/usr.bin/tmux/cmd-detach-client.c +++ b/usr.bin/tmux/cmd-detach-client.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cmd-detach-client.c,v 1.33 2020/04/13 08:26:27 nicm Exp $ */ +/* $OpenBSD: cmd-detach-client.c,v 1.34 2020/04/13 10:59:58 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com> @@ -57,11 +57,12 @@ const struct cmd_entry cmd_suspend_client_entry = { static enum cmd_retval cmd_detach_client_exec(struct cmd *self, struct cmdq_item *item) { - struct args *args = cmd_get_args(self); - struct client *c, *cloop; - struct session *s; - enum msgtype msgtype; - const char *cmd = args_get(args, 'E'); + struct args *args = cmd_get_args(self); + struct cmd_find_state *source = cmdq_get_source(item); + struct client *c, *cloop; + struct session *s; + enum msgtype msgtype; + const char *cmd = args_get(args, 'E'); if ((c = cmd_find_client(item, args_get(args, 't'), 0)) == NULL) return (CMD_RETURN_ERROR); @@ -77,7 +78,7 @@ cmd_detach_client_exec(struct cmd *self, struct cmdq_item *item) msgtype = MSG_DETACH; if (args_has(args, 's')) { - s = item->source.s; + s = source->s; if (s == NULL) return (CMD_RETURN_NORMAL); TAILQ_FOREACH(cloop, &clients, entry) { diff --git a/usr.bin/tmux/cmd-display-menu.c b/usr.bin/tmux/cmd-display-menu.c index 9d2eb206fcc..3eb989556f9 100644 --- a/usr.bin/tmux/cmd-display-menu.c +++ b/usr.bin/tmux/cmd-display-menu.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cmd-display-menu.c,v 1.13 2020/04/13 08:26:27 nicm Exp $ */ +/* $OpenBSD: cmd-display-menu.c,v 1.14 2020/04/13 10:59:58 nicm Exp $ */ /* * Copyright (c) 2019 Nicholas Marriott <nicholas.marriott@gmail.com> @@ -65,9 +65,11 @@ static void cmd_display_menu_get_position(struct client *c, struct cmdq_item *item, struct args *args, u_int *px, u_int *py, u_int w, u_int h) { + struct cmdq_shared *shared = cmdq_get_shared(item); + struct cmd_find_state *target = cmdq_get_target(item); struct session *s = c->session; - struct winlink *wl = item->target.wl; - struct window_pane *wp = item->target.wp; + struct winlink *wl = target->wl; + struct window_pane *wp = target->wp; struct style_ranges *ranges; struct style_range *sr; const char *xp, *yp; @@ -97,9 +99,9 @@ cmd_display_menu_get_position(struct client *c, struct cmdq_item *item, *px = wp->xoff - ox; else *px = 0; - } else if (strcmp(xp, "M") == 0 && item->shared->mouse.valid) { - if (item->shared->mouse.x > w / 2) - *px = item->shared->mouse.x - w / 2; + } else if (strcmp(xp, "M") == 0 && shared->mouse.valid) { + if (shared->mouse.x > w / 2) + *px = shared->mouse.x - w / 2; else *px = 0; } else if (strcmp(xp, "W") == 0) { @@ -131,8 +133,8 @@ cmd_display_menu_get_position(struct client *c, struct cmdq_item *item, *py = wp->yoff + wp->sy - oy; else *py = 0; - } else if (strcmp(yp, "M") == 0 && item->shared->mouse.valid) - *py = item->shared->mouse.y + h; + } else if (strcmp(yp, "M") == 0 && shared->mouse.valid) + *py = shared->mouse.y + h; else if (strcmp(yp, "S") == 0) { if (options_get_number(s->options, "status-position") == 0) { if (lines != 0) @@ -172,11 +174,9 @@ static enum cmd_retval cmd_display_menu_exec(struct cmd *self, struct cmdq_item *item) { struct args *args = cmd_get_args(self); + struct cmdq_shared *shared = cmdq_get_shared(item); + struct cmd_find_state *target = cmdq_get_target(item); struct client *c; - struct session *s = item->target.s; - struct winlink *wl = item->target.wl; - struct window_pane *wp = item->target.wp; - struct cmd_find_state *fs = &item->target; struct menu *menu = NULL; struct menu_item menu_item; const char *key; @@ -190,16 +190,15 @@ cmd_display_menu_exec(struct cmd *self, struct cmdq_item *item) return (CMD_RETURN_NORMAL); if (args_has(args, 'T')) - title = format_single(item, args_get(args, 'T'), c, s, wl, wp); + title = format_single_from_target(item, args_get(args, 'T'), c); else title = xstrdup(""); - menu = menu_create(title); for (i = 0; i != args->argc; /* nothing */) { name = args->argv[i++]; if (*name == '\0') { - menu_add_item(menu, NULL, item, c, fs); + menu_add_item(menu, NULL, item, c, target); continue; } @@ -215,7 +214,7 @@ cmd_display_menu_exec(struct cmd *self, struct cmdq_item *item) menu_item.key = key_string_lookup_string(key); menu_item.command = args->argv[i++]; - menu_add_item(menu, &menu_item, item, c, fs); + menu_add_item(menu, &menu_item, item, c, target); } free(title); if (menu == NULL) { @@ -229,9 +228,9 @@ cmd_display_menu_exec(struct cmd *self, struct cmdq_item *item) cmd_display_menu_get_position(c, item, args, &px, &py, menu->width + 4, menu->count + 2); - if (!item->shared->mouse.valid) + if (!shared->mouse.valid) flags |= MENU_NOMOUSE; - if (menu_display(menu, flags, item, px, py, c, fs, NULL, NULL) != 0) + if (menu_display(menu, flags, item, px, py, c, target, NULL, NULL) != 0) return (CMD_RETURN_NORMAL); return (CMD_RETURN_WAIT); } @@ -240,8 +239,8 @@ static enum cmd_retval cmd_display_popup_exec(struct cmd *self, struct cmdq_item *item) { struct args *args = cmd_get_args(self); + struct cmd_find_state *target = cmdq_get_target(item); struct client *c; - struct cmd_find_state *fs = &item->target; const char *value, *cmd = NULL, **lines = NULL; const char *shellcmd = NULL; char *cwd, *cause; @@ -278,7 +277,7 @@ cmd_display_popup_exec(struct cmd *self, struct cmdq_item *item) } if (nlines != 0) - w = popup_width(item, nlines, lines, c, fs) + 2; + w = popup_width(item, nlines, lines, c, target) + 2; else w = c->tty.sx / 2; if (args_has(args, 'w')) { @@ -298,13 +297,13 @@ cmd_display_popup_exec(struct cmd *self, struct cmdq_item *item) value = args_get(args, 'd'); if (value != NULL) - cwd = format_single(item, value, c, fs->s, fs->wl, fs->wp); + cwd = format_single_from_target(item, value, c); else - cwd = xstrdup(server_client_get_cwd(c, fs->s)); + cwd = xstrdup(server_client_get_cwd(c, target->s)); value = args_get(args, 'R'); if (value != NULL) - shellcmd = format_single(item, value, c, fs->s, fs->wl, fs->wp); + shellcmd = format_single_from_target(item, value, c); if (args_has(args, 'K')) flags |= POPUP_WRITEKEYS; @@ -313,7 +312,7 @@ cmd_display_popup_exec(struct cmd *self, struct cmdq_item *item) else if (args_has(args, 'E')) flags |= POPUP_CLOSEEXIT; if (popup_display(flags, item, px, py, w, h, nlines, lines, shellcmd, - cmd, cwd, c, fs) != 0) + cmd, cwd, c, target) != 0) return (CMD_RETURN_NORMAL); return (CMD_RETURN_WAIT); } diff --git a/usr.bin/tmux/cmd-display-message.c b/usr.bin/tmux/cmd-display-message.c index b8390ded740..f4f32ed7dda 100644 --- a/usr.bin/tmux/cmd-display-message.c +++ b/usr.bin/tmux/cmd-display-message.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cmd-display-message.c,v 1.51 2020/04/13 08:26:27 nicm Exp $ */ +/* $OpenBSD: cmd-display-message.c,v 1.52 2020/04/13 10:59:58 nicm Exp $ */ /* * Copyright (c) 2009 Tiago Cunha <me@tiagocunha.org> @@ -61,10 +61,11 @@ static enum cmd_retval cmd_display_message_exec(struct cmd *self, struct cmdq_item *item) { struct args *args = cmd_get_args(self); + struct cmd_find_state *target = cmdq_get_target(item); struct client *c, *target_c; - struct session *s = item->target.s; - struct winlink *wl = item->target.wl; - struct window_pane *wp = item->target.wp; + struct session *s = target->s; + struct winlink *wl = target->wl; + struct window_pane *wp = target->wp; const char *template; char *msg, *cause; struct format_tree *ft; @@ -105,7 +106,7 @@ cmd_display_message_exec(struct cmd *self, struct cmdq_item *item) flags = FORMAT_VERBOSE; else flags = 0; - ft = format_create(item->client, item, FORMAT_NONE, flags); + ft = format_create(cmdq_get_client(item), item, FORMAT_NONE, flags); format_defaults(ft, target_c, s, wl, wp); if (args_has(args, 'a')) { diff --git a/usr.bin/tmux/cmd-find-window.c b/usr.bin/tmux/cmd-find-window.c index 0f95ed1cc9c..d487d564053 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.48 2020/04/13 08:26:27 nicm Exp $ */ +/* $OpenBSD: cmd-find-window.c,v 1.49 2020/04/13 10:59:58 nicm Exp $ */ /* * Copyright (c) 2009 Nicholas Marriott <nicholas.marriott@gmail.com> @@ -45,7 +45,8 @@ static enum cmd_retval cmd_find_window_exec(struct cmd *self, struct cmdq_item *item) { struct args *args = cmd_get_args(self), *new_args; - struct window_pane *wp = item->target.wp; + struct cmd_find_state *target = cmdq_get_target(item); + struct window_pane *wp = target->wp; const char *s = args->argv[0]; char *filter, *argv = { NULL }; int C, N, T; @@ -116,8 +117,7 @@ cmd_find_window_exec(struct cmd *self, struct cmdq_item *item) args_set(new_args, 'Z', NULL); args_set(new_args, 'f', filter); - window_pane_set_mode(wp, NULL, &window_tree_mode, &item->target, - new_args); + window_pane_set_mode(wp, NULL, &window_tree_mode, target, new_args); args_free(new_args); free(filter); diff --git a/usr.bin/tmux/cmd-find.c b/usr.bin/tmux/cmd-find.c index 2e24e357704..4d19d2f8f5b 100644 --- a/usr.bin/tmux/cmd-find.c +++ b/usr.bin/tmux/cmd-find.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cmd-find.c,v 1.74 2020/04/09 13:54:38 nicm Exp $ */ +/* $OpenBSD: cmd-find.c,v 1.75 2020/04/13 10:59:58 nicm Exp $ */ /* * Copyright (c) 2015 Nicholas Marriott <nicholas.marriott@gmail.com> @@ -961,10 +961,11 @@ cmd_find_target(struct cmd_find_state *fs, struct cmdq_item *item, if (server_check_marked() && (flags & CMD_FIND_DEFAULT_MARKED)) { fs->current = &marked_pane; log_debug("%s: current is marked pane", __func__); - } else if (cmd_find_valid_state(&item->shared->current)) { - fs->current = &item->shared->current; + } else if (cmd_find_valid_state(&cmdq_get_shared(item)->current)) { + fs->current = &cmdq_get_shared(item)->current; log_debug("%s: current is from queue", __func__); - } else if (cmd_find_from_client(¤t, item->client, flags) == 0) { + } else if (cmd_find_from_client(¤t, cmdq_get_client(item), + flags) == 0) { fs->current = ¤t; log_debug("%s: current is from client", __func__); } else { @@ -981,7 +982,7 @@ cmd_find_target(struct cmd_find_state *fs, struct cmdq_item *item, /* Mouse target is a plain = or {mouse}. */ if (strcmp(target, "=") == 0 || strcmp(target, "{mouse}") == 0) { - m = &item->shared->mouse; + m = &cmdq_get_shared(item)->mouse; switch (type) { case CMD_FIND_PANE: fs->wp = cmd_mouse_pane(m, &fs->s, &fs->wl); @@ -1237,7 +1238,7 @@ cmd_find_current_client(struct cmdq_item *item, int quiet) struct cmd_find_state fs; if (item != NULL) - c = item->client; + c = cmdq_get_client(item); if (c != NULL && c->session != NULL) return (c); diff --git a/usr.bin/tmux/cmd-if-shell.c b/usr.bin/tmux/cmd-if-shell.c index f0c792d47be..6f307ed063b 100644 --- a/usr.bin/tmux/cmd-if-shell.c +++ b/usr.bin/tmux/cmd-if-shell.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cmd-if-shell.c,v 1.67 2020/04/13 08:26:27 nicm Exp $ */ +/* $OpenBSD: cmd-if-shell.c,v 1.68 2020/04/13 10:59:58 nicm Exp $ */ /* * Copyright (c) 2009 Tiago Cunha <me@tiagocunha.org> @@ -63,20 +63,19 @@ static enum cmd_retval cmd_if_shell_exec(struct cmd *self, struct cmdq_item *item) { struct args *args = cmd_get_args(self); - struct mouse_event *m = &item->shared->mouse; + struct cmdq_shared *shared = cmdq_get_shared(item); + struct cmd_find_state *target = cmdq_get_target(item); + struct mouse_event *m = &shared->mouse; struct cmd_if_shell_data *cdata; char *shellcmd, *cmd; const char *file; struct cmdq_item *new_item; - struct cmd_find_state *fs = &item->target; struct client *c = cmd_find_client(item, NULL, 1); - struct session *s = fs->s; - struct winlink *wl = fs->wl; - struct window_pane *wp = fs->wp; + struct session *s = target->s; struct cmd_parse_input pi; struct cmd_parse_result *pr; - shellcmd = format_single(item, args->argv[0], c, s, wl, wp); + shellcmd = format_single_from_target(item, args->argv[0], c); if (args_has(args, 'F')) { if (*shellcmd != '0' && *shellcmd != '\0') cmd = args->argv[1]; @@ -92,7 +91,7 @@ cmd_if_shell_exec(struct cmd *self, struct cmdq_item *item) cmd_get_source(self, &pi.file, &pi.line); pi.item = item; pi.c = c; - cmd_find_copy_state(&pi.fs, fs); + cmd_find_copy_state(&pi.fs, target); pr = cmd_parse_from_string(cmd, &pi); switch (pr->status) { @@ -103,7 +102,7 @@ cmd_if_shell_exec(struct cmd *self, struct cmdq_item *item) free(pr->error); return (CMD_RETURN_ERROR); case CMD_PARSE_SUCCESS: - new_item = cmdq_get_command(pr->cmdlist, fs, m, 0); + new_item = cmdq_get_command(pr->cmdlist, target, m, 0); cmdq_insert_after(item, new_item); cmd_list_free(pr->cmdlist); break; @@ -121,7 +120,7 @@ cmd_if_shell_exec(struct cmd *self, struct cmdq_item *item) memcpy(&cdata->mouse, m, sizeof cdata->mouse); if (!args_has(args, 'b')) - cdata->client = item->client; + cdata->client = cmdq_get_client(item); else cdata->client = c; if (cdata->client != NULL) @@ -139,9 +138,10 @@ cmd_if_shell_exec(struct cmd *self, struct cmdq_item *item) cdata->input.c = c; if (cdata->input.c != NULL) cdata->input.c->references++; - cmd_find_copy_state(&cdata->input.fs, fs); + cmd_find_copy_state(&cdata->input.fs, target); - if (job_run(shellcmd, s, server_client_get_cwd(item->client, s), NULL, + if (job_run(shellcmd, s, + server_client_get_cwd(cmdq_get_client(item), s), NULL, cmd_if_shell_callback, cmd_if_shell_free, cdata, 0, -1, -1) == NULL) { cmdq_error(item, "failed to run command: %s", shellcmd); diff --git a/usr.bin/tmux/cmd-join-pane.c b/usr.bin/tmux/cmd-join-pane.c index df2a9cb0605..3d9db557660 100644 --- a/usr.bin/tmux/cmd-join-pane.c +++ b/usr.bin/tmux/cmd-join-pane.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cmd-join-pane.c,v 1.40 2020/04/13 08:26:27 nicm Exp $ */ +/* $OpenBSD: cmd-join-pane.c,v 1.41 2020/04/13 10:59:58 nicm Exp $ */ /* * Copyright (c) 2011 George Nachman <tmux@georgester.com> @@ -64,7 +64,10 @@ static enum cmd_retval cmd_join_pane_exec(struct cmd *self, struct cmdq_item *item) { struct args *args = cmd_get_args(self); - struct cmd_find_state *current = &item->shared->current; + struct cmdq_shared *shared = cmdq_get_shared(item); + struct cmd_find_state *current = &shared->current; + struct cmd_find_state *target = cmdq_get_target(item); + struct cmd_find_state *source = cmdq_get_source(item); struct session *dst_s; struct winlink *src_wl, *dst_wl; struct window *src_w, *dst_w; @@ -80,15 +83,15 @@ cmd_join_pane_exec(struct cmd *self, struct cmdq_item *item) else not_same_window = 0; - dst_s = item->target.s; - dst_wl = item->target.wl; - dst_wp = item->target.wp; + dst_s = target->s; + dst_wl = target->wl; + dst_wp = target->wp; dst_w = dst_wl->window; dst_idx = dst_wl->idx; server_unzoom_window(dst_w); - src_wl = item->source.wl; - src_wp = item->source.wp; + src_wl = source->wl; + src_wp = source->wp; src_w = src_wl->window; server_unzoom_window(src_w); diff --git a/usr.bin/tmux/cmd-kill-pane.c b/usr.bin/tmux/cmd-kill-pane.c index 870147f3bd9..c57f1e84177 100644 --- a/usr.bin/tmux/cmd-kill-pane.c +++ b/usr.bin/tmux/cmd-kill-pane.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cmd-kill-pane.c,v 1.28 2020/04/13 08:26:27 nicm Exp $ */ +/* $OpenBSD: cmd-kill-pane.c,v 1.29 2020/04/13 10:59:58 nicm Exp $ */ /* * Copyright (c) 2009 Nicholas Marriott <nicholas.marriott@gmail.com> @@ -45,8 +45,9 @@ static enum cmd_retval cmd_kill_pane_exec(struct cmd *self, struct cmdq_item *item) { struct args *args = cmd_get_args(self); - struct winlink *wl = item->target.wl; - struct window_pane *loopwp, *tmpwp, *wp = item->target.wp; + struct cmd_find_state *target = cmdq_get_target(item); + struct winlink *wl = target->wl; + struct window_pane *loopwp, *tmpwp, *wp = target->wp; if (args_has(args, 'a')) { server_unzoom_window(wl->window); diff --git a/usr.bin/tmux/cmd-kill-session.c b/usr.bin/tmux/cmd-kill-session.c index f0ea8725989..a23933aa152 100644 --- a/usr.bin/tmux/cmd-kill-session.c +++ b/usr.bin/tmux/cmd-kill-session.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cmd-kill-session.c,v 1.26 2020/04/13 08:26:27 nicm Exp $ */ +/* $OpenBSD: cmd-kill-session.c,v 1.27 2020/04/13 10:59:58 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com> @@ -45,11 +45,10 @@ const struct cmd_entry cmd_kill_session_entry = { static enum cmd_retval cmd_kill_session_exec(struct cmd *self, struct cmdq_item *item) { - struct args *args = cmd_get_args(self); - struct session *s, *sloop, *stmp; - struct winlink *wl; - - s = item->target.s; + struct args *args = cmd_get_args(self); + struct cmd_find_state *target = cmdq_get_target(item); + struct session *s = target->s, *sloop, *stmp; + struct winlink *wl; if (args_has(args, 'C')) { RB_FOREACH(wl, winlinks, &s->windows) { diff --git a/usr.bin/tmux/cmd-kill-window.c b/usr.bin/tmux/cmd-kill-window.c index 33b26fdb34e..4c34225631b 100644 --- a/usr.bin/tmux/cmd-kill-window.c +++ b/usr.bin/tmux/cmd-kill-window.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cmd-kill-window.c,v 1.25 2020/04/13 08:26:27 nicm Exp $ */ +/* $OpenBSD: cmd-kill-window.c,v 1.26 2020/04/13 10:59:58 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com> @@ -56,9 +56,10 @@ static enum cmd_retval cmd_kill_window_exec(struct cmd *self, struct cmdq_item *item) { struct args *args = cmd_get_args(self); - struct winlink *wl = item->target.wl, *wl2, *wl3; + struct cmd_find_state *target = cmdq_get_target(item); + struct winlink *wl = target->wl, *wl2, *wl3; struct window *w = wl->window; - struct session *s = item->target.s; + struct session *s = target->s; if (cmd_get_entry(self) == &cmd_unlink_window_entry) { if (!args_has(args, 'k') && !session_is_linked(s, w)) { diff --git a/usr.bin/tmux/cmd-list-buffers.c b/usr.bin/tmux/cmd-list-buffers.c index ca002fb6426..d16b687f8ac 100644 --- a/usr.bin/tmux/cmd-list-buffers.c +++ b/usr.bin/tmux/cmd-list-buffers.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cmd-list-buffers.c,v 1.37 2020/04/13 08:26:27 nicm Exp $ */ +/* $OpenBSD: cmd-list-buffers.c,v 1.38 2020/04/13 10:59:58 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com> @@ -59,7 +59,7 @@ cmd_list_buffers_exec(struct cmd *self, struct cmdq_item *item) pb = NULL; while ((pb = paste_walk(pb)) != NULL) { - ft = format_create(item->client, item, FORMAT_NONE, 0); + ft = format_create(cmdq_get_client(item), item, FORMAT_NONE, 0); format_defaults_paste_buffer(ft, pb); if (filter != NULL) { diff --git a/usr.bin/tmux/cmd-list-clients.c b/usr.bin/tmux/cmd-list-clients.c index c16f09bb41a..93f709bd320 100644 --- a/usr.bin/tmux/cmd-list-clients.c +++ b/usr.bin/tmux/cmd-list-clients.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cmd-list-clients.c,v 1.35 2020/04/13 08:26:27 nicm Exp $ */ +/* $OpenBSD: cmd-list-clients.c,v 1.36 2020/04/13 10:59:58 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com> @@ -52,6 +52,7 @@ static enum cmd_retval cmd_list_clients_exec(struct cmd *self, struct cmdq_item *item) { struct args *args = cmd_get_args(self); + struct cmd_find_state *target = cmdq_get_target(item); struct client *c; struct session *s; struct format_tree *ft; @@ -60,7 +61,7 @@ cmd_list_clients_exec(struct cmd *self, struct cmdq_item *item) char *line; if (args_has(args, 't')) - s = item->target.s; + s = target->s; else s = NULL; @@ -72,7 +73,7 @@ cmd_list_clients_exec(struct cmd *self, struct cmdq_item *item) if (c->session == NULL || (s != NULL && s != c->session)) continue; - ft = format_create(item->client, item, FORMAT_NONE, 0); + ft = format_create(cmdq_get_client(item), item, FORMAT_NONE, 0); format_add(ft, "line", "%u", idx); format_defaults(ft, c, NULL, NULL, NULL); diff --git a/usr.bin/tmux/cmd-list-keys.c b/usr.bin/tmux/cmd-list-keys.c index fb1fa42eb10..1a011018e13 100644 --- a/usr.bin/tmux/cmd-list-keys.c +++ b/usr.bin/tmux/cmd-list-keys.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cmd-list-keys.c,v 1.54 2020/04/13 08:26:27 nicm Exp $ */ +/* $OpenBSD: cmd-list-keys.c,v 1.55 2020/04/13 10:59:58 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com> @@ -329,7 +329,7 @@ cmd_list_keys_commands(struct cmd *self, struct cmdq_item *item) "#{command_list_usage}"; } - ft = format_create(item->client, item, FORMAT_NONE, 0); + ft = format_create(cmdq_get_client(item), item, FORMAT_NONE, 0); format_defaults(ft, NULL, NULL, NULL, NULL); for (entryp = cmd_table; *entryp != NULL; entryp++) { diff --git a/usr.bin/tmux/cmd-list-panes.c b/usr.bin/tmux/cmd-list-panes.c index 0c1e669a768..83fcbf6ce33 100644 --- a/usr.bin/tmux/cmd-list-panes.c +++ b/usr.bin/tmux/cmd-list-panes.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cmd-list-panes.c,v 1.35 2020/04/13 08:26:27 nicm Exp $ */ +/* $OpenBSD: cmd-list-panes.c,v 1.36 2020/04/13 10:59:58 nicm Exp $ */ /* * Copyright (c) 2009 Nicholas Marriott <nicholas.marriott@gmail.com> @@ -50,9 +50,10 @@ const struct cmd_entry cmd_list_panes_entry = { static enum cmd_retval cmd_list_panes_exec(struct cmd *self, struct cmdq_item *item) { - struct args *args = cmd_get_args(self); - struct session *s = item->target.s; - struct winlink *wl = item->target.wl; + struct args *args = cmd_get_args(self); + struct cmd_find_state *target = cmdq_get_target(item); + struct session *s = target->s; + struct winlink *wl = target->wl; if (args_has(args, 'a')) cmd_list_panes_server(self, item); @@ -125,7 +126,7 @@ cmd_list_panes_window(struct cmd *self, struct session *s, struct winlink *wl, n = 0; TAILQ_FOREACH(wp, &wl->window->panes, entry) { - ft = format_create(item->client, item, FORMAT_NONE, 0); + ft = format_create(cmdq_get_client(item), item, FORMAT_NONE, 0); format_add(ft, "line", "%u", n); format_defaults(ft, NULL, s, wl, wp); diff --git a/usr.bin/tmux/cmd-list-sessions.c b/usr.bin/tmux/cmd-list-sessions.c index 0996e933845..0f5525c5330 100644 --- a/usr.bin/tmux/cmd-list-sessions.c +++ b/usr.bin/tmux/cmd-list-sessions.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cmd-list-sessions.c,v 1.32 2020/04/13 08:26:27 nicm Exp $ */ +/* $OpenBSD: cmd-list-sessions.c,v 1.33 2020/04/13 10:59:58 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com> @@ -66,7 +66,7 @@ cmd_list_sessions_exec(struct cmd *self, struct cmdq_item *item) n = 0; RB_FOREACH(s, sessions, &sessions) { - ft = format_create(item->client, item, FORMAT_NONE, 0); + ft = format_create(cmdq_get_client(item), item, FORMAT_NONE, 0); format_add(ft, "line", "%u", n); format_defaults(ft, NULL, s, NULL, NULL); diff --git a/usr.bin/tmux/cmd-list-windows.c b/usr.bin/tmux/cmd-list-windows.c index be4343328ab..0b599c64071 100644 --- a/usr.bin/tmux/cmd-list-windows.c +++ b/usr.bin/tmux/cmd-list-windows.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cmd-list-windows.c,v 1.45 2020/04/13 08:26:27 nicm Exp $ */ +/* $OpenBSD: cmd-list-windows.c,v 1.46 2020/04/13 10:59:58 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com> @@ -61,12 +61,13 @@ const struct cmd_entry cmd_list_windows_entry = { static enum cmd_retval cmd_list_windows_exec(struct cmd *self, struct cmdq_item *item) { - struct args *args = cmd_get_args(self); + struct args *args = cmd_get_args(self); + struct cmd_find_state *target = cmdq_get_target(item); if (args_has(args, 'a')) cmd_list_windows_server(self, item); else - cmd_list_windows_session(self, item->target.s, item, 0); + cmd_list_windows_session(self, target->s, item, 0); return (CMD_RETURN_NORMAL); } @@ -107,7 +108,7 @@ cmd_list_windows_session(struct cmd *self, struct session *s, n = 0; RB_FOREACH(wl, winlinks, &s->windows) { - ft = format_create(item->client, item, FORMAT_NONE, 0); + ft = format_create(cmdq_get_client(item), item, FORMAT_NONE, 0); format_add(ft, "line", "%u", n); format_defaults(ft, NULL, s, wl, NULL); diff --git a/usr.bin/tmux/cmd-load-buffer.c b/usr.bin/tmux/cmd-load-buffer.c index e70d936fa3f..90515f3ddf6 100644 --- a/usr.bin/tmux/cmd-load-buffer.c +++ b/usr.bin/tmux/cmd-load-buffer.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cmd-load-buffer.c,v 1.58 2020/04/13 08:26:27 nicm Exp $ */ +/* $OpenBSD: cmd-load-buffer.c,v 1.59 2020/04/13 10:59:58 nicm Exp $ */ /* * Copyright (c) 2009 Tiago Cunha <me@tiagocunha.org> @@ -86,9 +86,6 @@ cmd_load_buffer_exec(struct cmd *self, struct cmdq_item *item) struct args *args = cmd_get_args(self); struct cmd_load_buffer_data *cdata; struct client *c = cmd_find_client(item, NULL, 1); - struct session *s = item->target.s; - struct winlink *wl = item->target.wl; - struct window_pane *wp = item->target.wp; const char *bufname = args_get(args, 'b'); char *path; @@ -99,8 +96,8 @@ cmd_load_buffer_exec(struct cmd *self, struct cmdq_item *item) else cdata->name = NULL; - path = format_single(item, args->argv[0], c, s, wl, wp); - file_read(item->client, path, cmd_load_buffer_done, cdata); + path = format_single_from_target(item, args->argv[0], c); + file_read(cmdq_get_client(item), path, cmd_load_buffer_done, cdata); free(path); return (CMD_RETURN_WAIT); diff --git a/usr.bin/tmux/cmd-lock-server.c b/usr.bin/tmux/cmd-lock-server.c index 8de2a6b29dd..1d3dd0d2928 100644 --- a/usr.bin/tmux/cmd-lock-server.c +++ b/usr.bin/tmux/cmd-lock-server.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cmd-lock-server.c,v 1.27 2020/04/13 08:26:27 nicm Exp $ */ +/* $OpenBSD: cmd-lock-server.c,v 1.28 2020/04/13 10:59:58 nicm Exp $ */ /* * Copyright (c) 2008 Nicholas Marriott <nicholas.marriott@gmail.com> @@ -64,13 +64,14 @@ const struct cmd_entry cmd_lock_client_entry = { static enum cmd_retval cmd_lock_server_exec(struct cmd *self, struct cmdq_item *item) { - struct args *args = cmd_get_args(self); - struct client *c; + struct args *args = cmd_get_args(self); + struct cmd_find_state *target = cmdq_get_target(item); + struct client *c; if (cmd_get_entry(self) == &cmd_lock_server_entry) server_lock(); else if (cmd_get_entry(self) == &cmd_lock_session_entry) - server_lock_session(item->target.s); + server_lock_session(target->s); else { if ((c = cmd_find_client(item, args_get(args, 't'), 0)) == NULL) return (CMD_RETURN_ERROR); diff --git a/usr.bin/tmux/cmd-move-window.c b/usr.bin/tmux/cmd-move-window.c index 013fea1b74d..9f22f40f43b 100644 --- a/usr.bin/tmux/cmd-move-window.c +++ b/usr.bin/tmux/cmd-move-window.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cmd-move-window.c,v 1.30 2020/04/13 08:26:27 nicm Exp $ */ +/* $OpenBSD: cmd-move-window.c,v 1.31 2020/04/13 10:59:58 nicm Exp $ */ /* * Copyright (c) 2008 Nicholas Marriott <nicholas.marriott@gmail.com> @@ -59,32 +59,34 @@ const struct cmd_entry cmd_link_window_entry = { static enum cmd_retval cmd_move_window_exec(struct cmd *self, struct cmdq_item *item) { - struct args *args = cmd_get_args(self); - const char *tflag = args_get(args, 't'); - struct session *src; - struct session *dst; - struct winlink *wl; - char *cause; - int idx, kflag, dflag, sflag; + struct args *args = cmd_get_args(self); + struct cmd_find_state *source = cmdq_get_source(item); + struct cmd_find_state target; + const char *tflag = args_get(args, 't'); + struct session *src; + struct session *dst; + struct winlink *wl; + char *cause; + int idx, kflag, dflag, sflag; if (args_has(args, 'r')) { - if (cmd_find_target(&item->target, item, tflag, - CMD_FIND_SESSION, CMD_FIND_QUIET) != 0) + if (cmd_find_target(&target, item, tflag, CMD_FIND_SESSION, + CMD_FIND_QUIET) != 0) return (CMD_RETURN_ERROR); - session_renumber_windows(item->target.s); + session_renumber_windows(target.s); recalculate_sizes(); - server_status_session(item->target.s); + server_status_session(target.s); return (CMD_RETURN_NORMAL); } - if (cmd_find_target(&item->target, item, tflag, CMD_FIND_WINDOW, + if (cmd_find_target(&target, item, tflag, CMD_FIND_WINDOW, CMD_FIND_WINDOW_INDEX) != 0) return (CMD_RETURN_ERROR); - src = item->source.s; - dst = item->target.s; - wl = item->source.wl; - idx = item->target.idx; + src = source->s; + dst = target.s; + wl = source->wl; + idx = target.idx; kflag = args_has(args, 'k'); dflag = args_has(args, 'd'); @@ -95,8 +97,7 @@ cmd_move_window_exec(struct cmd *self, struct cmdq_item *item) return (CMD_RETURN_ERROR); } - if (server_link_window(src, wl, dst, idx, kflag, !dflag, - &cause) != 0) { + if (server_link_window(src, wl, dst, idx, kflag, !dflag, &cause) != 0) { cmdq_error(item, "can't link window: %s", cause); free(cause); return (CMD_RETURN_ERROR); diff --git a/usr.bin/tmux/cmd-new-session.c b/usr.bin/tmux/cmd-new-session.c index 5f5c2729c0d..da79e3c88ed 100644 --- a/usr.bin/tmux/cmd-new-session.c +++ b/usr.bin/tmux/cmd-new-session.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cmd-new-session.c,v 1.125 2020/04/13 08:26:27 nicm Exp $ */ +/* $OpenBSD: cmd-new-session.c,v 1.126 2020/04/13 10:59:58 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com> @@ -67,7 +67,10 @@ static enum cmd_retval cmd_new_session_exec(struct cmd *self, struct cmdq_item *item) { struct args *args = cmd_get_args(self); - struct client *c = item->client; + struct cmdq_shared *shared = cmdq_get_shared(item); + struct cmd_find_state *current = &shared->current; + struct cmd_find_state *target = cmdq_get_target(item); + struct client *c = cmdq_get_client(item); struct session *s, *as, *groupwith; struct environ *env; struct options *oo; @@ -106,7 +109,7 @@ cmd_new_session_exec(struct cmd *self, struct cmdq_item *item) if (newname != NULL) as = session_find(newname); else - as = item->target.s; + as = target->s; if (as != NULL) { retval = cmd_attach_session(item, as->name, args_has(args, 'D'), args_has(args, 'X'), 0, NULL, @@ -123,7 +126,7 @@ cmd_new_session_exec(struct cmd *self, struct cmdq_item *item) /* Is this going to be part of a session group? */ group = args_get(args, 't'); if (group != NULL) { - groupwith = item->target.s; + groupwith = target->s; if (groupwith == NULL) { if (!session_check_name(group)) { cmdq_error(item, "bad group name: %s", group); @@ -172,7 +175,7 @@ cmd_new_session_exec(struct cmd *self, struct cmdq_item *item) * over. */ if (!detached && !already_attached && c->tty.fd != -1) { - if (server_client_check_nested(item->client)) { + if (server_client_check_nested(cmdq_get_client(item))) { cmdq_error(item, "sessions should be nested with care, " "unset $TMUX to force"); goto fail; @@ -314,7 +317,7 @@ cmd_new_session_exec(struct cmd *self, struct cmdq_item *item) } else if (c->session != NULL) c->last_session = c->session; c->session = s; - if (~item->shared->flags & CMDQ_SHARED_REPEAT) + if (~shared->flags & CMDQ_SHARED_REPEAT) server_client_set_key_table(c, NULL); tty_update_client_offset(c); status_timer_start(c); @@ -344,7 +347,7 @@ cmd_new_session_exec(struct cmd *self, struct cmdq_item *item) if (!detached) { c->flags |= CLIENT_ATTACHED; - cmd_find_from_session(&item->shared->current, s, 0); + cmd_find_from_session(current, s, 0); } cmd_find_from_session(&fs, s, 0); diff --git a/usr.bin/tmux/cmd-new-window.c b/usr.bin/tmux/cmd-new-window.c index 6a57e3f1f56..2059e9d7e6a 100644 --- a/usr.bin/tmux/cmd-new-window.c +++ b/usr.bin/tmux/cmd-new-window.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cmd-new-window.c,v 1.83 2020/04/13 08:26:27 nicm Exp $ */ +/* $OpenBSD: cmd-new-window.c,v 1.84 2020/04/13 10:59:58 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com> @@ -52,12 +52,14 @@ static enum cmd_retval cmd_new_window_exec(struct cmd *self, struct cmdq_item *item) { struct args *args = cmd_get_args(self); - struct cmd_find_state *current = &item->shared->current; + struct cmdq_shared *shared = cmdq_get_shared(item); + struct cmd_find_state *current = &shared->current; + struct cmd_find_state *target = cmdq_get_target(item); struct spawn_context sc; struct client *c = cmd_find_client(item, NULL, 1); - struct session *s = item->target.s; - struct winlink *wl = item->target.wl; - int idx = item->target.idx; + struct session *s = target->s; + struct winlink *wl = target->wl; + int idx = target->idx; struct winlink *new_wl; char *cause = NULL, *cp; const char *template, *add; diff --git a/usr.bin/tmux/cmd-paste-buffer.c b/usr.bin/tmux/cmd-paste-buffer.c index 4c863bfd491..edd64740b26 100644 --- a/usr.bin/tmux/cmd-paste-buffer.c +++ b/usr.bin/tmux/cmd-paste-buffer.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cmd-paste-buffer.c,v 1.39 2020/04/13 08:26:27 nicm Exp $ */ +/* $OpenBSD: cmd-paste-buffer.c,v 1.40 2020/04/13 10:59:58 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com> @@ -48,7 +48,8 @@ static enum cmd_retval cmd_paste_buffer_exec(struct cmd *self, struct cmdq_item *item) { struct args *args = cmd_get_args(self); - struct window_pane *wp = item->target.wp; + struct cmd_find_state *target = cmdq_get_target(item); + struct window_pane *wp = target->wp; struct paste_buffer *pb; const char *sepstr, *bufname, *bufdata, *bufend, *line; size_t seplen, bufsize; diff --git a/usr.bin/tmux/cmd-pipe-pane.c b/usr.bin/tmux/cmd-pipe-pane.c index 42a6241958d..d7477b45675 100644 --- a/usr.bin/tmux/cmd-pipe-pane.c +++ b/usr.bin/tmux/cmd-pipe-pane.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cmd-pipe-pane.c,v 1.52 2020/04/13 08:26:27 nicm Exp $ */ +/* $OpenBSD: cmd-pipe-pane.c,v 1.53 2020/04/13 10:59:58 nicm Exp $ */ /* * Copyright (c) 2009 Nicholas Marriott <nicholas.marriott@gmail.com> @@ -57,10 +57,11 @@ static enum cmd_retval cmd_pipe_pane_exec(struct cmd *self, struct cmdq_item *item) { struct args *args = cmd_get_args(self); + struct cmd_find_state *target = cmdq_get_target(item); struct client *c = cmd_find_client(item, NULL, 1); - struct window_pane *wp = item->target.wp; - struct session *s = item->target.s; - struct winlink *wl = item->target.wl; + struct window_pane *wp = target->wp; + struct session *s = target->s; + struct winlink *wl = target->wl; char *cmd; int old_fd, pipe_fd[2], null_fd, in, out; struct format_tree *ft; @@ -108,7 +109,7 @@ cmd_pipe_pane_exec(struct cmd *self, struct cmdq_item *item) } /* Expand the command. */ - ft = format_create(item->client, item, FORMAT_NONE, 0); + ft = format_create(cmdq_get_client(item), item, FORMAT_NONE, 0); format_defaults(ft, c, s, wl, wp); cmd = format_expand_time(ft, args->argv[0]); format_free(ft); diff --git a/usr.bin/tmux/cmd-queue.c b/usr.bin/tmux/cmd-queue.c index 5af68a88f42..79694994e6f 100644 --- a/usr.bin/tmux/cmd-queue.c +++ b/usr.bin/tmux/cmd-queue.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cmd-queue.c,v 1.82 2020/04/13 08:26:27 nicm Exp $ */ +/* $OpenBSD: cmd-queue.c,v 1.83 2020/04/13 10:59:58 nicm Exp $ */ /* * Copyright (c) 2013 Nicholas Marriott <nicholas.marriott@gmail.com> @@ -25,8 +25,41 @@ #include "tmux.h" -/* Global command queue. */ -static struct cmdq_list global_queue = TAILQ_HEAD_INITIALIZER(global_queue); +/* Command queue item type. */ +enum cmdq_type { + CMDQ_COMMAND, + CMDQ_CALLBACK, +}; + +/* Command queue item. */ +struct cmdq_item { + char *name; + struct cmdq_list *queue; + struct cmdq_item *next; + + struct client *client; + + enum cmdq_type type; + u_int group; + + u_int number; + time_t time; + + int flags; + + struct cmdq_shared *shared; + struct cmd_find_state source; + struct cmd_find_state target; + + struct cmd_list *cmdlist; + struct cmd *cmd; + + cmdq_cb cb; + void *data; + + TAILQ_ENTRY(cmdq_item) entry; +}; +TAILQ_HEAD(cmdq_list, cmdq_item); /* Get command queue name. */ static const char * @@ -47,9 +80,83 @@ cmdq_name(struct client *c) static struct cmdq_list * cmdq_get(struct client *c) { - if (c == NULL) - return (&global_queue); - return (&c->queue); + static struct cmdq_list *global_queue; + + if (c == NULL) { + if (global_queue == NULL) + global_queue = cmdq_new(); + return (global_queue); + } + return (c->queue); +} + +/* Create a queue. */ +struct cmdq_list * +cmdq_new(void) +{ + struct cmdq_list *queue; + + queue = xcalloc (1, sizeof *queue); + TAILQ_INIT (queue); + return (queue); +} + +/* Free a queue. */ +void +cmdq_free(struct cmdq_list *queue) +{ + if (!TAILQ_EMPTY(queue)) + fatalx("queue not empty"); + free(queue); +} + +/* Get item name. */ +const char * +cmdq_get_name(struct cmdq_item *item) +{ + return (item->name); +} + +/* Get item client. */ +struct client * +cmdq_get_client(struct cmdq_item *item) +{ + return (item->client); +} + +/* Get item target. */ +struct cmd_find_state * +cmdq_get_target(struct cmdq_item *item) +{ + return (&item->target); +} + +/* Get item source. */ +struct cmd_find_state * +cmdq_get_source(struct cmdq_item *item) +{ + return (&item->source); +} + +/* Get item shared. */ +struct cmdq_shared * +cmdq_get_shared(struct cmdq_item *item) +{ + return (item->shared); +} + +/* Merge formats from item. */ +void +cmdq_merge_formats(struct cmdq_item *item, struct format_tree *ft) +{ + const struct cmd_entry *entry; + + if (item->cmd != NULL) { + entry = cmd_get_entry (item->cmd); + format_add(ft, "command", "%s", entry->name); + } + if (item->shared->formats != NULL) + format_merge(ft, item->shared->formats); } /* Append an item. */ diff --git a/usr.bin/tmux/cmd-rename-session.c b/usr.bin/tmux/cmd-rename-session.c index 1947720239f..fb8ee766834 100644 --- a/usr.bin/tmux/cmd-rename-session.c +++ b/usr.bin/tmux/cmd-rename-session.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cmd-rename-session.c,v 1.29 2020/04/13 08:26:27 nicm Exp $ */ +/* $OpenBSD: cmd-rename-session.c,v 1.30 2020/04/13 10:59:58 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com> @@ -47,11 +47,12 @@ static enum cmd_retval cmd_rename_session_exec(struct cmd *self, struct cmdq_item *item) { struct args *args = cmd_get_args(self); + struct cmd_find_state *target = cmdq_get_target(item); struct client *c = cmd_find_client(item, NULL, 1); - struct session *s = item->target.s; + struct session *s = target->s; char *newname; - newname = format_single(item, args->argv[0], c, s, NULL, NULL); + newname = format_single_from_target(item, args->argv[0], c); if (strcmp(newname, s->name) == 0) { free(newname); return (CMD_RETURN_NORMAL); diff --git a/usr.bin/tmux/cmd-rename-window.c b/usr.bin/tmux/cmd-rename-window.c index fe029b39997..7cb8928f361 100644 --- a/usr.bin/tmux/cmd-rename-window.c +++ b/usr.bin/tmux/cmd-rename-window.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cmd-rename-window.c,v 1.23 2020/04/13 08:26:27 nicm Exp $ */ +/* $OpenBSD: cmd-rename-window.c,v 1.24 2020/04/13 10:59:58 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com> @@ -45,13 +45,13 @@ const struct cmd_entry cmd_rename_window_entry = { static enum cmd_retval cmd_rename_window_exec(struct cmd *self, struct cmdq_item *item) { - struct args *args = cmd_get_args(self); - struct client *c = cmd_find_client(item, NULL, 1); - struct session *s = item->target.s; - struct winlink *wl = item->target.wl; - char *newname; + struct args *args = cmd_get_args(self); + struct cmd_find_state *target = cmdq_get_target(item); + struct client *c = cmd_find_client(item, NULL, 1); + struct winlink *wl = target->wl; + char *newname; - newname = format_single(item, args->argv[0], c, s, wl, NULL); + newname = format_single_from_target(item, args->argv[0], c); window_set_name(wl->window, newname); options_set_number(wl->window->options, "automatic-rename", 0); diff --git a/usr.bin/tmux/cmd-resize-pane.c b/usr.bin/tmux/cmd-resize-pane.c index 42c085729a9..ca6a2a2f5b6 100644 --- a/usr.bin/tmux/cmd-resize-pane.c +++ b/usr.bin/tmux/cmd-resize-pane.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cmd-resize-pane.c,v 1.42 2020/04/13 08:26:27 nicm Exp $ */ +/* $OpenBSD: cmd-resize-pane.c,v 1.43 2020/04/13 10:59:58 nicm Exp $ */ /* * Copyright (c) 2009 Nicholas Marriott <nicholas.marriott@gmail.com> @@ -50,12 +50,13 @@ static enum cmd_retval cmd_resize_pane_exec(struct cmd *self, struct cmdq_item *item) { struct args *args = cmd_get_args(self); - struct cmdq_shared *shared = item->shared; - struct window_pane *wp = item->target.wp; - struct winlink *wl = item->target.wl; + struct cmdq_shared *shared = cmdq_get_shared(item); + struct cmd_find_state *target = cmdq_get_target(item); + struct window_pane *wp = target->wp; + struct winlink *wl = target->wl; struct window *w = wl->window; - struct client *c = item->client; - struct session *s = item->target.s; + struct client *c = cmdq_get_client(item); + struct session *s = target->s; const char *errstr; char *cause; u_int adjust; diff --git a/usr.bin/tmux/cmd-resize-window.c b/usr.bin/tmux/cmd-resize-window.c index 2635992dd52..2f15155292b 100644 --- a/usr.bin/tmux/cmd-resize-window.c +++ b/usr.bin/tmux/cmd-resize-window.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cmd-resize-window.c,v 1.4 2020/04/13 08:26:27 nicm Exp $ */ +/* $OpenBSD: cmd-resize-window.c,v 1.5 2020/04/13 10:59:58 nicm Exp $ */ /* * Copyright (c) 2018 Nicholas Marriott <nicholas.marriott@gmail.com> @@ -47,9 +47,10 @@ static enum cmd_retval cmd_resize_window_exec(struct cmd *self, struct cmdq_item *item) { struct args *args = cmd_get_args(self); - struct winlink *wl = item->target.wl; + struct cmd_find_state *target = cmdq_get_target(item); + struct winlink *wl = target->wl; struct window *w = wl->window; - struct session *s = item->target.s; + struct session *s = target->s; const char *errstr; char *cause; u_int adjust, sx, sy; diff --git a/usr.bin/tmux/cmd-respawn-pane.c b/usr.bin/tmux/cmd-respawn-pane.c index 22780316885..ba0fa01a9a1 100644 --- a/usr.bin/tmux/cmd-respawn-pane.c +++ b/usr.bin/tmux/cmd-respawn-pane.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cmd-respawn-pane.c,v 1.31 2020/04/13 08:26:27 nicm Exp $ */ +/* $OpenBSD: cmd-respawn-pane.c,v 1.32 2020/04/13 10:59:58 nicm Exp $ */ /* * Copyright (c) 2008 Nicholas Marriott <nicholas.marriott@gmail.com> @@ -48,10 +48,11 @@ static enum cmd_retval cmd_respawn_pane_exec(struct cmd *self, struct cmdq_item *item) { struct args *args = cmd_get_args(self); + struct cmd_find_state *target = cmdq_get_target(item); struct spawn_context sc; - struct session *s = item->target.s; - struct winlink *wl = item->target.wl; - struct window_pane *wp = item->target.wp; + struct session *s = target->s; + struct winlink *wl = target->wl; + struct window_pane *wp = target->wp; char *cause = NULL; const char *add; struct args_value *value; diff --git a/usr.bin/tmux/cmd-respawn-window.c b/usr.bin/tmux/cmd-respawn-window.c index b6b1ad688ac..21fcbee119c 100644 --- a/usr.bin/tmux/cmd-respawn-window.c +++ b/usr.bin/tmux/cmd-respawn-window.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cmd-respawn-window.c,v 1.42 2020/04/13 08:26:27 nicm Exp $ */ +/* $OpenBSD: cmd-respawn-window.c,v 1.43 2020/04/13 10:59:58 nicm Exp $ */ /* * Copyright (c) 2008 Nicholas Marriott <nicholas.marriott@gmail.com> @@ -48,9 +48,10 @@ static enum cmd_retval cmd_respawn_window_exec(struct cmd *self, struct cmdq_item *item) { struct args *args = cmd_get_args(self); + struct cmd_find_state *target = cmdq_get_target(item); struct spawn_context sc; - struct session *s = item->target.s; - struct winlink *wl = item->target.wl; + struct session *s = target->s; + struct winlink *wl = target->wl; char *cause = NULL; const char *add; struct args_value *value; diff --git a/usr.bin/tmux/cmd-rotate-window.c b/usr.bin/tmux/cmd-rotate-window.c index 5082f9832cf..34c8b948907 100644 --- a/usr.bin/tmux/cmd-rotate-window.c +++ b/usr.bin/tmux/cmd-rotate-window.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cmd-rotate-window.c,v 1.28 2020/04/13 08:26:27 nicm Exp $ */ +/* $OpenBSD: cmd-rotate-window.c,v 1.29 2020/04/13 10:59:58 nicm Exp $ */ /* * Copyright (c) 2009 Nicholas Marriott <nicholas.marriott@gmail.com> @@ -44,8 +44,10 @@ static enum cmd_retval cmd_rotate_window_exec(struct cmd *self, struct cmdq_item *item) { struct args *args = cmd_get_args(self); - struct cmd_find_state *current = &item->shared->current; - struct winlink *wl = item->target.wl; + struct cmdq_shared *shared = cmdq_get_shared(item); + struct cmd_find_state *current = &shared->current; + struct cmd_find_state *target = cmdq_get_target(item); + struct winlink *wl = target->wl; struct window *w = wl->window; struct window_pane *wp, *wp2; struct layout_cell *lc; diff --git a/usr.bin/tmux/cmd-run-shell.c b/usr.bin/tmux/cmd-run-shell.c index 816826f8478..e83ca6aae45 100644 --- a/usr.bin/tmux/cmd-run-shell.c +++ b/usr.bin/tmux/cmd-run-shell.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cmd-run-shell.c,v 1.65 2020/04/13 08:26:27 nicm Exp $ */ +/* $OpenBSD: cmd-run-shell.c,v 1.66 2020/04/13 10:59:58 nicm Exp $ */ /* * Copyright (c) 2009 Tiago Cunha <me@tiagocunha.org> @@ -90,11 +90,11 @@ static enum cmd_retval cmd_run_shell_exec(struct cmd *self, struct cmdq_item *item) { struct args *args = cmd_get_args(self); + struct cmd_find_state *target = cmdq_get_target(item); struct cmd_run_shell_data *cdata; struct client *c = cmd_find_client(item, NULL, 1); - struct session *s = item->target.s; - struct winlink *wl = item->target.wl; - struct window_pane *wp = item->target.wp; + struct session *s = target->s; + struct window_pane *wp = target->wp; const char *delay; double d; struct timeval tv; @@ -102,7 +102,7 @@ cmd_run_shell_exec(struct cmd *self, struct cmdq_item *item) cdata = xcalloc(1, sizeof *cdata); if (args->argc != 0) - cdata->cmd = format_single(item, args->argv[0], c, s, wl, wp); + cdata->cmd = format_single_from_target(item, args->argv[0], c); if (args_has(args, 't') && wp != NULL) cdata->wp_id = wp->id; @@ -112,7 +112,7 @@ cmd_run_shell_exec(struct cmd *self, struct cmdq_item *item) if (!args_has(args, 'b')) cdata->item = item; - cdata->cwd = xstrdup(server_client_get_cwd(item->client, s)); + cdata->cwd = xstrdup(server_client_get_cwd(cmdq_get_client(item), s)); cdata->s = s; if (s != NULL) session_add_ref(s, __func__); @@ -197,8 +197,9 @@ cmd_run_shell_callback(struct job *job) free(msg); if (item != NULL) { - if (item->client != NULL && item->client->session == NULL) - item->client->retval = retcode; + if (cmdq_get_client(item) != NULL && + cmdq_get_client(item)->session == NULL) + cmdq_get_client(item)->retval = retcode; cmdq_continue(item); } } diff --git a/usr.bin/tmux/cmd-save-buffer.c b/usr.bin/tmux/cmd-save-buffer.c index bd229f64085..6b8901a723a 100644 --- a/usr.bin/tmux/cmd-save-buffer.c +++ b/usr.bin/tmux/cmd-save-buffer.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cmd-save-buffer.c,v 1.48 2020/04/13 08:26:27 nicm Exp $ */ +/* $OpenBSD: cmd-save-buffer.c,v 1.49 2020/04/13 10:59:58 nicm Exp $ */ /* * Copyright (c) 2009 Tiago Cunha <me@tiagocunha.org> @@ -75,9 +75,6 @@ cmd_save_buffer_exec(struct cmd *self, struct cmdq_item *item) { struct args *args = cmd_get_args(self); struct client *c = cmd_find_client(item, NULL, 1); - struct session *s = item->target.s; - struct winlink *wl = item->target.wl; - struct window_pane *wp = item->target.wp; struct paste_buffer *pb; int flags; const char *bufname = args_get(args, 'b'), *bufdata; @@ -101,12 +98,12 @@ cmd_save_buffer_exec(struct cmd *self, struct cmdq_item *item) if (cmd_get_entry(self) == &cmd_show_buffer_entry) path = xstrdup("-"); else - path = format_single(item, args->argv[0], c, s, wl, wp); + path = format_single_from_target(item, args->argv[0], c); if (args_has(args, 'a')) flags = O_APPEND; else flags = 0; - file_write(item->client, path, flags, bufdata, bufsize, + file_write(cmdq_get_client(item), path, flags, bufdata, bufsize, cmd_save_buffer_done, item); free(path); diff --git a/usr.bin/tmux/cmd-select-layout.c b/usr.bin/tmux/cmd-select-layout.c index 521c6643d4e..432a9e75309 100644 --- a/usr.bin/tmux/cmd-select-layout.c +++ b/usr.bin/tmux/cmd-select-layout.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cmd-select-layout.c,v 1.37 2020/04/13 08:26:27 nicm Exp $ */ +/* $OpenBSD: cmd-select-layout.c,v 1.38 2020/04/13 10:59:58 nicm Exp $ */ /* * Copyright (c) 2009 Nicholas Marriott <nicholas.marriott@gmail.com> @@ -72,9 +72,10 @@ static enum cmd_retval cmd_select_layout_exec(struct cmd *self, struct cmdq_item *item) { struct args *args = cmd_get_args(self); - struct winlink *wl = item->target.wl; + struct cmd_find_state *target = cmdq_get_target(item); + struct winlink *wl = target->wl; struct window *w = wl->window; - struct window_pane *wp = item->target.wp; + struct window_pane *wp = target->wp; const char *layoutname; char *oldlayout; int next, previous, layout; diff --git a/usr.bin/tmux/cmd-select-pane.c b/usr.bin/tmux/cmd-select-pane.c index 91678833215..064935551ba 100644 --- a/usr.bin/tmux/cmd-select-pane.c +++ b/usr.bin/tmux/cmd-select-pane.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cmd-select-pane.c,v 1.55 2020/04/13 08:26:27 nicm Exp $ */ +/* $OpenBSD: cmd-select-pane.c,v 1.56 2020/04/13 10:59:58 nicm Exp $ */ /* * Copyright (c) 2009 Nicholas Marriott <nicholas.marriott@gmail.com> @@ -85,12 +85,14 @@ cmd_select_pane_exec(struct cmd *self, struct cmdq_item *item) { struct args *args = cmd_get_args(self); const struct cmd_entry *entry = cmd_get_entry(self); - struct cmd_find_state *current = &item->shared->current; + struct cmdq_shared *shared = cmdq_get_shared(item); + struct cmd_find_state *current = &shared->current; + struct cmd_find_state *target = cmdq_get_target(item); struct client *c = cmd_find_client(item, NULL, 1); - struct winlink *wl = item->target.wl; + struct winlink *wl = target->wl; struct window *w = wl->window; - struct session *s = item->target.s; - struct window_pane *wp = item->target.wp, *lastwp, *markedwp; + struct session *s = target->s; + struct window_pane *wp = target->wp, *lastwp, *markedwp; char *pane_title; const char *style; struct style *sy; diff --git a/usr.bin/tmux/cmd-select-window.c b/usr.bin/tmux/cmd-select-window.c index 93248df5034..02bb124c50d 100644 --- a/usr.bin/tmux/cmd-select-window.c +++ b/usr.bin/tmux/cmd-select-window.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cmd-select-window.c,v 1.24 2020/04/13 08:26:27 nicm Exp $ */ +/* $OpenBSD: cmd-select-window.c,v 1.25 2020/04/13 10:59:58 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com> @@ -85,9 +85,11 @@ static enum cmd_retval cmd_select_window_exec(struct cmd *self, struct cmdq_item *item) { struct args *args = cmd_get_args(self); - struct cmd_find_state *current = &item->shared->current; - struct winlink *wl = item->target.wl; - struct session *s = item->target.s; + struct cmdq_shared *shared = cmdq_get_shared(item); + struct cmd_find_state *current = &shared->current; + struct cmd_find_state *target = cmdq_get_target(item); + struct winlink *wl = target->wl; + struct session *s = target->s; int next, previous, last, activity; next = (cmd_get_entry(self) == &cmd_next_window_entry); diff --git a/usr.bin/tmux/cmd-send-keys.c b/usr.bin/tmux/cmd-send-keys.c index 4514a64f873..a42356bd0e6 100644 --- a/usr.bin/tmux/cmd-send-keys.c +++ b/usr.bin/tmux/cmd-send-keys.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cmd-send-keys.c,v 1.55 2020/04/13 08:26:27 nicm Exp $ */ +/* $OpenBSD: cmd-send-keys.c,v 1.56 2020/04/13 10:59:58 nicm Exp $ */ /* * Copyright (c) 2008 Nicholas Marriott <nicholas.marriott@gmail.com> @@ -60,6 +60,7 @@ static struct cmdq_item * cmd_send_keys_inject_key(struct client *c, struct cmd_find_state *fs, struct cmdq_item *item, key_code key) { + struct cmd_find_state *target = cmdq_get_target(item); struct session *s = fs->s; struct winlink *wl = fs->wl; struct window_pane *wp = fs->wp; @@ -71,7 +72,8 @@ cmd_send_keys_inject_key(struct client *c, struct cmd_find_state *fs, if (wme == NULL || wme->mode->key_table == NULL) { if (options_get_number(fs->wp->window->options, "xterm-keys")) key |= KEYC_XTERM; - if (window_pane_key(wp, item->client, s, wl, key, NULL) != 0) + if (window_pane_key(wp, cmdq_get_client(item), s, wl, key, + NULL) != 0) return (NULL); return (item); } @@ -80,7 +82,7 @@ cmd_send_keys_inject_key(struct client *c, struct cmd_find_state *fs, bd = key_bindings_get(table, key & ~KEYC_XTERM); if (bd != NULL) { table->references++; - item = key_bindings_dispatch(bd, item, c, NULL, &item->target); + item = key_bindings_dispatch(bd, item, c, NULL, target); key_bindings_unref_table(table); } return (item); @@ -132,12 +134,13 @@ static enum cmd_retval cmd_send_keys_exec(struct cmd *self, struct cmdq_item *item) { struct args *args = cmd_get_args(self); + struct cmdq_shared *shared = cmdq_get_shared(item); + struct cmd_find_state *target = cmdq_get_target(item); struct client *c = cmd_find_client(item, NULL, 1); - struct cmd_find_state *fs = &item->target; - struct window_pane *wp = item->target.wp; - struct session *s = item->target.s; - struct winlink *wl = item->target.wl; - struct mouse_event *m = &item->shared->mouse; + struct window_pane *wp = target->wp; + struct session *s = target->s; + struct winlink *wl = target->wl; + struct mouse_event *m = &shared->mouse; struct window_mode_entry *wme = TAILQ_FIRST(&wp->modes); int i; key_code key; @@ -177,7 +180,7 @@ cmd_send_keys_exec(struct cmd *self, struct cmdq_item *item) cmdq_error(item, "no mouse target"); return (CMD_RETURN_ERROR); } - window_pane_key(wp, item->client, s, wl, m->key, m); + window_pane_key(wp, cmdq_get_client(item), s, wl, m->key, m); return (CMD_RETURN_NORMAL); } @@ -186,7 +189,7 @@ cmd_send_keys_exec(struct cmd *self, struct cmdq_item *item) key = options_get_number(s->options, "prefix2"); else key = options_get_number(s->options, "prefix"); - cmd_send_keys_inject_key(c, fs, item, key); + cmd_send_keys_inject_key(c, target, item, key); return (CMD_RETURN_NORMAL); } @@ -196,8 +199,10 @@ cmd_send_keys_exec(struct cmd *self, struct cmdq_item *item) } for (; np != 0; np--) { - for (i = 0; i < args->argc; i++) - item = cmd_send_keys_inject_string(c, fs, item, args, i); + for (i = 0; i < args->argc; i++) { + item = cmd_send_keys_inject_string(c, target, item, + args, i); + } } return (CMD_RETURN_NORMAL); diff --git a/usr.bin/tmux/cmd-set-environment.c b/usr.bin/tmux/cmd-set-environment.c index b7ba371fdb4..1164d753ec8 100644 --- a/usr.bin/tmux/cmd-set-environment.c +++ b/usr.bin/tmux/cmd-set-environment.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cmd-set-environment.c,v 1.24 2020/04/13 08:26:27 nicm Exp $ */ +/* $OpenBSD: cmd-set-environment.c,v 1.25 2020/04/13 10:59:58 nicm Exp $ */ /* * Copyright (c) 2009 Nicholas Marriott <nicholas.marriott@gmail.com> @@ -46,9 +46,10 @@ const struct cmd_entry cmd_set_environment_entry = { static enum cmd_retval cmd_set_environment_exec(struct cmd *self, struct cmdq_item *item) { - struct args *args = cmd_get_args(self); - struct environ *env; - const char *name, *value, *target; + struct args *args = cmd_get_args(self); + struct cmd_find_state *target = cmdq_get_target(item); + struct environ *env; + const char *name, *value, *tflag; name = args->argv[0]; if (*name == '\0') { @@ -68,15 +69,15 @@ cmd_set_environment_exec(struct cmd *self, struct cmdq_item *item) if (args_has(args, 'g')) env = global_environ; else { - if (item->target.s == NULL) { - target = args_get(args, 't'); - if (target != NULL) - cmdq_error(item, "no such session: %s", target); + if (target->s == NULL) { + tflag = args_get(args, 't'); + if (tflag != NULL) + cmdq_error(item, "no such session: %s", tflag); else cmdq_error(item, "no current session"); return (CMD_RETURN_ERROR); } - env = item->target.s->environ; + env = target->s->environ; } if (args_has(args, 'u')) { diff --git a/usr.bin/tmux/cmd-set-option.c b/usr.bin/tmux/cmd-set-option.c index fde6b8bc033..84fcd62c112 100644 --- a/usr.bin/tmux/cmd-set-option.c +++ b/usr.bin/tmux/cmd-set-option.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cmd-set-option.c,v 1.130 2020/04/13 08:26:27 nicm Exp $ */ +/* $OpenBSD: cmd-set-option.c,v 1.131 2020/04/13 10:59:58 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com> @@ -83,10 +83,9 @@ cmd_set_option_exec(struct cmd *self, struct cmdq_item *item) { struct args *args = cmd_get_args(self); int append = args_has(args, 'a'); - struct cmd_find_state *fs = &item->target; + struct cmd_find_state *target = cmdq_get_target(item); struct client *c, *loop; - struct session *s = fs->s; - struct winlink *wl = fs->wl; + struct session *s = target->s; struct window *w; struct window_pane *wp; struct options *oo; @@ -100,7 +99,7 @@ cmd_set_option_exec(struct cmd *self, struct cmdq_item *item) /* Expand argument. */ c = cmd_find_client(item, NULL, 1); - argument = format_single(item, args->argv[0], c, s, wl, NULL); + argument = format_single_from_target(item, args->argv[0], c); /* If set-hook -R, fire the hook straight away. */ if (cmd_get_entry(self) == &cmd_set_hook_entry && args_has(args, 'R')) { @@ -123,12 +122,13 @@ cmd_set_option_exec(struct cmd *self, struct cmdq_item *item) if (args->argc < 2) value = NULL; else if (args_has(args, 'F')) - value = format_single(item, args->argv[1], c, s, wl, NULL); + value = format_single_from_target(item, args->argv[1], c); else value = xstrdup(args->argv[1]); /* Get the scope and table for the option .*/ - scope = options_scope_from_name(args, window, name, fs, &oo, &cause); + scope = options_scope_from_name(args, window, name, target, &oo, + &cause); if (scope == OPTIONS_TABLE_NONE) { if (args_has(args, 'q')) goto out; diff --git a/usr.bin/tmux/cmd-show-environment.c b/usr.bin/tmux/cmd-show-environment.c index 571ba044f07..c0e0243b250 100644 --- a/usr.bin/tmux/cmd-show-environment.c +++ b/usr.bin/tmux/cmd-show-environment.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cmd-show-environment.c,v 1.25 2020/04/13 08:26:27 nicm Exp $ */ +/* $OpenBSD: cmd-show-environment.c,v 1.26 2020/04/13 10:59:58 nicm Exp $ */ /* * Copyright (c) 2009 Nicholas Marriott <nicholas.marriott@gmail.com> @@ -98,13 +98,14 @@ static enum cmd_retval cmd_show_environment_exec(struct cmd *self, struct cmdq_item *item) { struct args *args = cmd_get_args(self); + struct cmd_find_state *target = cmdq_get_target(item); struct environ *env; struct environ_entry *envent; - const char *target; + const char *tflag; - if ((target = args_get(args, 't')) != NULL) { - if (item->target.s == NULL) { - cmdq_error(item, "no such session: %s", target); + if ((tflag = args_get(args, 't')) != NULL) { + if (target->s == NULL) { + cmdq_error(item, "no such session: %s", tflag); return (CMD_RETURN_ERROR); } } @@ -112,15 +113,15 @@ cmd_show_environment_exec(struct cmd *self, struct cmdq_item *item) if (args_has(args, 'g')) env = global_environ; else { - if (item->target.s == NULL) { - target = args_get(args, 't'); - if (target != NULL) - cmdq_error(item, "no such session: %s", target); + if (target->s == NULL) { + tflag = args_get(args, 't'); + if (tflag != NULL) + cmdq_error(item, "no such session: %s", tflag); else cmdq_error(item, "no current session"); return (CMD_RETURN_ERROR); } - env = item->target.s->environ; + env = target->s->environ; } if (args->argc != 0) { diff --git a/usr.bin/tmux/cmd-show-options.c b/usr.bin/tmux/cmd-show-options.c index de4bfb0621b..521b7c41897 100644 --- a/usr.bin/tmux/cmd-show-options.c +++ b/usr.bin/tmux/cmd-show-options.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cmd-show-options.c,v 1.60 2020/04/13 08:26:27 nicm Exp $ */ +/* $OpenBSD: cmd-show-options.c,v 1.61 2020/04/13 10:59:58 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com> @@ -78,10 +78,8 @@ static enum cmd_retval cmd_show_options_exec(struct cmd *self, struct cmdq_item *item) { struct args *args = cmd_get_args(self); - struct cmd_find_state *fs = &item->target; + struct cmd_find_state *target = cmdq_get_target(item); struct client *c = cmd_find_client(item, NULL, 1); - struct session *s = item->target.s; - struct winlink *wl = item->target.wl; struct options *oo; char *argument, *name = NULL, *cause; int window, idx, ambiguous, parent, scope; @@ -90,7 +88,8 @@ cmd_show_options_exec(struct cmd *self, struct cmdq_item *item) window = (cmd_get_entry(self) == &cmd_show_window_options_entry); if (args->argc == 0) { - scope = options_scope_from_flags(args, window, fs, &oo, &cause); + scope = options_scope_from_flags(args, window, target, &oo, + &cause); if (scope == OPTIONS_TABLE_NONE) { if (args_has(args, 'q')) return (CMD_RETURN_NORMAL); @@ -100,7 +99,7 @@ cmd_show_options_exec(struct cmd *self, struct cmdq_item *item) } return (cmd_show_options_all(self, item, scope, oo)); } - argument = format_single(item, args->argv[0], c, s, wl, NULL); + argument = format_single_from_target(item, args->argv[0], c); name = options_match(argument, &idx, &ambiguous); if (name == NULL) { @@ -112,7 +111,8 @@ cmd_show_options_exec(struct cmd *self, struct cmdq_item *item) cmdq_error(item, "invalid option: %s", argument); goto fail; } - scope = options_scope_from_name(args, window, name, fs, &oo, &cause); + scope = options_scope_from_name(args, window, name, target, &oo, + &cause); if (scope == OPTIONS_TABLE_NONE) { if (args_has(args, 'q')) goto fail; diff --git a/usr.bin/tmux/cmd-source-file.c b/usr.bin/tmux/cmd-source-file.c index ffb183e3377..b5b01cc6068 100644 --- a/usr.bin/tmux/cmd-source-file.c +++ b/usr.bin/tmux/cmd-source-file.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cmd-source-file.c,v 1.46 2020/04/13 08:26:27 nicm Exp $ */ +/* $OpenBSD: cmd-source-file.c,v 1.47 2020/04/13 10:59:58 nicm Exp $ */ /* * Copyright (c) 2008 Tiago Cunha <me@tiagocunha.org> @@ -125,7 +125,7 @@ cmd_source_file_exec(struct cmd *self, struct cmdq_item *item) { struct args *args = cmd_get_args(self); struct cmd_source_file_data *cdata; - struct client *c = item->client; + struct client *c = cmdq_get_client(item); enum cmd_retval retval = CMD_RETURN_NORMAL; char *pattern, *cwd; const char *path, *error; diff --git a/usr.bin/tmux/cmd-split-window.c b/usr.bin/tmux/cmd-split-window.c index 07d396e2454..6b170516f89 100644 --- a/usr.bin/tmux/cmd-split-window.c +++ b/usr.bin/tmux/cmd-split-window.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cmd-split-window.c,v 1.99 2020/04/13 08:26:27 nicm Exp $ */ +/* $OpenBSD: cmd-split-window.c,v 1.100 2020/04/13 10:59:58 nicm Exp $ */ /* * Copyright (c) 2009 Nicholas Marriott <nicholas.marriott@gmail.com> @@ -54,12 +54,14 @@ static enum cmd_retval cmd_split_window_exec(struct cmd *self, struct cmdq_item *item) { struct args *args = cmd_get_args(self); - struct cmd_find_state *current = &item->shared->current; + struct cmdq_shared *shared = cmdq_get_shared(item); + struct cmd_find_state *current = &shared->current; + struct cmd_find_state *target = cmdq_get_target(item); struct spawn_context sc; struct client *c = cmd_find_client(item, NULL, 1); - struct session *s = item->target.s; - struct winlink *wl = item->target.wl; - struct window_pane *wp = item->target.wp, *new_wp; + struct session *s = target->s; + struct winlink *wl = target->wl; + struct window_pane *wp = target->wp, *new_wp; enum layout_type type; struct layout_cell *lc; struct cmd_find_state fs; diff --git a/usr.bin/tmux/cmd-swap-pane.c b/usr.bin/tmux/cmd-swap-pane.c index 2e9858c10d5..6b1dcf11494 100644 --- a/usr.bin/tmux/cmd-swap-pane.c +++ b/usr.bin/tmux/cmd-swap-pane.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cmd-swap-pane.c,v 1.36 2020/04/13 08:26:27 nicm Exp $ */ +/* $OpenBSD: cmd-swap-pane.c,v 1.37 2020/04/13 10:59:58 nicm Exp $ */ /* * Copyright (c) 2009 Nicholas Marriott <nicholas.marriott@gmail.com> @@ -46,15 +46,17 @@ static enum cmd_retval cmd_swap_pane_exec(struct cmd *self, struct cmdq_item *item) { struct args *args = cmd_get_args(self); + struct cmd_find_state *source = cmdq_get_source(item); + struct cmd_find_state *target = cmdq_get_target(item); struct window *src_w, *dst_w; struct window_pane *tmp_wp, *src_wp, *dst_wp; struct layout_cell *src_lc, *dst_lc; u_int sx, sy, xoff, yoff; - dst_w = item->target.wl->window; - dst_wp = item->target.wp; - src_w = item->source.wl->window; - src_wp = item->source.wp; + dst_w = target->wl->window; + dst_wp = target->wp; + src_w = source->wl->window; + src_wp = source->wp; if (window_push_zoom(dst_w, args_has(args, 'Z'))) server_redraw_window(dst_w); diff --git a/usr.bin/tmux/cmd-swap-window.c b/usr.bin/tmux/cmd-swap-window.c index 9c0464ca0fe..41684791d2d 100644 --- a/usr.bin/tmux/cmd-swap-window.c +++ b/usr.bin/tmux/cmd-swap-window.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cmd-swap-window.c,v 1.26 2020/04/13 08:26:27 nicm Exp $ */ +/* $OpenBSD: cmd-swap-window.c,v 1.27 2020/04/13 10:59:58 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com> @@ -46,20 +46,19 @@ static enum cmd_retval cmd_swap_window_exec(struct cmd *self, struct cmdq_item *item) { struct args *args = cmd_get_args(self); - struct session *src, *dst; + struct cmd_find_state *source = cmdq_get_source(item); + struct cmd_find_state *target = cmdq_get_target(item); + struct session *src = source->s, *dst = target->s; struct session_group *sg_src, *sg_dst; - struct winlink *wl_src, *wl_dst; + struct winlink *wl_src = source->wl, *wl_dst = target->wl; struct window *w_src, *w_dst; - wl_src = item->source.wl; - src = item->source.s; sg_src = session_group_contains(src); - - wl_dst = item->target.wl; - dst = item->target.s; sg_dst = session_group_contains(dst); - if (src != dst && sg_src != NULL && sg_dst != NULL && + if (src != dst && + sg_src != NULL && + sg_dst != NULL && sg_src == sg_dst) { cmdq_error(item, "can't move window, sessions are grouped"); return (CMD_RETURN_ERROR); diff --git a/usr.bin/tmux/cmd-switch-client.c b/usr.bin/tmux/cmd-switch-client.c index 89d3e223ae6..c45ad8d5f27 100644 --- a/usr.bin/tmux/cmd-switch-client.c +++ b/usr.bin/tmux/cmd-switch-client.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cmd-switch-client.c,v 1.61 2020/04/13 08:26:27 nicm Exp $ */ +/* $OpenBSD: cmd-switch-client.c,v 1.62 2020/04/13 10:59:58 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com> @@ -48,6 +48,9 @@ static enum cmd_retval cmd_switch_client_exec(struct cmd *self, struct cmdq_item *item) { struct args *args = cmd_get_args(self); + struct cmdq_shared *shared = cmdq_get_shared(item); + struct cmd_find_state *current = &shared->current; + struct cmd_find_state target; const char *tflag = args_get(args, 't'); enum cmd_find_type type; int flags; @@ -69,11 +72,11 @@ cmd_switch_client_exec(struct cmd *self, struct cmdq_item *item) type = CMD_FIND_SESSION; flags = CMD_FIND_PREFER_UNATTACHED; } - if (cmd_find_target(&item->target, item, tflag, type, flags) != 0) + if (cmd_find_target(&target, item, tflag, type, flags) != 0) return (CMD_RETURN_ERROR); - s = item->target.s; - wl = item->target.wl; - wp = item->target.wp; + s = target.s; + wl = target.wl; + wp = target.wp; if (args_has(args, 'r')) c->flags ^= CLIENT_READONLY; @@ -111,7 +114,7 @@ cmd_switch_client_exec(struct cmd *self, struct cmdq_item *item) return (CMD_RETURN_ERROR); } } else { - if (item->client == NULL) + if (cmdq_get_client(item) == NULL) return (CMD_RETURN_NORMAL); if (wl != NULL && wp != NULL) { w = wl->window; @@ -124,7 +127,7 @@ cmd_switch_client_exec(struct cmd *self, struct cmdq_item *item) } if (wl != NULL) { session_set_current(s, wl); - cmd_find_from_session(&item->shared->current, s, 0); + cmd_find_from_session(current, s, 0); } } @@ -134,7 +137,7 @@ cmd_switch_client_exec(struct cmd *self, struct cmdq_item *item) if (c->session != NULL && c->session != s) c->last_session = c->session; c->session = s; - if (~item->shared->flags & CMDQ_SHARED_REPEAT) + if (~shared->flags & CMDQ_SHARED_REPEAT) server_client_set_key_table(c, NULL); tty_update_client_offset(c); status_timer_start(c); diff --git a/usr.bin/tmux/cmd-wait-for.c b/usr.bin/tmux/cmd-wait-for.c index 5ebda4a402b..2c1ec063536 100644 --- a/usr.bin/tmux/cmd-wait-for.c +++ b/usr.bin/tmux/cmd-wait-for.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cmd-wait-for.c,v 1.19 2020/04/13 08:26:27 nicm Exp $ */ +/* $OpenBSD: cmd-wait-for.c,v 1.20 2020/04/13 10:59:58 nicm Exp $ */ /* * Copyright (c) 2013 Nicholas Marriott <nicholas.marriott@gmail.com> @@ -167,7 +167,7 @@ static enum cmd_retval cmd_wait_for_wait(struct cmdq_item *item, const char *name, struct wait_channel *wc) { - struct client *c = item->client; + struct client *c = cmdq_get_client(item); struct wait_item *wi; if (c == NULL) { @@ -198,7 +198,7 @@ cmd_wait_for_lock(struct cmdq_item *item, const char *name, { struct wait_item *wi; - if (item->client == NULL) { + if (cmdq_get_client(item) == NULL) { cmdq_error(item, "not able to lock"); return (CMD_RETURN_ERROR); } diff --git a/usr.bin/tmux/control.c b/usr.bin/tmux/control.c index 2a002d1b941..845838ab59d 100644 --- a/usr.bin/tmux/control.c +++ b/usr.bin/tmux/control.c @@ -1,4 +1,4 @@ -/* $OpenBSD: control.c,v 1.25 2019/12/12 11:39:56 nicm Exp $ */ +/* $OpenBSD: control.c,v 1.26 2020/04/13 10:59:58 nicm Exp $ */ /* * Copyright (c) 2012 Nicholas Marriott <nicholas.marriott@gmail.com> @@ -42,7 +42,7 @@ control_write(struct client *c, const char *fmt, ...) static enum cmd_retval control_error(struct cmdq_item *item, void *data) { - struct client *c = item->client; + struct client *c = cmdq_get_client(item); char *error = data; cmdq_guard(item, "begin", 1); @@ -86,7 +86,7 @@ control_callback(__unused struct client *c, __unused const char *path, break; case CMD_PARSE_SUCCESS: item = cmdq_get_command(pr->cmdlist, NULL, NULL, 0); - item->shared->flags |= CMDQ_SHARED_CONTROL; + cmdq_get_shared(item)->flags |= CMDQ_SHARED_CONTROL; cmdq_append(c, item); cmd_list_free(pr->cmdlist); break; diff --git a/usr.bin/tmux/format.c b/usr.bin/tmux/format.c index 8778f47e8dd..37dc1e39cf1 100644 --- a/usr.bin/tmux/format.c +++ b/usr.bin/tmux/format.c @@ -1,4 +1,4 @@ -/* $OpenBSD: format.c,v 1.236 2020/04/13 08:26:27 nicm Exp $ */ +/* $OpenBSD: format.c,v 1.237 2020/04/13 10:59:58 nicm Exp $ */ /* * Copyright (c) 2011 Nicholas Marriott <nicholas.marriott@gmail.com> @@ -1108,8 +1108,8 @@ format_cb_mouse_line(struct format_tree *ft, struct format_entry *fe) fe->value = s; } -/* Merge a format tree. */ -static void +/* Merge one format tree into another. */ +void format_merge(struct format_tree *ft, struct format_tree *from) { struct format_entry *fe; @@ -1124,21 +1124,16 @@ format_merge(struct format_tree *ft, struct format_tree *from) static void format_create_add_item(struct format_tree *ft, struct cmdq_item *item) { + struct cmdq_shared *shared = cmdq_get_shared(item); struct mouse_event *m; struct window_pane *wp; u_int x, y; - if (item->cmd != NULL) { - format_add(ft, "command", "%s", - cmd_get_entry (item->cmd)->name); - } + cmdq_merge_formats(item, ft); - if (item->shared == NULL) + if (shared == NULL) return; - if (item->shared->formats != NULL) - format_merge(ft, item->shared->formats); - - m = &item->shared->mouse; + m = &shared->mouse; if (m->valid && ((wp = cmd_mouse_pane(m, NULL, NULL)) != NULL)) { format_add(ft, "mouse_pane", "%%%u", wp->id); if (cmd_mouse_at(wp, m, &x, &y, 0) == 0) { @@ -2425,7 +2420,7 @@ format_single(struct cmdq_item *item, const char *fmt, struct client *c, char *expanded; if (item != NULL) - ft = format_create(item->client, item, FORMAT_NONE, 0); + ft = format_create(cmdq_get_client(item), item, FORMAT_NONE, 0); else ft = format_create(NULL, item, FORMAT_NONE, 0); format_defaults(ft, c, s, wl, wp); @@ -2435,6 +2430,16 @@ format_single(struct cmdq_item *item, const char *fmt, struct client *c, return (expanded); } +/* Expand a single string using target. */ +char * +format_single_from_target(struct cmdq_item *item, const char *fmt, + struct client *c) +{ + struct cmd_find_state *target = cmdq_get_target(item); + + return (format_single(item, fmt, c, target->s, target->wl, target->wp)); +} + /* Set defaults for any of arguments that are not NULL. */ void format_defaults(struct format_tree *ft, struct client *c, struct session *s, diff --git a/usr.bin/tmux/key-bindings.c b/usr.bin/tmux/key-bindings.c index ae2143d1df7..00c21019195 100644 --- a/usr.bin/tmux/key-bindings.c +++ b/usr.bin/tmux/key-bindings.c @@ -1,4 +1,4 @@ -/* $OpenBSD: key-bindings.c,v 1.118 2020/04/13 08:26:27 nicm Exp $ */ +/* $OpenBSD: key-bindings.c,v 1.119 2020/04/13 10:59:58 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com> @@ -549,7 +549,7 @@ key_bindings_dispatch(struct key_binding *bd, struct cmdq_item *item, else { new_item = cmdq_get_command(bd->cmdlist, fs, m, 0); if (bd->flags & KEY_BINDING_REPEAT) - new_item->shared->flags |= CMDQ_SHARED_REPEAT; + cmdq_get_shared(new_item)->flags |= CMDQ_SHARED_REPEAT; } if (item != NULL) new_item = cmdq_insert_after(item, new_item); diff --git a/usr.bin/tmux/menu.c b/usr.bin/tmux/menu.c index a11f4c5882a..41262c32bff 100644 --- a/usr.bin/tmux/menu.c +++ b/usr.bin/tmux/menu.c @@ -1,4 +1,4 @@ -/* $OpenBSD: menu.c,v 1.15 2020/03/24 08:09:44 nicm Exp $ */ +/* $OpenBSD: menu.c,v 1.16 2020/04/13 10:59:58 nicm Exp $ */ /* * Copyright (c) 2019 Nicholas Marriott <nicholas.marriott@gmail.com> @@ -282,7 +282,7 @@ chosen: break; case CMD_PARSE_SUCCESS: if (md->item != NULL) - m = &md->item->shared->mouse; + m = &cmdq_get_shared(md->item)->mouse; else m = NULL; new_item = cmdq_get_command(pr->cmdlist, &md->fs, m, 0); diff --git a/usr.bin/tmux/notify.c b/usr.bin/tmux/notify.c index 75a3632c92d..d6cf947ed30 100644 --- a/usr.bin/tmux/notify.c +++ b/usr.bin/tmux/notify.c @@ -1,4 +1,4 @@ -/* $OpenBSD: notify.c,v 1.30 2020/04/13 07:25:33 nicm Exp $ */ +/* $OpenBSD: notify.c,v 1.31 2020/04/13 10:59:58 nicm Exp $ */ /* * Copyright (c) 2012 George Nachman <tmux@georgester.com> @@ -189,17 +189,18 @@ notify_add(const char *name, struct cmd_find_state *fs, struct client *c, void notify_hook(struct cmdq_item *item, const char *name) { - struct notify_entry ne; + struct cmd_find_state *target = cmdq_get_target(item); + struct notify_entry ne; memset(&ne, 0, sizeof ne); ne.name = name; - cmd_find_copy_state(&ne.fs, &item->target); + cmd_find_copy_state(&ne.fs, target); - ne.client = item->client; - ne.session = item->target.s; - ne.window = item->target.w; - ne.pane = item->target.wp->id; + ne.client = cmdq_get_client(item); + ne.session = target->s; + ne.window = target->w; + ne.pane = target->wp->id; notify_insert_hook(item, &ne); } diff --git a/usr.bin/tmux/popup.c b/usr.bin/tmux/popup.c index bd061cf0cf2..ec331d8a9d5 100644 --- a/usr.bin/tmux/popup.c +++ b/usr.bin/tmux/popup.c @@ -1,4 +1,4 @@ -/* $OpenBSD: popup.c,v 1.7 2020/04/07 13:33:00 nicm Exp $ */ +/* $OpenBSD: popup.c,v 1.8 2020/04/13 10:59:59 nicm Exp $ */ /* * Copyright (c) 2020 Nicholas Marriott <nicholas.marriott@gmail.com> @@ -64,7 +64,7 @@ popup_write_screen(struct client *c, struct popup_data *pd) struct format_tree *ft; u_int i, y; - ft = format_create(item->client, item, FORMAT_NONE, 0); + ft = format_create(c, item, FORMAT_NONE, 0); if (cmd_find_valid_state(&pd->fs)) format_defaults(ft, c, pd->fs.s, pd->fs.wl, pd->fs.wp); else @@ -152,9 +152,9 @@ popup_free_cb(struct client *c) if (item != NULL) { if (pd->ictx != NULL && - item->client != NULL && - item->client->session == NULL) - item->client->retval = pd->status; + cmdq_get_client(item) != NULL && + cmdq_get_client(item)->session == NULL) + cmdq_get_client(item)->retval = pd->status; cmdq_continue(item); } server_client_unref(pd->c); @@ -305,7 +305,7 @@ popup_key_cb(struct client *c, struct key_event *event) break; case CMD_PARSE_SUCCESS: if (pd->item != NULL) - m = &pd->item->shared->mouse; + m = &cmdq_get_shared(pd->item)->mouse; else m = NULL; new_item = cmdq_get_command(pr->cmdlist, fs, m, 0); @@ -382,7 +382,7 @@ popup_width(struct cmdq_item *item, u_int nlines, const char **lines, struct format_tree *ft; u_int i, width = 0, tmpwidth; - ft = format_create(item->client, item, FORMAT_NONE, 0); + ft = format_create(cmdq_get_client(item), item, FORMAT_NONE, 0); if (fs != NULL && cmd_find_valid_state(fs)) format_defaults(ft, c, fs->s, fs->wl, fs->wp); else diff --git a/usr.bin/tmux/server-client.c b/usr.bin/tmux/server-client.c index 9f1a9a9e404..1e713b7f4ec 100644 --- a/usr.bin/tmux/server-client.c +++ b/usr.bin/tmux/server-client.c @@ -1,4 +1,4 @@ -/* $OpenBSD: server-client.c,v 1.315 2020/04/09 13:52:31 nicm Exp $ */ +/* $OpenBSD: server-client.c,v 1.316 2020/04/13 10:59:59 nicm Exp $ */ /* * Copyright (c) 2009 Nicholas Marriott <nicholas.marriott@gmail.com> @@ -210,7 +210,7 @@ server_client_create(int fd) c->fd = -1; c->cwd = NULL; - TAILQ_INIT(&c->queue); + c->queue = cmdq_new(); c->tty.fd = -1; c->title = NULL; @@ -355,8 +355,7 @@ server_client_free(__unused int fd, __unused short events, void *arg) log_debug("free client %p (%d references)", c, c->references); - if (!TAILQ_EMPTY(&c->queue)) - fatalx("queue not empty"); + cmdq_free(c->queue); if (c->references == 0) { free((void *)c->name); @@ -1082,7 +1081,7 @@ server_client_update_latest(struct client *c) static enum cmd_retval server_client_key_callback(struct cmdq_item *item, void *data) { - struct client *c = item->client; + struct client *c = cmdq_get_client(item); struct key_event *event = data; key_code key = event->key; struct mouse_event *m = &event->m; @@ -1893,7 +1892,7 @@ server_client_dispatch(struct imsg *imsg, void *arg) static enum cmd_retval server_client_command_done(struct cmdq_item *item, __unused void *data) { - struct client *c = item->client; + struct client *c = cmdq_get_client(item); if (~c->flags & CLIENT_ATTACHED) c->flags |= CLIENT_EXIT; diff --git a/usr.bin/tmux/spawn.c b/usr.bin/tmux/spawn.c index 646541ce373..349d7a138a2 100644 --- a/usr.bin/tmux/spawn.c +++ b/usr.bin/tmux/spawn.c @@ -1,4 +1,4 @@ -/* $OpenBSD: spawn.c,v 1.19 2020/03/31 17:14:40 nicm Exp $ */ +/* $OpenBSD: spawn.c,v 1.20 2020/04/13 10:59:59 nicm Exp $ */ /* * Copyright (c) 2019 Nicholas Marriott <nicholas.marriott@gmail.com> @@ -56,10 +56,10 @@ spawn_log(const char *from, struct spawn_context *sc) struct session *s = sc->s; struct winlink *wl = sc->wl; struct window_pane *wp0 = sc->wp0; + const char *name = cmdq_get_name(sc->item); char tmp[128]; - const char *name; - log_debug("%s: %s, flags=%#x", from, sc->item->name, sc->flags); + log_debug("%s: %s, flags=%#x", from, name, sc->flags); if (wl != NULL && wp0 != NULL) xsnprintf(tmp, sizeof tmp, "wl=%d wp0=%%%u", wl->idx, wp0->id); @@ -70,18 +70,14 @@ spawn_log(const char *from, struct spawn_context *sc) else xsnprintf(tmp, sizeof tmp, "wl=none wp0=none"); log_debug("%s: s=$%u %s idx=%d", from, s->id, tmp, sc->idx); - - name = sc->name; - if (name == NULL) - name = "none"; - log_debug("%s: name=%s", from, name); + log_debug("%s: name=%s", from, sc->name == NULL ? "none" : sc->name); } struct winlink * spawn_window(struct spawn_context *sc, char **cause) { struct cmdq_item *item = sc->item; - struct client *c = item->client; + struct client *c = cmdq_get_client(item); struct session *s = sc->s; struct window *w; struct window_pane *wp; @@ -207,7 +203,8 @@ struct window_pane * spawn_pane(struct spawn_context *sc, char **cause) { struct cmdq_item *item = sc->item; - struct client *c = item->client; + struct cmd_find_state *target = cmdq_get_target(item); + struct client *c = cmdq_get_client(item); struct session *s = sc->s; struct window *w = sc->wl->window; struct window_pane *new_wp; @@ -230,9 +227,9 @@ spawn_pane(struct spawn_context *sc, char **cause) * the pane's stored one unless specified. */ if (sc->cwd != NULL) - cwd = format_single(item, sc->cwd, c, item->target.s, NULL, NULL); + cwd = format_single(item, sc->cwd, c, target->s, NULL, NULL); else if (~sc->flags & SPAWN_RESPAWN) - cwd = xstrdup(server_client_get_cwd(c, item->target.s)); + cwd = xstrdup(server_client_get_cwd(c, target->s)); else cwd = NULL; diff --git a/usr.bin/tmux/tmux.h b/usr.bin/tmux/tmux.h index ed2561ce1c2..31f84fd861d 100644 --- a/usr.bin/tmux/tmux.h +++ b/usr.bin/tmux/tmux.h @@ -1,4 +1,4 @@ -/* $OpenBSD: tmux.h,v 1.981 2020/04/13 08:26:27 nicm Exp $ */ +/* $OpenBSD: tmux.h,v 1.982 2020/04/13 10:59:59 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com> @@ -1378,12 +1378,6 @@ struct cmd_parse_input { struct cmd_find_state fs; }; -/* Command queue item type. */ -enum cmdq_type { - CMDQ_COMMAND, - CMDQ_CALLBACK, -}; - /* Command queue item shared state. */ struct cmdq_shared { int references; @@ -1398,39 +1392,13 @@ struct cmdq_shared { struct cmd_find_state current; }; -/* Command queue item. */ -typedef enum cmd_retval (*cmdq_cb) (struct cmdq_item *, void *); -struct cmdq_item { - char *name; - struct cmdq_list *queue; - struct cmdq_item *next; - - struct client *client; - - enum cmdq_type type; - u_int group; - - u_int number; - time_t time; - - int flags; +/* Command queue flags. */ #define CMDQ_FIRED 0x1 #define CMDQ_WAITING 0x2 #define CMDQ_NOHOOKS 0x4 - struct cmdq_shared *shared; - struct cmd_find_state source; - struct cmd_find_state target; - - struct cmd_list *cmdlist; - struct cmd *cmd; - - cmdq_cb cb; - void *data; - - TAILQ_ENTRY(cmdq_item) entry; -}; -TAILQ_HEAD(cmdq_list, cmdq_item); +/* Command queue callback. */ +typedef enum cmd_retval (*cmdq_cb) (struct cmdq_item *, void *); /* Command definition flag. */ struct cmd_entry_flag { @@ -1513,7 +1481,7 @@ typedef void (*overlay_free_cb)(struct client *); struct client { const char *name; struct tmuxpeer *peer; - struct cmdq_list queue; + struct cmdq_list *queue; pid_t pid; int fd; @@ -1827,6 +1795,7 @@ int format_true(const char *); struct format_tree *format_create(struct client *, struct cmdq_item *, int, int); void format_free(struct format_tree *); +void format_merge(struct format_tree *, struct format_tree *); void printflike(3, 4) format_add(struct format_tree *, const char *, const char *, ...); void format_each(struct format_tree *, void (*)(const char *, @@ -1836,6 +1805,8 @@ char *format_expand(struct format_tree *, const char *); char *format_single(struct cmdq_item *, const char *, struct client *, struct session *, struct winlink *, struct window_pane *); +char *format_single_from_target(struct cmdq_item *, const char *, + struct client *); void format_defaults(struct format_tree *, struct client *, struct session *, struct winlink *, struct window_pane *); void format_defaults_window(struct format_tree *, struct window *); @@ -2135,6 +2106,14 @@ struct cmd_parse_result *cmd_parse_from_arguments(int, char **, struct cmd_parse_input *); /* cmd-queue.c */ +struct cmdq_list *cmdq_new(void); +void cmdq_free(struct cmdq_list *); +const char *cmdq_get_name(struct cmdq_item *); +struct client *cmdq_get_client(struct cmdq_item *); +struct cmd_find_state *cmdq_get_target(struct cmdq_item *); +struct cmd_find_state *cmdq_get_source(struct cmdq_item *); +struct cmdq_shared *cmdq_get_shared(struct cmdq_item *); +void cmdq_merge_formats(struct cmdq_item *, struct format_tree *); struct cmdq_item *cmdq_get_command(struct cmd_list *, struct cmd_find_state *, struct mouse_event *, int); #define cmdq_get_callback(cb, data) cmdq_get_callback1(#cb, cb, data) diff --git a/usr.bin/tmux/window.c b/usr.bin/tmux/window.c index c866fb67ccc..7ed3245ca3a 100644 --- a/usr.bin/tmux/window.c +++ b/usr.bin/tmux/window.c @@ -1,4 +1,4 @@ -/* $OpenBSD: window.c,v 1.255 2020/04/10 07:44:26 nicm Exp $ */ +/* $OpenBSD: window.c,v 1.256 2020/04/13 10:59:59 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com> @@ -1536,7 +1536,7 @@ int window_pane_start_input(struct window_pane *wp, struct cmdq_item *item, char **cause) { - struct client *c = item->client; + struct client *c = cmdq_get_client(item); struct window_pane_input_data *cdata; if (~wp->flags & PANE_EMPTY) { |