diff options
author | nicm <nicm> | 2017-04-22 10:22:39 +0000 |
---|---|---|
committer | nicm <nicm> | 2017-04-22 10:22:39 +0000 |
commit | ee45a8a149e1a3c8fe7c232a9e32f3a007e21bee (patch) | |
tree | 21cc9cafd10d55cd7cd92ec616d08ac59adc4a0a /cmd-switch-client.c | |
parent | 2c0f826c360fc5a8f0e125759b596eb28441ba65 (diff) | |
download | rtmux-ee45a8a149e1a3c8fe7c232a9e32f3a007e21bee.tar.gz rtmux-ee45a8a149e1a3c8fe7c232a9e32f3a007e21bee.tar.bz2 rtmux-ee45a8a149e1a3c8fe7c232a9e32f3a007e21bee.zip |
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.
Diffstat (limited to 'cmd-switch-client.c')
-rw-r--r-- | cmd-switch-client.c | 33 |
1 files changed, 25 insertions, 8 deletions
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); } } |