4 * Copyright (c) 2012 George Nachman <tmux@georgester.com>
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>
20 #include <sys/queue.h>
27 NOTIFY_WINDOW_LAYOUT_CHANGED
,
28 NOTIFY_WINDOW_UNLINKED
,
30 NOTIFY_WINDOW_RENAMED
,
31 NOTIFY_ATTACHED_SESSION_CHANGED
,
32 NOTIFY_SESSION_RENAMED
,
33 NOTIFY_SESSION_CREATED
,
38 enum notify_type type
;
40 struct client
*client
;
41 struct session
*session
;
42 struct window
*window
;
44 TAILQ_ENTRY(notify_entry
) entry
;
46 TAILQ_HEAD(, notify_entry
) notify_queue
= TAILQ_HEAD_INITIALIZER(notify_queue
);
47 int notify_enabled
= 1;
49 void notify_drain(void);
50 void notify_add(enum notify_type
, struct client
*, struct session
*,
67 notify_add(enum notify_type type
, struct client
*c
, struct session
*s
,
70 struct notify_entry
*ne
;
72 ne
= xcalloc(1, sizeof *ne
);
77 TAILQ_INSERT_TAIL(¬ify_queue
, ne
, entry
);
90 struct notify_entry
*ne
, *ne1
;
95 TAILQ_FOREACH_SAFE(ne
, ¬ify_queue
, entry
, ne1
) {
97 case NOTIFY_WINDOW_LAYOUT_CHANGED
:
98 control_notify_window_layout_changed(ne
->window
);
100 case NOTIFY_WINDOW_UNLINKED
:
101 control_notify_window_unlinked(ne
->session
, ne
->window
);
103 case NOTIFY_WINDOW_LINKED
:
104 control_notify_window_linked(ne
->session
, ne
->window
);
106 case NOTIFY_WINDOW_RENAMED
:
107 control_notify_window_renamed(ne
->window
);
109 case NOTIFY_ATTACHED_SESSION_CHANGED
:
110 control_notify_attached_session_changed(ne
->client
);
112 case NOTIFY_SESSION_RENAMED
:
113 control_notify_session_renamed(ne
->session
);
115 case NOTIFY_SESSION_CREATED
:
116 control_notify_session_created(ne
->session
);
118 case NOTIFY_SESSION_CLOSED
:
119 control_notify_session_close(ne
->session
);
123 if (ne
->client
!= NULL
)
124 ne
->client
->references
--;
125 if (ne
->session
!= NULL
)
126 ne
->session
->references
--;
127 if (ne
->window
!= NULL
)
128 window_remove_ref(ne
->window
);
130 TAILQ_REMOVE(¬ify_queue
, ne
, entry
);
136 notify_input(struct window_pane
*wp
, struct evbuffer
*input
)
142 * notify_input() is not queued and only does anything when
143 * notifications are enabled.
148 for (i
= 0; i
< ARRAY_LENGTH(&clients
); i
++) {
149 c
= ARRAY_ITEM(&clients
, i
);
150 if (c
!= NULL
&& (c
->flags
& CLIENT_CONTROL
))
151 control_notify_input(c
, wp
, input
);
156 notify_window_layout_changed(struct window
*w
)
158 notify_add(NOTIFY_WINDOW_LAYOUT_CHANGED
, NULL
, NULL
, w
);
163 notify_window_unlinked(struct session
*s
, struct window
*w
)
165 notify_add(NOTIFY_WINDOW_UNLINKED
, NULL
, s
, w
);
170 notify_window_linked(struct session
*s
, struct window
*w
)
172 notify_add(NOTIFY_WINDOW_LINKED
, NULL
, s
, w
);
177 notify_window_renamed(struct window
*w
)
179 notify_add(NOTIFY_WINDOW_RENAMED
, NULL
, NULL
, w
);
184 notify_attached_session_changed(struct client
*c
)
186 notify_add(NOTIFY_ATTACHED_SESSION_CHANGED
, c
, NULL
, NULL
);
191 notify_session_renamed(struct session
*s
)
193 notify_add(NOTIFY_SESSION_RENAMED
, NULL
, s
, NULL
);
198 notify_session_created(struct session
*s
)
200 notify_add(NOTIFY_SESSION_CREATED
, NULL
, s
, NULL
);
205 notify_session_closed(struct session
*s
)
207 notify_add(NOTIFY_SESSION_CLOSED
, NULL
, s
, NULL
);