From e3ddcaabc48e16dea26e4b96adae4c0bc7ef6203 Mon Sep 17 00:00:00 2001 From: Mikkel Oscar Lyderik Date: Sat, 9 Jan 2016 20:31:18 +0100 Subject: [PATCH 1/2] Add bindcode to binding events. --- sway/ipc-server.c | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/sway/ipc-server.c b/sway/ipc-server.c index bde209312..aea458510 100644 --- a/sway/ipc-server.c +++ b/sway/ipc-server.c @@ -667,19 +667,27 @@ void ipc_event_binding_keyboard(struct sway_binding *sb) { 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 *input_codes = json_object_new_array(); 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)); + + if (sb->bindcode) { // bindcode: populate input_codes + uint32_t keycode; + for (i = 0; i < sb->keys->length; ++i) { + keycode = *(uint32_t *)sb->keys->items[i]; + json_object_array_add(input_codes, json_object_new_int(keycode)); + } + } else { // bindsym: populate symbols + 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, "input_codes", input_codes); json_object_object_add(sb_obj, "symbols", symbols); json_object_object_add(sb_obj, "input_type", json_object_new_string("keyboard")); From 15621ea8ffdfe9e0a85ac395297c45bb3b3eb0de Mon Sep 17 00:00:00 2001 From: Mikkel Oscar Lyderik Date: Sat, 9 Jan 2016 20:56:42 +0100 Subject: [PATCH 2/2] Add backwards compatability for binding event --- sway/ipc-server.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/sway/ipc-server.c b/sway/ipc-server.c index aea458510..8d92b919f 100644 --- a/sway/ipc-server.c +++ b/sway/ipc-server.c @@ -668,13 +668,18 @@ void ipc_event_binding_keyboard(struct sway_binding *sb) { json_object_object_add(sb_obj, "event_state_mask", modifiers); json_object *input_codes = json_object_new_array(); + int input_code = 0; json_object *symbols = json_object_new_array(); + json_object *symbol = NULL; if (sb->bindcode) { // bindcode: populate input_codes uint32_t keycode; for (i = 0; i < sb->keys->length; ++i) { keycode = *(uint32_t *)sb->keys->items[i]; json_object_array_add(input_codes, json_object_new_int(keycode)); + if (i == 0) { + input_code = keycode; + } } } else { // bindsym: populate symbols uint32_t keysym; @@ -682,13 +687,19 @@ void ipc_event_binding_keyboard(struct sway_binding *sb) { 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 *str = json_object_new_string(buffer); + json_object_array_add(symbols, str); + if (i == 0) { + symbol = str; + } } } } json_object_object_add(sb_obj, "input_codes", input_codes); + json_object_object_add(sb_obj, "input_code", json_object_new_int(input_code)); json_object_object_add(sb_obj, "symbols", symbols); + json_object_object_add(sb_obj, "symbol", symbol); json_object_object_add(sb_obj, "input_type", json_object_new_string("keyboard")); ipc_event_binding(sb_obj);