Hi all,

Please see the patch attahed which should implement "monitor-silence" and
other options, along the same lines as the monitor-activity options.  I've
also included man page updates.

Feedback welcome.  Any questions, just shout.

The patch is applied on top of the sourceforge CVS repository, but is also
available here for those tracking Git:

https://github.com/ThomasAdam/tmux/tree/ta/monitor-silence

Kindly,

-- Thomas Adam

-- 
"Deep in my heart I wish I was wrong.  But deep in my heart I know I am
not." -- Morrissey ("Girl Least Likely To" -- off of Viva Hate.)
? Session.vim
? b
? blank.conf
? client-path-fix.patch
? lock-clients.patch
? lock-improvements-3.patch
? lock-improvements.patch
? lock-improvements2.patch
? lock-manpage-changes.patch
? lock.patch
? monitor-silence.patch
? tmuxblank
Index: cmd-choose-window.c
===================================================================
RCS file: /cvsroot/tmux/tmux/cmd-choose-window.c,v
retrieving revision 1.22
diff -u -p -r1.22 cmd-choose-window.c
--- cmd-choose-window.c	22 Jun 2010 23:26:18 -0000	1.22
+++ cmd-choose-window.c	6 Dec 2010 21:00:30 -0000
@@ -87,6 +87,8 @@ cmd_choose_window_exec(struct cmd *self,
 			flag = '!';
 		else if (wm->flags & WINLINK_CONTENT)
 			flag = '+';
+		else if (wm->flags & WINLINK_SILENCE)
+			flag = '~';
 		else if (wm == s->curw)
 			flag = '*';
 		else if (wm == TAILQ_FIRST(&s->lastw))
Index: cmd-set-option.c
===================================================================
RCS file: /cvsroot/tmux/tmux/cmd-set-option.c,v
retrieving revision 1.100
diff -u -p -r1.100 cmd-set-option.c
--- cmd-set-option.c	9 Oct 2010 14:29:32 -0000	1.100
+++ cmd-set-option.c	6 Dec 2010 21:00:31 -0000
@@ -136,6 +136,7 @@ const struct set_option_entry set_sessio
 	{ "visual-activity", SET_OPTION_FLAG, 0, 0, NULL },
 	{ "visual-bell", SET_OPTION_FLAG, 0, 0, NULL },
 	{ "visual-content", SET_OPTION_FLAG, 0, 0, NULL },
+	{ "visual-silence", SET_OPTION_FLAG, 0, 0, NULL },
 	{ NULL, 0, 0, 0, NULL }
 };
 
@@ -157,6 +158,8 @@ const struct set_option_entry set_window
 	{ "mode-mouse", SET_OPTION_FLAG, 0, 0, NULL },
 	{ "monitor-activity", SET_OPTION_FLAG, 0, 0, NULL },
 	{ "monitor-content", SET_OPTION_STRING, 0, 0, NULL },
+	{ "monitor-silence",SET_OPTION_FLAG, 0, 0, NULL},
+	{ "monitor-silence-interval", SET_OPTION_NUMBER, 0, INT_MAX, NULL },
 	{ "remain-on-exit", SET_OPTION_FLAG, 0, 0, NULL },
 	{ "synchronize-panes", SET_OPTION_FLAG, 0, 0, NULL },
 	{ "utf8", SET_OPTION_FLAG, 0, 0, NULL },
Index: input.c
===================================================================
RCS file: /cvsroot/tmux/tmux/input.c,v
retrieving revision 1.109
diff -u -p -r1.109 input.c
--- input.c	18 Apr 2010 15:11:47 -0000	1.109
+++ input.c	6 Dec 2010 21:00:31 -0000
@@ -681,7 +681,9 @@ input_parse(struct window_pane *wp)
 
 	if (EVBUFFER_LENGTH(evb) == 0)
 		return;
+
 	wp->window->flags |= WINDOW_ACTIVITY;
+	wp->window->flags &= ~WINDOW_SILENCE;
 
 	/*
 	 * Open the screen. Use NULL wp if there is a mode set as don't want to
Index: server-window.c
===================================================================
RCS file: /cvsroot/tmux/tmux/server-window.c,v
retrieving revision 1.17
diff -u -p -r1.17 server-window.c
--- server-window.c	11 Aug 2010 22:16:03 -0000	1.17
+++ server-window.c	6 Dec 2010 21:00:31 -0000
@@ -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,63 @@ server_window_check_activity(struct sess
 	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;
+	int		 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);
+	}
+
+	if (!options_get_number(&w->options, "monitor-silence"))
+		return (0);
+
+	if (gettimeofday(&timer, NULL) != 0)
+		fatal("gettimeofday");
+
+	silence_interval = options_get_number(
+		&w->options, "monitor-silence-interval");
+
+	timer_difference = timer.tv_sec - w->silence_timer.tv_sec;
+
+	if (silence_interval == 0)
+		return (0);
+
+	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(
Index: status.c
===================================================================
RCS file: /cvsroot/tmux/tmux/status.c,v
retrieving revision 1.149
diff -u -p -r1.149 status.c
--- status.c	22 Jun 2010 23:26:18 -0000	1.149
+++ status.c	6 Dec 2010 21:00:31 -0000
@@ -395,6 +395,8 @@ status_replace1(struct client *c,struct 
 			tmp[0] = '!';
 		else if (wl->flags & WINLINK_ACTIVITY)
 			tmp[0] = '#';
+		else if (wl->flags & WINLINK_SILENCE)
+			tmp[0] = '~';
 		else if (wl == s->curw)
 			tmp[0] = '*';
 		else if (wl == TAILQ_FIRST(&s->lastw))
Index: tmux.1
===================================================================
RCS file: /cvsroot/tmux/tmux/tmux.1,v
retrieving revision 1.269
diff -u -p -r1.269 tmux.1
--- tmux.1	24 Oct 2010 01:34:30 -0000	1.269
+++ tmux.1	6 Dec 2010 21:00:32 -0000
@@ -2044,6 +2044,14 @@ display a message when content is presen
 for which the
 .Ic monitor-content
 window option is enabled.
+.It Xo Ic visual-silence
+.Op Ic on | off
+.Xc
+If
+.Ic monitor-silence
+is enabled, prints a message after the
+.Ic monitor-silence-interval
+option has expired on a given window.
 .El
 .It Xo Ic set-window-option
 .Op Fl agu
@@ -2159,6 +2167,20 @@ pattern
 .Ar match-string
 appears in the window, it is highlighted in the status line.
 .Pp
+.It Xo Ic monitor-silence
+.Op Ic on | off
+.Xc
+Monitor for silence in the window, after the given
+.Ic monitor-silence-interval
+has elapsed.  
+Windows with silence are highlighted in the status line.
+.Pp
+.It Ic monitor-silence-interval Ar interval
+Set the timeout (in seconds) after which if no output happens in the given
+window, silence is flagged.  See the
+.Ic monitor-silence
+option.
+.Pp
 .It Xo Ic remain-on-exit
 .Op Ic on | off
 .Xc
Index: tmux.c
===================================================================
RCS file: /cvsroot/tmux/tmux/tmux.c,v
retrieving revision 1.221
diff -u -p -r1.221 tmux.c
--- tmux.c	24 Oct 2010 19:54:41 -0000	1.221
+++ tmux.c	6 Dec 2010 21:00:32 -0000
@@ -380,6 +380,7 @@ main(int argc, char **argv)
 	options_set_number(so, "visual-activity", 0);
 	options_set_number(so, "visual-bell", 0);
 	options_set_number(so, "visual-content", 0);
+	options_set_number(so, "visual-silence", 0);
 
 	keylist = xmalloc(sizeof *keylist);
 	ARRAY_INIT(keylist);
@@ -404,6 +405,8 @@ main(int argc, char **argv)
 	options_set_number(wo, "mode-mouse", 0);
 	options_set_number(wo, "monitor-activity", 0);
 	options_set_string(wo, "monitor-content", "%s", "");
+	options_set_number(wo, "monitor-silence", 0);
+	options_set_number(wo, "monitor-silence-interval", 5);
 	options_set_number(wo, "window-status-attr", 0);
 	options_set_number(wo, "window-status-bg", 8);
 	options_set_number(wo, "window-status-current-attr", 0);
Index: tmux.h
===================================================================
RCS file: /cvsroot/tmux/tmux/tmux.h,v
retrieving revision 1.581
diff -u -p -r1.581 tmux.h
--- tmux.h	24 Oct 2010 01:34:30 -0000	1.581
+++ tmux.h	6 Dec 2010 21:00:33 -0000
@@ -828,6 +828,7 @@ TAILQ_HEAD(window_panes, window_pane);
 struct window {
 	char		*name;
 	struct event	 name_timer;
+	struct timeval   silence_timer;
 
 	struct window_pane *active;
 	struct window_pane *last;
@@ -844,6 +845,7 @@ struct window {
 #define WINDOW_HIDDEN 0x2
 #define WINDOW_ACTIVITY 0x4
 #define WINDOW_REDRAW 0x8
+#define WINDOW_SILENCE 0x10
 
 	struct options	 options;
 
@@ -864,7 +866,8 @@ struct winlink {
 #define WINLINK_BELL 0x1
 #define WINLINK_ACTIVITY 0x2
 #define WINLINK_CONTENT 0x4
-#define WINLINK_ALERTFLAGS (WINLINK_BELL|WINLINK_ACTIVITY|WINLINK_CONTENT)
+#define WINLINK_SILENCE 0x8
+#define WINLINK_ALERTFLAGS (WINLINK_BELL|WINLINK_ACTIVITY|WINLINK_CONTENT|WINLINK_SILENCE)
 
 	RB_ENTRY(winlink) entry;
 	TAILQ_ENTRY(winlink) sentry;
Index: window.c
===================================================================
RCS file: /cvsroot/tmux/tmux/window.c,v
retrieving revision 1.140
diff -u -p -r1.140 window.c
--- window.c	24 Oct 2010 01:34:30 -0000	1.140
+++ window.c	6 Dec 2010 21:00:33 -0000
@@ -634,6 +634,13 @@ window_pane_read_callback(unused struct 
 	input_parse(wp);
 
 	wp->pipe_off = EVBUFFER_LENGTH(wp->event->input);
+
+	/* If we get here, we're not outputting anymore, so ensure we set the
+	 * silence flag on the window.
+	 */
+	wp->window->flags |= WINDOW_SILENCE;
+	if (gettimeofday(&wp->window->silence_timer, NULL) != 0)
+		fatal("gettimeofday failed.");
 }
 
 /* ARGSUSED */
------------------------------------------------------------------------------
What happens now with your Lotus Notes apps - do you make another costly 
upgrade, or settle for being marooned without product support? Time to move
off Lotus Notes and onto the cloud with Force.com, apps are easier to build,
use, and manage than apps on traditional platforms. Sign up for the Lotus 
Notes Migration Kit to learn more. http://p.sf.net/sfu/salesforce-d2d
_______________________________________________
tmux-users mailing list
tmux-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/tmux-users

Reply via email to