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.
This commit is contained in:
nicm
2016-10-13 10:01:49 +00:00
parent 05dac2e42c
commit 4d9e6ea310
10 changed files with 91 additions and 20 deletions

View File

@ -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);