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>
26 NOTIFY_WINDOW_LAYOUT_CHANGED
,
27 NOTIFY_WINDOW_UNLINKED
,
29 NOTIFY_WINDOW_RENAMED
,
30 NOTIFY_ATTACHED_SESSION_CHANGED
,
31 NOTIFY_SESSION_RENAMED
,
32 NOTIFY_SESSION_CREATED
,
37 enum notify_type type
;
39 struct client
*client
;
40 struct session
*session
;
41 struct window
*window
;
43 TAILQ_ENTRY(notify_entry
) entry
;
45 TAILQ_HEAD(, notify_entry
) notify_queue
= TAILQ_HEAD_INITIALIZER(notify_queue
);
46 int notify_enabled
= 1;
48 void notify_drain(void);
49 void notify_add(enum notify_type
, struct client
*, struct session
*,
66 notify_add(enum notify_type type
, struct client
*c
, struct session
*s
,
69 struct notify_entry
*ne
;
71 ne
= xcalloc(1, sizeof *ne
);
76 TAILQ_INSERT_TAIL(¬ify_queue
, ne
, entry
);
89 struct notify_entry
*ne
, *ne1
;
94 TAILQ_FOREACH_SAFE(ne
, ¬ify_queue
, entry
, ne1
) {
96 case NOTIFY_WINDOW_LAYOUT_CHANGED
:
97 control_notify_window_layout_changed(ne
->window
);
99 case NOTIFY_WINDOW_UNLINKED
:
100 control_notify_window_unlinked(ne
->session
, ne
->window
);
102 case NOTIFY_WINDOW_LINKED
:
103 control_notify_window_linked(ne
->session
, ne
->window
);
105 case NOTIFY_WINDOW_RENAMED
:
106 control_notify_window_renamed(ne
->window
);
108 case NOTIFY_ATTACHED_SESSION_CHANGED
:
109 control_notify_attached_session_changed(ne
->client
);
111 case NOTIFY_SESSION_RENAMED
:
112 control_notify_session_renamed(ne
->session
);
114 case NOTIFY_SESSION_CREATED
:
115 control_notify_session_created(ne
->session
);
117 case NOTIFY_SESSION_CLOSED
:
118 control_notify_session_close(ne
->session
);
122 if (ne
->client
!= NULL
)
123 ne
->client
->references
--;
124 if (ne
->session
!= NULL
)
125 ne
->session
->references
--;
126 if (ne
->window
!= NULL
)
127 window_remove_ref(ne
->window
);
129 TAILQ_REMOVE(¬ify_queue
, ne
, entry
);
135 notify_input(struct window_pane
*wp
, struct evbuffer
*input
)
141 * notify_input() is not queued and only does anything when
142 * notifications are enabled.
147 for (i
= 0; i
< ARRAY_LENGTH(&clients
); i
++) {
148 c
= ARRAY_ITEM(&clients
, i
);
149 if (c
!= NULL
&& (c
->flags
& CLIENT_CONTROL
))
150 control_notify_input(c
, wp
, input
);
155 notify_window_layout_changed(struct window
*w
)
157 notify_add(NOTIFY_WINDOW_LAYOUT_CHANGED
, NULL
, NULL
, w
);
162 notify_window_unlinked(struct session
*s
, struct window
*w
)
164 notify_add(NOTIFY_WINDOW_UNLINKED
, NULL
, s
, w
);
169 notify_window_linked(struct session
*s
, struct window
*w
)
171 notify_add(NOTIFY_WINDOW_LINKED
, NULL
, s
, w
);
176 notify_window_renamed(struct window
*w
)
178 notify_add(NOTIFY_WINDOW_RENAMED
, NULL
, NULL
, w
);
183 notify_attached_session_changed(struct client
*c
)
185 notify_add(NOTIFY_ATTACHED_SESSION_CHANGED
, c
, NULL
, NULL
);
190 notify_session_renamed(struct session
*s
)
192 notify_add(NOTIFY_SESSION_RENAMED
, NULL
, s
, NULL
);
197 notify_session_created(struct session
*s
)
199 notify_add(NOTIFY_SESSION_CREATED
, NULL
, s
, NULL
);
204 notify_session_closed(struct session
*s
)
206 notify_add(NOTIFY_SESSION_CLOSED
, NULL
, s
, NULL
);