summaryrefslogtreecommitdiffstats
path: root/cmd-queue.c
diff options
context:
space:
mode:
authornicm <nicm>2016-10-13 10:01:49 +0000
committernicm <nicm>2016-10-13 10:01:49 +0000
commit4d9e6ea3106ea06afa4583254549d525b31ed277 (patch)
tree8532ce29088d6b65b9615271dd6b5fdaa9984ca2 /cmd-queue.c
parent05dac2e42c257c87d1fdbc70d0d976f918d77cfd (diff)
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 'cmd-queue.c')
-rw-r--r--cmd-queue.c44
1 files changed, 28 insertions, 16 deletions
diff --git a/cmd-queue.c b/cmd-queue.c
index 5a81f88e..2464eb17 100644
--- a/cmd-queue.c
+++ b/cmd-queue.c
@@ -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);