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

Annotation of src/usr.bin/tmux/notify.c, Revision 1.10

1.10    ! nicm        1: /* $OpenBSD: notify.c,v 1.9 2016/10/10 21:29:23 nicm Exp $ */
1.1       nicm        2:
                      3: /*
                      4:  * Copyright (c) 2012 George Nachman <tmux@georgester.com>
                      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:
1.2       nicm       19: #include <sys/types.h>
                     20: #include <sys/queue.h>
                     21:
                     22: #include <stdlib.h>
                     23:
1.1       nicm       24: #include "tmux.h"
                     25:
1.2       nicm       26: enum notify_type {
                     27:        NOTIFY_WINDOW_LAYOUT_CHANGED,
                     28:        NOTIFY_WINDOW_UNLINKED,
                     29:        NOTIFY_WINDOW_LINKED,
                     30:        NOTIFY_WINDOW_RENAMED,
                     31:        NOTIFY_ATTACHED_SESSION_CHANGED,
                     32:        NOTIFY_SESSION_RENAMED,
                     33:        NOTIFY_SESSION_CREATED,
                     34:        NOTIFY_SESSION_CLOSED
                     35: };
                     36:
                     37: struct notify_entry {
                     38:        enum notify_type         type;
                     39:
                     40:        struct client           *client;
                     41:        struct session          *session;
                     42:        struct window           *window;
                     43:
                     44:        TAILQ_ENTRY(notify_entry) entry;
                     45: };
1.9       nicm       46: TAILQ_HEAD(notify_queue, notify_entry);
                     47: static struct notify_queue notify_queue = TAILQ_HEAD_INITIALIZER(notify_queue);
                     48:
                     49: static void    notify_add(enum notify_type, struct client *, struct session *,
                     50:                    struct window *);
1.2       nicm       51:
1.9       nicm       52: static void
1.2       nicm       53: notify_add(enum notify_type type, struct client *c, struct session *s,
                     54:     struct window *w)
                     55: {
                     56:        struct notify_entry     *ne;
                     57:
                     58:        ne = xcalloc(1, sizeof *ne);
                     59:        ne->type = type;
                     60:        ne->client = c;
                     61:        ne->session = s;
                     62:        ne->window = w;
                     63:        TAILQ_INSERT_TAIL(&notify_queue, ne, entry);
                     64:
                     65:        if (c != NULL)
                     66:                c->references++;
                     67:        if (s != NULL)
                     68:                s->references++;
                     69:        if (w != NULL)
                     70:                w->references++;
                     71: }
                     72:
1.10    ! nicm       73: void
1.2       nicm       74: notify_drain(void)
                     75: {
                     76:        struct notify_entry     *ne, *ne1;
                     77:
                     78:        TAILQ_FOREACH_SAFE(ne, &notify_queue, entry, ne1) {
                     79:                switch (ne->type) {
                     80:                case NOTIFY_WINDOW_LAYOUT_CHANGED:
1.4       nicm       81:                        control_notify_window_layout_changed(ne->window);
1.2       nicm       82:                        break;
                     83:                case NOTIFY_WINDOW_UNLINKED:
1.4       nicm       84:                        control_notify_window_unlinked(ne->session, ne->window);
1.2       nicm       85:                        break;
                     86:                case NOTIFY_WINDOW_LINKED:
1.4       nicm       87:                        control_notify_window_linked(ne->session, ne->window);
1.2       nicm       88:                        break;
                     89:                case NOTIFY_WINDOW_RENAMED:
1.4       nicm       90:                        control_notify_window_renamed(ne->window);
1.2       nicm       91:                        break;
                     92:                case NOTIFY_ATTACHED_SESSION_CHANGED:
1.4       nicm       93:                        control_notify_attached_session_changed(ne->client);
1.2       nicm       94:                        break;
                     95:                case NOTIFY_SESSION_RENAMED:
1.4       nicm       96:                        control_notify_session_renamed(ne->session);
1.2       nicm       97:                        break;
                     98:                case NOTIFY_SESSION_CREATED:
1.4       nicm       99:                        control_notify_session_created(ne->session);
1.2       nicm      100:                        break;
                    101:                case NOTIFY_SESSION_CLOSED:
1.4       nicm      102:                        control_notify_session_close(ne->session);
1.2       nicm      103:                        break;
                    104:                }
                    105:
                    106:                if (ne->client != NULL)
1.7       nicm      107:                        server_client_unref(ne->client);
1.2       nicm      108:                if (ne->session != NULL)
1.8       nicm      109:                        session_unref(ne->session);
1.2       nicm      110:                if (ne->window != NULL)
1.3       nicm      111:                        window_remove_ref(ne->window);
                    112:
1.2       nicm      113:                TAILQ_REMOVE(&notify_queue, ne, entry);
                    114:                free(ne);
1.5       nicm      115:        }
                    116: }
                    117:
                    118: void
                    119: notify_input(struct window_pane *wp, struct evbuffer *input)
                    120: {
                    121:        struct client   *c;
                    122:
1.6       nicm      123:        TAILQ_FOREACH(c, &clients, entry) {
                    124:                if (c->flags & CLIENT_CONTROL)
1.5       nicm      125:                        control_notify_input(c, wp, input);
1.2       nicm      126:        }
                    127: }
                    128:
1.1       nicm      129: void
1.2       nicm      130: notify_window_layout_changed(struct window *w)
1.1       nicm      131: {
1.2       nicm      132:        notify_add(NOTIFY_WINDOW_LAYOUT_CHANGED, NULL, NULL, w);
                    133:        notify_drain();
1.1       nicm      134: }
                    135:
                    136: void
1.2       nicm      137: notify_window_unlinked(struct session *s, struct window *w)
1.1       nicm      138: {
1.2       nicm      139:        notify_add(NOTIFY_WINDOW_UNLINKED, NULL, s, w);
                    140:        notify_drain();
1.1       nicm      141: }
                    142:
                    143: void
1.2       nicm      144: notify_window_linked(struct session *s, struct window *w)
1.1       nicm      145: {
1.2       nicm      146:        notify_add(NOTIFY_WINDOW_LINKED, NULL, s, w);
                    147:        notify_drain();
1.1       nicm      148: }
                    149:
                    150: void
1.2       nicm      151: notify_window_renamed(struct window *w)
1.1       nicm      152: {
1.2       nicm      153:        notify_add(NOTIFY_WINDOW_RENAMED, NULL, NULL, w);
                    154:        notify_drain();
1.1       nicm      155: }
                    156:
                    157: void
1.2       nicm      158: notify_attached_session_changed(struct client *c)
1.1       nicm      159: {
1.2       nicm      160:        notify_add(NOTIFY_ATTACHED_SESSION_CHANGED, c, NULL, NULL);
                    161:        notify_drain();
1.1       nicm      162: }
                    163:
                    164: void
1.2       nicm      165: notify_session_renamed(struct session *s)
1.1       nicm      166: {
1.2       nicm      167:        notify_add(NOTIFY_SESSION_RENAMED, NULL, s, NULL);
                    168:        notify_drain();
1.1       nicm      169: }
                    170:
                    171: void
1.2       nicm      172: notify_session_created(struct session *s)
1.1       nicm      173: {
1.2       nicm      174:        notify_add(NOTIFY_SESSION_CREATED, NULL, s, NULL);
                    175:        notify_drain();
1.1       nicm      176: }
                    177:
                    178: void
1.2       nicm      179: notify_session_closed(struct session *s)
1.1       nicm      180: {
1.2       nicm      181:        notify_add(NOTIFY_SESSION_CLOSED, NULL, s, NULL);
                    182:        notify_drain();
1.1       nicm      183: }