diff options
author | Thomas Adam <thomas@xteddy.org> | 2020-04-13 14:01:45 +0100 |
---|---|---|
committer | Thomas Adam <thomas@xteddy.org> | 2020-04-13 14:01:45 +0100 |
commit | 8f2b5d714a9f854c9583cab8bae70a2c7323fa00 (patch) | |
tree | 4e887ff4a1fcb3703fb0a1fcaa751183cff24c12 /cmd-queue.c | |
parent | b117c3b81217a11946ac784cfbe2ef1f3725b207 (diff) | |
parent | 04cdd035250b93b728678d515b69690653dced4e (diff) | |
download | rtmux-8f2b5d714a9f854c9583cab8bae70a2c7323fa00.tar.gz rtmux-8f2b5d714a9f854c9583cab8bae70a2c7323fa00.tar.bz2 rtmux-8f2b5d714a9f854c9583cab8bae70a2c7323fa00.zip |
Merge branch 'obsd-master'
Diffstat (limited to 'cmd-queue.c')
-rw-r--r-- | cmd-queue.c | 117 |
1 files changed, 112 insertions, 5 deletions
diff --git a/cmd-queue.c b/cmd-queue.c index 892bd03b..28642721 100644 --- a/cmd-queue.c +++ b/cmd-queue.c @@ -25,8 +25,41 @@ #include "tmux.h" -/* Global command queue. */ -static struct cmdq_list global_queue = TAILQ_HEAD_INITIALIZER(global_queue); +/* Command queue item type. */ +enum cmdq_type { + CMDQ_COMMAND, + CMDQ_CALLBACK, +}; + +/* Command queue item. */ +struct cmdq_item { + char *name; + struct cmdq_list *queue; + struct cmdq_item *next; + + struct client *client; + + enum cmdq_type type; + u_int group; + + u_int number; + time_t time; + + int flags; + + struct cmdq_shared *shared; + struct cmd_find_state source; + struct cmd_find_state target; + + struct cmd_list *cmdlist; + struct cmd *cmd; + + cmdq_cb cb; + void *data; + + TAILQ_ENTRY(cmdq_item) entry; +}; +TAILQ_HEAD(cmdq_list, cmdq_item); /* Get command queue name. */ static const char * @@ -47,9 +80,83 @@ cmdq_name(struct client *c) static struct cmdq_list * cmdq_get(struct client *c) { - if (c == NULL) - return (&global_queue); - return (&c->queue); + static struct cmdq_list *global_queue; + + if (c == NULL) { + if (global_queue == NULL) + global_queue = cmdq_new(); + return (global_queue); + } + return (c->queue); +} + +/* Create a queue. */ +struct cmdq_list * +cmdq_new(void) +{ + struct cmdq_list *queue; + + queue = xcalloc (1, sizeof *queue); + TAILQ_INIT (queue); + return (queue); +} + +/* Free a queue. */ +void +cmdq_free(struct cmdq_list *queue) +{ + if (!TAILQ_EMPTY(queue)) + fatalx("queue not empty"); + free(queue); +} + +/* Get item name. */ +const char * +cmdq_get_name(struct cmdq_item *item) +{ + return (item->name); +} + +/* Get item client. */ +struct client * +cmdq_get_client(struct cmdq_item *item) +{ + return (item->client); +} + +/* Get item target. */ +struct cmd_find_state * +cmdq_get_target(struct cmdq_item *item) +{ + return (&item->target); +} + +/* Get item source. */ +struct cmd_find_state * +cmdq_get_source(struct cmdq_item *item) +{ + return (&item->source); +} + +/* Get item shared. */ +struct cmdq_shared * +cmdq_get_shared(struct cmdq_item *item) +{ + return (item->shared); +} + +/* Merge formats from item. */ +void +cmdq_merge_formats(struct cmdq_item *item, struct format_tree *ft) +{ + const struct cmd_entry *entry; + + if (item->cmd != NULL) { + entry = cmd_get_entry (item->cmd); + format_add(ft, "command", "%s", entry->name); + } + if (item->shared->formats != NULL) + format_merge(ft, item->shared->formats); } /* Append an item. */ |