diff options
-rw-r--r-- | completions/bash/swaymsg | 1 | ||||
-rw-r--r-- | completions/zsh/_swaymsg | 1 | ||||
-rw-r--r-- | include/ipc.h | 2 | ||||
-rw-r--r-- | sway/ipc-server.c | 30 | ||||
-rw-r--r-- | swaymsg/main.c | 8 | ||||
-rw-r--r-- | swaymsg/swaymsg.1.scd | 3 |
6 files changed, 44 insertions, 1 deletions
diff --git a/completions/bash/swaymsg b/completions/bash/swaymsg index e4b2c1b7..20092bdc 100644 --- a/completions/bash/swaymsg +++ b/completions/bash/swaymsg | |||
@@ -16,6 +16,7 @@ _swaymsg() | |||
16 | 'get_version' | 16 | 'get_version' |
17 | 'get_binding_modes' | 17 | 'get_binding_modes' |
18 | 'get_config' | 18 | 'get_config' |
19 | 'send_tick' | ||
19 | ) | 20 | ) |
20 | 21 | ||
21 | short=( | 22 | short=( |
diff --git a/completions/zsh/_swaymsg b/completions/zsh/_swaymsg index 28de474d..a7a1c8e0 100644 --- a/completions/zsh/_swaymsg +++ b/completions/zsh/_swaymsg | |||
@@ -24,6 +24,7 @@ types=( | |||
24 | 'get_version' | 24 | 'get_version' |
25 | 'get_binding_modes' | 25 | 'get_binding_modes' |
26 | 'get_config' | 26 | 'get_config' |
27 | 'send_tick' | ||
27 | ) | 28 | ) |
28 | 29 | ||
29 | _arguments -s \ | 30 | _arguments -s \ |
diff --git a/include/ipc.h b/include/ipc.h index ffc57d1b..2138d3fa 100644 --- a/include/ipc.h +++ b/include/ipc.h | |||
@@ -15,6 +15,7 @@ enum ipc_command_type { | |||
15 | IPC_GET_VERSION = 7, | 15 | IPC_GET_VERSION = 7, |
16 | IPC_GET_BINDING_MODES = 8, | 16 | IPC_GET_BINDING_MODES = 8, |
17 | IPC_GET_CONFIG = 9, | 17 | IPC_GET_CONFIG = 9, |
18 | IPC_SEND_TICK = 10, | ||
18 | 19 | ||
19 | // sway-specific command types | 20 | // sway-specific command types |
20 | IPC_GET_INPUTS = 100, | 21 | IPC_GET_INPUTS = 100, |
@@ -28,6 +29,7 @@ enum ipc_command_type { | |||
28 | IPC_EVENT_BARCONFIG_UPDATE = ((1<<31) | 4), | 29 | IPC_EVENT_BARCONFIG_UPDATE = ((1<<31) | 4), |
29 | IPC_EVENT_BINDING = ((1<<31) | 5), | 30 | IPC_EVENT_BINDING = ((1<<31) | 5), |
30 | IPC_EVENT_SHUTDOWN = ((1<<31) | 6), | 31 | IPC_EVENT_SHUTDOWN = ((1<<31) | 6), |
32 | IPC_EVENT_TICK = ((1<<31) | 7), | ||
31 | IPC_EVENT_MODIFIER = ((1<<31) | 16), | 33 | IPC_EVENT_MODIFIER = ((1<<31) | 16), |
32 | IPC_EVENT_INPUT = ((1<<31) | 17), | 34 | IPC_EVENT_INPUT = ((1<<31) | 17), |
33 | }; | 35 | }; |
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 | ||
diff --git a/swaymsg/main.c b/swaymsg/main.c index c4141ca5..3767daf3 100644 --- a/swaymsg/main.c +++ b/swaymsg/main.c | |||
@@ -250,12 +250,16 @@ static void pretty_print(int type, json_object *resp) { | |||
250 | if (type != IPC_COMMAND && type != IPC_GET_WORKSPACES && | 250 | if (type != IPC_COMMAND && type != IPC_GET_WORKSPACES && |
251 | type != IPC_GET_INPUTS && type != IPC_GET_OUTPUTS && | 251 | type != IPC_GET_INPUTS && type != IPC_GET_OUTPUTS && |
252 | type != IPC_GET_VERSION && type != IPC_GET_SEATS && | 252 | type != IPC_GET_VERSION && type != IPC_GET_SEATS && |
253 | type != IPC_GET_CONFIG) { | 253 | type != IPC_GET_CONFIG && type != IPC_SEND_TICK) { |
254 | printf("%s\n", json_object_to_json_string_ext(resp, | 254 | printf("%s\n", json_object_to_json_string_ext(resp, |
255 | JSON_C_TO_STRING_PRETTY | JSON_C_TO_STRING_SPACED)); | 255 | JSON_C_TO_STRING_PRETTY | JSON_C_TO_STRING_SPACED)); |
256 | return; | 256 | return; |
257 | } | 257 | } |
258 | 258 | ||
259 | if (type == IPC_SEND_TICK) { | ||
260 | return; | ||
261 | } | ||
262 | |||
259 | if (type == IPC_GET_VERSION) { | 263 | if (type == IPC_GET_VERSION) { |
260 | pretty_print_version(resp); | 264 | pretty_print_version(resp); |
261 | return; | 265 | return; |
@@ -384,6 +388,8 @@ int main(int argc, char **argv) { | |||
384 | type = IPC_GET_BINDING_MODES; | 388 | type = IPC_GET_BINDING_MODES; |
385 | } else if (strcasecmp(cmdtype, "get_config") == 0) { | 389 | } else if (strcasecmp(cmdtype, "get_config") == 0) { |
386 | type = IPC_GET_CONFIG; | 390 | type = IPC_GET_CONFIG; |
391 | } else if (strcasecmp(cmdtype, "send_tick") == 0) { | ||
392 | type = IPC_SEND_TICK; | ||
387 | } else { | 393 | } else { |
388 | sway_abort("Unknown message type %s", cmdtype); | 394 | sway_abort("Unknown message type %s", cmdtype); |
389 | } | 395 | } |
diff --git a/swaymsg/swaymsg.1.scd b/swaymsg/swaymsg.1.scd index a6e279da..8cf1b222 100644 --- a/swaymsg/swaymsg.1.scd +++ b/swaymsg/swaymsg.1.scd | |||
@@ -64,3 +64,6 @@ _swaymsg_ [options...] [message] | |||
64 | 64 | ||
65 | *get\_config* | 65 | *get\_config* |
66 | Gets a JSON-encoded copy of the current configuration. | 66 | Gets a JSON-encoded copy of the current configuration. |
67 | |||
68 | *send\_tick* | ||
69 | Sends a tick event to all subscribed clients. | ||