diff options
author | Ian Fan <ianfan0@gmail.com> | 2018-07-18 12:30:39 +0100 |
---|---|---|
committer | Ian Fan <ianfan0@gmail.com> | 2018-08-01 16:57:15 +0100 |
commit | 3edaf2ce2a8a4753c162491329a7dfa492ff7e77 (patch) | |
tree | 28ae55150ef695a569aecaf114250a87a73d0d5a | |
parent | 33433c64347eb0bfd7c1465a3b60579fa88ef724 (diff) |
ipc: add tick event
-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() 'get_version' 'get_binding_modes' 'get_config' + 'send_tick' ) 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=( 'get_version' 'get_binding_modes' 'get_config' +'send_tick' ) _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 { IPC_GET_VERSION = 7, IPC_GET_BINDING_MODES = 8, IPC_GET_CONFIG = 9, + IPC_SEND_TICK = 10, // sway-specific command types IPC_GET_INPUTS = 100, @@ -28,6 +29,7 @@ enum ipc_command_type { IPC_EVENT_BARCONFIG_UPDATE = ((1<<31) | 4), IPC_EVENT_BINDING = ((1<<31) | 5), IPC_EVENT_SHUTDOWN = ((1<<31) | 6), + IPC_EVENT_TICK = ((1<<31) | 7), IPC_EVENT_MODIFIER = ((1<<31) | 16), IPC_EVENT_INPUT = ((1<<31) | 17), }; 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) { json_object_put(json); } +static void ipc_event_tick(const char *payload) { + if (!ipc_has_event_listeners(IPC_EVENT_TICK)) { + return; + } + wlr_log(WLR_DEBUG, "Sending tick event"); + + json_object *json = json_object_new_object(); + json_object_object_add(json, "first", json_object_new_boolean(false)); + json_object_object_add(json, "payload", json_object_new_string(payload)); + + const char *json_string = json_object_to_json_string(json); + ipc_send_event(json_string, IPC_EVENT_TICK); + json_object_put(json); +} + int ipc_client_handle_writable(int client_fd, uint32_t mask, void *data) { struct ipc_client *client = data; @@ -582,6 +597,13 @@ void ipc_client_handle_command(struct ipc_client *client) { goto exit_cleanup; } + case IPC_SEND_TICK: + { + ipc_event_tick(buf); + ipc_send_reply(client, "{\"success\": true}", 17); + goto exit_cleanup; + } + case IPC_GET_OUTPUTS: { json_object *outputs = json_object_new_array(); @@ -628,6 +650,7 @@ void ipc_client_handle_command(struct ipc_client *client) { goto exit_cleanup; } + bool is_tick = false; // parse requested event types for (size_t i = 0; i < json_object_array_length(request); i++) { 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) { client->subscribed_events |= event_mask(IPC_EVENT_MODIFIER); } else if (strcmp(event_type, "binding") == 0) { client->subscribed_events |= event_mask(IPC_EVENT_BINDING); + } else if (strcmp(event_type, "tick") == 0) { + client->subscribed_events |= event_mask(IPC_EVENT_TICK); + is_tick = true; } else { client_valid = ipc_send_reply(client, "{\"success\": false}", 18); @@ -656,6 +682,10 @@ void ipc_client_handle_command(struct ipc_client *client) { json_object_put(request); client_valid = ipc_send_reply(client, "{\"success\": true}", 17); + if (is_tick) { + client->current_command = IPC_EVENT_TICK; + ipc_send_reply(client, "{\"first\": true, \"payload\": \"\"}", 30); + } goto exit_cleanup; } 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) { if (type != IPC_COMMAND && type != IPC_GET_WORKSPACES && type != IPC_GET_INPUTS && type != IPC_GET_OUTPUTS && type != IPC_GET_VERSION && type != IPC_GET_SEATS && - type != IPC_GET_CONFIG) { + type != IPC_GET_CONFIG && type != IPC_SEND_TICK) { printf("%s\n", json_object_to_json_string_ext(resp, JSON_C_TO_STRING_PRETTY | JSON_C_TO_STRING_SPACED)); return; } + if (type == IPC_SEND_TICK) { + return; + } + if (type == IPC_GET_VERSION) { pretty_print_version(resp); return; @@ -384,6 +388,8 @@ int main(int argc, char **argv) { type = IPC_GET_BINDING_MODES; } else if (strcasecmp(cmdtype, "get_config") == 0) { type = IPC_GET_CONFIG; + } else if (strcasecmp(cmdtype, "send_tick") == 0) { + type = IPC_SEND_TICK; } else { sway_abort("Unknown message type %s", cmdtype); } 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] *get\_config* Gets a JSON-encoded copy of the current configuration. + +*send\_tick* + Sends a tick event to all subscribed clients. |