aboutsummaryrefslogtreecommitdiff
path: root/sway/ipc-server.c
diff options
context:
space:
mode:
authorDrew DeVault <sir@cmpwn.com>2016-01-08 09:48:24 -0500
committerDrew DeVault <sir@cmpwn.com>2016-01-08 09:48:24 -0500
commite2d49afb4a9cf1c333cbb1e18360026508b79a60 (patch)
tree37391772505203dd0ac0b533e89359b0d5d6e040 /sway/ipc-server.c
parent320c2915b0aeb4bbecb753bf00091e24905c5652 (diff)
parent15cbc53a771f35e5510b643193c4ba99e9f820a2 (diff)
Merge pull request #438 from mikkeloscar/binding-event
Implement IPC binding event (keyboard)
Diffstat (limited to 'sway/ipc-server.c')
-rw-r--r--sway/ipc-server.c53
1 files changed, 53 insertions, 0 deletions
diff --git a/sway/ipc-server.c b/sway/ipc-server.c
index f3a4647b..bde20931 100644
--- a/sway/ipc-server.c
+++ b/sway/ipc-server.c
@@ -298,6 +298,10 @@ void ipc_client_handle_command(struct ipc_client *client) {
client->subscribed_events |= IPC_EVENT_MODE;
} else if (strcmp(event_type, "modifier") == 0) {
client->subscribed_events |= IPC_EVENT_MODIFIER;
+#if SWAY_BINDING_EVENT
+ } else if (strcmp(event_type, "binding") == 0) {
+ client->subscribed_events |= IPC_EVENT_BINDING;
+#endif
} else {
ipc_send_reply(client, "{\"success\": false}", 18);
ipc_client_disconnect(client);
@@ -633,3 +637,52 @@ void ipc_event_modifier(uint32_t modifier, const char *state) {
json_object_put(obj); // free
}
+
+#if SWAY_BINDING_EVENT
+static void ipc_event_binding(json_object *sb_obj) {
+ json_object *obj = json_object_new_object();
+ json_object_object_add(obj, "change", json_object_new_string("run"));
+ json_object_object_add(obj, "binding", sb_obj);
+
+ const char *json_string = json_object_to_json_string(obj);
+ ipc_send_event(json_string, IPC_EVENT_BINDING);
+
+ json_object_put(obj); // free
+}
+#endif
+
+void ipc_event_binding_keyboard(struct sway_binding *sb) {
+#if SWAY_BINDING_EVENT
+ json_object *sb_obj = json_object_new_object();
+ json_object_object_add(sb_obj, "command", json_object_new_string(sb->command));
+
+ const char *names[10];
+
+ int len = get_modifier_names(names, sb->modifiers);
+ int i;
+ json_object *modifiers = json_object_new_array();
+ for (i = 0; i < len; ++i) {
+ json_object_array_add(modifiers, json_object_new_string(names[i]));
+ }
+
+ json_object_object_add(sb_obj, "event_state_mask", modifiers);
+
+ // TODO: implement bindcode
+ json_object_object_add(sb_obj, "input_code", json_object_new_int(0));
+
+ json_object *symbols = json_object_new_array();
+ uint32_t keysym;
+ char buffer[64];
+ for (i = 0; i < sb->keys->length; ++i) {
+ keysym = *(uint32_t *)sb->keys->items[i];
+ if (xkb_keysym_get_name(keysym, buffer, 64) > 0) {
+ json_object_array_add(symbols, json_object_new_string(buffer));
+ }
+ }
+
+ json_object_object_add(sb_obj, "symbols", symbols);
+ json_object_object_add(sb_obj, "input_type", json_object_new_string("keyboard"));
+
+ ipc_event_binding(sb_obj);
+#endif
+}