aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar Tony Crisci <tony@dubstepdish.com>2018-04-05 19:01:03 -0400
committerLibravatar Tony Crisci <tony@dubstepdish.com>2018-04-05 19:01:03 -0400
commit235798ff8e9e60d919cbb671f7c399ff97c164d5 (patch)
tree0f0f88fbbbce6c4c65cae47a34280cbd1539782f
parentadd layout to ipc containers (diff)
downloadsway-235798ff8e9e60d919cbb671f7c399ff97c164d5.tar.gz
sway-235798ff8e9e60d919cbb671f7c399ff97c164d5.tar.zst
sway-235798ff8e9e60d919cbb671f7c399ff97c164d5.zip
dont send ipc events when there are no listeners
-rw-r--r--sway/ipc-server.c31
1 files changed, 29 insertions, 2 deletions
diff --git a/sway/ipc-server.c b/sway/ipc-server.c
index df5fb699..5fe5c755 100644
--- a/sway/ipc-server.c
+++ b/sway/ipc-server.c
@@ -241,10 +241,25 @@ 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 bool has_listeners = false;
246
247 struct ipc_client *client;
248 for (int i = 0; i < ipc_client_list->length; i++) {
249 client = ipc_client_list->items[i];
250 if ((client->subscribed_events & event_mask(event)) == 0) {
251 continue;
252 }
253 has_listeners = true;
254 break;
255 }
256
257 return has_listeners;
258}
259
244static void ipc_send_event(const char *json_string, enum ipc_command_type event) { 260static void ipc_send_event(const char *json_string, enum ipc_command_type event) {
245 int i;
246 struct ipc_client *client; 261 struct ipc_client *client;
247 for (i = 0; i < ipc_client_list->length; i++) { 262 for (int i = 0; i < ipc_client_list->length; i++) {
248 client = ipc_client_list->items[i]; 263 client = ipc_client_list->items[i];
249 if ((client->subscribed_events & event_mask(event)) == 0) { 264 if ((client->subscribed_events & event_mask(event)) == 0) {
250 continue; 265 continue;
@@ -259,6 +274,9 @@ static void ipc_send_event(const char *json_string, enum ipc_command_type event)
259 274
260void ipc_event_workspace(struct sway_container *old, 275void ipc_event_workspace(struct sway_container *old,
261 struct sway_container *new, const char *change) { 276 struct sway_container *new, const char *change) {
277 if (!ipc_has_event_listeners(IPC_EVENT_WORKSPACE)) {
278 return;
279 }
262 wlr_log(L_DEBUG, "Sending workspace::%s event", change); 280 wlr_log(L_DEBUG, "Sending workspace::%s event", change);
263 json_object *obj = json_object_new_object(); 281 json_object *obj = json_object_new_object();
264 json_object_object_add(obj, "change", json_object_new_string(change)); 282 json_object_object_add(obj, "change", json_object_new_string(change));
@@ -284,6 +302,9 @@ void ipc_event_workspace(struct sway_container *old,
284} 302}
285 303
286void ipc_event_window(struct sway_container *window, const char *change) { 304void ipc_event_window(struct sway_container *window, const char *change) {
305 if (!ipc_has_event_listeners(IPC_EVENT_WINDOW)) {
306 return;
307 }
287 wlr_log(L_DEBUG, "Sending window::%s event", change); 308 wlr_log(L_DEBUG, "Sending window::%s event", change);
288 json_object *obj = json_object_new_object(); 309 json_object *obj = json_object_new_object();
289 json_object_object_add(obj, "change", json_object_new_string(change)); 310 json_object_object_add(obj, "change", json_object_new_string(change));
@@ -295,6 +316,9 @@ void ipc_event_window(struct sway_container *window, const char *change) {
295} 316}
296 317
297void ipc_event_barconfig_update(struct bar_config *bar) { 318void ipc_event_barconfig_update(struct bar_config *bar) {
319 if (!ipc_has_event_listeners(IPC_EVENT_BARCONFIG_UPDATE)) {
320 return;
321 }
298 wlr_log(L_DEBUG, "Sending barconfig_update event"); 322 wlr_log(L_DEBUG, "Sending barconfig_update event");
299 json_object *json = ipc_json_describe_bar_config(bar); 323 json_object *json = ipc_json_describe_bar_config(bar);
300 324
@@ -304,6 +328,9 @@ void ipc_event_barconfig_update(struct bar_config *bar) {
304} 328}
305 329
306void ipc_event_mode(const char *mode) { 330void ipc_event_mode(const char *mode) {
331 if (!ipc_has_event_listeners(IPC_EVENT_MODE)) {
332 return;
333 }
307 wlr_log(L_DEBUG, "Sending mode::%s event", mode); 334 wlr_log(L_DEBUG, "Sending mode::%s event", mode);
308 json_object *obj = json_object_new_object(); 335 json_object *obj = json_object_new_object();
309 json_object_object_add(obj, "change", json_object_new_string(mode)); 336 json_object_object_add(obj, "change", json_object_new_string(mode));