4 * Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
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.
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.
19 #include <sys/types.h>
26 int server_window_backoff(struct window_pane
*);
27 int server_window_check_bell(struct session
*, struct winlink
*);
28 int server_window_check_activity(struct session
*, struct winlink
*);
29 int server_window_check_content(
30 struct session
*, struct winlink
*, struct window_pane
*);
32 /* Check if this window should suspend reading. */
34 server_window_backoff(struct window_pane
*wp
)
39 if (!window_pane_visible(wp
))
42 for (i
= 0; i
< ARRAY_LENGTH(&clients
); i
++) {
43 c
= ARRAY_ITEM(&clients
, i
);
44 if (c
== NULL
|| c
->session
== NULL
)
46 if ((c
->flags
& (CLIENT_SUSPENDED
|CLIENT_DEAD
)) != 0)
48 if (c
->session
->curw
->window
!= wp
->window
)
51 if (EVBUFFER_LENGTH(c
->tty
.event
->output
) > BACKOFF_THRESHOLD
)
57 /* Window functions that need to happen every loop. */
59 server_window_loop(void)
63 struct window_pane
*wp
;
67 for (i
= 0; i
< ARRAY_LENGTH(&windows
); i
++) {
68 w
= ARRAY_ITEM(&windows
, i
);
72 TAILQ_FOREACH(wp
, &w
->panes
, entry
) {
75 if (!(wp
->flags
& PANE_FREEZE
)) {
76 if (server_window_backoff(wp
))
77 bufferevent_disable(wp
->event
, EV_READ
);
79 bufferevent_enable(wp
->event
, EV_READ
);
83 for (j
= 0; j
< ARRAY_LENGTH(&sessions
); j
++) {
84 s
= ARRAY_ITEM(&sessions
, j
);
87 wl
= session_has(s
, w
);
91 if (server_window_check_bell(s
, wl
) ||
92 server_window_check_activity(s
, wl
))
93 server_status_session(s
);
94 TAILQ_FOREACH(wp
, &w
->panes
, entry
)
95 server_window_check_content(s
, wl
, wp
);
97 w
->flags
&= ~(WINDOW_BELL
|WINDOW_ACTIVITY
);
101 /* Check for bell in window. */
103 server_window_check_bell(struct session
*s
, struct winlink
*wl
)
106 struct window
*w
= wl
->window
;
110 if (!(w
->flags
& WINDOW_BELL
) || wl
->flags
& WINLINK_BELL
)
113 wl
->flags
|= WINLINK_BELL
;
115 action
= options_get_number(&s
->options
, "bell-action");
118 if (s
->flags
& SESSION_UNATTACHED
)
120 visual
= options_get_number(&s
->options
, "visual-bell");
121 for (i
= 0; i
< ARRAY_LENGTH(&clients
); i
++) {
122 c
= ARRAY_ITEM(&clients
, i
);
123 if (c
== NULL
|| c
->session
!= s
)
126 tty_putcode(&c
->tty
, TTYC_BEL
);
129 if (c
->session
->curw
->window
== w
) {
130 status_message_set(c
, "Bell in current window");
133 status_message_set(c
, "Bell in window %u",
134 winlink_find_by_window(&s
->windows
, w
)->idx
);
138 if (s
->flags
& SESSION_UNATTACHED
)
140 visual
= options_get_number(&s
->options
, "visual-bell");
141 for (i
= 0; i
< ARRAY_LENGTH(&clients
); i
++) {
142 c
= ARRAY_ITEM(&clients
, i
);
143 if (c
== NULL
|| c
->session
!= s
)
145 if (c
->session
->curw
->window
!= w
)
148 tty_putcode(&c
->tty
, TTYC_BEL
);
151 status_message_set(c
, "Bell in current window");
159 /* Check for activity in window. */
161 server_window_check_activity(struct session
*s
, struct winlink
*wl
)
164 struct window
*w
= wl
->window
;
167 if (!(w
->flags
& WINDOW_ACTIVITY
) || wl
->flags
& WINLINK_ACTIVITY
)
172 if (!options_get_number(&w
->options
, "monitor-activity"))
175 wl
->flags
|= WINLINK_ACTIVITY
;
177 if (options_get_number(&s
->options
, "visual-activity")) {
178 for (i
= 0; i
< ARRAY_LENGTH(&clients
); i
++) {
179 c
= ARRAY_ITEM(&clients
, i
);
180 if (c
== NULL
|| c
->session
!= s
)
182 status_message_set(c
, "Activity in window %u",
183 winlink_find_by_window(&s
->windows
, w
)->idx
);
190 /* Check for content change in window. */
192 server_window_check_content(
193 struct session
*s
, struct winlink
*wl
, struct window_pane
*wp
)
196 struct window
*w
= wl
->window
;
200 /* Activity flag must be set for new content. */
201 if (!(w
->flags
& WINDOW_ACTIVITY
) || wl
->flags
& WINLINK_CONTENT
)
206 ptr
= options_get_string(&w
->options
, "monitor-content");
207 if (ptr
== NULL
|| *ptr
== '\0')
209 if ((found
= window_pane_search(wp
, ptr
, NULL
)) == NULL
)
213 wl
->flags
|= WINLINK_CONTENT
;
215 if (options_get_number(&s
->options
, "visual-content")) {
216 for (i
= 0; i
< ARRAY_LENGTH(&clients
); i
++) {
217 c
= ARRAY_ITEM(&clients
, i
);
218 if (c
== NULL
|| c
->session
!= s
)
220 status_message_set(c
, "Content in window %u",
221 winlink_find_by_window(&s
->windows
, w
)->idx
);