summaryrefslogtreecommitdiffstats
path: root/cmd-queue.c
diff options
context:
space:
mode:
authornicm <nicm>2016-10-13 22:48:51 +0000
committernicm <nicm>2016-10-13 22:48:51 +0000
commit4289a1ebfa7479413ec5ac543b88c4ea039d00a0 (patch)
treed17862b06b8822aa1b8ab91d83e51a47e25e60e3 /cmd-queue.c
parent7a1a01feeff7b2ab17e2caef2d6b2180a8c1e70e (diff)
Trying to do hooks generically is way too complicated and unreliable and
confusing, particularly trying to automatically figure out what target hooks should be using. So simplify it: - drop before hooks entirely, they don't seem to be very useful; - commands with special requirements now fire their own after hook (for example, if they change session or window, or if they have -t and -s and need to choose which one the hook uses as current target); - commands with no special requirements can have the CMD_AFTERHOOK flag added and they will use the -t state. At the moment new-session, new-window, split-window fire their own hook, and display-message uses the flag. The remaining commands still need to be looked at.
Diffstat (limited to 'cmd-queue.c')
-rw-r--r--cmd-queue.c88
1 files changed, 26 insertions, 62 deletions
diff --git a/cmd-queue.c b/cmd-queue.c
index 2464eb17..8b28dd65 100644
--- a/cmd-queue.c
+++ b/cmd-queue.c
@@ -182,34 +182,16 @@ 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 hooks *hooks;
- enum cmd_retval retval;
- char *tmp;
- int flags = !!(cmd->flags & CMD_CONTROL);
+ struct cmd *cmd = cmdq->cmd;
+ enum cmd_retval retval;
+ char *tmp;
+ int flags = !!(cmd->flags & CMD_CONTROL);
+ const char *name;
+ struct cmd_find_state *fsp, fs;
tmp = cmd_print(cmd);
log_debug("cmdq %p: %s", cmdq, tmp);
@@ -218,44 +200,35 @@ cmdq_continue_one(struct cmd_q *cmdq)
cmdq->time = time(NULL);
cmdq->number++;
- if (~cmdq->flags & CMD_Q_REENTRY)
- cmdq_guard(cmdq, "begin", flags);
+ cmdq_guard(cmdq, "begin", flags);
if (cmd_prepare_state(cmd, cmdq, cmdq->parent) != 0)
goto error;
- if (~cmdq->flags & CMD_Q_NOHOOKS) {
- hooks = cmdq_get_hooks(cmdq);
- if (~cmdq->flags & CMD_Q_REENTRY) {
- cmdq->flags |= CMD_Q_REENTRY;
- if (hooks_wait(hooks, cmdq, NULL,
- "before-%s", name) == 0)
- return (CMD_RETURN_WAIT);
- if (cmd_prepare_state(cmd, cmdq, cmdq->parent) != 0)
- goto error;
- }
- } else
- hooks = NULL;
- cmdq->flags &= ~CMD_Q_REENTRY;
-
retval = cmd->entry->exec(cmd, cmdq);
if (retval == CMD_RETURN_ERROR)
goto error;
- 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;
+ if (~cmd->entry->flags & CMD_AFTERHOOK)
+ goto end;
+
+ if (cmd_find_valid_state(&cmdq->state.tflag))
+ fsp = &cmdq->state.tflag;
+ else {
+ if (cmd_find_current(&fs, cmdq, CMD_FIND_QUIET) != 0)
+ goto end;
+ fsp = &fs;
}
- cmdq_guard(cmdq, "end", flags);
+ name = cmd->entry->name;
+ if (hooks_wait(fsp->s->hooks, cmdq, fsp, "after-%s", name) == 0)
+ retval = CMD_RETURN_WAIT;
+end:
+ cmdq_guard(cmdq, "end", flags);
return (retval);
error:
cmdq_guard(cmdq, "error", flags);
- cmdq->flags &= ~CMD_Q_REENTRY;
return (CMD_RETURN_ERROR);
}
@@ -271,8 +244,6 @@ 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);
@@ -280,18 +251,11 @@ cmdq_continue(struct cmd_q *cmdq)
if (empty)
goto empty;
- /*
- * If the command isn't in the middle of running hooks (due to
- * CMD_RETURN_WAIT), move onto the next command; otherwise, leave the
- * state of the queue as it is.
- */
- if (~cmdq->flags & CMD_Q_REENTRY) {
- if (cmdq->item == NULL) {
- cmdq->item = TAILQ_FIRST(&cmdq->queue);
- cmdq->cmd = TAILQ_FIRST(&cmdq->item->cmdlist->list);
- } else
- cmdq->cmd = TAILQ_NEXT(cmdq->cmd, qentry);
- }
+ if (cmdq->item == NULL) {
+ cmdq->item = TAILQ_FIRST(&cmdq->queue);
+ cmdq->cmd = TAILQ_FIRST(&cmdq->item->cmdlist->list);
+ } else
+ cmdq->cmd = TAILQ_NEXT(cmdq->cmd, qentry);
do {
while (cmdq->cmd != NULL) {