diff options
author | Nicholas Marriott <nicm@cvs.openbsd.org> | 2016-10-15 00:09:31 +0000 |
---|---|---|
committer | Nicholas Marriott <nicm@cvs.openbsd.org> | 2016-10-15 00:09:31 +0000 |
commit | 35c63127e24018b37d1591d720f6100f18bb4919 (patch) | |
tree | 7b48063f028eb75e96d192fbd1b6bf64c67f9354 /usr.bin | |
parent | 6254e9b89f92975cfb9a0c361df131bf554ffcfb (diff) |
Fire hooks on the simple notifys (window-renamed and session-renamed),
the complicated ones get no hooks for now (more to come).
Diffstat (limited to 'usr.bin')
-rw-r--r-- | usr.bin/tmux/cmd-find.c | 20 | ||||
-rw-r--r-- | usr.bin/tmux/notify.c | 54 | ||||
-rw-r--r-- | usr.bin/tmux/tmux.1 | 8 | ||||
-rw-r--r-- | usr.bin/tmux/tmux.h | 4 |
4 files changed, 79 insertions, 7 deletions
diff --git a/usr.bin/tmux/cmd-find.c b/usr.bin/tmux/cmd-find.c index 4bc069ada42..72d0ee401bd 100644 --- a/usr.bin/tmux/cmd-find.c +++ b/usr.bin/tmux/cmd-find.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cmd-find.c,v 1.34 2016/10/13 10:01:49 nicm Exp $ */ +/* $OpenBSD: cmd-find.c,v 1.35 2016/10/15 00:09:30 nicm Exp $ */ /* * Copyright (c) 2015 Nicholas Marriott <nicholas.marriott@gmail.com> @@ -904,6 +904,23 @@ cmd_find_from_winlink(struct cmd_find_state *fs, struct session *s, return (0); } +/* Find state from a session and window. */ +int +cmd_find_from_session_window(struct cmd_find_state *fs, struct session *s, + struct window *w) +{ + cmd_find_clear_state(fs, NULL, 0); + + fs->s = s; + fs->w = w; + if (cmd_find_best_winlink_with_window(fs) != 0) + return (-1); + fs->wp = fs->w->active; + + cmd_find_log_state(__func__, fs); + return (0); +} + /* Find state from a window. */ int cmd_find_from_window(struct cmd_find_state *fs, struct window *w) @@ -915,6 +932,7 @@ cmd_find_from_window(struct cmd_find_state *fs, struct window *w) return (-1); if (cmd_find_best_winlink_with_window(fs) != 0) return (-1); + fs->wp = fs->w->active; cmd_find_log_state(__func__, fs); return (0); diff --git a/usr.bin/tmux/notify.c b/usr.bin/tmux/notify.c index fdc2eb92623..7663c53d5a5 100644 --- a/usr.bin/tmux/notify.c +++ b/usr.bin/tmux/notify.c @@ -1,4 +1,4 @@ -/* $OpenBSD: notify.c,v 1.10 2016/10/15 00:01:01 nicm Exp $ */ +/* $OpenBSD: notify.c,v 1.11 2016/10/15 00:09:30 nicm Exp $ */ /* * Copyright (c) 2012 George Nachman <tmux@georgester.com> @@ -34,6 +34,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; @@ -50,6 +61,43 @@ static void notify_add(enum notify_type, struct client *, struct session *, 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,6 +150,8 @@ notify_drain(void) 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,8 +159,6 @@ notify_drain(void) session_unref(ne->session); if (ne->window != NULL) window_remove_ref(ne->window); - - TAILQ_REMOVE(¬ify_queue, ne, entry); free(ne); } } diff --git a/usr.bin/tmux/tmux.1 b/usr.bin/tmux/tmux.1 index fc270eca78e..6b8944ee736 100644 --- a/usr.bin/tmux/tmux.1 +++ b/usr.bin/tmux/tmux.1 @@ -1,4 +1,4 @@ -.\" $OpenBSD: tmux.1,v 1.506 2016/10/14 17:40:47 nicm Exp $ +.\" $OpenBSD: tmux.1,v 1.507 2016/10/15 00:09:30 nicm Exp $ .\" .\" Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com> .\" @@ -14,7 +14,7 @@ .\" IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING .\" OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. .\" -.Dd $Mdocdate: October 14 2016 $ +.Dd $Mdocdate: October 15 2016 $ .Dt TMUX 1 .Os .Sh NAME @@ -3244,6 +3244,10 @@ Run when the program running in a pane exits, but is on so the pane has not closed. .It pane-exited Run when the program running in a pane exits. +.It session-renamed +Run when a session is renamed. +.It window-renamed +Run when a window is renamed. .El .Pp Hooks are managed with these commands: diff --git a/usr.bin/tmux/tmux.h b/usr.bin/tmux/tmux.h index 52d0c355511..1c0cf6aa0b1 100644 --- a/usr.bin/tmux/tmux.h +++ b/usr.bin/tmux/tmux.h @@ -1,4 +1,4 @@ -/* $OpenBSD: tmux.h,v 1.663 2016/10/15 00:01:01 nicm Exp $ */ +/* $OpenBSD: tmux.h,v 1.664 2016/10/15 00:09:30 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com> @@ -1742,6 +1742,8 @@ int cmd_find_from_session(struct cmd_find_state *, struct session *); int cmd_find_from_winlink(struct cmd_find_state *, struct session *, struct winlink *); +int cmd_find_from_session_window(struct cmd_find_state *, + struct session *, struct window *); int cmd_find_from_window(struct cmd_find_state *, struct window *); int cmd_find_from_pane(struct cmd_find_state *, struct window_pane *); |