2009-10-22 21:41:51 +02:00
|
|
|
/* $OpenBSD$ */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
|
|
|
|
*
|
|
|
|
* Permission to use, copy, modify, and distribute this software for any
|
|
|
|
* purpose with or without fee is hereby granted, provided that the above
|
|
|
|
* copyright notice and this permission notice appear in all copies.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
|
|
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
|
|
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
|
|
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
|
|
* WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
|
|
|
|
* IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
|
2009-11-04 21:50:11 +01:00
|
|
|
#include <event.h>
|
2012-07-10 13:53:01 +02:00
|
|
|
#include <stdlib.h>
|
2009-10-22 21:41:51 +02:00
|
|
|
#include <unistd.h>
|
|
|
|
|
|
|
|
#include "tmux.h"
|
|
|
|
|
2010-06-21 03:27:46 +02:00
|
|
|
int server_window_check_bell(struct session *, struct winlink *);
|
|
|
|
int server_window_check_activity(struct session *, struct winlink *);
|
2010-12-06 23:51:02 +01:00
|
|
|
int server_window_check_silence(struct session *, struct winlink *);
|
2011-07-03 21:07:54 +02:00
|
|
|
void ring_bell(struct session *);
|
2009-10-22 21:41:51 +02:00
|
|
|
|
|
|
|
/* Window functions that need to happen every loop. */
|
|
|
|
void
|
|
|
|
server_window_loop(void)
|
|
|
|
{
|
2014-04-17 09:36:45 +02:00
|
|
|
struct window *w;
|
|
|
|
struct session *s;
|
2015-04-22 17:30:11 +02:00
|
|
|
struct winlink *wl;
|
2009-10-22 21:41:51 +02:00
|
|
|
|
2015-04-22 17:30:11 +02:00
|
|
|
RB_FOREACH(w, windows, &windows) {
|
2010-12-21 23:37:59 +01:00
|
|
|
RB_FOREACH(s, sessions, &sessions) {
|
2015-04-22 17:30:11 +02:00
|
|
|
RB_FOREACH(wl, winlinks, &s->windows) {
|
|
|
|
if (wl->window != w)
|
|
|
|
continue;
|
2009-12-03 23:50:09 +01:00
|
|
|
|
2015-04-22 17:30:11 +02:00
|
|
|
if (server_window_check_bell(s, wl) ||
|
|
|
|
server_window_check_activity(s, wl) ||
|
|
|
|
server_window_check_silence(s, wl))
|
|
|
|
server_status_session(s);
|
|
|
|
}
|
2009-10-22 21:41:51 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Check for bell in window. */
|
|
|
|
int
|
2010-06-21 03:27:46 +02:00
|
|
|
server_window_check_bell(struct session *s, struct winlink *wl)
|
2009-10-22 21:41:51 +02:00
|
|
|
{
|
|
|
|
struct client *c;
|
2010-06-21 03:27:46 +02:00
|
|
|
struct window *w = wl->window;
|
2009-10-22 21:41:51 +02:00
|
|
|
int action, visual;
|
|
|
|
|
2010-06-21 03:27:46 +02:00
|
|
|
if (!(w->flags & WINDOW_BELL) || wl->flags & WINLINK_BELL)
|
2009-10-22 21:41:51 +02:00
|
|
|
return (0);
|
2012-01-21 07:13:16 +01:00
|
|
|
if (s->curw != wl || s->flags & SESSION_UNATTACHED)
|
2010-07-19 23:13:03 +02:00
|
|
|
wl->flags |= WINLINK_BELL;
|
2012-06-18 12:58:44 +02:00
|
|
|
if (s->flags & SESSION_UNATTACHED)
|
2012-10-25 13:16:53 +02:00
|
|
|
return (0);
|
2014-02-14 13:44:45 +01:00
|
|
|
if (s->curw->window == w)
|
2012-07-08 09:27:32 +02:00
|
|
|
w->flags &= ~WINDOW_BELL;
|
2009-10-22 21:41:51 +02:00
|
|
|
|
2012-06-18 12:58:44 +02:00
|
|
|
visual = options_get_number(&s->options, "visual-bell");
|
2009-10-22 21:41:51 +02:00
|
|
|
action = options_get_number(&s->options, "bell-action");
|
2012-10-25 13:16:53 +02:00
|
|
|
if (action == BELL_NONE)
|
|
|
|
return (0);
|
2015-04-25 01:17:11 +02:00
|
|
|
TAILQ_FOREACH(c, &clients, entry) {
|
|
|
|
if (c->session != s || c->flags & CLIENT_CONTROL)
|
2012-06-18 12:58:44 +02:00
|
|
|
continue;
|
|
|
|
if (!visual) {
|
2014-04-02 19:14:24 +02:00
|
|
|
if (c->session->curw->window == w || action == BELL_ANY)
|
|
|
|
tty_bell(&c->tty);
|
2012-06-18 12:58:44 +02:00
|
|
|
continue;
|
2009-10-22 21:41:51 +02:00
|
|
|
}
|
2012-06-18 12:58:44 +02:00
|
|
|
if (c->session->curw->window == w)
|
2009-10-22 21:41:51 +02:00
|
|
|
status_message_set(c, "Bell in current window");
|
2014-02-14 13:44:45 +01:00
|
|
|
else if (action == BELL_ANY)
|
2015-03-31 19:45:10 +02:00
|
|
|
status_message_set(c, "Bell in window %d", wl->idx);
|
2009-10-22 21:41:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Check for activity in window. */
|
|
|
|
int
|
2010-06-21 03:27:46 +02:00
|
|
|
server_window_check_activity(struct session *s, struct winlink *wl)
|
2009-10-22 21:41:51 +02:00
|
|
|
{
|
|
|
|
struct client *c;
|
2010-06-21 03:27:46 +02:00
|
|
|
struct window *w = wl->window;
|
2009-10-22 21:41:51 +02:00
|
|
|
|
2014-02-14 13:44:45 +01:00
|
|
|
if (s->curw->window == w)
|
2012-07-08 09:27:32 +02:00
|
|
|
w->flags &= ~WINDOW_ACTIVITY;
|
|
|
|
|
2010-06-21 03:27:46 +02:00
|
|
|
if (!(w->flags & WINDOW_ACTIVITY) || wl->flags & WINLINK_ACTIVITY)
|
2009-10-22 21:41:51 +02:00
|
|
|
return (0);
|
2012-01-21 07:13:16 +01:00
|
|
|
if (s->curw == wl && !(s->flags & SESSION_UNATTACHED))
|
2009-10-22 21:41:51 +02:00
|
|
|
return (0);
|
|
|
|
|
2009-12-03 23:50:09 +01:00
|
|
|
if (!options_get_number(&w->options, "monitor-activity"))
|
2009-10-22 21:41:51 +02:00
|
|
|
return (0);
|
|
|
|
|
2011-07-03 21:07:54 +02:00
|
|
|
if (options_get_number(&s->options, "bell-on-alert"))
|
|
|
|
ring_bell(s);
|
2010-06-21 03:27:46 +02:00
|
|
|
wl->flags |= WINLINK_ACTIVITY;
|
2009-10-22 21:41:51 +02:00
|
|
|
|
2009-12-03 23:50:09 +01:00
|
|
|
if (options_get_number(&s->options, "visual-activity")) {
|
2015-04-25 01:17:11 +02:00
|
|
|
TAILQ_FOREACH(c, &clients, entry) {
|
|
|
|
if (c->session != s)
|
2009-10-22 21:41:51 +02:00
|
|
|
continue;
|
2015-03-31 19:45:10 +02:00
|
|
|
status_message_set(c, "Activity in window %d", wl->idx);
|
2010-12-06 23:51:02 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
int silence_interval, timer_difference;
|
|
|
|
|
|
|
|
if (!(w->flags & WINDOW_SILENCE) || wl->flags & WINLINK_SILENCE)
|
|
|
|
return (0);
|
|
|
|
|
2012-01-21 07:13:16 +01:00
|
|
|
if (s->curw == wl && !(s->flags & SESSION_UNATTACHED)) {
|
2010-12-06 23:51:02 +01:00
|
|
|
/*
|
|
|
|
* 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);
|
2011-07-03 21:07:54 +02:00
|
|
|
|
|
|
|
if (options_get_number(&s->options, "bell-on-alert"))
|
|
|
|
ring_bell(s);
|
2010-12-06 23:51:02 +01:00
|
|
|
wl->flags |= WINLINK_SILENCE;
|
|
|
|
|
|
|
|
if (options_get_number(&s->options, "visual-silence")) {
|
2015-04-25 01:17:11 +02:00
|
|
|
TAILQ_FOREACH(c, &clients, entry) {
|
|
|
|
if (c->session != s)
|
2010-12-06 23:51:02 +01:00
|
|
|
continue;
|
2015-03-31 19:45:10 +02:00
|
|
|
status_message_set(c, "Silence in window %d", wl->idx);
|
2009-10-22 21:41:51 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
|
2011-07-03 21:07:54 +02:00
|
|
|
/* Ring terminal bell. */
|
|
|
|
void
|
|
|
|
ring_bell(struct session *s)
|
|
|
|
{
|
|
|
|
struct client *c;
|
|
|
|
|
2015-04-25 01:17:11 +02:00
|
|
|
TAILQ_FOREACH(c, &clients, entry) {
|
|
|
|
if (c->session == s && !(c->flags & CLIENT_CONTROL))
|
2011-08-24 11:58:44 +02:00
|
|
|
tty_bell(&c->tty);
|
2011-07-03 21:07:54 +02:00
|
|
|
}
|
|
|
|
}
|