[BACK]Return to server-window.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / tmux

Annotation of src/usr.bin/tmux/server-window.c, Revision 1.34

1.34    ! nicm        1: /* $OpenBSD: server-window.c,v 1.33 2015/04/22 15:30:11 nicm Exp $ */
1.1       nicm        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:
1.5       nicm       21: #include <event.h>
1.26      nicm       22: #include <stdlib.h>
1.1       nicm       23: #include <unistd.h>
                     24:
                     25: #include "tmux.h"
                     26:
1.15      nicm       27: int    server_window_check_bell(struct session *, struct winlink *);
                     28: int    server_window_check_activity(struct session *, struct winlink *);
1.18      nicm       29: int    server_window_check_silence(struct session *, struct winlink *);
1.21      nicm       30: void   ring_bell(struct session *);
1.2       nicm       31:
1.1       nicm       32: /* Window functions that need to happen every loop. */
                     33: void
                     34: server_window_loop(void)
                     35: {
1.31      nicm       36:        struct window   *w;
1.33      nicm       37:        struct session  *s;
1.31      nicm       38:        struct winlink  *wl;
1.1       nicm       39:
1.33      nicm       40:        RB_FOREACH(w, windows, &windows) {
1.19      nicm       41:                RB_FOREACH(s, sessions, &sessions) {
1.33      nicm       42:                        RB_FOREACH(wl, winlinks, &s->windows) {
                     43:                                if (wl->window != w)
                     44:                                        continue;
                     45:
                     46:                                if (server_window_check_bell(s, wl) ||
                     47:                                    server_window_check_activity(s, wl) ||
                     48:                                    server_window_check_silence(s, wl))
                     49:                                        server_status_session(s);
                     50:                        }
1.1       nicm       51:                }
                     52:        }
                     53: }
                     54:
                     55: /* Check for bell in window. */
                     56: int
1.15      nicm       57: server_window_check_bell(struct session *s, struct winlink *wl)
1.1       nicm       58: {
                     59:        struct client   *c;
1.15      nicm       60:        struct window   *w = wl->window;
1.1       nicm       61:        int              action, visual;
                     62:
1.15      nicm       63:        if (!(w->flags & WINDOW_BELL) || wl->flags & WINLINK_BELL)
                     64:                return (0);
1.23      nicm       65:        if (s->curw != wl || s->flags & SESSION_UNATTACHED)
1.16      nicm       66:                wl->flags |= WINLINK_BELL;
1.24      nicm       67:        if (s->flags & SESSION_UNATTACHED)
1.27      nicm       68:                return (0);
1.29      nicm       69:        if (s->curw->window == w)
1.25      nicm       70:                w->flags &= ~WINDOW_BELL;
1.1       nicm       71:
1.24      nicm       72:        visual = options_get_number(&s->options, "visual-bell");
1.1       nicm       73:        action = options_get_number(&s->options, "bell-action");
1.27      nicm       74:        if (action == BELL_NONE)
                     75:                return (0);
1.34    ! nicm       76:        TAILQ_FOREACH(c, &clients, entry) {
        !            77:                if (c->session != s || c->flags & CLIENT_CONTROL)
1.24      nicm       78:                        continue;
                     79:                if (!visual) {
1.30      nicm       80:                        if (c->session->curw->window == w || action == BELL_ANY)
                     81:                                tty_bell(&c->tty);
1.24      nicm       82:                        continue;
1.1       nicm       83:                }
1.24      nicm       84:                if (c->session->curw->window == w)
1.1       nicm       85:                        status_message_set(c, "Bell in current window");
1.29      nicm       86:                else if (action == BELL_ANY)
1.32      nicm       87:                        status_message_set(c, "Bell in window %d", wl->idx);
1.1       nicm       88:        }
                     89:
                     90:        return (1);
                     91: }
                     92:
                     93: /* Check for activity in window. */
                     94: int
1.15      nicm       95: server_window_check_activity(struct session *s, struct winlink *wl)
1.1       nicm       96: {
                     97:        struct client   *c;
1.15      nicm       98:        struct window   *w = wl->window;
1.1       nicm       99:
1.29      nicm      100:        if (s->curw->window == w)
1.25      nicm      101:                w->flags &= ~WINDOW_ACTIVITY;
                    102:
1.15      nicm      103:        if (!(w->flags & WINDOW_ACTIVITY) || wl->flags & WINLINK_ACTIVITY)
1.1       nicm      104:                return (0);
1.23      nicm      105:        if (s->curw == wl && !(s->flags & SESSION_UNATTACHED))
1.1       nicm      106:                return (0);
                    107:
1.13      nicm      108:        if (!options_get_number(&w->options, "monitor-activity"))
1.1       nicm      109:                return (0);
                    110:
1.21      nicm      111:        if (options_get_number(&s->options, "bell-on-alert"))
                    112:                ring_bell(s);
1.15      nicm      113:        wl->flags |= WINLINK_ACTIVITY;
1.1       nicm      114:
1.13      nicm      115:        if (options_get_number(&s->options, "visual-activity")) {
1.34    ! nicm      116:                TAILQ_FOREACH(c, &clients, entry) {
        !           117:                        if (c->session != s)
1.1       nicm      118:                                continue;
1.32      nicm      119:                        status_message_set(c, "Activity in window %d", wl->idx);
1.18      nicm      120:                }
                    121:        }
                    122:
                    123:        return (1);
                    124: }
                    125:
                    126: /* Check for silence in window. */
                    127: int
                    128: server_window_check_silence(struct session *s, struct winlink *wl)
                    129: {
                    130:        struct client   *c;
                    131:        struct window   *w = wl->window;
                    132:        struct timeval   timer;
                    133:        int              silence_interval, timer_difference;
                    134:
                    135:        if (!(w->flags & WINDOW_SILENCE) || wl->flags & WINLINK_SILENCE)
                    136:                return (0);
                    137:
1.23      nicm      138:        if (s->curw == wl && !(s->flags & SESSION_UNATTACHED)) {
1.18      nicm      139:                /*
                    140:                 * Reset the timer for this window if we've focused it.  We
                    141:                 * don't want the timer tripping as soon as we've switched away
                    142:                 * from this window.
                    143:                 */
                    144:                if (gettimeofday(&w->silence_timer, NULL) != 0)
                    145:                        fatal("gettimeofday failed.");
                    146:
                    147:                return (0);
                    148:        }
                    149:
                    150:        silence_interval = options_get_number(&w->options, "monitor-silence");
                    151:        if (silence_interval == 0)
                    152:                return (0);
                    153:
                    154:        if (gettimeofday(&timer, NULL) != 0)
                    155:                fatal("gettimeofday");
                    156:        timer_difference = timer.tv_sec - w->silence_timer.tv_sec;
                    157:        if (timer_difference <= silence_interval)
                    158:                return (0);
1.21      nicm      159:
                    160:        if (options_get_number(&s->options, "bell-on-alert"))
                    161:                ring_bell(s);
1.18      nicm      162:        wl->flags |= WINLINK_SILENCE;
                    163:
                    164:        if (options_get_number(&s->options, "visual-silence")) {
1.34    ! nicm      165:                TAILQ_FOREACH(c, &clients, entry) {
        !           166:                        if (c->session != s)
1.18      nicm      167:                                continue;
1.32      nicm      168:                        status_message_set(c, "Silence in window %d", wl->idx);
1.1       nicm      169:                }
                    170:        }
                    171:
                    172:        return (1);
1.21      nicm      173: }
                    174:
                    175: /* Ring terminal bell. */
                    176: void
                    177: ring_bell(struct session *s)
                    178: {
                    179:        struct client   *c;
                    180:
1.34    ! nicm      181:        TAILQ_FOREACH(c, &clients, entry) {
        !           182:                if (c->session == s && !(c->flags & CLIENT_CONTROL))
1.22      nicm      183:                        tty_bell(&c->tty);
1.21      nicm      184:        }
1.1       nicm      185: }