summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authornicm <nicm>2017-05-04 07:16:43 +0000
committernicm <nicm>2017-05-04 07:16:43 +0000
commitd98d31690354ec6b53206c0b24834c877cd8ad5a (patch)
tree8d63d0b30f4742990a6e687d4569f9981c3182a4
parentca6a121e63c61eb45a81dc7318ed290b8dca45e6 (diff)
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--cmd-switch-client.c1
-rw-r--r--control-notify.c71
-rw-r--r--notify.c6
-rw-r--r--session.c1
-rw-r--r--tmux.119
-rw-r--r--tmux.h3
-rw-r--r--window.c13
7 files changed, 103 insertions, 11 deletions
diff --git a/cmd-switch-client.c b/cmd-switch-client.c
index 2bc1e10c..a24f0276 100644
--- a/cmd-switch-client.c
+++ b/cmd-switch-client.c
@@ -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/control-notify.c b/control-notify.c
index 230bce61..49291483 100644
--- a/control-notify.c
+++ b/control-notify.c
@@ -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/notify.c b/notify.c
index 78278e09..9d3a91e3 100644
--- a/notify.c
+++ b/notify.c
@@ -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/session.c b/session.c
index ca8215ee..9fa76dc3 100644
--- a/session.c
+++ b/session.c
@@ -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/tmux.1 b/tmux.1
index 1258c6d3..23a28a1f 100644
--- a/tmux.1
+++ b/tmux.1
@@ -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/tmux.h b/tmux.h
index 65b22284..ac2991e8 100644
--- a/tmux.h
+++ b/tmux.h
@@ -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/window.c b/window.c
index 029e4689..297192b7 100644
--- a/window.c
+++ b/window.c
@@ -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