summaryrefslogtreecommitdiffstats
path: root/usr.bin/tmux/cmd-queue.c
diff options
context:
space:
mode:
authornicm <nicm@openbsd.org>2016-10-13 10:01:49 +0000
committernicm <nicm@openbsd.org>2016-10-13 10:01:49 +0000
commit788e192f1e52e7b4e4b046f4a21806c22cce079d (patch)
tree2f49c218475facd9ed503941a8f0f51626a9eac9 /usr.bin/tmux/cmd-queue.c
parent-f missed from splitw usage, from Felix Rosencrantz. (diff)
downloadwireguard-openbsd-788e192f1e52e7b4e4b046f4a21806c22cce079d.tar.xz
wireguard-openbsd-788e192f1e52e7b4e4b046f4a21806c22cce079d.zip
Some improvements and bug fixes for hooks:
- Prepare the state again before the "after" hooks are run, because the command may have killed or moved windows. - Use the hooks list from the newly prepared target, not the old hooks list (only matters for new-session really). - Correctly detect an invalid current state and ignore it in cmd_find_target ("killw; swapw"). - Change neww, new, killp, killw, splitw, swapp, swapw to update the current state (used if no explicit target is given) to something more useful after they have finished. For example, neww changes it to the newly created window. Hooks are still relatively new and primitive so there are likely to be more changes to come. Parts based on bug reports from Uwe Werler and Iblis Lin.
Diffstat (limited to 'usr.bin/tmux/cmd-queue.c')
-rw-r--r--usr.bin/tmux/cmd-queue.c46
1 files changed, 29 insertions, 17 deletions
diff --git a/usr.bin/tmux/cmd-queue.c b/usr.bin/tmux/cmd-queue.c
index 0824a425922..b976e984546 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.38 2016/10/11 13:21:59 nicm Exp $ */
+/* $OpenBSD: cmd-queue.c,v 1.39 2016/10/13 10:01:49 nicm Exp $ */
/*
* Copyright (c) 2013 Nicholas Marriott <nicholas.marriott@gmail.com>
@@ -182,13 +182,30 @@ cmdq_append(struct cmd_q *cmdq, struct cmd_list *cmdlist, struct mouse_event *m)
item->mouse.valid = 0;
}
+/* Find hooks list. */
+static struct hooks *
+cmdq_get_hooks(struct cmd_q *cmdq)
+{
+ struct session *s;
+
+ s = NULL;
+ if (cmdq->state.tflag.s != NULL)
+ s = cmdq->state.tflag.s;
+ else if (cmdq->state.sflag.s != NULL)
+ s = cmdq->state.sflag.s;
+ else if (cmdq->state.c != NULL)
+ s = cmdq->state.c->session;
+ if (s != NULL)
+ return (s->hooks);
+ return (global_hooks);
+}
+
/* Process one command. */
static enum cmd_retval
cmdq_continue_one(struct cmd_q *cmdq)
{
struct cmd *cmd = cmdq->cmd;
const char *name = cmd->entry->name;
- struct session *s;
struct hooks *hooks;
enum cmd_retval retval;
char *tmp;
@@ -208,18 +225,7 @@ cmdq_continue_one(struct cmd_q *cmdq)
goto error;
if (~cmdq->flags & CMD_Q_NOHOOKS) {
- s = NULL;
- if (cmdq->state.tflag.s != NULL)
- s = cmdq->state.tflag.s;
- else if (cmdq->state.sflag.s != NULL)
- s = cmdq->state.sflag.s;
- else if (cmdq->state.c != NULL)
- s = cmdq->state.c->session;
- if (s != NULL)
- hooks = s->hooks;
- else
- hooks = global_hooks;
-
+ hooks = cmdq_get_hooks(cmdq);
if (~cmdq->flags & CMD_Q_REENTRY) {
cmdq->flags |= CMD_Q_REENTRY;
if (hooks_wait(hooks, cmdq, NULL,
@@ -236,9 +242,13 @@ cmdq_continue_one(struct cmd_q *cmdq)
if (retval == CMD_RETURN_ERROR)
goto error;
- if (hooks != NULL && hooks_wait(hooks, cmdq, NULL,
- "after-%s", name) == 0)
- retval = CMD_RETURN_WAIT;
+ if (hooks != NULL) {
+ if (cmd_prepare_state(cmd, cmdq, cmdq->parent) != 0)
+ goto error;
+ hooks = cmdq_get_hooks(cmdq);
+ if (hooks_wait(hooks, cmdq, NULL, "after-%s", name) == 0)
+ retval = CMD_RETURN_WAIT;
+ }
cmdq_guard(cmdq, "end", flags);
return (retval);
@@ -261,6 +271,8 @@ cmdq_continue(struct cmd_q *cmdq)
cmdq->references++;
notify_disable();
+ cmd_find_clear_state(&cmdq->current, NULL, 0);
+
log_debug("continuing cmdq %p: flags %#x, client %p", cmdq, cmdq->flags,
c);