From 2c0f826c360fc5a8f0e125759b596eb28441ba65 Mon Sep 17 00:00:00 2001 From: nicm Date: Sat, 22 Apr 2017 08:56:24 +0000 Subject: Mouse bindings and hooks set up an initial current state when running a command. This is used for the session, window and pane for all commands in the command sequence if there is no -t or -s. However, using it for all commands in the command sequence means that if the active pane or current session is changed, subsequent commands still use the previous state. So make commands which explicitly change the current state (such as neww and selectp) update it themselves for later commands. Commands which may invalidate the state (like killp) are already OK because an invalid state will be ignored. Also fill in the current state for all key bindings rather than just the mouse, so that any omissions are easier to spot. --- cmd-switch-client.c | 1 + 1 file changed, 1 insertion(+) (limited to 'cmd-switch-client.c') diff --git a/cmd-switch-client.c b/cmd-switch-client.c index 06388d44..dbb57ff0 100644 --- a/cmd-switch-client.c +++ b/cmd-switch-client.c @@ -99,6 +99,7 @@ cmd_switch_client_exec(struct cmd *self, struct cmdq_item *item) if (wp != NULL) window_set_active_pane(wp->window, wp); session_set_current(s, state->tflag.wl); + cmd_find_from_session(&item->shared->current, s); } } -- cgit From ee45a8a149e1a3c8fe7c232a9e32f3a007e21bee Mon Sep 17 00:00:00 2001 From: nicm Date: Sat, 22 Apr 2017 10:22:39 +0000 Subject: Get rid of the extra layer of flags and cmd_prepare() and just store the CMD_FIND_* flags in the cmd_entry and call it for the command. Commands with special requirements call it themselves and update the target for hooks to use. --- cmd-switch-client.c | 33 +++++++++++++++++++++++++-------- 1 file changed, 25 insertions(+), 8 deletions(-) (limited to 'cmd-switch-client.c') diff --git a/cmd-switch-client.c b/cmd-switch-client.c index dbb57ff0..2bc1e10c 100644 --- a/cmd-switch-client.c +++ b/cmd-switch-client.c @@ -38,8 +38,7 @@ const struct cmd_entry cmd_switch_client_entry = { .usage = "[-Elnpr] [-c target-client] [-t target-session] " "[-T key-table]", - .cflag = CMD_CLIENT, - .tflag = CMD_SESSION_WITHPANE, + /* -t is special */ .flags = CMD_READONLY, .exec = cmd_switch_client_exec @@ -49,13 +48,32 @@ static enum cmd_retval cmd_switch_client_exec(struct cmd *self, struct cmdq_item *item) { struct args *args = self->args; - struct cmd_state *state = &item->state; - struct client *c = state->c; - struct session *s = item->state.tflag.s; + const char *tflag = args_get(args, 't'); + enum cmd_find_type type; + int flags; + struct client *c; + struct session *s; + struct winlink *wl; struct window_pane *wp; 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; + } else { + type = CMD_FIND_SESSION; + flags = CMD_FIND_PREFER_UNATTACHED; + } + if (cmd_find_target(&item->target, item, tflag, type, flags) != 0) + return (CMD_RETURN_ERROR); + s = item->target.s; + wl = item->target.wl; + wp = item->target.wp; + if (args_has(args, 'r')) c->flags ^= CLIENT_READONLY; @@ -94,11 +112,10 @@ cmd_switch_client_exec(struct cmd *self, struct cmdq_item *item) } else { if (item->client == NULL) return (CMD_RETURN_NORMAL); - if (state->tflag.wl != NULL) { - wp = state->tflag.wp; + if (wl != NULL) { if (wp != NULL) window_set_active_pane(wp->window, wp); - session_set_current(s, state->tflag.wl); + session_set_current(s, wl); cmd_find_from_session(&item->shared->current, s); } } -- cgit