summaryrefslogtreecommitdiffstats
path: root/notify.c
diff options
context:
space:
mode:
authorThomas Adam <thomas@xteddy.org>2016-10-15 02:01:12 +0100
committerThomas Adam <thomas@xteddy.org>2016-10-15 02:01:12 +0100
commit623e54788e77068779933eb60a042e5a82f32673 (patch)
tree02ce8da6ff4062b9d4c4b9846960f6f9849e0b2b /notify.c
parent3d2686a236b4ffee762ada8ebb493d8db91f7375 (diff)
parent3f138dc40c37ddee021b92e5d29676ed96b6cab8 (diff)
Merge branch 'obsd-master'
Diffstat (limited to 'notify.c')
-rw-r--r--notify.c73
1 files changed, 48 insertions, 25 deletions
diff --git a/notify.c b/notify.c
index d3b6ce63..31f23b6f 100644
--- a/notify.c
+++ b/notify.c
@@ -33,6 +33,17 @@ enum notify_type {
NOTIFY_SESSION_CLOSED
};
+static const char *notify_hooks[] = {
+ "window-layout-changed",
+ NULL, /* "window-unlinked", */
+ NULL, /* "window-linked", */
+ "window-renamed",
+ NULL, /* "attached-session-changed", */
+ "session-renamed",
+ NULL, /* "session-created", */
+ NULL, /* "session-closed" */
+};
+
struct notify_entry {
enum notify_type type;
@@ -44,23 +55,45 @@ struct notify_entry {
};
TAILQ_HEAD(notify_queue, notify_entry);
static struct notify_queue notify_queue = TAILQ_HEAD_INITIALIZER(notify_queue);
-static int notify_enabled = 1;
-static void notify_drain(void);
static void notify_add(enum notify_type, struct client *, struct session *,
struct window *);
-void
-notify_enable(void)
+static void
+notify_hook(struct notify_entry *ne)
{
- notify_enabled = 1;
- notify_drain();
-}
+ const char *name;
+ struct cmd_find_state fs;
+ struct hook *hook;
+ struct cmd_q *hooks_cmdq;
-void
-notify_disable(void)
-{
- notify_enabled = 0;
+ 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 (cmd_find_empty_state(&fs) || !cmd_find_valid_state(&fs))
+ return;
+
+ hook = hooks_find(fs.s->hooks, name);
+ if (hook == NULL)
+ return;
+ log_debug("notify hook %s", name);
+
+ hooks_cmdq = cmdq_new(NULL);
+ hooks_cmdq->flags |= CMD_Q_NOHOOKS;
+
+ cmd_find_copy_state(&hooks_cmdq->current, &fs);
+ hooks_cmdq->parent = NULL;
+
+ cmdq_run(hooks_cmdq, hook->cmdlist, NULL);
+ cmdq_free(hooks_cmdq);
}
static void
@@ -84,14 +117,11 @@ notify_add(enum notify_type type, struct client *c, struct session *s,
w->references++;
}
-static void
+void
notify_drain(void)
{
struct notify_entry *ne, *ne1;
- if (!notify_enabled)
- return;
-
TAILQ_FOREACH_SAFE(ne, &notify_queue, entry, ne1) {
switch (ne->type) {
case NOTIFY_WINDOW_LAYOUT_CHANGED:
@@ -116,9 +146,11 @@ notify_drain(void)
control_notify_session_created(ne->session);
break;
case NOTIFY_SESSION_CLOSED:
- control_notify_session_close(ne->session);
+ control_notify_session_closed(ne->session);
break;
}
+ TAILQ_REMOVE(&notify_queue, ne, entry);
+ notify_hook(ne);
if (ne->client != NULL)
server_client_unref(ne->client);
@@ -126,8 +158,6 @@ notify_drain(void)
session_unref(ne->session);
if (ne->window != NULL)
window_remove_ref(ne->window);
-
- TAILQ_REMOVE(&notify_queue, ne, entry);
free(ne);
}
}
@@ -137,13 +167,6 @@ notify_input(struct window_pane *wp, struct evbuffer *input)
{
struct client *c;
- /*
- * notify_input() is not queued and only does anything when
- * notifications are enabled.
- */
- if (!notify_enabled)
- return;
-
TAILQ_FOREACH(c, &clients, entry) {
if (c->flags & CLIENT_CONTROL)
control_notify_input(c, wp, input);