aboutsummaryrefslogtreecommitdiffstats
path: root/sway/ipc-server.c
diff options
context:
space:
mode:
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) {
298 client->subscribed_events |= IPC_EVENT_MODE; 298 client->subscribed_events |= IPC_EVENT_MODE;
299 } else if (strcmp(event_type, "modifier") == 0) { 299 } else if (strcmp(event_type, "modifier") == 0) {
300 client->subscribed_events |= IPC_EVENT_MODIFIER; 300 client->subscribed_events |= IPC_EVENT_MODIFIER;
301#if SWAY_BINDING_EVENT
302 } else if (strcmp(event_type, "binding") == 0) {
303 client->subscribed_events |= IPC_EVENT_BINDING;
304#endif
301 } else { 305 } else {
302 ipc_send_reply(client, "{\"success\": false}", 18); 306 ipc_send_reply(client, "{\"success\": false}", 18);
303 ipc_client_disconnect(client); 307 ipc_client_disconnect(client);
@@ -633,3 +637,52 @@ void ipc_event_modifier(uint32_t modifier, const char *state) {
633 637
634 json_object_put(obj); // free 638 json_object_put(obj); // free
635} 639}
640
641#if SWAY_BINDING_EVENT
642static void ipc_event_binding(json_object *sb_obj) {
643 json_object *obj = json_object_new_object();
644 json_object_object_add(obj, "change", json_object_new_string("run"));
645 json_object_object_add(obj, "binding", sb_obj);
646
647 const char *json_string = json_object_to_json_string(obj);
648 ipc_send_event(json_string, IPC_EVENT_BINDING);
649
650 json_object_put(obj); // free
651}
652#endif
653
654void ipc_event_binding_keyboard(struct sway_binding *sb) {
655#if SWAY_BINDING_EVENT
656 json_object *sb_obj = json_object_new_object();
657 json_object_object_add(sb_obj, "command", json_object_new_string(sb->command));
658
659 const char *names[10];
660
661 int len = get_modifier_names(names, sb->modifiers);
662 int i;
663 json_object *modifiers = json_object_new_array();
664 for (i = 0; i < len; ++i) {
665 json_object_array_add(modifiers, json_object_new_string(names[i]));
666 }
667
668 json_object_object_add(sb_obj, "event_state_mask", modifiers);
669
670 // TODO: implement bindcode
671 json_object_object_add(sb_obj, "input_code", json_object_new_int(0));
672
673 json_object *symbols = json_object_new_array();
674 uint32_t keysym;
675 char buffer[64];
676 for (i = 0; i < sb->keys->length; ++i) {
677 keysym = *(uint32_t *)sb->keys->items[i];
678 if (xkb_keysym_get_name(keysym, buffer, 64) > 0) {
679 json_object_array_add(symbols, json_object_new_string(buffer));
680 }
681 }
682
683 json_object_object_add(sb_obj, "symbols", symbols);
684 json_object_object_add(sb_obj, "input_type", json_object_new_string("keyboard"));
685
686 ipc_event_binding(sb_obj);
687#endif
688}