From b342bd0b462f69a9fc9a59d52bcd4bb34b57114f Mon Sep 17 00:00:00 2001 From: nicm Date: Sun, 16 Oct 2016 19:04:05 +0000 Subject: Mass rename struct cmd_q to struct cmdq_item and related. --- notify.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'notify.c') diff --git a/notify.c b/notify.c index a75b3182..93276809 100644 --- a/notify.c +++ b/notify.c @@ -66,7 +66,7 @@ notify_hook(struct notify_entry *ne) const char *name; struct cmd_find_state fs; struct hook *hook; - struct cmd_q *new_cmdq, *loop; + struct cmdq_item *new_item, *loop; name = notify_hooks[ne->type]; if (name == NULL) @@ -87,12 +87,12 @@ notify_hook(struct notify_entry *ne) return; log_debug("notify hook %s", name); - new_cmdq = cmdq_get_command(hook->cmdlist, &fs, NULL, CMD_Q_NOHOOKS); + new_item = cmdq_get_command(hook->cmdlist, &fs, NULL, CMDQ_NOHOOKS); - for (loop = new_cmdq; loop != NULL; loop = loop->next) + for (loop = new_item; loop != NULL; loop = loop->next) loop->hook = xstrdup(name); - cmdq_append(NULL, new_cmdq); + cmdq_append(NULL, new_item); } static void -- cgit v1.2.3 From 026ad08b56b4577beab6bad06b8a7a21602bca11 Mon Sep 17 00:00:00 2001 From: nicm Date: Sun, 16 Oct 2016 19:15:02 +0000 Subject: Notifys can go via the command queue instead of using their own queue. --- notify.c | 113 ++++++++++++++++++++++++++++----------------------------------- 1 file changed, 51 insertions(+), 62 deletions(-) (limited to 'notify.c') diff --git a/notify.c b/notify.c index 93276809..392797ba 100644 --- a/notify.c +++ b/notify.c @@ -51,17 +51,10 @@ struct notify_entry { struct client *client; struct session *session; struct window *window; - - TAILQ_ENTRY(notify_entry) entry; }; -TAILQ_HEAD(notify_queue, notify_entry); -static struct notify_queue notify_queue = TAILQ_HEAD_INITIALIZER(notify_queue); - -static void notify_add(enum notify_type, struct client *, struct session *, - struct window *); static void -notify_hook(struct notify_entry *ne) +notify_hook(struct cmdq_item *item, struct notify_entry *ne) { const char *name; struct cmd_find_state fs; @@ -79,6 +72,8 @@ notify_hook(struct notify_entry *ne) cmd_find_from_window(&fs, ne->window); else if (ne->session != NULL) cmd_find_from_session(&fs, ne->session); + else + cmd_find_current(&fs, item, CMD_FIND_QUIET); if (cmd_find_empty_state(&fs) || !cmd_find_valid_state(&fs)) return; @@ -92,7 +87,51 @@ notify_hook(struct notify_entry *ne) for (loop = new_item; loop != NULL; loop = loop->next) loop->hook = xstrdup(name); - cmdq_append(NULL, new_item); + cmdq_insert_after(item, new_item); +} + +static enum cmd_retval +notify_callback(struct cmdq_item *item, void *data) +{ + struct notify_entry *ne = data; + + switch (ne->type) { + case NOTIFY_WINDOW_LAYOUT_CHANGED: + control_notify_window_layout_changed(ne->window); + break; + case NOTIFY_WINDOW_UNLINKED: + control_notify_window_unlinked(ne->session, ne->window); + break; + case NOTIFY_WINDOW_LINKED: + control_notify_window_linked(ne->session, ne->window); + break; + case NOTIFY_WINDOW_RENAMED: + control_notify_window_renamed(ne->window); + break; + case NOTIFY_ATTACHED_SESSION_CHANGED: + control_notify_attached_session_changed(ne->client); + break; + case NOTIFY_SESSION_RENAMED: + control_notify_session_renamed(ne->session); + break; + case NOTIFY_SESSION_CREATED: + control_notify_session_created(ne->session); + break; + case NOTIFY_SESSION_CLOSED: + control_notify_session_closed(ne->session); + break; + } + notify_hook(item, ne); + + if (ne->client != NULL) + server_client_unref(ne->client); + if (ne->session != NULL) + session_unref(ne->session); + if (ne->window != NULL) + window_remove_ref(ne->window); + free(ne); + + return (CMD_RETURN_NORMAL); } static void @@ -100,13 +139,13 @@ notify_add(enum notify_type type, struct client *c, struct session *s, struct window *w) { struct notify_entry *ne; + struct cmdq_item *new_item; ne = xcalloc(1, sizeof *ne); ne->type = type; ne->client = c; ne->session = s; ne->window = w; - TAILQ_INSERT_TAIL(¬ify_queue, ne, entry); if (c != NULL) c->references++; @@ -114,51 +153,9 @@ notify_add(enum notify_type type, struct client *c, struct session *s, s->references++; if (w != NULL) w->references++; -} -void -notify_drain(void) -{ - struct notify_entry *ne, *ne1; - - TAILQ_FOREACH_SAFE(ne, ¬ify_queue, entry, ne1) { - switch (ne->type) { - case NOTIFY_WINDOW_LAYOUT_CHANGED: - control_notify_window_layout_changed(ne->window); - break; - case NOTIFY_WINDOW_UNLINKED: - control_notify_window_unlinked(ne->session, ne->window); - break; - case NOTIFY_WINDOW_LINKED: - control_notify_window_linked(ne->session, ne->window); - break; - case NOTIFY_WINDOW_RENAMED: - control_notify_window_renamed(ne->window); - break; - case NOTIFY_ATTACHED_SESSION_CHANGED: - control_notify_attached_session_changed(ne->client); - break; - case NOTIFY_SESSION_RENAMED: - control_notify_session_renamed(ne->session); - break; - case NOTIFY_SESSION_CREATED: - control_notify_session_created(ne->session); - break; - case NOTIFY_SESSION_CLOSED: - control_notify_session_closed(ne->session); - break; - } - TAILQ_REMOVE(¬ify_queue, ne, entry); - notify_hook(ne); - - if (ne->client != NULL) - server_client_unref(ne->client); - if (ne->session != NULL) - session_unref(ne->session); - if (ne->window != NULL) - window_remove_ref(ne->window); - free(ne); - } + new_item = cmdq_get_callback(notify_callback, ne); + cmdq_append(NULL, new_item); } void @@ -176,54 +173,46 @@ void notify_window_layout_changed(struct window *w) { notify_add(NOTIFY_WINDOW_LAYOUT_CHANGED, NULL, NULL, w); - notify_drain(); } void notify_window_unlinked(struct session *s, struct window *w) { notify_add(NOTIFY_WINDOW_UNLINKED, NULL, s, w); - notify_drain(); } void notify_window_linked(struct session *s, struct window *w) { notify_add(NOTIFY_WINDOW_LINKED, NULL, s, w); - notify_drain(); } void notify_window_renamed(struct window *w) { notify_add(NOTIFY_WINDOW_RENAMED, NULL, NULL, w); - notify_drain(); } void notify_attached_session_changed(struct client *c) { notify_add(NOTIFY_ATTACHED_SESSION_CHANGED, c, NULL, NULL); - notify_drain(); } void notify_session_renamed(struct session *s) { notify_add(NOTIFY_SESSION_RENAMED, NULL, s, NULL); - notify_drain(); } void notify_session_created(struct session *s) { notify_add(NOTIFY_SESSION_CREATED, NULL, s, NULL); - notify_drain(); } void notify_session_closed(struct session *s) { notify_add(NOTIFY_SESSION_CLOSED, NULL, s, NULL); - notify_drain(); } -- cgit v1.2.3 From 3f35b5299fb2c08637aa12757185e5b82eeb3fc1 Mon Sep 17 00:00:00 2001 From: nicm Date: Sun, 16 Oct 2016 19:36:37 +0000 Subject: Provide a way for hooks to tag formats onto the commands they fire so that the user can get at additional information - now used for the "hook" format, more to come. --- notify.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) (limited to 'notify.c') diff --git a/notify.c b/notify.c index 392797ba..20709e53 100644 --- a/notify.c +++ b/notify.c @@ -59,7 +59,7 @@ notify_hook(struct cmdq_item *item, struct notify_entry *ne) const char *name; struct cmd_find_state fs; struct hook *hook; - struct cmdq_item *new_item, *loop; + struct cmdq_item *new_item; name = notify_hooks[ne->type]; if (name == NULL) @@ -83,10 +83,7 @@ notify_hook(struct cmdq_item *item, struct notify_entry *ne) log_debug("notify hook %s", name); new_item = cmdq_get_command(hook->cmdlist, &fs, NULL, CMDQ_NOHOOKS); - - for (loop = new_item; loop != NULL; loop = loop->next) - loop->hook = xstrdup(name); - + cmdq_format(new_item, "hook", "%s", name); cmdq_insert_after(item, new_item); } -- cgit v1.2.3 From d15d54c2c8e6b95695169442eb2a27d814efc078 Mon Sep 17 00:00:00 2001 From: nicm Date: Sun, 16 Oct 2016 19:55:52 +0000 Subject: Add hook_session and hook_window formats to get information on the affected session or window when a hook fires. Enable session-created and session-closed hooks now that that is available. --- notify.c | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) (limited to 'notify.c') diff --git a/notify.c b/notify.c index 20709e53..49d7e32f 100644 --- a/notify.c +++ b/notify.c @@ -41,8 +41,8 @@ static const char *notify_hooks[] = { "window-renamed", NULL, /* "attached-session-changed", */ "session-renamed", - NULL, /* "session-created", */ - NULL, /* "session-closed" */ + "session-created", + "session-closed" }; struct notify_entry { @@ -60,18 +60,20 @@ notify_hook(struct cmdq_item *item, struct notify_entry *ne) struct cmd_find_state fs; struct hook *hook; struct cmdq_item *new_item; + struct session *s = ne->session; + struct window *w = ne->window; name = notify_hooks[ne->type]; if (name == NULL) return; cmd_find_clear_state(&fs, NULL, 0); - if (ne->session != NULL && ne->window != NULL) - cmd_find_from_session_window(&fs, ne->session, ne->window); - else if (ne->window != NULL) - cmd_find_from_window(&fs, ne->window); - else if (ne->session != NULL) - cmd_find_from_session(&fs, ne->session); + if (s != NULL && w != NULL) + cmd_find_from_session_window(&fs, s, w); + else if (w != NULL) + cmd_find_from_window(&fs, w); + else if (s != NULL && session_alive(s)) + cmd_find_from_session(&fs, s); else cmd_find_current(&fs, item, CMD_FIND_QUIET); if (cmd_find_empty_state(&fs) || !cmd_find_valid_state(&fs)) @@ -84,6 +86,16 @@ notify_hook(struct cmdq_item *item, struct notify_entry *ne) new_item = cmdq_get_command(hook->cmdlist, &fs, NULL, CMDQ_NOHOOKS); cmdq_format(new_item, "hook", "%s", name); + + if (s != NULL) { + cmdq_format(new_item, "hook_session", "$%u", s->id); + cmdq_format(new_item, "hook_session_name", "%s", s->name); + } + if (w != NULL) { + cmdq_format(new_item, "hook_window", "@%u", w->id); + cmdq_format(new_item, "hook_window_name", "%s", w->name); + } + cmdq_insert_after(item, new_item); } -- cgit v1.2.3