=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/tmux/notify.c,v retrieving revision 1.10 retrieving revision 1.11 diff -c -r1.10 -r1.11 *** src/usr.bin/tmux/notify.c 2016/10/15 00:01:01 1.10 --- src/usr.bin/tmux/notify.c 2016/10/15 00:09:30 1.11 *************** *** 1,4 **** ! /* $OpenBSD: notify.c,v 1.10 2016/10/15 00:01:01 nicm Exp $ */ /* * Copyright (c) 2012 George Nachman --- 1,4 ---- ! /* $OpenBSD: notify.c,v 1.11 2016/10/15 00:09:30 nicm Exp $ */ /* * Copyright (c) 2012 George Nachman *************** *** 34,39 **** --- 34,50 ---- 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; *************** *** 50,55 **** --- 61,103 ---- struct window *); static void + notify_hook(struct notify_entry *ne) + { + const char *name; + struct cmd_find_state fs; + struct hook *hook; + struct cmd_q *hooks_cmdq; + + 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 notify_add(enum notify_type type, struct client *c, struct session *s, struct window *w) { *************** *** 102,107 **** --- 150,157 ---- control_notify_session_close(ne->session); break; } + TAILQ_REMOVE(¬ify_queue, ne, entry); + notify_hook(ne); if (ne->client != NULL) server_client_unref(ne->client); *************** *** 109,116 **** session_unref(ne->session); if (ne->window != NULL) window_remove_ref(ne->window); - - TAILQ_REMOVE(¬ify_queue, ne, entry); free(ne); } } --- 159,164 ----