summaryrefslogtreecommitdiff
path: root/usr.bin/tmux
diff options
context:
space:
mode:
authorNicholas Marriott <nicm@cvs.openbsd.org>2015-08-29 08:30:55 +0000
committerNicholas Marriott <nicm@cvs.openbsd.org>2015-08-29 08:30:55 +0000
commit1ce284cec8d97398f43fbf909e6b1c8ca6fd76c2 (patch)
treeee3365cd549bc21142f9c1c40b02f14256176c3e /usr.bin/tmux
parentb469585d2b4cd88122a021b5a82a63bc7d6ea7c0 (diff)
Move alerts onto events rather than checking every loop.
Diffstat (limited to 'usr.bin/tmux')
-rw-r--r--usr.bin/tmux/Makefile6
-rw-r--r--usr.bin/tmux/alerts.c (renamed from usr.bin/tmux/server-window.c)170
-rw-r--r--usr.bin/tmux/cmd-set-option.c4
-rw-r--r--usr.bin/tmux/input.c11
-rw-r--r--usr.bin/tmux/server.c7
-rw-r--r--usr.bin/tmux/session.c3
-rw-r--r--usr.bin/tmux/tmux.h13
-rw-r--r--usr.bin/tmux/window.c25
8 files changed, 158 insertions, 81 deletions
diff --git a/usr.bin/tmux/Makefile b/usr.bin/tmux/Makefile
index 6a16f399704..c36d581a227 100644
--- a/usr.bin/tmux/Makefile
+++ b/usr.bin/tmux/Makefile
@@ -1,7 +1,8 @@
-# $OpenBSD: Makefile,v 1.78 2015/04/27 16:25:57 nicm Exp $
+# $OpenBSD: Makefile,v 1.79 2015/08/29 08:30:54 nicm Exp $
PROG= tmux
-SRCS= arguments.c \
+SRCS= alerts.c \
+ arguments.c \
attributes.c \
cfg.c \
client.c \
@@ -101,7 +102,6 @@ SRCS= arguments.c \
screen.c \
server-client.c \
server-fn.c \
- server-window.c \
server.c \
session.c \
signal.c \
diff --git a/usr.bin/tmux/server-window.c b/usr.bin/tmux/alerts.c
index 191a1210696..baa5bb0d9b9 100644
--- a/usr.bin/tmux/server-window.c
+++ b/usr.bin/tmux/alerts.c
@@ -1,7 +1,7 @@
-/* $OpenBSD: server-window.c,v 1.39 2015/08/29 00:29:15 nicm Exp $ */
+/* $OpenBSD: alerts.c,v 1.1 2015/08/29 08:30:54 nicm Exp $ */
/*
- * Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
+ * Copyright (c) 2015 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
@@ -19,43 +19,133 @@
#include <sys/types.h>
#include <event.h>
-#include <stdlib.h>
-#include <unistd.h>
#include "tmux.h"
-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 *);
-void ring_bell(struct session *);
+int alerts_fired;
+
+void alerts_timer(int, short, void *);
+int alerts_enabled(struct window *, int);
+void alerts_callback(int, short, void *);
+void alerts_reset(struct window *);
+
+int alerts_check_bell(struct session *, struct winlink *);
+int alerts_check_activity(struct session *, struct winlink *);
+int alerts_check_silence(struct session *, struct winlink *);
+void alerts_ring_bell(struct session *);
+
+void
+alerts_timer(unused int fd, unused short events, void *arg)
+{
+ struct window *w = arg;
+
+ log_debug("@%u alerts timer expired", w->id);
+ alerts_reset(w);
+ alerts_queue(w, WINDOW_SILENCE);
+}
-/* Window functions that need to happen every loop. */
void
-server_window_loop(void)
+alerts_callback(unused int fd, unused short events, unused void *arg)
{
struct window *w;
struct session *s;
struct winlink *wl;
+ int flags, alerts;
RB_FOREACH(w, windows, &windows) {
RB_FOREACH(s, sessions, &sessions) {
RB_FOREACH(wl, winlinks, &s->windows) {
if (wl->window != w)
continue;
+ flags = w->flags;
- if (server_window_check_bell(s, wl) ||
- server_window_check_activity(s, wl) ||
- server_window_check_silence(s, wl))
+ 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);
+
+ log_debug("%s:%d @%u alerts check, alerts %#x, "
+ "flags %#x", s->name, wl->idx, w->id,
+ alerts, flags);
}
}
- check_window_name(w);
}
+ alerts_fired = 0;
}
-/* Check for bell in window. */
int
-server_window_check_bell(struct session *s, struct winlink *wl)
+alerts_enabled(struct window *w, int flags)
+{
+ struct session *s;
+
+ if (flags & WINDOW_ACTIVITY) {
+ if (options_get_number(&w->options, "monitor-activity"))
+ return (1);
+ }
+ if (flags & WINDOW_SILENCE) {
+ if (options_get_number(&w->options, "monitor-silence") != 0)
+ return (1);
+ }
+ if (~flags & WINDOW_BELL)
+ return (0);
+ RB_FOREACH(s, sessions, &sessions) {
+ if (!session_has(s, w))
+ continue;
+ if (options_get_number(&s->options, "bell-action") != BELL_NONE)
+ return (1);
+ }
+ return (0);
+}
+
+void
+alerts_reset_all(void)
+{
+ struct window *w;
+
+ RB_FOREACH(w, windows, &windows)
+ alerts_reset(w);
+}
+
+void
+alerts_reset(struct window *w)
+{
+ struct timeval tv;
+
+ w->flags &= ~WINDOW_SILENCE;
+ event_del(&w->alerts_timer);
+
+ timerclear(&tv);
+ tv.tv_sec = options_get_number(&w->options, "monitor-silence");
+
+ log_debug("@%u alerts timer reset %u", w->id, (u_int)tv.tv_sec);
+ if (tv.tv_sec != 0)
+ event_add(&w->alerts_timer, &tv);
+}
+
+void
+alerts_queue(struct window *w, int flags)
+{
+ if (!event_initialized(&w->alerts_timer))
+ evtimer_set(&w->alerts_timer, alerts_timer, w);
+
+ if (w->flags & flags)
+ return;
+ w->flags |= flags;
+ log_debug("@%u alerts flags added %#x", w->id, flags);
+
+ if (!alerts_fired && alerts_enabled(w, flags)) {
+ log_debug("alerts check queued (by @%u)", w->id);
+ event_once(-1, EV_TIMEOUT, alerts_callback, NULL, NULL);
+ alerts_fired = 1;
+ }
+
+ if (flags & WINDOW_ACTIVITY)
+ alerts_reset(w);
+}
+
+int
+alerts_check_bell(struct session *s, struct winlink *wl)
{
struct client *c;
struct window *w = wl->window;
@@ -70,10 +160,11 @@ server_window_check_bell(struct session *s, struct winlink *wl)
if (s->curw->window == w)
w->flags &= ~WINDOW_BELL;
- visual = options_get_number(&s->options, "visual-bell");
action = options_get_number(&s->options, "bell-action");
if (action == BELL_NONE)
return (0);
+
+ visual = options_get_number(&s->options, "visual-bell");
TAILQ_FOREACH(c, &clients, entry) {
if (c->session != s || c->flags & CLIENT_CONTROL)
continue;
@@ -93,12 +184,11 @@ server_window_check_bell(struct session *s, struct winlink *wl)
status_message_set(c, "Bell in window %d", wl->idx);
}
- return (1);
+ return (WINDOW_BELL);
}
-/* Check for activity in window. */
int
-server_window_check_activity(struct session *s, struct winlink *wl)
+alerts_check_activity(struct session *s, struct winlink *wl)
{
struct client *c;
struct window *w = wl->window;
@@ -115,7 +205,7 @@ server_window_check_activity(struct session *s, struct winlink *wl)
return (0);
if (options_get_number(&s->options, "bell-on-alert"))
- ring_bell(s);
+ alerts_ring_bell(s);
wl->flags |= WINLINK_ACTIVITY;
if (options_get_number(&s->options, "visual-activity")) {
@@ -126,45 +216,28 @@ server_window_check_activity(struct session *s, struct winlink *wl)
}
}
- return (1);
+ return (WINDOW_ACTIVITY);
}
-/* Check for silence in window. */
int
-server_window_check_silence(struct session *s, struct winlink *wl)
+alerts_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);
- if (s->curw == wl && !(s->flags & SESSION_UNATTACHED)) {
- /*
- * 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");
+ if (s->curw->window == w)
+ w->flags &= ~WINDOW_SILENCE;
+ if (!(w->flags & WINDOW_SILENCE) || wl->flags & WINLINK_SILENCE)
return (0);
- }
-
- silence_interval = options_get_number(&w->options, "monitor-silence");
- if (silence_interval == 0)
+ if (s->curw == wl && !(s->flags & SESSION_UNATTACHED))
return (0);
- if (gettimeofday(&timer, NULL) != 0)
- fatal("gettimeofday");
- timer_difference = timer.tv_sec - w->silence_timer.tv_sec;
- if (timer_difference <= silence_interval)
+ if (options_get_number(&w->options, "monitor-silence") == 0)
return (0);
if (options_get_number(&s->options, "bell-on-alert"))
- ring_bell(s);
+ alerts_ring_bell(s);
wl->flags |= WINLINK_SILENCE;
if (options_get_number(&s->options, "visual-silence")) {
@@ -175,12 +248,11 @@ server_window_check_silence(struct session *s, struct winlink *wl)
}
}
- return (1);
+ return (WINDOW_SILENCE);
}
-/* Ring terminal bell. */
void
-ring_bell(struct session *s)
+alerts_ring_bell(struct session *s)
{
struct client *c;
diff --git a/usr.bin/tmux/cmd-set-option.c b/usr.bin/tmux/cmd-set-option.c
index 78929028292..45b7ebc1f99 100644
--- a/usr.bin/tmux/cmd-set-option.c
+++ b/usr.bin/tmux/cmd-set-option.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: cmd-set-option.c,v 1.81 2015/08/29 00:29:15 nicm Exp $ */
+/* $OpenBSD: cmd-set-option.c,v 1.82 2015/08/29 08:30:54 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -186,6 +186,8 @@ cmd_set_option_exec(struct cmd *self, struct cmd_q *cmdq)
if (strcmp(oe->name, "status") == 0 ||
strcmp(oe->name, "status-interval") == 0)
status_timer_start_all();
+ if (strcmp(oe->name, "monitor-silence") == 0)
+ alerts_reset_all();
/* Update sizes and redraw. May not need it but meh. */
recalculate_sizes();
diff --git a/usr.bin/tmux/input.c b/usr.bin/tmux/input.c
index 5d8fa7f2f2d..979cee00325 100644
--- a/usr.bin/tmux/input.c
+++ b/usr.bin/tmux/input.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: input.c,v 1.82 2015/08/28 07:49:24 nicm Exp $ */
+/* $OpenBSD: input.c,v 1.83 2015/08/29 08:30:54 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -844,14 +844,9 @@ input_parse(struct window_pane *wp)
if (EVBUFFER_LENGTH(evb) == 0)
return;
+ window_update_activity(wp->window);
wp->flags |= PANE_CHANGED;
- wp->window->flags |= WINDOW_ACTIVITY;
- wp->window->flags &= ~WINDOW_SILENCE;
-
- if (gettimeofday(&wp->window->activity_time, NULL) != 0)
- fatal("gettimeofday failed");
-
/*
* Open the screen. Use NULL wp if there is a mode set as don't want to
* update the tty.
@@ -1081,7 +1076,7 @@ input_c0_dispatch(struct input_ctx *ictx)
case '\000': /* NUL */
break;
case '\007': /* BEL */
- wp->window->flags |= WINDOW_BELL;
+ alerts_queue(wp->window, WINDOW_BELL);
break;
case '\010': /* BS */
screen_write_backspace(sctx);
diff --git a/usr.bin/tmux/server.c b/usr.bin/tmux/server.c
index 25c255823cf..50fe4e1e03f 100644
--- a/usr.bin/tmux/server.c
+++ b/usr.bin/tmux/server.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: server.c,v 1.135 2015/08/28 13:21:25 nicm Exp $ */
+/* $OpenBSD: server.c,v 1.136 2015/08/29 08:30:54 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -249,10 +249,13 @@ server_start(int lockfd, char *lockfile)
void
server_loop(void)
{
+ struct window *w;
+
while (!server_should_shutdown()) {
event_loop(EVLOOP_ONCE);
- server_window_loop();
+ RB_FOREACH(w, windows, &windows)
+ check_window_name(w);
server_client_loop();
}
}
diff --git a/usr.bin/tmux/session.c b/usr.bin/tmux/session.c
index fb3b827dbd5..3c97aabf0db 100644
--- a/usr.bin/tmux/session.c
+++ b/usr.bin/tmux/session.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: session.c,v 1.53 2015/08/28 13:16:03 nicm Exp $ */
+/* $OpenBSD: session.c,v 1.54 2015/08/29 08:30:54 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -519,6 +519,7 @@ session_set_current(struct session *s, struct winlink *wl)
winlink_stack_push(&s->lastw, s->curw);
s->curw = wl;
winlink_clear_flags(wl);
+ window_update_activity(wl->window);
return (0);
}
diff --git a/usr.bin/tmux/tmux.h b/usr.bin/tmux/tmux.h
index a10dca96fd1..dd8721ae185 100644
--- a/usr.bin/tmux/tmux.h
+++ b/usr.bin/tmux/tmux.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: tmux.h,v 1.540 2015/08/29 00:29:15 nicm Exp $ */
+/* $OpenBSD: tmux.h,v 1.541 2015/08/29 08:30:54 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -874,7 +874,8 @@ struct window {
struct event name_event;
struct timeval name_time;
- struct timeval silence_timer;
+ struct event alerts_timer;
+
struct timeval activity_time;
struct window_pane *active;
@@ -1829,6 +1830,10 @@ void key_bindings_dispatch(struct key_binding *, struct client *,
int key_string_lookup_string(const char *);
const char *key_string_lookup_key(int);
+/* alerts.c */
+void alerts_reset_all(void);
+void alerts_queue(struct window *, int);
+
/* server.c */
extern struct clients clients;
extern struct clients dead_clients;
@@ -1856,9 +1861,6 @@ void server_client_callback(int, short, void *);
void server_client_status_timer(void);
void server_client_loop(void);
-/* server-window.c */
-void server_window_loop(void);
-
/* server-fn.c */
void server_fill_environ(struct session *, struct environ *);
void server_write_ready(struct client *);
@@ -2084,6 +2086,7 @@ void winlink_stack_push(struct winlink_stack *, struct winlink *);
void winlink_stack_remove(struct winlink_stack *, struct winlink *);
struct window *window_find_by_id_str(const char *);
struct window *window_find_by_id(u_int);
+void window_update_activity(struct window *);
struct window *window_create1(u_int, u_int);
struct window *window_create(const char *, int, char **, const char *,
const char *, int, struct environ *, struct termios *,
diff --git a/usr.bin/tmux/window.c b/usr.bin/tmux/window.c
index d9ec3d84922..758bfb3dcdc 100644
--- a/usr.bin/tmux/window.c
+++ b/usr.bin/tmux/window.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: window.c,v 1.142 2015/08/29 00:39:18 nicm Exp $ */
+/* $OpenBSD: window.c,v 1.143 2015/08/29 08:30:54 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -277,6 +277,13 @@ window_find_by_id(u_int id)
return (RB_FIND(windows, &windows, &w));
}
+void
+window_update_activity(struct window *w)
+{
+ gettimeofday(&w->activity_time, NULL);
+ alerts_queue(w, WINDOW_ACTIVITY);
+}
+
struct window *
window_create1(u_int sx, u_int sy)
{
@@ -295,9 +302,6 @@ window_create1(u_int sx, u_int sy)
w->sx = sx;
w->sy = sy;
- if (gettimeofday(&w->activity_time, NULL) != 0)
- fatal("gettimeofday failed");
-
options_init(&w->options, &global_w_options);
w->references = 0;
@@ -305,6 +309,8 @@ window_create1(u_int sx, u_int sy)
w->id = next_window_id++;
RB_INSERT(windows, &windows, w);
+ window_update_activity(w);
+
return (w);
}
@@ -350,6 +356,9 @@ window_destroy(struct window *w)
if (event_initialized(&w->name_event))
evtimer_del(&w->name_event);
+ if (event_initialized(&w->alerts_timer))
+ evtimer_del(&w->alerts_timer);
+
options_free(&w->options);
window_destroy_panes(w);
@@ -929,14 +938,6 @@ window_pane_read_callback(unused struct bufferevent *bufev, void *data)
input_parse(wp);
wp->pipe_off = EVBUFFER_LENGTH(evb);
-
- /*
- * If we get here, we're not outputting anymore, so set the silence
- * flag on the window.
- */
- wp->window->flags |= WINDOW_SILENCE;
- if (gettimeofday(&wp->window->silence_timer, NULL) != 0)
- fatal("gettimeofday failed");
return;
start_timer: