diff options
author | Mikkel Oscar Lyderik <mikkeloscar@gmail.com> | 2016-01-06 17:01:45 +0100 |
---|---|---|
committer | Mikkel Oscar Lyderik <mikkeloscar@gmail.com> | 2016-01-08 03:03:55 +0100 |
commit | 6392abe35b32c66c642c25a7c6911021862d3413 (patch) | |
tree | 0949eee2d8dd8833478adc8f145f4e840f267359 /sway/ipc-server.c | |
parent | Add function for duplication a sway_binding (diff) | |
download | sway-6392abe35b32c66c642c25a7c6911021862d3413.tar.gz sway-6392abe35b32c66c642c25a7c6911021862d3413.tar.zst sway-6392abe35b32c66c642c25a7c6911021862d3413.zip |
Implement IPC binding event (keyboard)
This implements the IPC binding event for keyboard bindings. It is
slightly different from the i3 implementation [1] since sway supports
more than one non-modifier key in a binding. Thus the json interface has
been changed from:
{
...
"symbol": "t",
...
}
to:
{
...
"symbols": [ "t" ],
...
}
[1] http://i3wm.org/docs/ipc.html#_binding_event
Diffstat (limited to 'sway/ipc-server.c')
-rw-r--r-- | sway/ipc-server.c | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/sway/ipc-server.c b/sway/ipc-server.c index f3a4647b..d8d8434c 100644 --- a/sway/ipc-server.c +++ b/sway/ipc-server.c | |||
@@ -298,6 +298,8 @@ 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 | } else if (strcmp(event_type, "binding") == 0) { | ||
302 | client->subscribed_events |= IPC_EVENT_BINDING; | ||
301 | } else { | 303 | } else { |
302 | ipc_send_reply(client, "{\"success\": false}", 18); | 304 | ipc_send_reply(client, "{\"success\": false}", 18); |
303 | ipc_client_disconnect(client); | 305 | ipc_client_disconnect(client); |
@@ -633,3 +635,48 @@ void ipc_event_modifier(uint32_t modifier, const char *state) { | |||
633 | 635 | ||
634 | json_object_put(obj); // free | 636 | json_object_put(obj); // free |
635 | } | 637 | } |
638 | |||
639 | static void ipc_event_binding(json_object *sb_obj) { | ||
640 | json_object *obj = json_object_new_object(); | ||
641 | json_object_object_add(obj, "change", json_object_new_string("run")); | ||
642 | json_object_object_add(obj, "binding", sb_obj); | ||
643 | |||
644 | const char *json_string = json_object_to_json_string(obj); | ||
645 | ipc_send_event(json_string, IPC_EVENT_BINDING); | ||
646 | |||
647 | json_object_put(obj); // free | ||
648 | } | ||
649 | |||
650 | void ipc_event_binding_keyboard(struct sway_binding *sb) { | ||
651 | json_object *sb_obj = json_object_new_object(); | ||
652 | json_object_object_add(sb_obj, "command", json_object_new_string(sb->command)); | ||
653 | |||
654 | const char *names[10]; | ||
655 | |||
656 | int len = get_modifier_names(names, sb->modifiers); | ||
657 | int i; | ||
658 | json_object *modifiers = json_object_new_array(); | ||
659 | for (i = 0; i < len; ++i) { | ||
660 | json_object_array_add(modifiers, json_object_new_string(names[i])); | ||
661 | } | ||
662 | |||
663 | json_object_object_add(sb_obj, "event_state_mask", modifiers); | ||
664 | |||
665 | // TODO: implement bindcode | ||
666 | json_object_object_add(sb_obj, "input_code", json_object_new_int(0)); | ||
667 | |||
668 | json_object *symbols = json_object_new_array(); | ||
669 | uint32_t keysym; | ||
670 | char buffer[64]; | ||
671 | for (i = 0; i < sb->keys->length; ++i) { | ||
672 | keysym = *(uint32_t *)sb->keys->items[i]; | ||
673 | if (xkb_keysym_get_name(keysym, buffer, 64) > 0) { | ||
674 | json_object_array_add(symbols, json_object_new_string(buffer)); | ||
675 | } | ||
676 | } | ||
677 | |||
678 | json_object_object_add(sb_obj, "symbols", symbols); | ||
679 | json_object_object_add(sb_obj, "input_type", json_object_new_string("keyboard")); | ||
680 | |||
681 | ipc_event_binding(sb_obj); | ||
682 | } | ||