4 * Copyright (c) 2012 Nicholas Marriott <nicholas.marriott@gmail.com>
5 * Copyright (c) 2012 George Nachman <tmux@georgester.com>
7 * Permission to use, copy, modify, and distribute this software for any
8 * purpose with or without fee is hereby granted, provided that the above
9 * copyright notice and this permission notice appear in all copies.
11 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15 * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
16 * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
17 * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
20 #include <sys/types.h>
26 #define CONTROL_SHOULD_NOTIFY_CLIENT(c) \
27 ((c) != NULL && ((c)->flags & CLIENT_CONTROL))
30 control_notify_pane_mode_changed(int pane
)
34 TAILQ_FOREACH(c
, &clients
, entry
) {
35 if (!CONTROL_SHOULD_NOTIFY_CLIENT(c
))
38 control_write(c
, "%%pane-mode-changed %%%u", pane
);
43 control_notify_window_layout_changed(struct window
*w
)
51 template = "%layout-change #{window_id} #{window_layout} "
52 "#{window_visible_layout} #{window_raw_flags}";
54 TAILQ_FOREACH(c
, &clients
, entry
) {
55 if (!CONTROL_SHOULD_NOTIFY_CLIENT(c
) || c
->session
== NULL
)
59 if (winlink_find_by_window_id(&s
->windows
, w
->id
) == NULL
)
63 * When the last pane in a window is closed it won't have a
64 * layout root and we don't need to inform the client about the
65 * layout change because the whole window will go away soon.
67 if (w
->layout_root
== NULL
)
70 wl
= winlink_find_by_window(&s
->windows
, w
);
72 cp
= format_single(NULL
, template, c
, NULL
, wl
, NULL
);
73 control_write(c
, "%s", cp
);
80 control_notify_window_pane_changed(struct window
*w
)
84 TAILQ_FOREACH(c
, &clients
, entry
) {
85 if (!CONTROL_SHOULD_NOTIFY_CLIENT(c
))
88 control_write(c
, "%%window-pane-changed @%u %%%u", w
->id
,
94 control_notify_window_unlinked(__unused
struct session
*s
, struct window
*w
)
99 TAILQ_FOREACH(c
, &clients
, entry
) {
100 if (!CONTROL_SHOULD_NOTIFY_CLIENT(c
) || c
->session
== NULL
)
104 if (winlink_find_by_window_id(&cs
->windows
, w
->id
) != NULL
)
105 control_write(c
, "%%window-close @%u", w
->id
);
107 control_write(c
, "%%unlinked-window-close @%u", w
->id
);
112 control_notify_window_linked(__unused
struct session
*s
, struct window
*w
)
117 TAILQ_FOREACH(c
, &clients
, entry
) {
118 if (!CONTROL_SHOULD_NOTIFY_CLIENT(c
) || c
->session
== NULL
)
122 if (winlink_find_by_window_id(&cs
->windows
, w
->id
) != NULL
)
123 control_write(c
, "%%window-add @%u", w
->id
);
125 control_write(c
, "%%unlinked-window-add @%u", w
->id
);
130 control_notify_window_renamed(struct window
*w
)
135 TAILQ_FOREACH(c
, &clients
, entry
) {
136 if (!CONTROL_SHOULD_NOTIFY_CLIENT(c
) || c
->session
== NULL
)
140 if (winlink_find_by_window_id(&cs
->windows
, w
->id
) != NULL
) {
141 control_write(c
, "%%window-renamed @%u %s", w
->id
,
144 control_write(c
, "%%unlinked-window-renamed @%u %s",
151 control_notify_client_session_changed(struct client
*cc
)
156 if (cc
->session
== NULL
)
160 TAILQ_FOREACH(c
, &clients
, entry
) {
161 if (!CONTROL_SHOULD_NOTIFY_CLIENT(c
) || c
->session
== NULL
)
165 control_write(c
, "%%session-changed $%u %s", s
->id
,
168 control_write(c
, "%%client-session-changed %s $%u %s",
169 cc
->name
, s
->id
, s
->name
);
175 control_notify_client_detached(struct client
*cc
)
179 TAILQ_FOREACH(c
, &clients
, entry
) {
180 if (CONTROL_SHOULD_NOTIFY_CLIENT(c
))
181 control_write(c
, "%%client-detached %s", cc
->name
);
186 control_notify_session_renamed(struct session
*s
)
190 TAILQ_FOREACH(c
, &clients
, entry
) {
191 if (!CONTROL_SHOULD_NOTIFY_CLIENT(c
))
194 control_write(c
, "%%session-renamed $%u %s", s
->id
, s
->name
);
199 control_notify_session_created(__unused
struct session
*s
)
203 TAILQ_FOREACH(c
, &clients
, entry
) {
204 if (!CONTROL_SHOULD_NOTIFY_CLIENT(c
))
207 control_write(c
, "%%sessions-changed");
212 control_notify_session_closed(__unused
struct session
*s
)
216 TAILQ_FOREACH(c
, &clients
, entry
) {
217 if (!CONTROL_SHOULD_NOTIFY_CLIENT(c
))
220 control_write(c
, "%%sessions-changed");
225 control_notify_session_window_changed(struct session
*s
)
229 TAILQ_FOREACH(c
, &clients
, entry
) {
230 if (!CONTROL_SHOULD_NOTIFY_CLIENT(c
))
233 control_write(c
, "%%session-window-changed $%u @%u", s
->id
,
234 s
->curw
->window
->id
);