From 3f7f9a0e20522c73e33480673496240f1bac724b Mon Sep 17 00:00:00 2001 From: nicm Date: Mon, 13 Apr 2020 20:51:57 +0000 Subject: [PATCH 1/2] 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. --- cmd-break-pane.c | 6 +-- cmd-command-prompt.c | 11 ++--- cmd-confirm-before.c | 12 ++---- cmd-detach-client.c | 31 +++++++------- cmd-display-menu.c | 97 +++++++++++++++++++++---------------------- cmd-display-message.c | 17 ++++---- cmd-display-panes.c | 14 +++---- cmd-if-shell.c | 10 ++--- cmd-list-keys.c | 6 +-- cmd-load-buffer.c | 3 +- cmd-new-session.c | 1 - cmd-new-window.c | 6 +-- cmd-pipe-pane.c | 4 +- cmd-queue.c | 37 +++++++++++++++-- cmd-refresh-client.c | 71 +++++++++++++++---------------- cmd-rename-session.c | 3 +- cmd-rename-window.c | 3 +- cmd-respawn-window.c | 3 +- cmd-run-shell.c | 3 +- cmd-save-buffer.c | 3 +- cmd-select-pane.c | 10 ++--- cmd-send-keys.c | 56 ++++++++++++------------- cmd-split-window.c | 4 +- cmd-switch-client.c | 41 +++++++++--------- format.c | 6 +-- spawn.c | 4 +- tmux.h | 9 ++-- window-copy.c | 3 +- window.c | 2 +- 29 files changed, 239 insertions(+), 237 deletions(-) diff --git a/cmd-break-pane.c b/cmd-break-pane.c index e12b09b6..880ee7f5 100644 --- a/cmd-break-pane.c +++ b/cmd-break-pane.c @@ -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/cmd-command-prompt.c b/cmd-command-prompt.c index 510600e3..e53c4320 100644 --- a/cmd-command-prompt.c +++ b/cmd-command-prompt.c @@ -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/cmd-confirm-before.c b/cmd-confirm-before.c index 026d0e11..0d881178 100644 --- a/cmd-confirm-before.c +++ b/cmd-confirm-before.c @@ -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/cmd-detach-client.c b/cmd-detach-client.c index f4e350a8..02a43f4e 100644 --- a/cmd-detach-client.c +++ b/cmd-detach-client.c @@ -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/cmd-display-menu.c b/cmd-display-menu.c index 830491dc..0a5c7f78 100644 --- a/cmd-display-menu.c +++ b/cmd-display-menu.c @@ -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/cmd-display-message.c b/cmd-display-message.c index 8fb09f20..4e69f03a 100644 --- a/cmd-display-message.c +++ b/cmd-display-message.c @@ -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/cmd-display-panes.c b/cmd-display-panes.c index 7e1a9e3d..0f12b14b 100644 --- a/cmd-display-panes.c +++ b/cmd-display-panes.c @@ -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/cmd-if-shell.c b/cmd-if-shell.c index 75f462ad..d980472a 100644 --- a/cmd-if-shell.c +++ b/cmd-if-shell.c @@ -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/cmd-list-keys.c b/cmd-list-keys.c index cfdceee7..1141bbb5 100644 --- a/cmd-list-keys.c +++ b/cmd-list-keys.c @@ -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/cmd-load-buffer.c b/cmd-load-buffer.c index 1fc45b0f..49e834d6 100644 --- a/cmd-load-buffer.c +++ b/cmd-load-buffer.c @@ -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/cmd-new-session.c b/cmd-new-session.c index 574cd5cd..353f7bed 100644 --- a/cmd-new-session.c +++ b/cmd-new-session.c @@ -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/cmd-new-window.c b/cmd-new-window.c index 87aae659..722f89b9 100644 --- a/cmd-new-window.c +++ b/cmd-new-window.c @@ -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/cmd-pipe-pane.c b/cmd-pipe-pane.c index 4ccc22c6..185bdc12 100644 --- a/cmd-pipe-pane.c +++ b/cmd-pipe-pane.c @@ -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/cmd-queue.c b/cmd-queue.c index 97d19f81..16c58401 100644 --- a/cmd-queue.c +++ b/cmd-queue.c @@ -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/cmd-refresh-client.c b/cmd-refresh-client.c index 1becaaae..5514ff73 100644 --- a/cmd-refresh-client.c +++ b/cmd-refresh-client.c @@ -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/cmd-rename-session.c b/cmd-rename-session.c index 5f003473..4b2c3d88 100644 --- a/cmd-rename-session.c +++ b/cmd-rename-session.c @@ -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/cmd-rename-window.c b/cmd-rename-window.c index d3e6d883..1fb17ad9 100644 --- a/cmd-rename-window.c +++ b/cmd-rename-window.c @@ -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/cmd-respawn-window.c b/cmd-respawn-window.c index 9e745dda..39d19ddb 100644 --- a/cmd-respawn-window.c +++ b/cmd-respawn-window.c @@ -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/cmd-run-shell.c b/cmd-run-shell.c index 3c82ffdb..82d4a1a2 100644 --- a/cmd-run-shell.c +++ b/cmd-run-shell.c @@ -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/cmd-save-buffer.c b/cmd-save-buffer.c index 9aaa365f..a6ad188f 100644 --- a/cmd-save-buffer.c +++ b/cmd-save-buffer.c @@ -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/cmd-select-pane.c b/cmd-select-pane.c index 5f4a2e63..db110ff9 100644 --- a/cmd-select-pane.c +++ b/cmd-select-pane.c @@ -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/cmd-send-keys.c b/cmd-send-keys.c index de910904..173d3713 100644 --- a/cmd-send-keys.c +++ b/cmd-send-keys.c @@ -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/cmd-split-window.c b/cmd-split-window.c index 84419a1e..c0e0e22a 100644 --- a/cmd-split-window.c +++ b/cmd-split-window.c @@ -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/cmd-switch-client.c b/cmd-switch-client.c index bc6a8174..82510ce6 100644 --- a/cmd-switch-client.c +++ b/cmd-switch-client.c @@ -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/format.c b/format.c index 08fa38df..fd3b45b9 100644 --- a/format.c +++ b/format.c @@ -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/spawn.c b/spawn.c index 49ab2a1e..91fb310a 100644 --- a/spawn.c +++ b/spawn.c @@ -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/tmux.h b/tmux.h index bce2ec69..d9fc0a9a 100644 --- a/tmux.h +++ b/tmux.h @@ -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/window-copy.c b/window-copy.c index 995dc35c..efb4a43f 100644 --- a/window-copy.c +++ b/window-copy.c @@ -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/window.c b/window.c index 13fb3bec..b0194eaf 100644 --- a/window.c +++ b/window.c @@ -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); } From fc83517913c8280c222a6cf78ca7fb8053421b37 Mon Sep 17 00:00:00 2001 From: nicm Date: Mon, 13 Apr 2020 20:54:15 +0000 Subject: [PATCH 2/2] Missed a few warnings in previous. --- cmd-lock-server.c | 12 ++++-------- cmd-set-option.c | 7 +++---- cmd-show-messages.c | 10 +++------- cmd-show-options.c | 3 +-- 4 files changed, 11 insertions(+), 21 deletions(-) diff --git a/cmd-lock-server.c b/cmd-lock-server.c index 086cf639..a0df95b0 100644 --- a/cmd-lock-server.c +++ b/cmd-lock-server.c @@ -57,26 +57,22 @@ 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 }; static enum cmd_retval 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/cmd-set-option.c b/cmd-set-option.c index 4e81dc5e..1752d093 100644 --- a/cmd-set-option.c +++ b/cmd-set-option.c @@ -84,7 +84,7 @@ 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 *loop; struct session *s = target->s; struct window *w; struct window_pane *wp; @@ -98,8 +98,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 +121,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/cmd-show-messages.c b/cmd-show-messages.c index cedf1093..78e5859c 100644 --- a/cmd-show-messages.c +++ b/cmd-show-messages.c @@ -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 }; @@ -70,14 +70,11 @@ static enum cmd_retval cmd_show_messages_exec(struct cmd *self, struct cmdq_item *item) { struct args *args = cmd_get_args(self); - struct client *c; + struct client *tc = cmdq_get_target_client(item); struct message_entry *msg; 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); @@ -90,10 +87,9 @@ cmd_show_messages_exec(struct cmd *self, struct cmdq_item *item) if (done) return (CMD_RETURN_NORMAL); - TAILQ_FOREACH(msg, &c->message_log, entry) { + TAILQ_FOREACH(msg, &tc->message_log, entry) { tim = ctime(&msg->msg_time); *strchr(tim, '\n') = '\0'; - cmdq_print(item, "%s %s", tim, msg->msg); } diff --git a/cmd-show-options.c b/cmd-show-options.c index 5b62a78e..e2aec930 100644 --- a/cmd-show-options.c +++ b/cmd-show-options.c @@ -79,7 +79,6 @@ 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 options *oo; char *argument, *name = NULL, *cause; int window, idx, ambiguous, parent, scope; @@ -99,7 +98,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) {