aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cmd-find.c18
-rw-r--r--notify.c52
-rw-r--r--tmux.14
-rw-r--r--tmux.h2
4 files changed, 74 insertions, 2 deletions
diff --git a/cmd-find.c b/cmd-find.c
index 10f2fd04..21691f67 100644
--- a/cmd-find.c
+++ b/cmd-find.c
@@ -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/notify.c b/notify.c
index 3ec41e99..5f4f046e 100644
--- a/notify.c
+++ b/notify.c
@@ -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(&notify_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(&notify_queue, ne, entry);
free(ne);
}
}
diff --git a/tmux.1 b/tmux.1
index 79746d01..877318c0 100644
--- a/tmux.1
+++ b/tmux.1
@@ -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/tmux.h b/tmux.h
index a57ac5b0..0db6f031 100644
--- a/tmux.h
+++ b/tmux.h
@@ -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 *);