aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--include/ipc.h7
-rw-r--r--sway/ipc-server.c36
2 files changed, 24 insertions, 19 deletions
diff --git a/include/ipc.h b/include/ipc.h
index 75be58a6..e0b3b736 100644
--- a/include/ipc.h
+++ b/include/ipc.h
@@ -10,6 +10,13 @@ enum ipc_command_type {
10 IPC_GET_MARKS = 5, 10 IPC_GET_MARKS = 5,
11 IPC_GET_BAR_CONFIG = 6, 11 IPC_GET_BAR_CONFIG = 6,
12 IPC_GET_VERSION = 7, 12 IPC_GET_VERSION = 7,
13 // Events send from sway to clients. Events have the higest bit set.
14 IPC_EVENT_WORKSPACE = (1 << 31 | 0),
15 IPC_EVENT_OUTPUT = (1 << 31 | 1),
16 IPC_EVENT_MODE = (1 << 31 | 2),
17 IPC_EVENT_WINDOW = (1 << 31 | 3),
18 IPC_EVENT_BARCONFIG_UPDATE = (1 << 31 | 4),
19 IPC_EVENT_BINDING = (1 << 31 | 5),
13 IPC_SWAY_GET_PIXELS = 0x81 20 IPC_SWAY_GET_PIXELS = 0x81
14}; 21};
15 22
diff --git a/sway/ipc-server.c b/sway/ipc-server.c
index e161c756..2bb25202 100644
--- a/sway/ipc-server.c
+++ b/sway/ipc-server.c
@@ -290,9 +290,9 @@ void ipc_client_handle_command(struct ipc_client *client) {
290 for (int i = 0; i < json_object_array_length(request); i++) { 290 for (int i = 0; i < json_object_array_length(request); i++) {
291 const char *event_type = json_object_get_string(json_object_array_get_idx(request, i)); 291 const char *event_type = json_object_get_string(json_object_array_get_idx(request, i));
292 if (strcmp(event_type, "workspace") == 0) { 292 if (strcmp(event_type, "workspace") == 0) {
293 client->subscribed_events |= IPC_GET_WORKSPACES; 293 client->subscribed_events |= IPC_EVENT_WORKSPACE;
294 } else if (strcmp(event_type, "barconfig_update") == 0) { 294 } else if (strcmp(event_type, "barconfig_update") == 0) {
295 client->subscribed_events |= IPC_GET_BAR_CONFIG; 295 client->subscribed_events |= IPC_EVENT_BARCONFIG_UPDATE;
296 } else { 296 } else {
297 ipc_send_reply(client, "{\"success\": false}", 18); 297 ipc_send_reply(client, "{\"success\": false}", 18);
298 ipc_client_disconnect(client); 298 ipc_client_disconnect(client);
@@ -562,6 +562,19 @@ json_object *ipc_json_describe_bar_config(struct bar_config *bar) {
562 return json; 562 return json;
563} 563}
564 564
565void ipc_send_event(const char *json_string, enum ipc_command_type event) {
566 int i;
567 struct ipc_client *client;
568 for (i = 0; i < ipc_client_list->length; i++) {
569 client = ipc_client_list->items[i];
570 if ((client->subscribed_events & event) == 0) {
571 continue;
572 }
573 client->current_command = event;
574 ipc_send_reply(client, json_string, (uint32_t) strlen(json_string));
575 }
576}
577
565void ipc_event_workspace(swayc_t *old, swayc_t *new, const char *change) { 578void ipc_event_workspace(swayc_t *old, swayc_t *new, const char *change) {
566 json_object *obj = json_object_new_object(); 579 json_object *obj = json_object_new_object();
567 json_object_object_add(obj, "change", json_object_new_string(change)); 580 json_object_object_add(obj, "change", json_object_new_string(change));
@@ -580,14 +593,7 @@ void ipc_event_workspace(swayc_t *old, swayc_t *new, const char *change) {
580 } 593 }
581 594
582 const char *json_string = json_object_to_json_string(obj); 595 const char *json_string = json_object_to_json_string(obj);
583 596 ipc_send_event(json_string, IPC_EVENT_WORKSPACE);
584 for (int i = 0; i < ipc_client_list->length; i++) {
585 struct ipc_client *client = ipc_client_list->items[i];
586 if ((client->subscribed_events & IPC_GET_WORKSPACES) == 0) {
587 continue;
588 }
589 ipc_send_reply(client, json_string, (uint32_t) strlen(json_string));
590 }
591 597
592 json_object_put(obj); // free 598 json_object_put(obj); // free
593} 599}
@@ -595,15 +601,7 @@ void ipc_event_workspace(swayc_t *old, swayc_t *new, const char *change) {
595void ipc_event_barconfig_update(struct bar_config *bar) { 601void ipc_event_barconfig_update(struct bar_config *bar) {
596 json_object *json = ipc_json_describe_bar_config(bar); 602 json_object *json = ipc_json_describe_bar_config(bar);
597 const char *json_string = json_object_to_json_string(json); 603 const char *json_string = json_object_to_json_string(json);
598 int i; 604 ipc_send_event(json_string, IPC_EVENT_BARCONFIG_UPDATE);
599 struct ipc_client *client;
600 for (i = 0; i < ipc_client_list->length; ++i) {
601 client = ipc_client_list->items[i];
602 if ((client->subscribed_events & IPC_GET_BAR_CONFIG) == 0) {
603 continue;
604 }
605 ipc_send_reply(client, json_string, (uint32_t)strlen(json_string));
606 }
607 605
608 json_object_put(json); // free 606 json_object_put(json); // free
609} 607}