Skip to content

Commit

Permalink
Fix bell indicators across detach, reported by Torbjorn Lonnemark, diff
Browse files Browse the repository at this point in the history
from Thomas Adam.
  • Loading branch information
nicm committed Dec 7, 2015
1 parent 0417f1f commit b956334
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 11 deletions.
44 changes: 33 additions & 11 deletions alerts.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ int alerts_enabled(struct window *, int);
void alerts_callback(int, short, void *);
void alerts_reset(struct window *);

int alerts_check_all(struct session *, struct winlink *);
int alerts_check_bell(struct session *, struct winlink *);
int alerts_check_activity(struct session *, struct winlink *);
int alerts_check_silence(struct session *, struct winlink *);
Expand All @@ -54,16 +55,14 @@ 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;
flags = w->flags;

alerts = alerts_check_bell(s, wl);
alerts |= alerts_check_activity(s, wl);
alerts |= alerts_check_silence(s, wl);
if (alerts != 0)
server_status_session(s);
alerts = alerts_check_all(s, wl);

log_debug("%s:%d @%u alerts check, alerts %#x, "
"flags %#x", s->name, wl->idx, w->id,
Expand All @@ -74,6 +73,29 @@ alerts_callback(__unused int fd, __unused short events, __unused void *arg)
alerts_fired = 0;
}

int
alerts_check_all(struct session *s, struct winlink *wl)
{
int alerts;

alerts = alerts_check_bell(s, wl);
alerts |= alerts_check_activity(s, wl);
alerts |= alerts_check_silence(s, wl);
if (alerts != 0)
server_status_session(s);

return (alerts);
}

void
alerts_check_session(struct session *s)
{
struct winlink *wl;

RB_FOREACH(wl, winlinks, &s->windows)
alerts_check_all(s, wl);
}

int
alerts_enabled(struct window *w, int flags)
{
Expand Down Expand Up @@ -143,12 +165,12 @@ alerts_check_bell(struct session *s, struct winlink *wl)
struct window *w = wl->window;
int action, visual;

if (!(w->flags & WINDOW_BELL) || wl->flags & WINLINK_BELL)
if (!(w->flags & WINDOW_BELL))
return (0);
if (s->curw != wl || s->flags & SESSION_UNATTACHED)
if (s->curw != wl) {
wl->flags |= WINLINK_BELL;
if (s->flags & SESSION_UNATTACHED)
return (0);
w->flags &= ~WINDOW_BELL;
}
if (s->curw->window == w)
w->flags &= ~WINDOW_BELL;

Expand Down Expand Up @@ -190,7 +212,7 @@ alerts_check_activity(struct session *s, struct winlink *wl)

if (!(w->flags & WINDOW_ACTIVITY) || wl->flags & WINLINK_ACTIVITY)
return (0);
if (s->curw == wl && !(s->flags & SESSION_UNATTACHED))
if (s->curw == wl)
return (0);

if (!options_get_number(w->options, "monitor-activity"))
Expand Down Expand Up @@ -222,7 +244,7 @@ alerts_check_silence(struct session *s, struct winlink *wl)

if (!(w->flags & WINDOW_SILENCE) || wl->flags & WINLINK_SILENCE)
return (0);
if (s->curw == wl && !(s->flags & SESSION_UNATTACHED))
if (s->curw == wl)
return (0);

if (options_get_number(w->options, "monitor-silence") == 0)
Expand Down
1 change: 1 addition & 0 deletions cmd-attach-session.c
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ cmd_attach_session(struct cmd_q *cmdq, const char *tflag, int dflag, int rflag,
cmdq->client_exit = 0;
}
recalculate_sizes();
alerts_check_session(s);
server_update_socket();

return (CMD_RETURN_NORMAL);
Expand Down
1 change: 1 addition & 0 deletions tmux.h
Original file line number Diff line number Diff line change
Expand Up @@ -1757,6 +1757,7 @@ const char *key_string_lookup_key(key_code);
/* alerts.c */
void alerts_reset_all(void);
void alerts_queue(struct window *, int);
void alerts_check_session(struct session *);

/* server.c */
extern struct tmuxproc *server_proc;
Expand Down

0 comments on commit b956334

Please sign in to comment.