[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.37

1.37    ! nicm        1: /* $OpenBSD: server-window.c,v 1.36 2015/08/28 07:55:43 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:                }
1.37    ! nicm       52:                check_window_name(w);
1.1       nicm       53:        }
                     54: }
                     55:
                     56: /* Check for bell in window. */
                     57: int
1.15      nicm       58: server_window_check_bell(struct session *s, struct winlink *wl)
1.1       nicm       59: {
                     60:        struct client   *c;
1.15      nicm       61:        struct window   *w = wl->window;
1.1       nicm       62:        int              action, visual;
                     63:
1.15      nicm       64:        if (!(w->flags & WINDOW_BELL) || wl->flags & WINLINK_BELL)
                     65:                return (0);
1.23      nicm       66:        if (s->curw != wl || s->flags & SESSION_UNATTACHED)
1.16      nicm       67:                wl->flags |= WINLINK_BELL;
1.24      nicm       68:        if (s->flags & SESSION_UNATTACHED)
1.27      nicm       69:                return (0);
1.29      nicm       70:        if (s->curw->window == w)
1.25      nicm       71:                w->flags &= ~WINDOW_BELL;
1.1       nicm       72:
1.24      nicm       73:        visual = options_get_number(&s->options, "visual-bell");
1.1       nicm       74:        action = options_get_number(&s->options, "bell-action");
1.27      nicm       75:        if (action == BELL_NONE)
                     76:                return (0);
1.34      nicm       77:        TAILQ_FOREACH(c, &clients, entry) {
                     78:                if (c->session != s || c->flags & CLIENT_CONTROL)
1.24      nicm       79:                        continue;
                     80:                if (!visual) {
1.35      nicm       81:                        if ((action == BELL_CURRENT &&
                     82:                            c->session->curw->window == w) ||
                     83:                            (action == BELL_OTHER &&
                     84:                            c->session->curw->window != w) ||
                     85:                            action == BELL_ANY)
1.30      nicm       86:                                tty_bell(&c->tty);
1.24      nicm       87:                        continue;
1.1       nicm       88:                }
1.35      nicm       89:                if (action == BELL_CURRENT && c->session->curw->window == w)
1.1       nicm       90:                        status_message_set(c, "Bell in current window");
1.35      nicm       91:                else if (action == BELL_ANY || (action == BELL_OTHER &&
                     92:                    c->session->curw->window != w))
1.32      nicm       93:                        status_message_set(c, "Bell in window %d", wl->idx);
1.1       nicm       94:        }
                     95:
                     96:        return (1);
                     97: }
                     98:
                     99: /* Check for activity in window. */
                    100: int
1.15      nicm      101: server_window_check_activity(struct session *s, struct winlink *wl)
1.1       nicm      102: {
                    103:        struct client   *c;
1.15      nicm      104:        struct window   *w = wl->window;
1.1       nicm      105:
1.29      nicm      106:        if (s->curw->window == w)
1.25      nicm      107:                w->flags &= ~WINDOW_ACTIVITY;
                    108:
1.15      nicm      109:        if (!(w->flags & WINDOW_ACTIVITY) || wl->flags & WINLINK_ACTIVITY)
1.1       nicm      110:                return (0);
1.23      nicm      111:        if (s->curw == wl && !(s->flags & SESSION_UNATTACHED))
1.1       nicm      112:                return (0);
                    113:
1.13      nicm      114:        if (!options_get_number(&w->options, "monitor-activity"))
1.1       nicm      115:                return (0);
                    116:
1.21      nicm      117:        if (options_get_number(&s->options, "bell-on-alert"))
                    118:                ring_bell(s);
1.15      nicm      119:        wl->flags |= WINLINK_ACTIVITY;
1.1       nicm      120:
1.13      nicm      121:        if (options_get_number(&s->options, "visual-activity")) {
1.34      nicm      122:                TAILQ_FOREACH(c, &clients, entry) {
                    123:                        if (c->session != s)
1.1       nicm      124:                                continue;
1.32      nicm      125:                        status_message_set(c, "Activity in window %d", wl->idx);
1.18      nicm      126:                }
                    127:        }
                    128:
                    129:        return (1);
                    130: }
                    131:
                    132: /* Check for silence in window. */
                    133: int
                    134: server_window_check_silence(struct session *s, struct winlink *wl)
                    135: {
                    136:        struct client   *c;
                    137:        struct window   *w = wl->window;
                    138:        struct timeval   timer;
                    139:        int              silence_interval, timer_difference;
                    140:
                    141:        if (!(w->flags & WINDOW_SILENCE) || wl->flags & WINLINK_SILENCE)
                    142:                return (0);
                    143:
1.23      nicm      144:        if (s->curw == wl && !(s->flags & SESSION_UNATTACHED)) {
1.18      nicm      145:                /*
                    146:                 * Reset the timer for this window if we've focused it.  We
                    147:                 * don't want the timer tripping as soon as we've switched away
                    148:                 * from this window.
                    149:                 */
                    150:                if (gettimeofday(&w->silence_timer, NULL) != 0)
1.36      nicm      151:                        fatal("gettimeofday failed");
1.18      nicm      152:
                    153:                return (0);
                    154:        }
                    155:
                    156:        silence_interval = options_get_number(&w->options, "monitor-silence");
                    157:        if (silence_interval == 0)
                    158:                return (0);
                    159:
                    160:        if (gettimeofday(&timer, NULL) != 0)
                    161:                fatal("gettimeofday");
                    162:        timer_difference = timer.tv_sec - w->silence_timer.tv_sec;
                    163:        if (timer_difference <= silence_interval)
                    164:                return (0);
1.21      nicm      165:
                    166:        if (options_get_number(&s->options, "bell-on-alert"))
                    167:                ring_bell(s);
1.18      nicm      168:        wl->flags |= WINLINK_SILENCE;
                    169:
                    170:        if (options_get_number(&s->options, "visual-silence")) {
1.34      nicm      171:                TAILQ_FOREACH(c, &clients, entry) {
                    172:                        if (c->session != s)
1.18      nicm      173:                                continue;
1.32      nicm      174:                        status_message_set(c, "Silence in window %d", wl->idx);
1.1       nicm      175:                }
                    176:        }
                    177:
                    178:        return (1);
1.21      nicm      179: }
                    180:
                    181: /* Ring terminal bell. */
                    182: void
                    183: ring_bell(struct session *s)
                    184: {
                    185:        struct client   *c;
                    186:
1.34      nicm      187:        TAILQ_FOREACH(c, &clients, entry) {
                    188:                if (c->session == s && !(c->flags & CLIENT_CONTROL))
1.22      nicm      189:                        tty_bell(&c->tty);
1.21      nicm      190:        }
1.1       nicm      191: }