diff options
Diffstat (limited to 'sway/ipc-server.c')
-rw-r--r-- | sway/ipc-server.c | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/sway/ipc-server.c b/sway/ipc-server.c index dc6b353b..63633567 100644 --- a/sway/ipc-server.c +++ b/sway/ipc-server.c | |||
@@ -441,6 +441,21 @@ void ipc_event_binding(struct sway_binding *binding) { | |||
441 | json_object_put(json); | 441 | json_object_put(json); |
442 | } | 442 | } |
443 | 443 | ||
444 | static void ipc_event_tick(const char *payload) { | ||
445 | if (!ipc_has_event_listeners(IPC_EVENT_TICK)) { | ||
446 | return; | ||
447 | } | ||
448 | wlr_log(WLR_DEBUG, "Sending tick event"); | ||
449 | |||
450 | json_object *json = json_object_new_object(); | ||
451 | json_object_object_add(json, "first", json_object_new_boolean(false)); | ||
452 | json_object_object_add(json, "payload", json_object_new_string(payload)); | ||
453 | |||
454 | const char *json_string = json_object_to_json_string(json); | ||
455 | ipc_send_event(json_string, IPC_EVENT_TICK); | ||
456 | json_object_put(json); | ||
457 | } | ||
458 | |||
444 | int ipc_client_handle_writable(int client_fd, uint32_t mask, void *data) { | 459 | int ipc_client_handle_writable(int client_fd, uint32_t mask, void *data) { |
445 | struct ipc_client *client = data; | 460 | struct ipc_client *client = data; |
446 | 461 | ||
@@ -582,6 +597,13 @@ void ipc_client_handle_command(struct ipc_client *client) { | |||
582 | goto exit_cleanup; | 597 | goto exit_cleanup; |
583 | } | 598 | } |
584 | 599 | ||
600 | case IPC_SEND_TICK: | ||
601 | { | ||
602 | ipc_event_tick(buf); | ||
603 | ipc_send_reply(client, "{\"success\": true}", 17); | ||
604 | goto exit_cleanup; | ||
605 | } | ||
606 | |||
585 | case IPC_GET_OUTPUTS: | 607 | case IPC_GET_OUTPUTS: |
586 | { | 608 | { |
587 | json_object *outputs = json_object_new_array(); | 609 | json_object *outputs = json_object_new_array(); |
@@ -628,6 +650,7 @@ void ipc_client_handle_command(struct ipc_client *client) { | |||
628 | goto exit_cleanup; | 650 | goto exit_cleanup; |
629 | } | 651 | } |
630 | 652 | ||
653 | bool is_tick = false; | ||
631 | // parse requested event types | 654 | // parse requested event types |
632 | for (size_t i = 0; i < json_object_array_length(request); i++) { | 655 | for (size_t i = 0; i < json_object_array_length(request); i++) { |
633 | const char *event_type = json_object_get_string(json_object_array_get_idx(request, i)); | 656 | const char *event_type = json_object_get_string(json_object_array_get_idx(request, i)); |
@@ -645,6 +668,9 @@ void ipc_client_handle_command(struct ipc_client *client) { | |||
645 | client->subscribed_events |= event_mask(IPC_EVENT_MODIFIER); | 668 | client->subscribed_events |= event_mask(IPC_EVENT_MODIFIER); |
646 | } else if (strcmp(event_type, "binding") == 0) { | 669 | } else if (strcmp(event_type, "binding") == 0) { |
647 | client->subscribed_events |= event_mask(IPC_EVENT_BINDING); | 670 | client->subscribed_events |= event_mask(IPC_EVENT_BINDING); |
671 | } else if (strcmp(event_type, "tick") == 0) { | ||
672 | client->subscribed_events |= event_mask(IPC_EVENT_TICK); | ||
673 | is_tick = true; | ||
648 | } else { | 674 | } else { |
649 | client_valid = | 675 | client_valid = |
650 | ipc_send_reply(client, "{\"success\": false}", 18); | 676 | ipc_send_reply(client, "{\"success\": false}", 18); |
@@ -656,6 +682,10 @@ void ipc_client_handle_command(struct ipc_client *client) { | |||
656 | 682 | ||
657 | json_object_put(request); | 683 | json_object_put(request); |
658 | client_valid = ipc_send_reply(client, "{\"success\": true}", 17); | 684 | client_valid = ipc_send_reply(client, "{\"success\": true}", 17); |
685 | if (is_tick) { | ||
686 | client->current_command = IPC_EVENT_TICK; | ||
687 | ipc_send_reply(client, "{\"first\": true, \"payload\": \"\"}", 30); | ||
688 | } | ||
659 | goto exit_cleanup; | 689 | goto exit_cleanup; |
660 | } | 690 | } |
661 | 691 | ||