diff options
author | Nicholas Marriott <nicholas.marriott@gmail.com> | 2010-12-06 22:52:21 +0000 |
---|---|---|
committer | Nicholas Marriott <nicholas.marriott@gmail.com> | 2010-12-06 22:52:21 +0000 |
commit | 3a4f765a51fd7cf98d655dc5a63746a6121d0212 (patch) | |
tree | 725352590fa509f59fdc3c8d297c2b3b7a586b49 /server-window.c | |
parent | d0adcbc98a0261716c094c2e83c6d2eaa90a1c95 (diff) |
Add an option to alert (monitor) for silence (lack of activity) in a
window. From Thomas Adam.
Diffstat (limited to 'server-window.c')
-rw-r--r-- | server-window.c | 55 |
1 files changed, 53 insertions, 2 deletions
diff --git a/server-window.c b/server-window.c index a0d4e737..7f43a91e 100644 --- a/server-window.c +++ b/server-window.c @@ -1,4 +1,4 @@ -/* $Id: server-window.c,v 1.17 2010-08-11 22:16:03 tcunha Exp $ */ +/* $Id: server-window.c,v 1.18 2010-12-06 22:52:21 nicm Exp $ */ /* * Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net> @@ -26,6 +26,7 @@ int server_window_backoff(struct window_pane *); int server_window_check_bell(struct session *, struct winlink *); int server_window_check_activity(struct session *, struct winlink *); +int server_window_check_silence(struct session *, struct winlink *); int server_window_check_content( struct session *, struct winlink *, struct window_pane *); @@ -53,7 +54,8 @@ server_window_loop(void) continue; if (server_window_check_bell(s, wl) || - server_window_check_activity(s, wl)) + server_window_check_activity(s, wl) || + server_window_check_silence(s, wl)) server_status_session(s); TAILQ_FOREACH(wp, &w->panes, entry) server_window_check_content(s, wl, wp); @@ -151,6 +153,55 @@ server_window_check_activity(struct session *s, struct winlink *wl) return (1); } +/* Check for silence in window. */ +int +server_window_check_silence(struct session *s, struct winlink *wl) +{ + struct client *c; + struct window *w = wl->window; + struct timeval timer; + u_int i; + int silence_interval, timer_difference; + + if (!(w->flags & WINDOW_SILENCE) || wl->flags & WINLINK_SILENCE) + return (0); + + if (s->curw == wl) { + /* + * Reset the timer for this window if we've focused it. We + * don't want the timer tripping as soon as we've switched away + * from this window. + */ + if (gettimeofday(&w->silence_timer, NULL) != 0) + fatal("gettimeofday failed."); + + return (0); + } + + silence_interval = options_get_number(&w->options, "monitor-silence"); + if (silence_interval == 0) + return (0); + + if (gettimeofday(&timer, NULL) != 0) + fatal("gettimeofday"); + timer_difference = timer.tv_sec - w->silence_timer.tv_sec; + if (timer_difference <= silence_interval) + return (0); + wl->flags |= WINLINK_SILENCE; + + if (options_get_number(&s->options, "visual-silence")) { + for (i = 0; i < ARRAY_LENGTH(&clients); i++) { + c = ARRAY_ITEM(&clients, i); + if (c == NULL || c->session != s) + continue; + status_message_set(c, "Silence in window %u", + winlink_find_by_window(&s->windows, w)->idx); + } + } + + return (1); +} + /* Check for content change in window. */ int server_window_check_content( |