From 4d9e6ea3106ea06afa4583254549d525b31ed277 Mon Sep 17 00:00:00 2001 From: nicm Date: Thu, 13 Oct 2016 10:01:49 +0000 Subject: 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. --- cmd-queue.c | 44 ++++++++++++++++++++++++++++---------------- 1 file changed, 28 insertions(+), 16 deletions(-) (limited to 'cmd-queue.c') 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); -- cgit