summaryrefslogtreecommitdiffstats
path: root/sway/ipc-server.c
diff options
context:
space:
mode:
Diffstat (limited to 'sway/ipc-server.c')
-rw-r--r--sway/ipc-server.c25
1 files changed, 23 insertions, 2 deletions
diff --git a/sway/ipc-server.c b/sway/ipc-server.c
index df5fb699..045802e1 100644
--- a/sway/ipc-server.c
+++ b/sway/ipc-server.c
@@ -241,10 +241,19 @@ int ipc_client_handle_readable(int client_fd, uint32_t mask, void *data) {
241 return 0; 241 return 0;
242} 242}
243 243
244static bool ipc_has_event_listeners(enum ipc_command_type event) {
245 for (int i = 0; i < ipc_client_list->length; i++) {
246 struct ipc_client *client = ipc_client_list->items[i];
247 if ((client->subscribed_events & event_mask(event)) == 0) {
248 return true;
249 }
250 }
251 return false;
252}
253
244static void ipc_send_event(const char *json_string, enum ipc_command_type event) { 254static void ipc_send_event(const char *json_string, enum ipc_command_type event) {
245 int i;
246 struct ipc_client *client; 255 struct ipc_client *client;
247 for (i = 0; i < ipc_client_list->length; i++) { 256 for (int i = 0; i < ipc_client_list->length; i++) {
248 client = ipc_client_list->items[i]; 257 client = ipc_client_list->items[i];
249 if ((client->subscribed_events & event_mask(event)) == 0) { 258 if ((client->subscribed_events & event_mask(event)) == 0) {
250 continue; 259 continue;
@@ -259,6 +268,9 @@ static void ipc_send_event(const char *json_string, enum ipc_command_type event)
259 268
260void ipc_event_workspace(struct sway_container *old, 269void ipc_event_workspace(struct sway_container *old,
261 struct sway_container *new, const char *change) { 270 struct sway_container *new, const char *change) {
271 if (!ipc_has_event_listeners(IPC_EVENT_WORKSPACE)) {
272 return;
273 }
262 wlr_log(L_DEBUG, "Sending workspace::%s event", change); 274 wlr_log(L_DEBUG, "Sending workspace::%s event", change);
263 json_object *obj = json_object_new_object(); 275 json_object *obj = json_object_new_object();
264 json_object_object_add(obj, "change", json_object_new_string(change)); 276 json_object_object_add(obj, "change", json_object_new_string(change));
@@ -284,6 +296,9 @@ void ipc_event_workspace(struct sway_container *old,
284} 296}
285 297
286void ipc_event_window(struct sway_container *window, const char *change) { 298void ipc_event_window(struct sway_container *window, const char *change) {
299 if (!ipc_has_event_listeners(IPC_EVENT_WINDOW)) {
300 return;
301 }
287 wlr_log(L_DEBUG, "Sending window::%s event", change); 302 wlr_log(L_DEBUG, "Sending window::%s event", change);
288 json_object *obj = json_object_new_object(); 303 json_object *obj = json_object_new_object();
289 json_object_object_add(obj, "change", json_object_new_string(change)); 304 json_object_object_add(obj, "change", json_object_new_string(change));
@@ -295,6 +310,9 @@ void ipc_event_window(struct sway_container *window, const char *change) {
295} 310}
296 311
297void ipc_event_barconfig_update(struct bar_config *bar) { 312void ipc_event_barconfig_update(struct bar_config *bar) {
313 if (!ipc_has_event_listeners(IPC_EVENT_BARCONFIG_UPDATE)) {
314 return;
315 }
298 wlr_log(L_DEBUG, "Sending barconfig_update event"); 316 wlr_log(L_DEBUG, "Sending barconfig_update event");
299 json_object *json = ipc_json_describe_bar_config(bar); 317 json_object *json = ipc_json_describe_bar_config(bar);
300 318
@@ -304,6 +322,9 @@ void ipc_event_barconfig_update(struct bar_config *bar) {
304} 322}
305 323
306void ipc_event_mode(const char *mode) { 324void ipc_event_mode(const char *mode) {
325 if (!ipc_has_event_listeners(IPC_EVENT_MODE)) {
326 return;
327 }
307 wlr_log(L_DEBUG, "Sending mode::%s event", mode); 328 wlr_log(L_DEBUG, "Sending mode::%s event", mode);
308 json_object *obj = json_object_new_object(); 329 json_object *obj = json_object_new_object();
309 json_object_object_add(obj, "change", json_object_new_string(mode)); 330 json_object_object_add(obj, "change", json_object_new_string(mode));