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-new-session.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'cmd-new-session.c') diff --git a/cmd-new-session.c b/cmd-new-session.c index 0808b60c..cf0528d3 100644 --- a/cmd-new-session.c +++ b/cmd-new-session.c @@ -324,8 +324,10 @@ cmd_new_session_exec(struct cmd *self, struct cmdq_item *item) free(cp); } - if (!detached) + if (!detached) { c->flags |= CLIENT_ATTACHED; + cmd_find_from_session(&item->shared->current, s); + } if (to_free != NULL) free((void *)to_free); -- 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-new-session.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'cmd-new-session.c') diff --git a/cmd-new-session.c b/cmd-new-session.c index cf0528d3..8c347ce6 100644 --- a/cmd-new-session.c +++ b/cmd-new-session.c @@ -44,7 +44,7 @@ const struct cmd_entry cmd_new_session_entry = { "[-s session-name] " CMD_TARGET_SESSION_USAGE " [-x width] " "[-y height] [command]", - .tflag = CMD_SESSION_CANFAIL, + .target = { 't', CMD_FIND_SESSION, CMD_FIND_CANFAIL }, .flags = CMD_STARTSERVER, .exec = cmd_new_session_exec @@ -57,7 +57,7 @@ const struct cmd_entry cmd_has_session_entry = { .args = { "t:", 0, 0 }, .usage = CMD_TARGET_SESSION_USAGE, - .tflag = CMD_SESSION, + .target = { 't', CMD_FIND_SESSION, 0 }, .flags = 0, .exec = cmd_new_session_exec @@ -108,10 +108,10 @@ cmd_new_session_exec(struct cmd *self, struct cmdq_item *item) * have already been prepared, copy this * session into its tflag so it can be used. */ - cmd_find_from_session(&item->state.tflag, as); + cmd_find_from_session(&item->target, as); return (cmd_attach_session(item, - args_has(args, 'D'), 0, NULL, - args_has(args, 'E'))); + args_get(args, 't'), args_has(args, 'D'), + 0, NULL, args_has(args, 'E'))); } cmdq_error(item, "duplicate session: %s", newname); return (CMD_RETURN_ERROR); @@ -121,7 +121,7 @@ cmd_new_session_exec(struct cmd *self, struct cmdq_item *item) /* Is this going to be part of a session group? */ group = args_get(args, 't'); if (group != NULL) { - groupwith = item->state.tflag.s; + groupwith = item->target.s; if (groupwith == NULL) { if (!session_check_name(group)) { cmdq_error(item, "bad group name: %s", group); -- cgit From a4eaac359a244a2036265c81c74bc4cd46e05a76 Mon Sep 17 00:00:00 2001 From: nicm Date: Sat, 22 Apr 2017 10:26:44 +0000 Subject: new -A should use the session name. --- cmd-new-session.c | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) (limited to 'cmd-new-session.c') diff --git a/cmd-new-session.c b/cmd-new-session.c index 8c347ce6..1813288d 100644 --- a/cmd-new-session.c +++ b/cmd-new-session.c @@ -83,8 +83,8 @@ cmd_new_session_exec(struct cmd *self, struct cmdq_item *item) if (self->entry == &cmd_has_session_entry) { /* - * cmd_prepare() will fail if the session cannot be found, - * hence always return success here. + * cmd_find_target() will fail if the session cannot be found, + * so always return success here. */ return (CMD_RETURN_NORMAL); } @@ -102,15 +102,8 @@ cmd_new_session_exec(struct cmd *self, struct cmdq_item *item) } if ((as = session_find(newname)) != NULL) { if (args_has(args, 'A')) { - /* - * This item is now destined for - * attach-session. Because attach-session will - * have already been prepared, copy this - * session into its tflag so it can be used. - */ - cmd_find_from_session(&item->target, as); return (cmd_attach_session(item, - args_get(args, 't'), args_has(args, 'D'), + newname, args_has(args, 'D'), 0, NULL, args_has(args, 'E'))); } cmdq_error(item, "duplicate session: %s", newname); -- cgit