Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 262 lines (224 sloc) 6.917 kB
0f2e336 @orebokech Import upstream snapshot from SVN r2670
orebokech authored
1 /* $Id: server-window.c 2665 2012-01-21 19:30:07Z tcunha $ */
8fade26 Imported Upstream version 1.1
Karl Ferdinand Ebert authored
2
3 /*
4 * Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
5 *
6 * Permission to use, copy, modify, and distribute this software for any
7 * purpose with or without fee is hereby granted, provided that the above
8 * copyright notice and this permission notice appear in all copies.
9 *
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
15 * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
16 * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 */
18
19 #include <sys/types.h>
20
dda8e8e @kfebert Imported Upstream version 1.2
kfebert authored
21 #include <event.h>
8fade26 Imported Upstream version 1.1
Karl Ferdinand Ebert authored
22 #include <unistd.h>
23
24 #include "tmux.h"
25
fb53a63 @kfebert Imported Upstream version 1.3
kfebert authored
26 int server_window_check_bell(struct session *, struct winlink *);
27 int server_window_check_activity(struct session *, struct winlink *);
77c63de @orebokech Import upstream version 1.4
orebokech authored
28 int server_window_check_silence(struct session *, struct winlink *);
8fade26 Imported Upstream version 1.1
Karl Ferdinand Ebert authored
29 int server_window_check_content(
fb53a63 @kfebert Imported Upstream version 1.3
kfebert authored
30 struct session *, struct winlink *, struct window_pane *);
7216c39 @kfebert Imported Upstream version 1.5
kfebert authored
31 void ring_bell(struct session *);
8fade26 Imported Upstream version 1.1
Karl Ferdinand Ebert authored
32
33 /* Window functions that need to happen every loop. */
34 void
35 server_window_loop(void)
36 {
37 struct window *w;
fb53a63 @kfebert Imported Upstream version 1.3
kfebert authored
38 struct winlink *wl;
8fade26 Imported Upstream version 1.1
Karl Ferdinand Ebert authored
39 struct window_pane *wp;
40 struct session *s;
77c63de @orebokech Import upstream version 1.4
orebokech authored
41 u_int i;
8fade26 Imported Upstream version 1.1
Karl Ferdinand Ebert authored
42
43 for (i = 0; i < ARRAY_LENGTH(&windows); i++) {
44 w = ARRAY_ITEM(&windows, i);
45 if (w == NULL)
46 continue;
47
77c63de @orebokech Import upstream version 1.4
orebokech authored
48 RB_FOREACH(s, sessions, &sessions) {
fb53a63 @kfebert Imported Upstream version 1.3
kfebert authored
49 wl = session_has(s, w);
50 if (wl == NULL)
8fade26 Imported Upstream version 1.1
Karl Ferdinand Ebert authored
51 continue;
dda8e8e @kfebert Imported Upstream version 1.2
kfebert authored
52
fb53a63 @kfebert Imported Upstream version 1.3
kfebert authored
53 if (server_window_check_bell(s, wl) ||
77c63de @orebokech Import upstream version 1.4
orebokech authored
54 server_window_check_activity(s, wl) ||
55 server_window_check_silence(s, wl))
8fade26 Imported Upstream version 1.1
Karl Ferdinand Ebert authored
56 server_status_session(s);
57 TAILQ_FOREACH(wp, &w->panes, entry)
fb53a63 @kfebert Imported Upstream version 1.3
kfebert authored
58 server_window_check_content(s, wl, wp);
0f2e336 @orebokech Import upstream snapshot from SVN r2670
orebokech authored
59
60 if (!(s->flags & SESSION_UNATTACHED))
61 w->flags &= ~(WINDOW_BELL|WINDOW_ACTIVITY);
8fade26 Imported Upstream version 1.1
Karl Ferdinand Ebert authored
62 }
63 }
64 }
65
66 /* Check for bell in window. */
67 int
fb53a63 @kfebert Imported Upstream version 1.3
kfebert authored
68 server_window_check_bell(struct session *s, struct winlink *wl)
8fade26 Imported Upstream version 1.1
Karl Ferdinand Ebert authored
69 {
70 struct client *c;
fb53a63 @kfebert Imported Upstream version 1.3
kfebert authored
71 struct window *w = wl->window;
8fade26 Imported Upstream version 1.1
Karl Ferdinand Ebert authored
72 u_int i;
73 int action, visual;
74
fb53a63 @kfebert Imported Upstream version 1.3
kfebert authored
75 if (!(w->flags & WINDOW_BELL) || wl->flags & WINLINK_BELL)
8fade26 Imported Upstream version 1.1
Karl Ferdinand Ebert authored
76 return (0);
0f2e336 @orebokech Import upstream snapshot from SVN r2670
orebokech authored
77 if (s->curw != wl || s->flags & SESSION_UNATTACHED)
77c63de @orebokech Import upstream version 1.4
orebokech authored
78 wl->flags |= WINLINK_BELL;
8fade26 Imported Upstream version 1.1
Karl Ferdinand Ebert authored
79
80 action = options_get_number(&s->options, "bell-action");
81 switch (action) {
82 case BELL_ANY:
83 if (s->flags & SESSION_UNATTACHED)
84 break;
85 visual = options_get_number(&s->options, "visual-bell");
86 for (i = 0; i < ARRAY_LENGTH(&clients); i++) {
87 c = ARRAY_ITEM(&clients, i);
88 if (c == NULL || c->session != s)
89 continue;
90 if (!visual) {
b016948 @orebokech Import upstream snapshot from SVN r2608
orebokech authored
91 tty_bell(&c->tty);
8fade26 Imported Upstream version 1.1
Karl Ferdinand Ebert authored
92 continue;
93 }
dda8e8e @kfebert Imported Upstream version 1.2
kfebert authored
94 if (c->session->curw->window == w) {
8fade26 Imported Upstream version 1.1
Karl Ferdinand Ebert authored
95 status_message_set(c, "Bell in current window");
96 continue;
97 }
98 status_message_set(c, "Bell in window %u",
99 winlink_find_by_window(&s->windows, w)->idx);
100 }
101 break;
102 case BELL_CURRENT:
103 if (s->flags & SESSION_UNATTACHED)
104 break;
105 visual = options_get_number(&s->options, "visual-bell");
106 for (i = 0; i < ARRAY_LENGTH(&clients); i++) {
107 c = ARRAY_ITEM(&clients, i);
108 if (c == NULL || c->session != s)
109 continue;
dda8e8e @kfebert Imported Upstream version 1.2
kfebert authored
110 if (c->session->curw->window != w)
8fade26 Imported Upstream version 1.1
Karl Ferdinand Ebert authored
111 continue;
112 if (!visual) {
b016948 @orebokech Import upstream snapshot from SVN r2608
orebokech authored
113 tty_bell(&c->tty);
8fade26 Imported Upstream version 1.1
Karl Ferdinand Ebert authored
114 continue;
115 }
116 status_message_set(c, "Bell in current window");
117 }
118 break;
119 }
120
121 return (1);
122 }
123
124 /* Check for activity in window. */
125 int
fb53a63 @kfebert Imported Upstream version 1.3
kfebert authored
126 server_window_check_activity(struct session *s, struct winlink *wl)
8fade26 Imported Upstream version 1.1
Karl Ferdinand Ebert authored
127 {
128 struct client *c;
fb53a63 @kfebert Imported Upstream version 1.3
kfebert authored
129 struct window *w = wl->window;
8fade26 Imported Upstream version 1.1
Karl Ferdinand Ebert authored
130 u_int i;
131
fb53a63 @kfebert Imported Upstream version 1.3
kfebert authored
132 if (!(w->flags & WINDOW_ACTIVITY) || wl->flags & WINLINK_ACTIVITY)
8fade26 Imported Upstream version 1.1
Karl Ferdinand Ebert authored
133 return (0);
0f2e336 @orebokech Import upstream snapshot from SVN r2670
orebokech authored
134 if (s->curw == wl && !(s->flags & SESSION_UNATTACHED))
8fade26 Imported Upstream version 1.1
Karl Ferdinand Ebert authored
135 return (0);
136
dda8e8e @kfebert Imported Upstream version 1.2
kfebert authored
137 if (!options_get_number(&w->options, "monitor-activity"))
8fade26 Imported Upstream version 1.1
Karl Ferdinand Ebert authored
138 return (0);
139
7216c39 @kfebert Imported Upstream version 1.5
kfebert authored
140 if (options_get_number(&s->options, "bell-on-alert"))
141 ring_bell(s);
fb53a63 @kfebert Imported Upstream version 1.3
kfebert authored
142 wl->flags |= WINLINK_ACTIVITY;
8fade26 Imported Upstream version 1.1
Karl Ferdinand Ebert authored
143
dda8e8e @kfebert Imported Upstream version 1.2
kfebert authored
144 if (options_get_number(&s->options, "visual-activity")) {
8fade26 Imported Upstream version 1.1
Karl Ferdinand Ebert authored
145 for (i = 0; i < ARRAY_LENGTH(&clients); i++) {
146 c = ARRAY_ITEM(&clients, i);
147 if (c == NULL || c->session != s)
148 continue;
149 status_message_set(c, "Activity in window %u",
77c63de @orebokech Import upstream version 1.4
orebokech authored
150 winlink_find_by_window(&s->windows, w)->idx);
151 }
152 }
153
154 return (1);
155 }
156
157 /* Check for silence in window. */
158 int
159 server_window_check_silence(struct session *s, struct winlink *wl)
160 {
161 struct client *c;
162 struct window *w = wl->window;
163 struct timeval timer;
164 u_int i;
165 int silence_interval, timer_difference;
166
167 if (!(w->flags & WINDOW_SILENCE) || wl->flags & WINLINK_SILENCE)
168 return (0);
169
0f2e336 @orebokech Import upstream snapshot from SVN r2670
orebokech authored
170 if (s->curw == wl && !(s->flags & SESSION_UNATTACHED)) {
77c63de @orebokech Import upstream version 1.4
orebokech authored
171 /*
172 * Reset the timer for this window if we've focused it. We
173 * don't want the timer tripping as soon as we've switched away
174 * from this window.
175 */
176 if (gettimeofday(&w->silence_timer, NULL) != 0)
177 fatal("gettimeofday failed.");
178
179 return (0);
180 }
181
182 silence_interval = options_get_number(&w->options, "monitor-silence");
183 if (silence_interval == 0)
184 return (0);
185
186 if (gettimeofday(&timer, NULL) != 0)
187 fatal("gettimeofday");
188 timer_difference = timer.tv_sec - w->silence_timer.tv_sec;
189 if (timer_difference <= silence_interval)
190 return (0);
7216c39 @kfebert Imported Upstream version 1.5
kfebert authored
191
192 if (options_get_number(&s->options, "bell-on-alert"))
193 ring_bell(s);
77c63de @orebokech Import upstream version 1.4
orebokech authored
194 wl->flags |= WINLINK_SILENCE;
195
196 if (options_get_number(&s->options, "visual-silence")) {
197 for (i = 0; i < ARRAY_LENGTH(&clients); i++) {
198 c = ARRAY_ITEM(&clients, i);
199 if (c == NULL || c->session != s)
200 continue;
201 status_message_set(c, "Silence in window %u",
8fade26 Imported Upstream version 1.1
Karl Ferdinand Ebert authored
202 winlink_find_by_window(&s->windows, w)->idx);
203 }
204 }
205
206 return (1);
207 }
208
209 /* Check for content change in window. */
210 int
211 server_window_check_content(
fb53a63 @kfebert Imported Upstream version 1.3
kfebert authored
212 struct session *s, struct winlink *wl, struct window_pane *wp)
8fade26 Imported Upstream version 1.1
Karl Ferdinand Ebert authored
213 {
214 struct client *c;
fb53a63 @kfebert Imported Upstream version 1.3
kfebert authored
215 struct window *w = wl->window;
8fade26 Imported Upstream version 1.1
Karl Ferdinand Ebert authored
216 u_int i;
217 char *found, *ptr;
dda8e8e @kfebert Imported Upstream version 1.2
kfebert authored
218
fb53a63 @kfebert Imported Upstream version 1.3
kfebert authored
219 /* Activity flag must be set for new content. */
220 if (!(w->flags & WINDOW_ACTIVITY) || wl->flags & WINLINK_CONTENT)
8fade26 Imported Upstream version 1.1
Karl Ferdinand Ebert authored
221 return (0);
0f2e336 @orebokech Import upstream snapshot from SVN r2670
orebokech authored
222 if (s->curw == wl && !(s->flags & SESSION_UNATTACHED))
8fade26 Imported Upstream version 1.1
Karl Ferdinand Ebert authored
223 return (0);
224
225 ptr = options_get_string(&w->options, "monitor-content");
226 if (ptr == NULL || *ptr == '\0')
227 return (0);
228 if ((found = window_pane_search(wp, ptr, NULL)) == NULL)
229 return (0);
dda8e8e @kfebert Imported Upstream version 1.2
kfebert authored
230 xfree(found);
8fade26 Imported Upstream version 1.1
Karl Ferdinand Ebert authored
231
7216c39 @kfebert Imported Upstream version 1.5
kfebert authored
232 if (options_get_number(&s->options, "bell-on-alert"))
233 ring_bell(s);
fb53a63 @kfebert Imported Upstream version 1.3
kfebert authored
234 wl->flags |= WINLINK_CONTENT;
235
dda8e8e @kfebert Imported Upstream version 1.2
kfebert authored
236 if (options_get_number(&s->options, "visual-content")) {
8fade26 Imported Upstream version 1.1
Karl Ferdinand Ebert authored
237 for (i = 0; i < ARRAY_LENGTH(&clients); i++) {
238 c = ARRAY_ITEM(&clients, i);
239 if (c == NULL || c->session != s)
240 continue;
241 status_message_set(c, "Content in window %u",
242 winlink_find_by_window(&s->windows, w)->idx);
243 }
244 }
245
246 return (1);
247 }
7216c39 @kfebert Imported Upstream version 1.5
kfebert authored
248
249 /* Ring terminal bell. */
250 void
251 ring_bell(struct session *s)
252 {
253 struct client *c;
254 u_int i;
255
256 for (i = 0; i < ARRAY_LENGTH(&clients); i++) {
257 c = ARRAY_ITEM(&clients, i);
258 if (c != NULL && c->session == s)
b016948 @orebokech Import upstream snapshot from SVN r2608
orebokech authored
259 tty_bell(&c->tty);
7216c39 @kfebert Imported Upstream version 1.5
kfebert authored
260 }
261 }
Something went wrong with that request. Please try again.