diff options
author | Nicholas Marriott <nicm@cvs.openbsd.org> | 2020-04-13 20:51:58 +0000 |
---|---|---|
committer | Nicholas Marriott <nicm@cvs.openbsd.org> | 2020-04-13 20:51:58 +0000 |
commit | 26f6725dd2e64084db715b9b5e0c39840231b7e7 (patch) | |
tree | 172d79beae1eef134e867069dfabd6f4d86436a5 /usr.bin/tmux | |
parent | 0eef1273d6a59849f52e5f23509ae3546d3fcde7 (diff) |
Make client -c and -t handling common in cmd-queue.c and try to be
clearer about whether the client is the target client (must have a
session) or not.
Diffstat (limited to 'usr.bin/tmux')
33 files changed, 283 insertions, 287 deletions
diff --git a/usr.bin/tmux/cmd-break-pane.c b/usr.bin/tmux/cmd-break-pane.c index e4606c364b4..3aea48411af 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.54 2020/04/13 14:46:04 nicm Exp $ */ +/* $OpenBSD: cmd-break-pane.c,v 1.55 2020/04/13 20:51:57 nicm Exp $ */ /* * Copyright (c) 2009 Nicholas Marriott <nicholas.marriott@gmail.com> @@ -52,7 +52,7 @@ cmd_break_pane_exec(struct cmd *self, struct cmdq_item *item) struct cmd_find_state *current = cmdq_get_current(item); 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 client *tc = cmdq_get_target_client(item); struct winlink *wl = source->wl; struct session *src_s = source->s; struct session *dst_s = target->s; @@ -83,7 +83,7 @@ cmd_break_pane_exec(struct cmd *self, struct cmdq_item *item) wp->flags |= PANE_STYLECHANGED; TAILQ_INSERT_HEAD(&w->panes, wp, entry); w->active = wp; - w->latest = c; + w->latest = tc; if (!args_has(args, 'n')) { name = default_window_name(w); @@ -115,7 +115,7 @@ cmd_break_pane_exec(struct cmd *self, struct cmdq_item *item) if (args_has(args, 'P')) { if ((template = args_get(args, 'F')) == NULL) template = BREAK_PANE_TEMPLATE; - cp = format_single(item, template, c, dst_s, wl, wp); + cp = format_single(item, template, tc, dst_s, wl, wp); cmdq_print(item, "%s", cp); free(cp); } diff --git a/usr.bin/tmux/cmd-command-prompt.c b/usr.bin/tmux/cmd-command-prompt.c index 0cb37cddb48..b5eeed79c0d 100644 --- a/usr.bin/tmux/cmd-command-prompt.c +++ b/usr.bin/tmux/cmd-command-prompt.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cmd-command-prompt.c,v 1.50 2020/04/13 18:59:41 nicm Exp $ */ +/* $OpenBSD: cmd-command-prompt.c,v 1.51 2020/04/13 20:51:57 nicm Exp $ */ /* * Copyright (c) 2008 Nicholas Marriott <nicholas.marriott@gmail.com> @@ -44,7 +44,7 @@ const struct cmd_entry cmd_command_prompt_entry = { .usage = "[-1kiN] [-I inputs] [-p prompts] " CMD_TARGET_CLIENT_USAGE " " "[template]", - .flags = 0, + .flags = CMD_CLIENT_TFLAG, .exec = cmd_command_prompt_exec }; @@ -65,16 +65,13 @@ static enum cmd_retval cmd_command_prompt_exec(struct cmd *self, struct cmdq_item *item) { struct args *args = cmd_get_args(self); + struct client *tc = cmdq_get_target_client(item); const char *inputs, *prompts; struct cmd_command_prompt_cdata *cdata; - struct client *c; char *prompt, *ptr, *input = NULL; size_t n; - if ((c = cmd_find_client(item, args_get(args, 't'), 0)) == NULL) - return (CMD_RETURN_ERROR); - - if (c->prompt_string != NULL) + if (tc->prompt_string != NULL) return (CMD_RETURN_NORMAL); cdata = xcalloc(1, sizeof *cdata); @@ -124,7 +121,7 @@ cmd_command_prompt_exec(struct cmd *self, struct cmdq_item *item) cdata->flags |= PROMPT_INCREMENTAL; else if (args_has(args, 'k')) cdata->flags |= PROMPT_KEY; - status_prompt_set(c, prompt, input, cmd_command_prompt_callback, + status_prompt_set(tc, prompt, input, cmd_command_prompt_callback, cmd_command_prompt_free, cdata, cdata->flags); free(prompt); diff --git a/usr.bin/tmux/cmd-confirm-before.c b/usr.bin/tmux/cmd-confirm-before.c index 9c8f127fc13..d60360a6d33 100644 --- a/usr.bin/tmux/cmd-confirm-before.c +++ b/usr.bin/tmux/cmd-confirm-before.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cmd-confirm-before.c,v 1.40 2020/04/13 18:59:41 nicm Exp $ */ +/* $OpenBSD: cmd-confirm-before.c,v 1.41 2020/04/13 20:51:57 nicm Exp $ */ /* * Copyright (c) 2009 Tiago Cunha <me@tiagocunha.org> @@ -42,7 +42,7 @@ const struct cmd_entry cmd_confirm_before_entry = { .args = { "p:t:", 1, 1 }, .usage = "[-p prompt] " CMD_TARGET_CLIENT_USAGE " command", - .flags = 0, + .flags = CMD_CLIENT_TFLAG, .exec = cmd_confirm_before_exec }; @@ -55,13 +55,10 @@ cmd_confirm_before_exec(struct cmd *self, struct cmdq_item *item) { struct args *args = cmd_get_args(self); struct cmd_confirm_before_data *cdata; - struct client *c; + struct client *tc = cmdq_get_target_client(item); char *cmd, *copy, *new_prompt, *ptr; const char *prompt; - if ((c = cmd_find_client(item, args_get(args, 't'), 0)) == NULL) - return (CMD_RETURN_ERROR); - if ((prompt = args_get(args, 'p')) != NULL) xasprintf(&new_prompt, "%s ", prompt); else { @@ -74,9 +71,8 @@ cmd_confirm_before_exec(struct cmd *self, struct cmdq_item *item) cdata = xmalloc(sizeof *cdata); cdata->cmd = xstrdup(args->argv[0]); - status_prompt_set(c, new_prompt, NULL, - cmd_confirm_before_callback, cmd_confirm_before_free, cdata, - PROMPT_SINGLE); + status_prompt_set(tc, new_prompt, NULL, cmd_confirm_before_callback, + cmd_confirm_before_free, cdata, PROMPT_SINGLE); free(new_prompt); return (CMD_RETURN_NORMAL); diff --git a/usr.bin/tmux/cmd-detach-client.c b/usr.bin/tmux/cmd-detach-client.c index f329e211237..a822cff8337 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.34 2020/04/13 10:59:58 nicm Exp $ */ +/* $OpenBSD: cmd-detach-client.c,v 1.35 2020/04/13 20:51:57 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com> @@ -39,7 +39,7 @@ const struct cmd_entry cmd_detach_client_entry = { .source = { 's', CMD_FIND_SESSION, CMD_FIND_CANFAIL }, - .flags = CMD_READONLY, + .flags = CMD_READONLY|CMD_CLIENT_TFLAG, .exec = cmd_detach_client_exec }; @@ -50,7 +50,7 @@ const struct cmd_entry cmd_suspend_client_entry = { .args = { "t:", 0, 0 }, .usage = CMD_TARGET_CLIENT_USAGE, - .flags = 0, + .flags = CMD_CLIENT_TFLAG, .exec = cmd_detach_client_exec }; @@ -59,16 +59,13 @@ cmd_detach_client_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 client *c, *cloop; + struct client *tc = cmdq_get_target_client(item), *loop; 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); - if (cmd_get_entry(self) == &cmd_suspend_client_entry) { - server_client_suspend(c); + server_client_suspend(tc); return (CMD_RETURN_NORMAL); } @@ -81,32 +78,32 @@ cmd_detach_client_exec(struct cmd *self, struct cmdq_item *item) s = source->s; if (s == NULL) return (CMD_RETURN_NORMAL); - TAILQ_FOREACH(cloop, &clients, entry) { - if (cloop->session == s) { + TAILQ_FOREACH(loop, &clients, entry) { + if (loop->session == s) { if (cmd != NULL) - server_client_exec(cloop, cmd); + server_client_exec(loop, cmd); else - server_client_detach(cloop, msgtype); + server_client_detach(loop, msgtype); } } return (CMD_RETURN_STOP); } if (args_has(args, 'a')) { - TAILQ_FOREACH(cloop, &clients, entry) { - if (cloop->session != NULL && cloop != c) { + TAILQ_FOREACH(loop, &clients, entry) { + if (loop->session != NULL && loop != tc) { if (cmd != NULL) - server_client_exec(cloop, cmd); + server_client_exec(loop, cmd); else - server_client_detach(cloop, msgtype); + server_client_detach(loop, msgtype); } } return (CMD_RETURN_NORMAL); } if (cmd != NULL) - server_client_exec(c, cmd); + server_client_exec(tc, cmd); else - server_client_detach(c, msgtype); + server_client_detach(tc, msgtype); return (CMD_RETURN_STOP); } diff --git a/usr.bin/tmux/cmd-display-menu.c b/usr.bin/tmux/cmd-display-menu.c index 118defbe98a..0ce222cce63 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.17 2020/04/13 14:46:04 nicm Exp $ */ +/* $OpenBSD: cmd-display-menu.c,v 1.18 2020/04/13 20:51:57 nicm Exp $ */ /* * Copyright (c) 2019 Nicholas Marriott <nicholas.marriott@gmail.com> @@ -42,7 +42,7 @@ const struct cmd_entry cmd_display_menu_entry = { .target = { 't', CMD_FIND_PANE, 0 }, - .flags = CMD_AFTERHOOK, + .flags = CMD_AFTERHOOK|CMD_CLIENT_CFLAG, .exec = cmd_display_menu_exec }; @@ -57,17 +57,18 @@ const struct cmd_entry cmd_display_popup_entry = { .target = { 't', CMD_FIND_PANE, 0 }, - .flags = CMD_AFTERHOOK, + .flags = CMD_AFTERHOOK|CMD_CLIENT_CFLAG, .exec = cmd_display_popup_exec }; static void -cmd_display_menu_get_position(struct client *c, struct cmdq_item *item, +cmd_display_menu_get_position(struct client *tc, struct cmdq_item *item, struct args *args, u_int *px, u_int *py, u_int w, u_int h) { + struct tty *tty = &tc->tty; struct cmd_find_state *target = cmdq_get_target(item); struct key_event *event = cmdq_get_event(item); - struct session *s = c->session; + struct session *s = tc->session; struct winlink *wl = target->wl; struct window_pane *wp = target->wp; struct style_ranges *ranges; @@ -75,9 +76,9 @@ cmd_display_menu_get_position(struct client *c, struct cmdq_item *item, const char *xp, *yp; u_int line, ox, oy, sx, sy, lines; - lines = status_line_size(c); + lines = status_line_size(tc); for (line = 0; line < lines; line++) { - ranges = &c->status.entries[line].ranges; + ranges = &tc->status.entries[line].ranges; TAILQ_FOREACH(sr, ranges, entry) { if (sr->type == STYLE_RANGE_WINDOW) break; @@ -86,15 +87,15 @@ cmd_display_menu_get_position(struct client *c, struct cmdq_item *item, break; } if (line == lines) - ranges = &c->status.entries[0].ranges; + ranges = &tc->status.entries[0].ranges; xp = args_get(args, 'x'); if (xp == NULL || strcmp(xp, "C") == 0) - *px = (c->tty.sx - 1) / 2 - w / 2; + *px = (tty->sx - 1) / 2 - w / 2; else if (strcmp(xp, "R") == 0) - *px = c->tty.sx - 1; + *px = tty->sx - 1; else if (strcmp(xp, "P") == 0) { - tty_window_offset(&c->tty, &ox, &oy, &sx, &sy); + tty_window_offset(&tc->tty, &ox, &oy, &sx, &sy); if (wp->xoff >= ox) *px = wp->xoff - ox; else @@ -105,7 +106,7 @@ cmd_display_menu_get_position(struct client *c, struct cmdq_item *item, else *px = 0; } else if (strcmp(xp, "W") == 0) { - if (status_at_line(c) == -1) + if (status_at_line(tc) == -1) *px = 0; else { TAILQ_FOREACH(sr, ranges, entry) { @@ -121,14 +122,14 @@ cmd_display_menu_get_position(struct client *c, struct cmdq_item *item, } } else *px = strtoul(xp, NULL, 10); - if ((*px) + w >= c->tty.sx) - *px = c->tty.sx - w; + if ((*px) + w >= tty->sx) + *px = tty->sx - w; yp = args_get(args, 'y'); if (yp == NULL || strcmp(yp, "C") == 0) - *py = (c->tty.sy - 1) / 2 + h / 2; + *py = (tty->sy - 1) / 2 + h / 2; else if (strcmp(yp, "P") == 0) { - tty_window_offset(&c->tty, &ox, &oy, &sx, &sy); + tty_window_offset(&tc->tty, &ox, &oy, &sx, &sy); if (wp->yoff + wp->sy >= oy) *py = wp->yoff + wp->sy - oy; else @@ -146,9 +147,9 @@ cmd_display_menu_get_position(struct client *c, struct cmdq_item *item, *py = 0; } else { if (lines != 0) - *py = c->tty.sy - lines; + *py = tty->sy - lines; else - *py = c->tty.sy; + *py = tty->sy; } } else if (strcmp(yp, "W") == 0) { if (options_get_number(s->options, "status-position") == 0) { @@ -158,9 +159,9 @@ cmd_display_menu_get_position(struct client *c, struct cmdq_item *item, *py = 0; } else { if (lines != 0) - *py = c->tty.sy - lines + line; + *py = tty->sy - lines + line; else - *py = c->tty.sy; + *py = tty->sy; } } else *py = strtoul(yp, NULL, 10); @@ -168,8 +169,8 @@ cmd_display_menu_get_position(struct client *c, struct cmdq_item *item, *py = 0; else *py -= h; - if ((*py) + h >= c->tty.sy) - *py = c->tty.sy - h; + if ((*py) + h >= tty->sy) + *py = tty->sy - h; } static enum cmd_retval @@ -178,7 +179,7 @@ cmd_display_menu_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 key_event *event = cmdq_get_event(item); - struct client *c; + struct client *tc = cmdq_get_target_client(item); struct menu *menu = NULL; struct menu_item menu_item; const char *key; @@ -186,13 +187,11 @@ cmd_display_menu_exec(struct cmd *self, struct cmdq_item *item) int flags = 0, i; u_int px, py; - if ((c = cmd_find_client(item, args_get(args, 'c'), 0)) == NULL) - return (CMD_RETURN_ERROR); - if (c->overlay_draw != NULL) + if (tc->overlay_draw != NULL) return (CMD_RETURN_NORMAL); if (args_has(args, 'T')) - title = format_single_from_target(item, args_get(args, 'T'), c); + title = format_single_from_target(item, args_get(args, 'T')); else title = xstrdup(""); menu = menu_create(title); @@ -200,7 +199,7 @@ cmd_display_menu_exec(struct cmd *self, struct cmdq_item *item) for (i = 0; i != args->argc; /* nothing */) { name = args->argv[i++]; if (*name == '\0') { - menu_add_item(menu, NULL, item, c, target); + menu_add_item(menu, NULL, item, tc, target); continue; } @@ -216,7 +215,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, target); + menu_add_item(menu, &menu_item, item, tc, target); } free(title); if (menu == NULL) { @@ -227,12 +226,13 @@ cmd_display_menu_exec(struct cmd *self, struct cmdq_item *item) menu_free(menu); return (CMD_RETURN_NORMAL); } - cmd_display_menu_get_position(c, item, args, &px, &py, menu->width + 4, + cmd_display_menu_get_position(tc, item, args, &px, &py, menu->width + 4, menu->count + 2); if (!event->m.valid) flags |= MENU_NOMOUSE; - if (menu_display(menu, flags, item, px, py, c, target, NULL, NULL) != 0) + if (menu_display(menu, flags, item, px, py, tc, target, NULL, + NULL) != 0) return (CMD_RETURN_NORMAL); return (CMD_RETURN_WAIT); } @@ -242,20 +242,19 @@ 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 client *tc = cmdq_get_target_client(item); + struct tty *tty = &tc->tty; const char *value, *cmd = NULL, **lines = NULL; const char *shellcmd = NULL; char *cwd, *cause; int flags = 0; u_int px, py, w, h, nlines = 0; - if ((c = cmd_find_client(item, args_get(args, 'c'), 0)) == NULL) - return (CMD_RETURN_ERROR); if (args_has(args, 'C')) { - server_client_clear_overlay(c); + server_client_clear_overlay(tc); return (CMD_RETURN_NORMAL); } - if (c->overlay_draw != NULL) + if (tc->overlay_draw != NULL) return (CMD_RETURN_NORMAL); if (args->argc >= 1) @@ -268,9 +267,9 @@ cmd_display_popup_exec(struct cmd *self, struct cmdq_item *item) if (nlines != 0) h = popup_height(nlines, lines) + 2; else - h = c->tty.sy / 2; + h = tty->sy / 2; if (args_has(args, 'h')) { - h = args_percentage(args, 'h', 1, c->tty.sy, c->tty.sy, &cause); + h = args_percentage(args, 'h', 1, tty->sy, tty->sy, &cause); if (cause != NULL) { cmdq_error(item, "height %s", cause); free(cause); @@ -279,11 +278,11 @@ cmd_display_popup_exec(struct cmd *self, struct cmdq_item *item) } if (nlines != 0) - w = popup_width(item, nlines, lines, c, target) + 2; + w = popup_width(item, nlines, lines, tc, target) + 2; else - w = c->tty.sx / 2; + w = tty->sx / 2; if (args_has(args, 'w')) { - w = args_percentage(args, 'w', 1, c->tty.sx, c->tty.sx, &cause); + w = args_percentage(args, 'w', 1, tty->sx, tty->sx, &cause); if (cause != NULL) { cmdq_error(item, "width %s", cause); free(cause); @@ -291,21 +290,21 @@ cmd_display_popup_exec(struct cmd *self, struct cmdq_item *item) } } - if (w > c->tty.sx - 1) - w = c->tty.sx - 1; - if (h > c->tty.sy - 1) - h = c->tty.sy - 1; - cmd_display_menu_get_position(c, item, args, &px, &py, w, h); + if (w > tty->sx - 1) + w = tty->sx - 1; + if (h > tty->sy - 1) + h = tty->sy - 1; + cmd_display_menu_get_position(tc, item, args, &px, &py, w, h); value = args_get(args, 'd'); if (value != NULL) - cwd = format_single_from_target(item, value, c); + cwd = format_single_from_target(item, value); else - cwd = xstrdup(server_client_get_cwd(c, target->s)); + cwd = xstrdup(server_client_get_cwd(tc, target->s)); value = args_get(args, 'R'); if (value != NULL) - shellcmd = format_single_from_target(item, value, c); + shellcmd = format_single_from_target(item, value); if (args_has(args, 'K')) flags |= POPUP_WRITEKEYS; @@ -314,7 +313,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, target) != 0) + cmd, cwd, tc, 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 f4f32ed7dda..f3e6900239b 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.52 2020/04/13 10:59:58 nicm Exp $ */ +/* $OpenBSD: cmd-display-message.c,v 1.53 2020/04/13 20:51:57 nicm Exp $ */ /* * Copyright (c) 2009 Tiago Cunha <me@tiagocunha.org> @@ -45,7 +45,7 @@ const struct cmd_entry cmd_display_message_entry = { .target = { 't', CMD_FIND_PANE, 0 }, - .flags = CMD_AFTERHOOK, + .flags = CMD_AFTERHOOK|CMD_CLIENT_CFLAG|CMD_CLIENT_CANFAIL, .exec = cmd_display_message_exec }; @@ -62,7 +62,7 @@ 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 client *tc = cmdq_get_target_client(item), *c; struct session *s = target->s; struct winlink *wl = target->wl; struct window_pane *wp = target->wp; @@ -97,17 +97,16 @@ cmd_display_message_exec(struct cmd *self, struct cmdq_item *item) * formats too, assuming it matches the session. If it doesn't, use the * best client for the session. */ - c = cmd_find_client(item, args_get(args, 'c'), 1); - if (c != NULL && c->session == s) - target_c = c; + if (tc != NULL && tc->session == s) + c = tc; else - target_c = cmd_find_best_client(s); + c = cmd_find_best_client(s); if (args_has(args, 'v')) flags = FORMAT_VERBOSE; else flags = 0; ft = format_create(cmdq_get_client(item), item, FORMAT_NONE, flags); - format_defaults(ft, target_c, s, wl, wp); + format_defaults(ft, c, s, wl, wp); if (args_has(args, 'a')) { format_each(ft, cmd_display_message_each, item); @@ -117,8 +116,8 @@ cmd_display_message_exec(struct cmd *self, struct cmdq_item *item) msg = format_expand_time(ft, template); if (args_has(args, 'p')) cmdq_print(item, "%s", msg); - else if (c != NULL) - status_message_set(c, "%s", msg); + else if (tc != NULL) + status_message_set(tc, "%s", msg); free(msg); format_free(ft); diff --git a/usr.bin/tmux/cmd-display-panes.c b/usr.bin/tmux/cmd-display-panes.c index 43e0c2f0759..2680c9835a1 100644 --- a/usr.bin/tmux/cmd-display-panes.c +++ b/usr.bin/tmux/cmd-display-panes.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cmd-display-panes.c,v 1.33 2020/04/13 18:59:41 nicm Exp $ */ +/* $OpenBSD: cmd-display-panes.c,v 1.34 2020/04/13 20:51:57 nicm Exp $ */ /* * Copyright (c) 2009 Nicholas Marriott <nicholas.marriott@gmail.com> @@ -37,7 +37,7 @@ const struct cmd_entry cmd_display_panes_entry = { .args = { "bd:t:", 0, 1 }, .usage = "[-b] [-d duration] " CMD_TARGET_CLIENT_USAGE " [template]", - .flags = CMD_AFTERHOOK, + .flags = CMD_AFTERHOOK|CMD_CLIENT_TFLAG, .exec = cmd_display_panes_exec }; @@ -228,17 +228,13 @@ static enum cmd_retval cmd_display_panes_exec(struct cmd *self, struct cmdq_item *item) { struct args *args = cmd_get_args(self); - struct client *c; - struct session *s; + struct client *tc = cmdq_get_target_client(item); + struct session *s = tc->session; u_int delay; char *cause; struct cmd_display_panes_data *cdata; - if ((c = cmd_find_client(item, args_get(args, 't'), 0)) == NULL) - return (CMD_RETURN_ERROR); - s = c->session; - - if (c->overlay_draw != NULL) + if (tc->overlay_draw != NULL) return (CMD_RETURN_NORMAL); if (args_has(args, 'd')) { @@ -261,7 +257,7 @@ cmd_display_panes_exec(struct cmd *self, struct cmdq_item *item) else cdata->item = item; - server_client_set_overlay(c, delay, NULL, NULL, cmd_display_panes_draw, + server_client_set_overlay(tc, delay, NULL, NULL, cmd_display_panes_draw, cmd_display_panes_key, cmd_display_panes_free, cdata); if (args_has(args, 'b')) diff --git a/usr.bin/tmux/cmd-if-shell.c b/usr.bin/tmux/cmd-if-shell.c index c9b74642946..1dd7878264c 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.73 2020/04/13 18:59:41 nicm Exp $ */ +/* $OpenBSD: cmd-if-shell.c,v 1.74 2020/04/13 20:51:57 nicm Exp $ */ /* * Copyright (c) 2009 Tiago Cunha <me@tiagocunha.org> @@ -67,12 +67,12 @@ cmd_if_shell_exec(struct cmd *self, struct cmdq_item *item) struct cmd_if_shell_data *cdata; char *shellcmd, *cmd, *error; const char *file; - struct client *c = cmd_find_client(item, NULL, 1); + struct client *tc = cmdq_get_target_client(item); struct session *s = target->s; struct cmd_parse_input pi; enum cmd_parse_status status; - shellcmd = format_single_from_target(item, args->argv[0], c); + shellcmd = format_single_from_target(item, args->argv[0]); if (args_has(args, 'F')) { if (*shellcmd != '0' && *shellcmd != '\0') cmd = args->argv[1]; @@ -87,7 +87,7 @@ cmd_if_shell_exec(struct cmd *self, struct cmdq_item *item) memset(&pi, 0, sizeof pi); cmd_get_source(self, &pi.file, &pi.line); pi.item = item; - pi.c = c; + pi.c = tc; cmd_find_copy_state(&pi.fs, target); status = cmd_parse_and_insert(cmd, &pi, item, state, &error); @@ -110,7 +110,7 @@ cmd_if_shell_exec(struct cmd *self, struct cmdq_item *item) if (!args_has(args, 'b')) cdata->client = cmdq_get_client(item); else - cdata->client = c; + cdata->client = tc; if (cdata->client != NULL) cdata->client->references++; @@ -123,7 +123,7 @@ cmd_if_shell_exec(struct cmd *self, struct cmdq_item *item) cmd_get_source(self, &file, &cdata->input.line); if (file != NULL) cdata->input.file = xstrdup(file); - cdata->input.c = c; + cdata->input.c = tc; if (cdata->input.c != NULL) cdata->input.c->references++; cmd_find_copy_state(&cdata->input.fs, target); diff --git a/usr.bin/tmux/cmd-list-keys.c b/usr.bin/tmux/cmd-list-keys.c index 1a011018e13..c6c1ed57eff 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.55 2020/04/13 10:59:58 nicm Exp $ */ +/* $OpenBSD: cmd-list-keys.c,v 1.56 2020/04/13 20:51:57 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com> @@ -85,7 +85,7 @@ static int cmd_list_keys_print_notes(struct cmdq_item *item, struct args *args, const char *tablename, u_int keywidth, key_code only, const char *prefix) { - struct client *c = cmd_find_client(item, NULL, 1); + struct client *tc = cmdq_get_target_client(item); struct key_table *table; struct key_binding *bd; const char *key; @@ -111,8 +111,8 @@ cmd_list_keys_print_notes(struct cmdq_item *item, struct args *args, else note = xstrdup(bd->note); tmp = utf8_padcstr(key, keywidth + 1); - if (args_has(args, '1') && c != NULL) - status_message_set(c, "%s%s%s", prefix, tmp, note); + if (args_has(args, '1') && tc != NULL) + status_message_set(tc, "%s%s%s", prefix, tmp, note); else cmdq_print(item, "%s%s%s", prefix, tmp, note); free(tmp); diff --git a/usr.bin/tmux/cmd-load-buffer.c b/usr.bin/tmux/cmd-load-buffer.c index 90515f3ddf6..475ead54c0a 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.59 2020/04/13 10:59:58 nicm Exp $ */ +/* $OpenBSD: cmd-load-buffer.c,v 1.60 2020/04/13 20:51:57 nicm Exp $ */ /* * Copyright (c) 2009 Tiago Cunha <me@tiagocunha.org> @@ -85,7 +85,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); const char *bufname = args_get(args, 'b'); char *path; @@ -96,7 +95,7 @@ cmd_load_buffer_exec(struct cmd *self, struct cmdq_item *item) else cdata->name = NULL; - path = format_single_from_target(item, args->argv[0], c); + path = format_single_from_target(item, args->argv[0]); file_read(cmdq_get_client(item), path, cmd_load_buffer_done, cdata); free(path); diff --git a/usr.bin/tmux/cmd-lock-server.c b/usr.bin/tmux/cmd-lock-server.c index 1d3dd0d2928..6508294999a 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.28 2020/04/13 10:59:58 nicm Exp $ */ +/* $OpenBSD: cmd-lock-server.c,v 1.29 2020/04/13 20:51:57 nicm Exp $ */ /* * Copyright (c) 2008 Nicholas Marriott <nicholas.marriott@gmail.com> @@ -57,7 +57,7 @@ const struct cmd_entry cmd_lock_client_entry = { .args = { "t:", 0, 0 }, .usage = CMD_TARGET_CLIENT_USAGE, - .flags = CMD_AFTERHOOK, + .flags = CMD_AFTERHOOK|CMD_CLIENT_TFLAG, .exec = cmd_lock_server_exec }; @@ -66,17 +66,14 @@ cmd_lock_server_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 client *tc = cmdq_get_target_client(item); if (cmd_get_entry(self) == &cmd_lock_server_entry) server_lock(); else if (cmd_get_entry(self) == &cmd_lock_session_entry) server_lock_session(target->s); - else { - if ((c = cmd_find_client(item, args_get(args, 't'), 0)) == NULL) - return (CMD_RETURN_ERROR); - server_lock_client(c); - } + else + server_lock_client(tc); recalculate_sizes(); return (CMD_RETURN_NORMAL); diff --git a/usr.bin/tmux/cmd-new-session.c b/usr.bin/tmux/cmd-new-session.c index 58836a0de49..93fe640d1e0 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.129 2020/04/13 15:55:51 nicm Exp $ */ +/* $OpenBSD: cmd-new-session.c,v 1.130 2020/04/13 20:51:57 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com> @@ -269,7 +269,6 @@ cmd_new_session_exec(struct cmd *self, struct cmdq_item *item) memset(&sc, 0, sizeof sc); sc.item = item; sc.s = s; - sc.c = c; sc.name = args_get(args, 'n'); sc.argc = args->argc; diff --git a/usr.bin/tmux/cmd-new-window.c b/usr.bin/tmux/cmd-new-window.c index d4d72765cc4..954950be50d 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.86 2020/04/13 14:46:04 nicm Exp $ */ +/* $OpenBSD: cmd-new-window.c,v 1.87 2020/04/13 20:51:57 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com> @@ -55,7 +55,7 @@ cmd_new_window_exec(struct cmd *self, struct cmdq_item *item) struct cmd_find_state *current = cmdq_get_current(item); struct cmd_find_state *target = cmdq_get_target(item); struct spawn_context sc; - struct client *c = cmd_find_client(item, NULL, 1); + struct client *tc = cmdq_get_target_client(item); struct session *s = target->s; struct winlink *wl = target->wl; int idx = target->idx; @@ -73,7 +73,7 @@ cmd_new_window_exec(struct cmd *self, struct cmdq_item *item) memset(&sc, 0, sizeof sc); sc.item = item; sc.s = s; - sc.c = c; + sc.tc = tc; sc.name = args_get(args, 'n'); sc.argc = args->argc; @@ -109,7 +109,7 @@ cmd_new_window_exec(struct cmd *self, struct cmdq_item *item) if (args_has(args, 'P')) { if ((template = args_get(args, 'F')) == NULL) template = NEW_WINDOW_TEMPLATE; - cp = format_single(item, template, c, s, new_wl, + cp = format_single(item, template, tc, s, new_wl, new_wl->window->active); cmdq_print(item, "%s", cp); free(cp); diff --git a/usr.bin/tmux/cmd-pipe-pane.c b/usr.bin/tmux/cmd-pipe-pane.c index d7477b45675..2c0ab3f38c1 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.53 2020/04/13 10:59:58 nicm Exp $ */ +/* $OpenBSD: cmd-pipe-pane.c,v 1.54 2020/04/13 20:51:57 nicm Exp $ */ /* * Copyright (c) 2009 Nicholas Marriott <nicholas.marriott@gmail.com> @@ -58,7 +58,7 @@ 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 client *tc = cmdq_get_target_client(item); struct window_pane *wp = target->wp; struct session *s = target->s; struct winlink *wl = target->wl; @@ -110,7 +110,7 @@ cmd_pipe_pane_exec(struct cmd *self, struct cmdq_item *item) /* Expand the command. */ ft = format_create(cmdq_get_client(item), item, FORMAT_NONE, 0); - format_defaults(ft, c, s, wl, wp); + format_defaults(ft, tc, 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 6df98c3fe75..3276fd9b6fe 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.88 2020/04/13 15:55:51 nicm Exp $ */ +/* $OpenBSD: cmd-queue.c,v 1.89 2020/04/13 20:51:57 nicm Exp $ */ /* * Copyright (c) 2013 Nicholas Marriott <nicholas.marriott@gmail.com> @@ -42,6 +42,7 @@ struct cmdq_item { struct cmdq_item *next; struct client *client; + struct client *target_client; enum cmdq_type type; u_int group; @@ -145,6 +146,13 @@ cmdq_get_client(struct cmdq_item *item) return (item->client); } +/* Get item target client. */ +struct client * +cmdq_get_target_client(struct cmdq_item *item) +{ + return (item->target_client); +} + /* Get item state. */ struct cmdq_state * cmdq_get_state(struct cmdq_item *item) @@ -483,14 +491,15 @@ cmdq_find_flag(struct cmdq_item *item, struct cmd_find_state *fs, static enum cmd_retval cmdq_fire_command(struct cmdq_item *item) { - struct client *c = item->client; - const char *name = cmdq_name(c); + const char *name = cmdq_name(item->client); struct cmdq_state *state = item->state; struct cmd *cmd = item->cmd; + struct args *args = cmd_get_args(cmd); const struct cmd_entry *entry = cmd_get_entry(cmd); + struct client *tc, *saved = item->client; enum cmd_retval retval; struct cmd_find_state *fsp, fs; - int flags; + int flags, quiet = 0; char *tmp; if (log_get_level() > 1) { @@ -504,6 +513,25 @@ cmdq_fire_command(struct cmdq_item *item) if (item->client == NULL) item->client = cmd_find_client(item, NULL, 1); + + if (entry->flags & CMD_CLIENT_CANFAIL) + quiet = 1; + if (entry->flags & CMD_CLIENT_CFLAG) { + tc = cmd_find_client(item, args_get(args, 'c'), quiet); + if (tc == NULL && !quiet) { + retval = CMD_RETURN_ERROR; + goto out; + } + } else if (entry->flags & CMD_CLIENT_TFLAG) { + tc = cmd_find_client(item, args_get(args, 't'), quiet); + if (tc == NULL && !quiet) { + retval = CMD_RETURN_ERROR; + goto out; + } + } else + tc = cmd_find_client(item, NULL, 1); + item->target_client = tc; + retval = cmdq_find_flag(item, &item->source, &entry->source); if (retval == CMD_RETURN_ERROR) goto out; @@ -511,6 +539,7 @@ cmdq_fire_command(struct cmdq_item *item) if (retval == CMD_RETURN_ERROR) goto out; + retval = entry->exec(cmd, item); if (retval == CMD_RETURN_ERROR) goto out; @@ -528,7 +557,7 @@ cmdq_fire_command(struct cmdq_item *item) } out: - item->client = c; + item->client = saved; if (retval == CMD_RETURN_ERROR) cmdq_guard(item, "error", flags); else diff --git a/usr.bin/tmux/cmd-refresh-client.c b/usr.bin/tmux/cmd-refresh-client.c index dd42651934e..704b46a3564 100644 --- a/usr.bin/tmux/cmd-refresh-client.c +++ b/usr.bin/tmux/cmd-refresh-client.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cmd-refresh-client.c,v 1.31 2020/04/13 08:26:27 nicm Exp $ */ +/* $OpenBSD: cmd-refresh-client.c,v 1.32 2020/04/13 20:51:57 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com> @@ -38,7 +38,7 @@ const struct cmd_entry cmd_refresh_client_entry = { .usage = "[-cDlLRSU] [-C XxY] [-F flags] " CMD_TARGET_CLIENT_USAGE " [adjustment]", - .flags = CMD_AFTERHOOK, + .flags = CMD_AFTERHOOK|CMD_CLIENT_TFLAG, .exec = cmd_refresh_client_exec }; @@ -46,17 +46,13 @@ static enum cmd_retval cmd_refresh_client_exec(struct cmd *self, struct cmdq_item *item) { struct args *args = cmd_get_args(self); - struct client *c; - struct tty *tty; + struct client *tc = cmdq_get_target_client(item); + struct tty *tty = &tc->tty; struct window *w; const char *size, *errstr; char *copy, *next, *s; u_int x, y, adjust; - if ((c = cmd_find_client(item, args_get(args, 't'), 0)) == NULL) - return (CMD_RETURN_ERROR); - tty = &c->tty; - if (args_has(args, 'c') || args_has(args, 'L') || args_has(args, 'R') || @@ -74,48 +70,47 @@ cmd_refresh_client_exec(struct cmd *self, struct cmdq_item *item) } if (args_has(args, 'c')) - c->pan_window = NULL; + tc->pan_window = NULL; else { - w = c->session->curw->window; - if (c->pan_window != w) { - c->pan_window = w; - c->pan_ox = tty->oox; - c->pan_oy = tty->ooy; + w = tc->session->curw->window; + if (tc->pan_window != w) { + tc->pan_window = w; + tc->pan_ox = tty->oox; + tc->pan_oy = tty->ooy; } if (args_has(args, 'L')) { - if (c->pan_ox > adjust) - c->pan_ox -= adjust; + if (tc->pan_ox > adjust) + tc->pan_ox -= adjust; else - c->pan_ox = 0; + tc->pan_ox = 0; } else if (args_has(args, 'R')) { - c->pan_ox += adjust; - if (c->pan_ox > w->sx - tty->osx) - c->pan_ox = w->sx - tty->osx; + tc->pan_ox += adjust; + if (tc->pan_ox > w->sx - tty->osx) + tc->pan_ox = w->sx - tty->osx; } else if (args_has(args, 'U')) { - if (c->pan_oy > adjust) - c->pan_oy -= adjust; + if (tc->pan_oy > adjust) + tc->pan_oy -= adjust; else - c->pan_oy = 0; + tc->pan_oy = 0; } else if (args_has(args, 'D')) { - c->pan_oy += adjust; - if (c->pan_oy > w->sy - tty->osy) - c->pan_oy = w->sy - tty->osy; + tc->pan_oy += adjust; + if (tc->pan_oy > w->sy - tty->osy) + tc->pan_oy = w->sy - tty->osy; } } - tty_update_client_offset(c); - server_redraw_client(c); + tty_update_client_offset(tc); + server_redraw_client(tc); return (CMD_RETURN_NORMAL); } if (args_has(args, 'l')) { - if (c->session != NULL) - tty_putcode_ptr2(&c->tty, TTYC_MS, "", "?"); + tty_putcode_ptr2(&tc->tty, TTYC_MS, "", "?"); return (CMD_RETURN_NORMAL); } if (args_has(args, 'C') || args_has(args, 'F')) { if (args_has(args, 'C')) { - if (!(c->flags & CLIENT_CONTROL)) { + if (!(tc->flags & CLIENT_CONTROL)) { cmdq_error(item, "not a control client"); return (CMD_RETURN_ERROR); } @@ -130,12 +125,12 @@ cmd_refresh_client_exec(struct cmd *self, struct cmdq_item *item) cmdq_error(item, "size too small or too big"); return (CMD_RETURN_ERROR); } - tty_set_size(&c->tty, x, y, 0, 0); - c->flags |= CLIENT_SIZECHANGED; + tty_set_size(&tc->tty, x, y, 0, 0); + tc->flags |= CLIENT_SIZECHANGED; recalculate_sizes(); } if (args_has(args, 'F')) { - if (!(c->flags & CLIENT_CONTROL)) { + if (!(tc->flags & CLIENT_CONTROL)) { cmdq_error(item, "not a control client"); return (CMD_RETURN_ERROR); } @@ -143,7 +138,7 @@ cmd_refresh_client_exec(struct cmd *self, struct cmdq_item *item) while ((next = strsep(&s, ",")) != NULL) { /* Unknown flags are ignored. */ if (strcmp(next, "no-output") == 0) - c->flags |= CLIENT_CONTROL_NOOUTPUT; + tc->flags |= CLIENT_CONTROL_NOOUTPUT; } free(copy); } @@ -151,11 +146,11 @@ cmd_refresh_client_exec(struct cmd *self, struct cmdq_item *item) } if (args_has(args, 'S')) { - c->flags |= CLIENT_STATUSFORCE; - server_status_client(c); + tc->flags |= CLIENT_STATUSFORCE; + server_status_client(tc); } else { - c->flags |= CLIENT_STATUSFORCE; - server_redraw_client(c); + tc->flags |= CLIENT_STATUSFORCE; + server_redraw_client(tc); } return (CMD_RETURN_NORMAL); } diff --git a/usr.bin/tmux/cmd-rename-session.c b/usr.bin/tmux/cmd-rename-session.c index fb8ee766834..bd7fe72e0d3 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.30 2020/04/13 10:59:58 nicm Exp $ */ +/* $OpenBSD: cmd-rename-session.c,v 1.31 2020/04/13 20:51:57 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com> @@ -48,11 +48,10 @@ 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 = target->s; char *newname; - newname = format_single_from_target(item, args->argv[0], c); + newname = format_single_from_target(item, args->argv[0]); 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 7cb8928f361..f5f527181f9 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.24 2020/04/13 10:59:58 nicm Exp $ */ +/* $OpenBSD: cmd-rename-window.c,v 1.25 2020/04/13 20:51:57 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com> @@ -47,11 +47,10 @@ cmd_rename_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 client *c = cmd_find_client(item, NULL, 1); struct winlink *wl = target->wl; char *newname; - newname = format_single_from_target(item, args->argv[0], c); + newname = format_single_from_target(item, args->argv[0]); window_set_name(wl->window, newname); options_set_number(wl->window->options, "automatic-rename", 0); diff --git a/usr.bin/tmux/cmd-respawn-window.c b/usr.bin/tmux/cmd-respawn-window.c index 21fcbee119c..39033bf26ba 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.43 2020/04/13 10:59:58 nicm Exp $ */ +/* $OpenBSD: cmd-respawn-window.c,v 1.44 2020/04/13 20:51:57 nicm Exp $ */ /* * Copyright (c) 2008 Nicholas Marriott <nicholas.marriott@gmail.com> @@ -50,6 +50,7 @@ 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 client *tc = cmdq_get_target_client(item); struct session *s = target->s; struct winlink *wl = target->wl; char *cause = NULL; @@ -60,7 +61,7 @@ cmd_respawn_window_exec(struct cmd *self, struct cmdq_item *item) sc.item = item; sc.s = s; sc.wl = wl; - sc.c = cmd_find_client(item, NULL, 1); + sc.tc = tc; sc.name = NULL; sc.argc = args->argc; diff --git a/usr.bin/tmux/cmd-run-shell.c b/usr.bin/tmux/cmd-run-shell.c index e83ca6aae45..a28199b788a 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.66 2020/04/13 10:59:58 nicm Exp $ */ +/* $OpenBSD: cmd-run-shell.c,v 1.67 2020/04/13 20:51:57 nicm Exp $ */ /* * Copyright (c) 2009 Tiago Cunha <me@tiagocunha.org> @@ -92,7 +92,6 @@ 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 = target->s; struct window_pane *wp = target->wp; const char *delay; @@ -102,7 +101,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_from_target(item, args->argv[0], c); + cdata->cmd = format_single_from_target(item, args->argv[0]); if (args_has(args, 't') && wp != NULL) cdata->wp_id = wp->id; diff --git a/usr.bin/tmux/cmd-save-buffer.c b/usr.bin/tmux/cmd-save-buffer.c index 6b8901a723a..1a31ad951e0 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.49 2020/04/13 10:59:58 nicm Exp $ */ +/* $OpenBSD: cmd-save-buffer.c,v 1.50 2020/04/13 20:51:57 nicm Exp $ */ /* * Copyright (c) 2009 Tiago Cunha <me@tiagocunha.org> @@ -74,7 +74,6 @@ static enum cmd_retval 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 paste_buffer *pb; int flags; const char *bufname = args_get(args, 'b'), *bufdata; @@ -98,7 +97,7 @@ 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_from_target(item, args->argv[0], c); + path = format_single_from_target(item, args->argv[0]); if (args_has(args, 'a')) flags = O_APPEND; else diff --git a/usr.bin/tmux/cmd-select-pane.c b/usr.bin/tmux/cmd-select-pane.c index 19ce436ef69..3d72092d3d6 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.58 2020/04/13 14:46:04 nicm Exp $ */ +/* $OpenBSD: cmd-select-pane.c,v 1.59 2020/04/13 20:51:57 nicm Exp $ */ /* * Copyright (c) 2009 Nicholas Marriott <nicholas.marriott@gmail.com> @@ -87,12 +87,11 @@ cmd_select_pane_exec(struct cmd *self, struct cmdq_item *item) const struct cmd_entry *entry = cmd_get_entry(self); struct cmd_find_state *current = cmdq_get_current(item); struct cmd_find_state *target = cmdq_get_target(item); - struct client *c = cmd_find_client(item, NULL, 1); struct winlink *wl = target->wl; struct window *w = wl->window; struct session *s = target->s; struct window_pane *wp = target->wp, *lastwp, *markedwp; - char *pane_title; + char *title; const char *style; struct style *sy; struct options_entry *o; @@ -197,11 +196,10 @@ cmd_select_pane_exec(struct cmd *self, struct cmdq_item *item) } if (args_has(args, 'T')) { - pane_title = format_single(item, args_get(args, 'T'), - c, s, wl, wp); - if (screen_set_title(&wp->base, pane_title)) + title = format_single_from_target(item, args_get(args, 'T')); + if (screen_set_title(&wp->base, title)) server_status_window(wp->window); - free(pane_title); + free(title); return (CMD_RETURN_NORMAL); } diff --git a/usr.bin/tmux/cmd-send-keys.c b/usr.bin/tmux/cmd-send-keys.c index 53d9e5b64bb..6f9fa7bc5fe 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.59 2020/04/13 14:46:04 nicm Exp $ */ +/* $OpenBSD: cmd-send-keys.c,v 1.60 2020/04/13 20:51:57 nicm Exp $ */ /* * Copyright (c) 2008 Nicholas Marriott <nicholas.marriott@gmail.com> @@ -57,23 +57,23 @@ const struct cmd_entry cmd_send_prefix_entry = { }; static struct cmdq_item * -cmd_send_keys_inject_key(struct client *c, struct cmd_find_state *fs, - struct cmdq_item *item, key_code key) +cmd_send_keys_inject_key(struct cmdq_item *item, struct cmdq_item *after, + 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; + struct client *tc = cmdq_get_target_client(item); + struct session *s = target->s; + struct winlink *wl = target->wl; + struct window_pane *wp = target->wp; struct window_mode_entry *wme; struct key_table *table; struct key_binding *bd; - wme = TAILQ_FIRST(&fs->wp->modes); + wme = TAILQ_FIRST(&wp->modes); if (wme == NULL || wme->mode->key_table == NULL) { - if (options_get_number(fs->wp->window->options, "xterm-keys")) + if (options_get_number(wp->window->options, "xterm-keys")) key |= KEYC_XTERM; - if (window_pane_key(wp, cmdq_get_client(item), s, wl, key, - NULL) != 0) + if (window_pane_key(wp, tc, s, wl, key, NULL) != 0) return (NULL); return (item); } @@ -82,18 +82,17 @@ 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, target); + after = key_bindings_dispatch(bd, after, tc, NULL, target); key_bindings_unref_table(table); } - return (item); + return (after); } static struct cmdq_item * -cmd_send_keys_inject_string(struct client *c, struct cmd_find_state *fs, - struct cmdq_item *item, struct args *args, int i) +cmd_send_keys_inject_string(struct cmdq_item *item, struct cmdq_item *after, + struct args *args, int i) { const char *s = args->argv[i]; - struct cmdq_item *new_item; struct utf8_data *ud, *uc; wchar_t wc; key_code key; @@ -105,29 +104,29 @@ cmd_send_keys_inject_string(struct client *c, struct cmd_find_state *fs, n = strtol(s, &endptr, 16); if (*s =='\0' || n < 0 || n > 0xff || *endptr != '\0') return (item); - return (cmd_send_keys_inject_key(c, fs, item, KEYC_LITERAL|n)); + return (cmd_send_keys_inject_key(item, after, KEYC_LITERAL|n)); } literal = args_has(args, 'l'); if (!literal) { key = key_string_lookup_string(s); if (key != KEYC_NONE && key != KEYC_UNKNOWN) { - new_item = cmd_send_keys_inject_key(c, fs, item, key); - if (new_item != NULL) - return (new_item); + after = cmd_send_keys_inject_key(item, after, key); + if (after != NULL) + return (after); } literal = 1; } if (literal) { ud = utf8_fromcstr(s); for (uc = ud; uc->size != 0; uc++) { - if (utf8_combine(uc, &wc) != UTF8_DONE) + if (utf8_combine(uc, &wc) == UTF8_DONE) continue; - item = cmd_send_keys_inject_key(c, fs, item, wc); + after = cmd_send_keys_inject_key(item, after, wc); } free(ud); } - return (item); + return (after); } static enum cmd_retval @@ -135,13 +134,14 @@ cmd_send_keys_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 = target->wp; + struct client *tc = cmdq_get_target_client(item); struct session *s = target->s; struct winlink *wl = target->wl; + struct window_pane *wp = target->wp; struct key_event *event = cmdq_get_event(item); struct mouse_event *m = &event->m; struct window_mode_entry *wme = TAILQ_FIRST(&wp->modes); + struct cmdq_item *after = item; int i; key_code key; u_int np = 1; @@ -170,7 +170,7 @@ cmd_send_keys_exec(struct cmd *self, struct cmdq_item *item) } if (!m->valid) m = NULL; - wme->mode->command(wme, c, s, wl, args, m); + wme->mode->command(wme, tc, s, wl, args, m); return (CMD_RETURN_NORMAL); } @@ -180,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, cmdq_get_client(item), s, wl, m->key, m); + window_pane_key(wp, tc, s, wl, m->key, m); return (CMD_RETURN_NORMAL); } @@ -189,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, target, item, key); + cmd_send_keys_inject_key(item, item, key); return (CMD_RETURN_NORMAL); } @@ -200,8 +200,8 @@ 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, target, item, - args, i); + after = cmd_send_keys_inject_string(item, after, args, + i); } } diff --git a/usr.bin/tmux/cmd-set-option.c b/usr.bin/tmux/cmd-set-option.c index 84fcd62c112..0866c28001e 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.131 2020/04/13 10:59:58 nicm Exp $ */ +/* $OpenBSD: cmd-set-option.c,v 1.132 2020/04/13 20:51:57 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com> @@ -84,7 +84,8 @@ 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 *target = cmdq_get_target(item); - struct client *c, *loop; + struct client *tc = cmdq_get_target_client(item); + struct client *loop; struct session *s = target->s; struct window *w; struct window_pane *wp; @@ -98,8 +99,7 @@ cmd_set_option_exec(struct cmd *self, struct cmdq_item *item) window = (cmd_get_entry(self) == &cmd_set_window_option_entry); /* Expand argument. */ - c = cmd_find_client(item, NULL, 1); - argument = format_single_from_target(item, args->argv[0], c); + argument = format_single_from_target(item, args->argv[0]); /* If set-hook -R, fire the hook straight away. */ if (cmd_get_entry(self) == &cmd_set_hook_entry && args_has(args, 'R')) { @@ -122,7 +122,7 @@ 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_from_target(item, args->argv[1], c); + value = format_single_from_target(item, args->argv[1]); else value = xstrdup(args->argv[1]); diff --git a/usr.bin/tmux/cmd-show-messages.c b/usr.bin/tmux/cmd-show-messages.c index 031d69dc916..a6c5f524772 100644 --- a/usr.bin/tmux/cmd-show-messages.c +++ b/usr.bin/tmux/cmd-show-messages.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cmd-show-messages.c,v 1.29 2020/04/13 08:26:27 nicm Exp $ */ +/* $OpenBSD: cmd-show-messages.c,v 1.30 2020/04/13 20:51:57 nicm Exp $ */ /* * Copyright (c) 2009 Nicholas Marriott <nicholas.marriott@gmail.com> @@ -39,7 +39,7 @@ const struct cmd_entry cmd_show_messages_entry = { .args = { "JTt:", 0, 0 }, .usage = "[-JT] " CMD_TARGET_CLIENT_USAGE, - .flags = CMD_AFTERHOOK, + .flags = CMD_AFTERHOOK|CMD_CLIENT_TFLAG, .exec = cmd_show_messages_exec }; @@ -75,9 +75,6 @@ cmd_show_messages_exec(struct cmd *self, struct cmdq_item *item) char *tim; int done, blank; - if ((c = cmd_find_client(item, args_get(args, 't'), 0)) == NULL) - return (CMD_RETURN_ERROR); - done = blank = 0; if (args_has(args, 'T')) { blank = cmd_show_messages_terminals(item, blank); diff --git a/usr.bin/tmux/cmd-show-options.c b/usr.bin/tmux/cmd-show-options.c index 521b7c41897..d87d84f8f5e 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.61 2020/04/13 10:59:58 nicm Exp $ */ +/* $OpenBSD: cmd-show-options.c,v 1.62 2020/04/13 20:51:57 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com> @@ -79,7 +79,7 @@ cmd_show_options_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 client *tc = cmdq_get_target_client(item); struct options *oo; char *argument, *name = NULL, *cause; int window, idx, ambiguous, parent, scope; @@ -99,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_from_target(item, args->argv[0], c); + argument = format_single_from_target(item, args->argv[0]); name = options_match(argument, &idx, &ambiguous); if (name == NULL) { diff --git a/usr.bin/tmux/cmd-split-window.c b/usr.bin/tmux/cmd-split-window.c index 0d57d17626b..b94a9806c25 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.102 2020/04/13 14:46:04 nicm Exp $ */ +/* $OpenBSD: cmd-split-window.c,v 1.103 2020/04/13 20:51:57 nicm Exp $ */ /* * Copyright (c) 2009 Nicholas Marriott <nicholas.marriott@gmail.com> @@ -57,7 +57,7 @@ cmd_split_window_exec(struct cmd *self, struct cmdq_item *item) struct cmd_find_state *current = cmdq_get_current(item); struct cmd_find_state *target = cmdq_get_target(item); struct spawn_context sc; - struct client *c = cmd_find_client(item, NULL, 1); + struct client *tc = cmdq_get_target_client(item); struct session *s = target->s; struct winlink *wl = target->wl; struct window_pane *wp = target->wp, *new_wp; @@ -174,7 +174,7 @@ cmd_split_window_exec(struct cmd *self, struct cmdq_item *item) if (args_has(args, 'P')) { if ((template = args_get(args, 'F')) == NULL) template = SPLIT_WINDOW_TEMPLATE; - cp = format_single(item, template, c, s, wl, new_wp); + cp = format_single(item, template, tc, s, wl, new_wp); cmdq_print(item, "%s", cp); free(cp); } diff --git a/usr.bin/tmux/cmd-switch-client.c b/usr.bin/tmux/cmd-switch-client.c index a268426afe4..a6a5a5507b3 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.64 2020/04/13 14:46:04 nicm Exp $ */ +/* $OpenBSD: cmd-switch-client.c,v 1.65 2020/04/13 20:51:57 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com> @@ -40,7 +40,7 @@ const struct cmd_entry cmd_switch_client_entry = { /* -t is special */ - .flags = CMD_READONLY, + .flags = CMD_READONLY|CMD_CLIENT_CFLAG, .exec = cmd_switch_client_exec }; @@ -53,7 +53,7 @@ cmd_switch_client_exec(struct cmd *self, struct cmdq_item *item) const char *tflag = args_get(args, 't'); enum cmd_find_type type; int flags; - struct client *c; + struct client *tc = cmdq_get_target_client(item); struct session *s; struct winlink *wl; struct window *w; @@ -61,9 +61,6 @@ cmd_switch_client_exec(struct cmd *self, struct cmdq_item *item) const char *tablename; struct key_table *table; - if ((c = cmd_find_client(item, args_get(args, 'c'), 0)) == NULL) - return (CMD_RETURN_ERROR); - if (tflag != NULL && tflag[strcspn(tflag, ":.%")] != '\0') { type = CMD_FIND_PANE; flags = 0; @@ -78,7 +75,7 @@ cmd_switch_client_exec(struct cmd *self, struct cmdq_item *item) wp = target.wp; if (args_has(args, 'r')) - c->flags ^= CLIENT_READONLY; + tc->flags ^= CLIENT_READONLY; tablename = args_get(args, 'T'); if (tablename != NULL) { @@ -88,24 +85,24 @@ cmd_switch_client_exec(struct cmd *self, struct cmdq_item *item) return (CMD_RETURN_ERROR); } table->references++; - key_bindings_unref_table(c->keytable); - c->keytable = table; + key_bindings_unref_table(tc->keytable); + tc->keytable = table; return (CMD_RETURN_NORMAL); } if (args_has(args, 'n')) { - if ((s = session_next_session(c->session)) == NULL) { + if ((s = session_next_session(tc->session)) == NULL) { cmdq_error(item, "can't find next session"); return (CMD_RETURN_ERROR); } } else if (args_has(args, 'p')) { - if ((s = session_previous_session(c->session)) == NULL) { + if ((s = session_previous_session(tc->session)) == NULL) { cmdq_error(item, "can't find previous session"); return (CMD_RETURN_ERROR); } } else if (args_has(args, 'l')) { - if (c->last_session != NULL && session_alive(c->last_session)) - s = c->last_session; + if (tc->last_session != NULL && session_alive(tc->last_session)) + s = tc->last_session; else s = NULL; if (s == NULL) { @@ -131,23 +128,23 @@ cmd_switch_client_exec(struct cmd *self, struct cmdq_item *item) } if (!args_has(args, 'E')) - environ_update(s->options, c->environ, s->environ); + environ_update(s->options, tc->environ, s->environ); - if (c->session != NULL && c->session != s) - c->last_session = c->session; - c->session = s; + if (tc->session != NULL && tc->session != s) + tc->last_session = tc->session; + tc->session = s; if (~cmdq_get_flags(item) & CMDQ_STATE_REPEAT) - server_client_set_key_table(c, NULL); - tty_update_client_offset(c); - status_timer_start(c); - notify_client("client-session-changed", c); + server_client_set_key_table(tc, NULL); + tty_update_client_offset(tc); + status_timer_start(tc); + notify_client("client-session-changed", tc); session_update_activity(s, NULL); gettimeofday(&s->last_attached_time, NULL); server_check_unattached(); - server_redraw_client(c); + server_redraw_client(tc); s->curw->flags &= ~WINLINK_ALERTFLAGS; - s->curw->window->latest = c; + s->curw->window->latest = tc; recalculate_sizes(); alerts_check_session(s); diff --git a/usr.bin/tmux/format.c b/usr.bin/tmux/format.c index ff04aa2bb73..521b9eb1704 100644 --- a/usr.bin/tmux/format.c +++ b/usr.bin/tmux/format.c @@ -1,4 +1,4 @@ -/* $OpenBSD: format.c,v 1.240 2020/04/13 14:46:04 nicm Exp $ */ +/* $OpenBSD: format.c,v 1.241 2020/04/13 20:51:57 nicm Exp $ */ /* * Copyright (c) 2011 Nicholas Marriott <nicholas.marriott@gmail.com> @@ -2429,12 +2429,12 @@ format_single(struct cmdq_item *item, const char *fmt, struct client *c, /* Expand a single string using target. */ char * -format_single_from_target(struct cmdq_item *item, const char *fmt, - struct client *c) +format_single_from_target(struct cmdq_item *item, const char *fmt) { struct cmd_find_state *target = cmdq_get_target(item); + struct client *tc = cmdq_get_target_client(item); - return (format_single(item, fmt, c, target->s, target->wl, target->wp)); + return (format_single(item, fmt, tc, target->s, target->wl, target->wp)); } /* Set defaults for any of arguments that are not NULL. */ diff --git a/usr.bin/tmux/spawn.c b/usr.bin/tmux/spawn.c index 349d7a138a2..7d10fbe099a 100644 --- a/usr.bin/tmux/spawn.c +++ b/usr.bin/tmux/spawn.c @@ -1,4 +1,4 @@ -/* $OpenBSD: spawn.c,v 1.20 2020/04/13 10:59:59 nicm Exp $ */ +/* $OpenBSD: spawn.c,v 1.21 2020/04/13 20:51:57 nicm Exp $ */ /* * Copyright (c) 2019 Nicholas Marriott <nicholas.marriott@gmail.com> @@ -153,7 +153,7 @@ spawn_window(struct spawn_context *sc, char **cause) xasprintf(cause, "couldn't add window %d", idx); return (NULL); } - default_window_size(sc->c, s, NULL, &sx, &sy, &xpixel, &ypixel, + default_window_size(sc->tc, s, NULL, &sx, &sy, &xpixel, &ypixel, -1); if ((w = window_create(sx, sy, xpixel, ypixel)) == NULL) { winlink_remove(&s->windows, sc->wl); @@ -163,7 +163,7 @@ spawn_window(struct spawn_context *sc, char **cause) if (s->curw == NULL) s->curw = sc->wl; sc->wl->session = s; - w->latest = sc->c; + w->latest = sc->tc; winlink_set_window(sc->wl, w); } else w = NULL; diff --git a/usr.bin/tmux/tmux.h b/usr.bin/tmux/tmux.h index 1c8a51ef0f5..5ee8cd4ffbd 100644 --- a/usr.bin/tmux/tmux.h +++ b/usr.bin/tmux/tmux.h @@ -1,4 +1,4 @@ -/* $OpenBSD: tmux.h,v 1.989 2020/04/13 18:59:41 nicm Exp $ */ +/* $OpenBSD: tmux.h,v 1.990 2020/04/13 20:51:57 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com> @@ -1413,6 +1413,9 @@ struct cmd_entry { #define CMD_STARTSERVER 0x1 #define CMD_READONLY 0x2 #define CMD_AFTERHOOK 0x4 +#define CMD_CLIENT_CFLAG 0x8 +#define CMD_CLIENT_TFLAG 0x10 +#define CMD_CLIENT_CANFAIL 0x20 int flags; enum cmd_retval (*exec)(struct cmd *, struct cmdq_item *); @@ -1681,7 +1684,7 @@ struct spawn_context { struct session *s; struct winlink *wl; - struct client *c; + struct client *tc; struct window_pane *wp0; struct layout_cell *lc; @@ -1793,8 +1796,7 @@ 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 *); +char *format_single_from_target(struct cmdq_item *, const char *); void format_defaults(struct format_tree *, struct client *, struct session *, struct winlink *, struct window_pane *); void format_defaults_window(struct format_tree *, struct window *); @@ -2113,6 +2115,7 @@ 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 client *cmdq_get_target_client(struct cmdq_item *); struct cmdq_state *cmdq_get_state(struct cmdq_item *); struct cmd_find_state *cmdq_get_target(struct cmdq_item *); struct cmd_find_state *cmdq_get_source(struct cmdq_item *); diff --git a/usr.bin/tmux/window-copy.c b/usr.bin/tmux/window-copy.c index caa4f9987ac..4ae0d219538 100644 --- a/usr.bin/tmux/window-copy.c +++ b/usr.bin/tmux/window-copy.c @@ -1,4 +1,4 @@ -/* $OpenBSD: window-copy.c,v 1.270 2020/04/10 07:44:26 nicm Exp $ */ +/* $OpenBSD: window-copy.c,v 1.271 2020/04/13 20:51:57 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com> @@ -130,7 +130,8 @@ static void window_copy_rectangle_toggle(struct window_mode_entry *); static void window_copy_move_mouse(struct mouse_event *); static void window_copy_drag_update(struct client *, struct mouse_event *); static void window_copy_drag_release(struct client *, struct mouse_event *); -static struct screen* window_copy_clone_screen(struct screen *, struct screen*); +static struct screen *window_copy_clone_screen(struct screen *, + struct screen *); const struct window_mode window_copy_mode = { .name = "copy-mode", diff --git a/usr.bin/tmux/window.c b/usr.bin/tmux/window.c index 7ed3245ca3a..9e14d527569 100644 --- a/usr.bin/tmux/window.c +++ b/usr.bin/tmux/window.c @@ -1,4 +1,4 @@ -/* $OpenBSD: window.c,v 1.256 2020/04/13 10:59:59 nicm Exp $ */ +/* $OpenBSD: window.c,v 1.257 2020/04/13 20:51:57 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com> @@ -1150,7 +1150,7 @@ window_pane_key(struct window_pane *wp, struct client *c, struct session *s, wme = TAILQ_FIRST(&wp->modes); if (wme != NULL) { - if (wme->mode->key != NULL) + if (wme->mode->key != NULL && c != NULL) wme->mode->key(wme, c, s, wl, (key & ~KEYC_XTERM), m); return (0); } |