diff options
Diffstat (limited to 'sway/ipc-server.c')
-rw-r--r-- | sway/ipc-server.c | 31 |
1 files changed, 25 insertions, 6 deletions
diff --git a/sway/ipc-server.c b/sway/ipc-server.c index 0729bfd5..305b6944 100644 --- a/sway/ipc-server.c +++ b/sway/ipc-server.c | |||
@@ -54,6 +54,8 @@ bool ipc_send_reply(struct ipc_client *client, const char *payload, uint32_t pay | |||
54 | void ipc_get_workspaces_callback(swayc_t *workspace, void *data); | 54 | void ipc_get_workspaces_callback(swayc_t *workspace, void *data); |
55 | void ipc_get_outputs_callback(swayc_t *container, void *data); | 55 | void ipc_get_outputs_callback(swayc_t *container, void *data); |
56 | 56 | ||
57 | #define event_mask(ev) (1 << (ev & 0x7F)) | ||
58 | |||
57 | void ipc_init(void) { | 59 | void ipc_init(void) { |
58 | ipc_socket = socket(AF_UNIX, SOCK_STREAM | SOCK_NONBLOCK | SOCK_CLOEXEC, 0); | 60 | ipc_socket = socket(AF_UNIX, SOCK_STREAM | SOCK_NONBLOCK | SOCK_CLOEXEC, 0); |
59 | if (ipc_socket == -1) { | 61 | if (ipc_socket == -1) { |
@@ -334,16 +336,18 @@ void ipc_client_handle_command(struct ipc_client *client) { | |||
334 | for (int i = 0; i < json_object_array_length(request); i++) { | 336 | for (int i = 0; i < json_object_array_length(request); i++) { |
335 | const char *event_type = json_object_get_string(json_object_array_get_idx(request, i)); | 337 | const char *event_type = json_object_get_string(json_object_array_get_idx(request, i)); |
336 | if (strcmp(event_type, "workspace") == 0) { | 338 | if (strcmp(event_type, "workspace") == 0) { |
337 | client->subscribed_events |= IPC_EVENT_WORKSPACE; | 339 | client->subscribed_events |= event_mask(IPC_EVENT_WORKSPACE); |
338 | } else if (strcmp(event_type, "barconfig_update") == 0) { | 340 | } else if (strcmp(event_type, "barconfig_update") == 0) { |
339 | client->subscribed_events |= IPC_EVENT_BARCONFIG_UPDATE; | 341 | client->subscribed_events |= event_mask(IPC_EVENT_BARCONFIG_UPDATE); |
340 | } else if (strcmp(event_type, "mode") == 0) { | 342 | } else if (strcmp(event_type, "mode") == 0) { |
341 | client->subscribed_events |= IPC_EVENT_MODE; | 343 | client->subscribed_events |= event_mask(IPC_EVENT_MODE); |
344 | } else if (strcmp(event_type, "window") == 0) { | ||
345 | client->subscribed_events |= event_mask(IPC_EVENT_WINDOW); | ||
342 | } else if (strcmp(event_type, "modifier") == 0) { | 346 | } else if (strcmp(event_type, "modifier") == 0) { |
343 | client->subscribed_events |= IPC_EVENT_MODIFIER; | 347 | client->subscribed_events |= event_mask(IPC_EVENT_MODIFIER); |
344 | #if SWAY_BINDING_EVENT | 348 | #if SWAY_BINDING_EVENT |
345 | } else if (strcmp(event_type, "binding") == 0) { | 349 | } else if (strcmp(event_type, "binding") == 0) { |
346 | client->subscribed_events |= IPC_EVENT_BINDING; | 350 | client->subscribed_events |= event_mask(IPC_EVENT_BINDING); |
347 | #endif | 351 | #endif |
348 | } else { | 352 | } else { |
349 | ipc_send_reply(client, "{\"success\": false}", 18); | 353 | ipc_send_reply(client, "{\"success\": false}", 18); |
@@ -522,7 +526,7 @@ void ipc_send_event(const char *json_string, enum ipc_command_type event) { | |||
522 | struct ipc_client *client; | 526 | struct ipc_client *client; |
523 | for (i = 0; i < ipc_client_list->length; i++) { | 527 | for (i = 0; i < ipc_client_list->length; i++) { |
524 | client = ipc_client_list->items[i]; | 528 | client = ipc_client_list->items[i]; |
525 | if ((client->subscribed_events & event) == 0) { | 529 | if ((client->subscribed_events & event_mask(event)) == 0) { |
526 | continue; | 530 | continue; |
527 | } | 531 | } |
528 | client->current_command = event; | 532 | client->current_command = event; |
@@ -556,6 +560,21 @@ void ipc_event_workspace(swayc_t *old, swayc_t *new, const char *change) { | |||
556 | json_object_put(obj); // free | 560 | json_object_put(obj); // free |
557 | } | 561 | } |
558 | 562 | ||
563 | void ipc_event_window(swayc_t *window, const char *change) { | ||
564 | json_object *obj = json_object_new_object(); | ||
565 | json_object_object_add(obj, "change", json_object_new_string(change)); | ||
566 | if (strcmp(change, "close") == 0 || !window) { | ||
567 | json_object_object_add(obj, "container", NULL); | ||
568 | } else { | ||
569 | json_object_object_add(obj, "container", ipc_json_describe_container(window)); | ||
570 | } | ||
571 | |||
572 | const char *json_string = json_object_to_json_string(obj); | ||
573 | ipc_send_event(json_string, IPC_EVENT_WINDOW); | ||
574 | |||
575 | json_object_put(obj); // free | ||
576 | } | ||
577 | |||
559 | void ipc_event_barconfig_update(struct bar_config *bar) { | 578 | void ipc_event_barconfig_update(struct bar_config *bar) { |
560 | json_object *json = ipc_json_describe_bar_config(bar); | 579 | json_object *json = ipc_json_describe_bar_config(bar); |
561 | const char *json_string = json_object_to_json_string(json); | 580 | const char *json_string = json_object_to_json_string(json); |