summaryrefslogtreecommitdiffstats
path: root/cmd-queue.c
diff options
context:
space:
mode:
authornicm <nicm>2020-04-13 14:46:04 +0000
committernicm <nicm>2020-04-13 14:46:04 +0000
commitadb76fd1ce8753a958d4ffe14db724f9f4d674ea (patch)
tree7d724330c7347975fa1546b99b55a145ee5f2be3 /cmd-queue.c
parent9a65102bfc2ed5d1e1f41e47451b8296c84f133d (diff)
Move cmdq_state into cmd-queue.c.
Diffstat (limited to 'cmd-queue.c')
-rw-r--r--cmd-queue.c48
1 files changed, 39 insertions, 9 deletions
diff --git a/cmd-queue.c b/cmd-queue.c
index 12ad8c2d..40db3fef 100644
--- a/cmd-queue.c
+++ b/cmd-queue.c
@@ -65,6 +65,23 @@ struct cmdq_item {
};
TAILQ_HEAD(cmdq_list, cmdq_item);
+/*
+ * Command queue state. This is the context for commands on the command queue.
+ * It holds information about how the commands were fired (the key and flags),
+ * any additional formats for the commands, and the current default target.
+ * Multiple commands can share the same state and a command may update the
+ * default target.
+ */
+struct cmdq_state {
+ int references;
+ int flags;
+
+ struct format_tree *formats;
+
+ struct key_event event;
+ struct cmd_find_state current;
+};
+
/* Get command queue name. */
static const char *
cmdq_name(struct client *c)
@@ -142,11 +159,25 @@ cmdq_get_source(struct cmdq_item *item)
return (&item->source);
}
-/* Get item state. */
-struct cmdq_state *
-cmdq_get_state(struct cmdq_item *item)
+/* Get state event. */
+struct key_event *
+cmdq_get_event(struct cmdq_item *item)
+{
+ return (&item->state->event);
+}
+
+/* Get state current target. */
+struct cmd_find_state *
+cmdq_get_current(struct cmdq_item *item)
+{
+ return (&item->state->current);
+}
+
+/* Get state flags. */
+int
+cmdq_get_flags(struct cmdq_item *item)
{
- return (item->state);
+ return (item->state->flags);
}
/* Merge formats from item. */
@@ -317,7 +348,7 @@ cmdq_remove_group(struct cmdq_item *item)
/* Get a command for the command queue. */
struct cmdq_item *
cmdq_get_command(struct cmd_list *cmdlist, struct cmd_find_state *current,
- struct mouse_event *m, int flags)
+ struct key_event *event, int flags)
{
struct cmdq_item *item, *first = NULL, *last = NULL;
struct cmd *cmd;
@@ -333,10 +364,9 @@ cmdq_get_command(struct cmd_list *cmdlist, struct cmd_find_state *current,
cmd_find_copy_state(&state->current, current);
else
cmd_find_clear_state(&state->current, 0);
- if (m != NULL) {
- state->event.key = KEYC_NONE;
- memcpy(&state->event.m, m,
- sizeof state->event.m);
+ if (event != NULL) {
+ memcpy(&state->event, event,
+ sizeof state->event);
}
state->flags = flags;
last_group = group;