Skip to content

Commit

Permalink
Merge branch 'obsd-master'
Browse files Browse the repository at this point in the history
  • Loading branch information
ThomasAdam committed Jan 16, 2016
2 parents 506adf3 + c981530 commit 5d21faa
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 3 deletions.
23 changes: 20 additions & 3 deletions alerts.c
Expand Up @@ -29,6 +29,7 @@ int alerts_enabled(struct window *, int);
void alerts_callback(int, short, void *);
void alerts_reset(struct window *);

void alerts_run_hook(struct session *, struct winlink *, int);
int alerts_check_all(struct session *, struct winlink *);
int alerts_check_bell(struct session *, struct winlink *);
int alerts_check_activity(struct session *, struct winlink *);
Expand All @@ -55,8 +56,6 @@ alerts_callback(__unused int fd, __unused short events, __unused void *arg)

RB_FOREACH(w, windows, &windows) {
RB_FOREACH(s, sessions, &sessions) {
if (s->flags & SESSION_UNATTACHED)
continue;
RB_FOREACH(wl, winlinks, &s->windows) {
if (wl->window != w)
continue;
Expand All @@ -73,6 +72,22 @@ alerts_callback(__unused int fd, __unused short events, __unused void *arg)
alerts_fired = 0;
}

void
alerts_run_hook(struct session *s, struct winlink *wl, int flags)
{
struct cmd_find_state fs;

if (cmd_find_from_winlink(&fs, s, wl) != 0)
return;

if (flags & WINDOW_BELL)
hooks_run(s->hooks, NULL, &fs, "alert-bell");
if (flags & WINDOW_SILENCE)
hooks_run(s->hooks, NULL, &fs, "alert-silence");
if (flags & WINDOW_ACTIVITY)
hooks_run(s->hooks, NULL, &fs, "alert-activity");
}

int
alerts_check_all(struct session *s, struct winlink *wl)
{
Expand All @@ -81,8 +96,10 @@ alerts_check_all(struct session *s, struct winlink *wl)
alerts = alerts_check_bell(s, wl);
alerts |= alerts_check_activity(s, wl);
alerts |= alerts_check_silence(s, wl);
if (alerts != 0)
if (alerts != 0) {
alerts_run_hook(s, wl, alerts);
server_status_session(s);
}

return (alerts);
}
Expand Down
16 changes: 16 additions & 0 deletions cmd-find.c
Expand Up @@ -878,6 +878,22 @@ cmd_find_from_session(struct cmd_find_state *fs, struct session *s)
return (0);
}

/* Find state from a winlink. */
int
cmd_find_from_winlink(struct cmd_find_state *fs, struct session *s,
struct winlink *wl)
{
cmd_find_clear_state(fs, NULL, 0);

fs->s = s;
fs->wl = wl;
fs->w = wl->window;
fs->wp = wl->window->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)
Expand Down
10 changes: 10 additions & 0 deletions tmux.1
Expand Up @@ -3228,6 +3228,16 @@ Each hook has a
.Em name .
The following hooks are available:
.Bl -tag -width "XXXXXXXXXXXXXXXX"
.It alert-activity
Run when a window has activity.
See
.Ic monitor-activity .
.It alert-bell
Run when a window has received a bell.
.It alert-silence
Run when a window has been silent.
See
.Ic monitor-silence .
.It client-attached
Run when a client is attached.
.It client-detached
Expand Down
2 changes: 2 additions & 0 deletions tmux.h
Expand Up @@ -1782,6 +1782,8 @@ void cmd_find_copy_state(struct cmd_find_state *,
void cmd_find_log_state(const char *, struct cmd_find_state *);
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_window(struct cmd_find_state *, struct window *);
int cmd_find_from_pane(struct cmd_find_state *,
struct window_pane *);
Expand Down

0 comments on commit 5d21faa

Please sign in to comment.