summaryrefslogtreecommitdiff
path: root/sway/ipc-server.c
diff options
context:
space:
mode:
authorBrian Ashworth <[email protected]>2019-07-17 17:12:20 -0400
committerSimon Ser <[email protected]>2019-07-23 20:45:46 +0300
commit6effca7b61e87c7d17885d007d94e556a0137651 (patch)
tree686cc1e219d8236f8c9864c9992b3cb6b44c9583 /sway/ipc-server.c
parent36aa67e549609ce6c786c382f14ab866536cac47 (diff)
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.c17
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) {
json_object_put(json);
}
+void ipc_event_input(const char *change, struct sway_input_device *device) {
+ if (!ipc_has_event_listeners(IPC_EVENT_INPUT)) {
+ return;
+ }
+ sway_log(SWAY_DEBUG, "Sending input event");
+
+ json_object *json = json_object_new_object();
+ json_object_object_add(json, "change", json_object_new_string(change));
+ json_object_object_add(json, "input", ipc_json_describe_input(device));
+
+ const char *json_string = json_object_to_json_string(json);
+ ipc_send_event(json_string, IPC_EVENT_INPUT);
+ json_object_put(json);
+}
+
int ipc_client_handle_writable(int client_fd, uint32_t mask, void *data) {
struct ipc_client *client = data;
@@ -716,6 +731,8 @@ void ipc_client_handle_command(struct ipc_client *client, uint32_t payload_lengt
} else if (strcmp(event_type, "tick") == 0) {
client->subscribed_events |= event_mask(IPC_EVENT_TICK);
is_tick = true;
+ } else if (strcmp(event_type, "input") == 0) {
+ client->subscribed_events |= event_mask(IPC_EVENT_INPUT);
} else {
const char msg[] = "{\"success\": false}";
ipc_send_reply(client, payload_type, msg, strlen(msg));