summaryrefslogtreecommitdiffstats
path: root/cmd.c
diff options
context:
space:
mode:
authornicm <nicm>2016-10-16 17:55:14 +0000
committernicm <nicm>2016-10-16 17:55:14 +0000
commitddc4512d2e0eda6c705e002cb5dbf80719d709e1 (patch)
treecd9ff99f4b1ccb3e76ab99633d59772ae07c3092 /cmd.c
parentbfe14b531267f3762a518f98b72a3148a134396a (diff)
Rewrite command queue handling. Each client still has a command queue,
but there is also now a global command queue. Instead of command queues being dispatched on demand from wherever the command happens to be added, they are now all dispatched from the top level server loop. Command queues may now also include callbacks as well as commands, and items may be inserted after the current command as well as at the end. This all makes command queues significantly more predictable and easier to use, and avoids the complex multiple nested command queues used by source-file, if-shell and friends. A mass rename of struct cmdq to a better name (cmdq_item probably) is coming.
Diffstat (limited to 'cmd.c')
-rw-r--r--cmd.c51
1 files changed, 21 insertions, 30 deletions
diff --git a/cmd.c b/cmd.c
index 7964f654..9c37b849 100644
--- a/cmd.c
+++ b/cmd.c
@@ -390,12 +390,11 @@ usage:
static int
cmd_prepare_state_flag(char c, const char *target, enum cmd_entry_flag flag,
- struct cmd_q *cmdq, struct cmd_q *parent)
+ struct cmd_q *cmdq)
{
int targetflags, error;
struct cmd_find_state *fs = NULL;
- struct cmd_find_state *current = NULL;
- struct cmd_find_state tmp;
+ struct cmd_find_state current;
if (flag == CMD_NONE ||
flag == CMD_CLIENT ||
@@ -449,21 +448,12 @@ cmd_prepare_state_flag(char c, const char *target, enum cmd_entry_flag flag,
default:
fatalx("unknown %cflag %d", c, flag);
}
-
log_debug("%s: flag %c %d %#x", __func__, c, flag, targetflags);
- if (parent != NULL) {
- if (c == 't')
- current = &parent->state.tflag;
- else if (c == 's')
- current = &parent->state.sflag;
- }
- if (current == NULL || !cmd_find_valid_state(current)) {
- error = cmd_find_current(&tmp, cmdq, targetflags);
- if (error != 0 && ~targetflags & CMD_FIND_QUIET)
- return (-1);
- current = &tmp;
- }
- if (!cmd_find_empty_state(current) && !cmd_find_valid_state(current))
+
+ error = cmd_find_current(&current, cmdq, targetflags);
+ if (error != 0 && ~targetflags & CMD_FIND_QUIET)
+ return (-1);
+ if (!cmd_find_empty_state(&current) && !cmd_find_valid_state(&current))
fatalx("invalid current state");
switch (flag) {
@@ -475,13 +465,13 @@ cmd_prepare_state_flag(char c, const char *target, enum cmd_entry_flag flag,
case CMD_SESSION_CANFAIL:
case CMD_SESSION_PREFERUNATTACHED:
case CMD_SESSION_WITHPANE:
- error = cmd_find_target(fs, current, cmdq, target,
+ error = cmd_find_target(fs, &current, cmdq, target,
CMD_FIND_SESSION, targetflags);
if (error != 0 && ~targetflags & CMD_FIND_QUIET)
return (-1);
break;
case CMD_MOVEW_R:
- error = cmd_find_target(fs, current, cmdq, target,
+ error = cmd_find_target(fs, &current, cmdq, target,
CMD_FIND_SESSION, CMD_FIND_QUIET);
if (error == 0)
break;
@@ -490,7 +480,7 @@ cmd_prepare_state_flag(char c, const char *target, enum cmd_entry_flag flag,
case CMD_WINDOW_CANFAIL:
case CMD_WINDOW_MARKED:
case CMD_WINDOW_INDEX:
- error = cmd_find_target(fs, current, cmdq, target,
+ error = cmd_find_target(fs, &current, cmdq, target,
CMD_FIND_WINDOW, targetflags);
if (error != 0 && ~targetflags & CMD_FIND_QUIET)
return (-1);
@@ -498,7 +488,7 @@ cmd_prepare_state_flag(char c, const char *target, enum cmd_entry_flag flag,
case CMD_PANE:
case CMD_PANE_CANFAIL:
case CMD_PANE_MARKED:
- error = cmd_find_target(fs, current, cmdq, target,
+ error = cmd_find_target(fs, &current, cmdq, target,
CMD_FIND_PANE, targetflags);
if (error != 0 && ~targetflags & CMD_FIND_QUIET)
return (-1);
@@ -510,14 +500,14 @@ cmd_prepare_state_flag(char c, const char *target, enum cmd_entry_flag flag,
}
int
-cmd_prepare_state(struct cmd *cmd, struct cmd_q *cmdq, struct cmd_q *parent)
+cmd_prepare_state(struct cmd *cmd, struct cmd_q *cmdq)
{
- const struct cmd_entry *entry = cmd->entry;
- struct cmd_state *state = &cmdq->state;
- char *tmp;
- enum cmd_entry_flag flag;
- const char *s;
- int error;
+ const struct cmd_entry *entry = cmd->entry;
+ struct cmd_state *state = &cmdq->state;
+ char *tmp;
+ enum cmd_entry_flag flag;
+ const char *s;
+ int error;
tmp = cmd_print(cmd);
log_debug("preparing state for %s (client %p)", tmp, cmdq->client);
@@ -546,18 +536,19 @@ cmd_prepare_state(struct cmd *cmd, struct cmd_q *cmdq, struct cmd_q *parent)
state->c = cmd_find_client(cmdq, s, 1);
break;
}
+ log_debug("using client %p", state->c);
s = args_get(cmd->args, 't');
log_debug("preparing -t state: target %s", s == NULL ? "none" : s);
- error = cmd_prepare_state_flag('t', s, entry->tflag, cmdq, parent);
+ error = cmd_prepare_state_flag('t', s, entry->tflag, cmdq);
if (error != 0)
return (error);
s = args_get(cmd->args, 's');
log_debug("preparing -s state: target %s", s == NULL ? "none" : s);
- error = cmd_prepare_state_flag('s', s, entry->sflag, cmdq, parent);
+ error = cmd_prepare_state_flag('s', s, entry->sflag, cmdq);
if (error != 0)
return (error);