diff options
author | 2017-05-04 07:16:43 +0000 | |
---|---|---|
committer | 2017-05-04 07:16:43 +0000 | |
commit | 3c14ce2038ea3c7f19ff48bbec684c0dcfa9b272 (patch) | |
tree | aeb8dbc0605728ebf7b56034ff7ba0598c35a1e9 | |
parent | since a couple of people have asked, leave a comment explaining why we (diff) | |
download | wireguard-openbsd-3c14ce2038ea3c7f19ff48bbec684c0dcfa9b272.tar.xz wireguard-openbsd-3c14ce2038ea3c7f19ff48bbec684c0dcfa9b272.zip |
Some new notifications, mainly for active pane and current window and
session:
pane-mode-changed
window-pane-changed
client-session-changed
session-window-changed
From Joshua Brot.
-rw-r--r-- | usr.bin/tmux/cmd-switch-client.c | 3 | ||||
-rw-r--r-- | usr.bin/tmux/control-notify.c | 73 | ||||
-rw-r--r-- | usr.bin/tmux/notify.c | 8 | ||||
-rw-r--r-- | usr.bin/tmux/session.c | 3 | ||||
-rw-r--r-- | usr.bin/tmux/tmux.1 | 23 | ||||
-rw-r--r-- | usr.bin/tmux/tmux.h | 5 | ||||
-rw-r--r-- | usr.bin/tmux/window.c | 15 |
7 files changed, 111 insertions, 19 deletions
diff --git a/usr.bin/tmux/cmd-switch-client.c b/usr.bin/tmux/cmd-switch-client.c index ef7f2ce3226..1179ceff87e 100644 --- a/usr.bin/tmux/cmd-switch-client.c +++ b/usr.bin/tmux/cmd-switch-client.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cmd-switch-client.c,v 1.51 2017/04/22 10:22:39 nicm Exp $ */ +/* $OpenBSD: cmd-switch-client.c,v 1.52 2017/05/04 07:16:43 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com> @@ -129,6 +129,7 @@ cmd_switch_client_exec(struct cmd *self, struct cmdq_item *item) if (~item->shared->flags & CMDQ_SHARED_REPEAT) server_client_set_key_table(c, NULL); status_timer_start(c); + notify_client("client-session-changed", c); session_update_activity(s, NULL); gettimeofday(&s->last_attached_time, NULL); diff --git a/usr.bin/tmux/control-notify.c b/usr.bin/tmux/control-notify.c index dd330ba2fee..ecd64aca943 100644 --- a/usr.bin/tmux/control-notify.c +++ b/usr.bin/tmux/control-notify.c @@ -1,4 +1,4 @@ -/* $OpenBSD: control-notify.c,v 1.20 2017/03/08 13:36:12 nicm Exp $ */ +/* $OpenBSD: control-notify.c,v 1.21 2017/05/04 07:16:43 nicm Exp $ */ /* * Copyright (c) 2012 Nicholas Marriott <nicholas.marriott@gmail.com> @@ -60,13 +60,26 @@ control_notify_input(struct client *c, struct window_pane *wp, } void +control_notify_pane_mode_changed(int pane) +{ + struct client *c; + + TAILQ_FOREACH(c, &clients, entry) { + if (!CONTROL_SHOULD_NOTIFY_CLIENT(c)) + continue; + + control_write(c, "%%pane-mode-changed %%%u", pane); + } +} + +void control_notify_window_layout_changed(struct window *w) { - struct client *c; - struct session *s; - struct winlink *wl; - const char *template; - char *cp; + struct client *c; + struct session *s; + struct winlink *wl; + const char *template; + char *cp; template = "%layout-change #{window_id} #{window_layout} " "#{window_visible_layout} #{window_flags}"; @@ -97,6 +110,20 @@ control_notify_window_layout_changed(struct window *w) } void +control_notify_window_pane_changed(struct window *w) +{ + struct client *c; + + TAILQ_FOREACH(c, &clients, entry) { + if (!CONTROL_SHOULD_NOTIFY_CLIENT(c)) + continue; + + control_write(c, "%%window-pane-changed @%u %%%u", w->id, + w->active->id); + } +} + +void control_notify_window_unlinked(__unused struct session *s, struct window *w) { struct client *c; @@ -154,15 +181,27 @@ control_notify_window_renamed(struct window *w) } void -control_notify_client_session_changed(struct client *c) +control_notify_client_session_changed(struct client *cc) { + struct client *c; struct session *s; - if (!CONTROL_SHOULD_NOTIFY_CLIENT(c) || c->session == NULL) + if (cc->session == NULL) return; - s = c->session; + s = cc->session; - control_write(c, "%%session-changed $%u %s", s->id, s->name); + TAILQ_FOREACH(c, &clients, entry) { + if (!CONTROL_SHOULD_NOTIFY_CLIENT(c) || c->session == NULL) + continue; + + if (cc == c) { + control_write(c, "%%session-changed $%u %s", s->id, + s->name); + } else { + control_write(c, "%%client-session-changed %s $%u %s", + cc->name, s->id, s->name); + } + } } void @@ -203,3 +242,17 @@ control_notify_session_closed(__unused struct session *s) control_write(c, "%%sessions-changed"); } } + +void +control_notify_session_window_changed(struct session *s) +{ + struct client *c; + + TAILQ_FOREACH(c, &clients, entry) { + if (!CONTROL_SHOULD_NOTIFY_CLIENT(c)) + continue; + + control_write(c, "%%session-window-changed $%u @%u", s->id, + s->curw->window->id); + } +} diff --git a/usr.bin/tmux/notify.c b/usr.bin/tmux/notify.c index dd559092fdb..deba323a2ec 100644 --- a/usr.bin/tmux/notify.c +++ b/usr.bin/tmux/notify.c @@ -1,4 +1,4 @@ -/* $OpenBSD: notify.c,v 1.23 2017/04/28 19:13:55 nicm Exp $ */ +/* $OpenBSD: notify.c,v 1.24 2017/05/04 07:16:43 nicm Exp $ */ /* * Copyright (c) 2012 George Nachman <tmux@georgester.com> @@ -79,8 +79,12 @@ notify_callback(struct cmdq_item *item, void *data) log_debug("%s: %s", __func__, ne->name); + if (strcmp(ne->name, "pane-mode-changed") == 0) + control_notify_pane_mode_changed(ne->pane); if (strcmp(ne->name, "window-layout-changed") == 0) control_notify_window_layout_changed(ne->window); + if (strcmp(ne->name, "window-pane-changed") == 0) + control_notify_window_pane_changed(ne->window); if (strcmp(ne->name, "window-unlinked") == 0) control_notify_window_unlinked(ne->session, ne->window); if (strcmp(ne->name, "window-linked") == 0) @@ -95,6 +99,8 @@ notify_callback(struct cmdq_item *item, void *data) control_notify_session_created(ne->session); if (strcmp(ne->name, "session-closed") == 0) control_notify_session_closed(ne->session); + if (strcmp(ne->name, "session-window-changed") == 0) + control_notify_session_window_changed(ne->session); notify_hook(item, ne); diff --git a/usr.bin/tmux/session.c b/usr.bin/tmux/session.c index 456f13a2364..eb0aae4a6df 100644 --- a/usr.bin/tmux/session.c +++ b/usr.bin/tmux/session.c @@ -1,4 +1,4 @@ -/* $OpenBSD: session.c,v 1.75 2017/04/28 19:13:55 nicm Exp $ */ +/* $OpenBSD: session.c,v 1.76 2017/05/04 07:16:43 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com> @@ -553,6 +553,7 @@ session_set_current(struct session *s, struct winlink *wl) s->curw = wl; winlink_clear_flags(wl); window_update_activity(wl->window); + notify_session("session-window-changed", s); return (0); } diff --git a/usr.bin/tmux/tmux.1 b/usr.bin/tmux/tmux.1 index 8db298af82b..ca2a9b4704c 100644 --- a/usr.bin/tmux/tmux.1 +++ b/usr.bin/tmux/tmux.1 @@ -1,4 +1,4 @@ -.\" $OpenBSD: tmux.1,v 1.546 2017/05/03 05:53:34 nicm Exp $ +.\" $OpenBSD: tmux.1,v 1.547 2017/05/04 07:16:43 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: May 3 2017 $ +.Dd $Mdocdate: May 4 2017 $ .Dt TMUX 1 .Os .Sh NAME @@ -4231,6 +4231,11 @@ A notification will never occur inside an output block. .Pp The following notifications are defined: .Bl -tag -width Ds +.It Ic %client-session-changed Ar client Ar session-id Ar name +The client is now attached to the session with ID +.Ar session-id , +which is named +.Ar name . .It Ic %exit Op Ar reason The .Nm @@ -4253,6 +4258,10 @@ and the window flags are A window pane produced output. .Ar value escapes non-printable characters and backslash as octal \\xxx. +.It Ic %pane-mode-changed Ar pane-id +The pane with ID +.Ar pane-id +has changed mode. .It Ic %session-changed Ar session-id Ar name The client is now attached to the session with ID .Ar session-id , @@ -4261,6 +4270,11 @@ which is named .It Ic %session-renamed Ar name The current session was renamed to .Ar name . +.It Ic %session-window-changed Ar session-id Ar window-id +The session with ID +.Ar session-id +changed its active window to the window with ID +.Ar window-id . .It Ic %sessions-changed A session was created or destroyed. .It Ic %unlinked-window-add Ar window-id @@ -4275,6 +4289,11 @@ was linked to the current session. The window with ID .Ar window-id closed. +.It Ic %window-pane-changed Ar window-id Ar pane-id +The active pane in the window with ID +.Ar window-id +changed to the pane with ID +.Ar pane-id . .It Ic %window-renamed Ar window-id Ar name The window with ID .Ar window-id diff --git a/usr.bin/tmux/tmux.h b/usr.bin/tmux/tmux.h index ae1d8ae3cf5..13c8dbc79ae 100644 --- a/usr.bin/tmux/tmux.h +++ b/usr.bin/tmux/tmux.h @@ -1,4 +1,4 @@ -/* $OpenBSD: tmux.h,v 1.757 2017/05/03 05:53:34 nicm Exp $ */ +/* $OpenBSD: tmux.h,v 1.758 2017/05/04 07:16:43 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com> @@ -2208,7 +2208,9 @@ void control_write_buffer(struct client *, struct evbuffer *); /* control-notify.c */ void control_notify_input(struct client *, struct window_pane *, struct evbuffer *); +void control_notify_pane_mode_changed(int); void control_notify_window_layout_changed(struct window *); +void control_notify_window_pane_changed(struct window *); void control_notify_window_unlinked(struct session *, struct window *); void control_notify_window_linked(struct session *, struct window *); void control_notify_window_renamed(struct window *); @@ -2216,6 +2218,7 @@ void control_notify_client_session_changed(struct client *); void control_notify_session_renamed(struct session *); void control_notify_session_created(struct session *); void control_notify_session_closed(struct session *); +void control_notify_session_window_changed(struct session *); /* session.c */ extern struct sessions sessions; diff --git a/usr.bin/tmux/window.c b/usr.bin/tmux/window.c index 45edbde1c22..c55d916a02e 100644 --- a/usr.bin/tmux/window.c +++ b/usr.bin/tmux/window.c @@ -1,4 +1,4 @@ -/* $OpenBSD: window.c,v 1.192 2017/04/28 19:13:55 nicm Exp $ */ +/* $OpenBSD: window.c,v 1.193 2017/05/04 07:16:43 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com> @@ -355,6 +355,8 @@ window_create_spawn(const char *name, int argc, char **argv, const char *path, } else w->name = default_window_name(w); + notify_window("window-pane-changed", w); + return (w); } @@ -441,11 +443,14 @@ window_set_active_pane(struct window *w, struct window_pane *wp) w->active = TAILQ_PREV(w->active, window_panes, entry); if (w->active == NULL) w->active = TAILQ_LAST(&w->panes, window_panes); - if (w->active == wp) + if (w->active == wp) { + notify_window("window-pane-changed", w); return (1); + } } w->active->active_point = next_active_point++; w->active->flags |= PANE_CHANGED; + notify_window("window-pane-changed", w); return (1); } @@ -621,8 +626,10 @@ window_lost_pane(struct window *w, struct window_pane *wp) if (w->active == NULL) w->active = TAILQ_NEXT(wp, entry); } - if (w->active != NULL) + if (w->active != NULL) { w->active->flags |= PANE_CHANGED; + notify_window("window-pane-changed", w); + } } else if (wp == w->last) w->last = NULL; } @@ -1181,6 +1188,7 @@ window_pane_set_mode(struct window_pane *wp, const struct window_mode *mode) wp->flags |= (PANE_REDRAW|PANE_CHANGED); server_status_window(wp->window); + notify_pane("pane-mode-changed", wp); return (0); } @@ -1200,6 +1208,7 @@ window_pane_reset_mode(struct window_pane *wp) wp->flags |= (PANE_REDRAW|PANE_CHANGED); server_status_window(wp->window); + notify_pane("pane-mode-changed", wp); } void |