diff options
author | Brian Ashworth <bosrsf04@gmail.com> | 2019-07-17 17:12:20 -0400 |
---|---|---|
committer | Simon Ser <contact@emersion.fr> | 2019-07-23 20:45:46 +0300 |
commit | 6effca7b61e87c7d17885d007d94e556a0137651 (patch) | |
tree | 686cc1e219d8236f8c9864c9992b3cb6b44c9583 /sway/ipc-server.c | |
parent | input_cmd_xkb_switch_layout: support input types (diff) | |
download | sway-6effca7b61e87c7d17885d007d94e556a0137651.tar.gz sway-6effca7b61e87c7d17885d007d94e556a0137651.tar.zst sway-6effca7b61e87c7d17885d007d94e556a0137651.zip |
ipc: add an input event
This adds an ipc event related to input devices. Currently the
following changes are supported:
- added: when an input device becomes available
- removed: when an input device is no longer available
- xkb_keymap_changed: (keyboards only) the keymap changed
- xkb_layout_changed: (keyboards only) the effective layout changed
Diffstat (limited to 'sway/ipc-server.c')
-rw-r--r-- | sway/ipc-server.c | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/sway/ipc-server.c b/sway/ipc-server.c index ca1c1b12..773e90fd 100644 --- a/sway/ipc-server.c +++ b/sway/ipc-server.c | |||
@@ -487,6 +487,21 @@ static void ipc_event_tick(const char *payload) { | |||
487 | json_object_put(json); | 487 | json_object_put(json); |
488 | } | 488 | } |
489 | 489 | ||
490 | void ipc_event_input(const char *change, struct sway_input_device *device) { | ||
491 | if (!ipc_has_event_listeners(IPC_EVENT_INPUT)) { | ||
492 | return; | ||
493 | } | ||
494 | sway_log(SWAY_DEBUG, "Sending input event"); | ||
495 | |||
496 | json_object *json = json_object_new_object(); | ||
497 | json_object_object_add(json, "change", json_object_new_string(change)); | ||
498 | json_object_object_add(json, "input", ipc_json_describe_input(device)); | ||
499 | |||
500 | const char *json_string = json_object_to_json_string(json); | ||
501 | ipc_send_event(json_string, IPC_EVENT_INPUT); | ||
502 | json_object_put(json); | ||
503 | } | ||
504 | |||
490 | int ipc_client_handle_writable(int client_fd, uint32_t mask, void *data) { | 505 | int ipc_client_handle_writable(int client_fd, uint32_t mask, void *data) { |
491 | struct ipc_client *client = data; | 506 | struct ipc_client *client = data; |
492 | 507 | ||
@@ -716,6 +731,8 @@ void ipc_client_handle_command(struct ipc_client *client, uint32_t payload_lengt | |||
716 | } else if (strcmp(event_type, "tick") == 0) { | 731 | } else if (strcmp(event_type, "tick") == 0) { |
717 | client->subscribed_events |= event_mask(IPC_EVENT_TICK); | 732 | client->subscribed_events |= event_mask(IPC_EVENT_TICK); |
718 | is_tick = true; | 733 | is_tick = true; |
734 | } else if (strcmp(event_type, "input") == 0) { | ||
735 | client->subscribed_events |= event_mask(IPC_EVENT_INPUT); | ||
719 | } else { | 736 | } else { |
720 | const char msg[] = "{\"success\": false}"; | 737 | const char msg[] = "{\"success\": false}"; |
721 | ipc_send_reply(client, payload_type, msg, strlen(msg)); | 738 | ipc_send_reply(client, payload_type, msg, strlen(msg)); |