4 * Copyright (c) 2012 Nicholas Marriott <nicm@users.sourceforge.net>
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>
24 #define CONTROL_SHOULD_NOTIFY_CLIENT(c) \
25 ((c) != NULL && ((c)->flags & CLIENT_CONTROL))
28 control_notify_input(struct client
*c
, struct window_pane
*wp
,
29 struct evbuffer
*input
)
33 struct evbuffer
*message
;
36 if (c
->session
== NULL
)
39 buf
= EVBUFFER_DATA(input
);
40 len
= EVBUFFER_LENGTH(input
);
43 * Only write input if the window pane is linked to a window belonging
44 * to the client's session.
46 if (winlink_find_by_window(&c
->session
->windows
, wp
->window
) != NULL
) {
47 message
= evbuffer_new();
48 evbuffer_add_printf(message
, "%%output %%%u ", wp
->id
);
49 for (i
= 0; i
< len
; i
++) {
50 if (buf
[i
] < ' ' || buf
[i
] == '\\')
51 evbuffer_add_printf(message
, "\\%03o", buf
[i
]);
53 evbuffer_add_printf(message
, "%c", buf
[i
]);
55 control_write_buffer(c
, message
);
56 evbuffer_free(message
);
61 control_notify_window_layout_changed(struct window
*w
)
65 struct format_tree
*ft
;
70 for (i
= 0; i
< ARRAY_LENGTH(&clients
); i
++) {
71 c
= ARRAY_ITEM(&clients
, i
);
72 if (!CONTROL_SHOULD_NOTIFY_CLIENT(c
) || c
->session
== NULL
)
76 if (winlink_find_by_window_id(&s
->windows
, w
->id
) == NULL
)
80 * When the last pane in a window is closed it won't have a
81 * layout root and we don't need to inform the client about the
82 * layout change because the whole window will go away soon.
84 if (w
->layout_root
== NULL
)
86 template = "%layout-change #{window_id} #{window_layout}";
89 wl
= winlink_find_by_window(&s
->windows
, w
);
91 format_winlink(ft
, c
->session
, wl
);
92 control_write(c
, "%s", format_expand(ft
, template));
99 control_notify_window_unlinked(unused
struct session
*s
, struct window
*w
)
104 for (i
= 0; i
< ARRAY_LENGTH(&clients
); i
++) {
105 c
= ARRAY_ITEM(&clients
, i
);
106 if (!CONTROL_SHOULD_NOTIFY_CLIENT(c
) || c
->session
== NULL
)
109 control_write(c
, "%%window-close @%u", w
->id
);
114 control_notify_window_linked(unused
struct session
*s
, struct window
*w
)
120 for (i
= 0; i
< ARRAY_LENGTH(&clients
); i
++) {
121 c
= ARRAY_ITEM(&clients
, i
);
122 if (!CONTROL_SHOULD_NOTIFY_CLIENT(c
) || c
->session
== NULL
)
126 if (winlink_find_by_window_id(&cs
->windows
, w
->id
) != NULL
)
127 control_write(c
, "%%window-add @%u", w
->id
);
129 control_write(c
, "%%unlinked-window-add @%u", w
->id
);
134 control_notify_window_renamed(struct window
*w
)
139 for (i
= 0; i
< ARRAY_LENGTH(&clients
); i
++) {
140 c
= ARRAY_ITEM(&clients
, i
);
141 if (!CONTROL_SHOULD_NOTIFY_CLIENT(c
) || c
->session
== NULL
)
144 control_write(c
, "%%window-renamed @%u %s", w
->id
, w
->name
);
149 control_notify_attached_session_changed(struct client
*c
)
153 if (!CONTROL_SHOULD_NOTIFY_CLIENT(c
) || c
->session
== NULL
)
157 control_write(c
, "%%session-changed $%u %s", s
->id
, s
->name
);
161 control_notify_session_renamed(struct session
*s
)
166 for (i
= 0; i
< ARRAY_LENGTH(&clients
); i
++) {
167 c
= ARRAY_ITEM(&clients
, i
);
168 if (!CONTROL_SHOULD_NOTIFY_CLIENT(c
))
171 control_write(c
, "%%session-renamed $%u %s", s
->id
, s
->name
);
176 control_notify_session_created(unused
struct session
*s
)
181 for (i
= 0; i
< ARRAY_LENGTH(&clients
); i
++) {
182 c
= ARRAY_ITEM(&clients
, i
);
183 if (!CONTROL_SHOULD_NOTIFY_CLIENT(c
))
186 control_write(c
, "%%sessions-changed");
191 control_notify_session_close(unused
struct session
*s
)
196 for (i
= 0; i
< ARRAY_LENGTH(&clients
); i
++) {
197 c
= ARRAY_ITEM(&clients
, i
);
198 if (!CONTROL_SHOULD_NOTIFY_CLIENT(c
))
201 control_write(c
, "%%sessions-changed");