summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--include/ipc-server.h4
-rw-r--r--sway/handlers.c6
-rw-r--r--sway/ipc-server.c47
3 files changed, 57 insertions, 0 deletions
diff --git a/include/ipc-server.h b/include/ipc-server.h
index 47026bfd..96b7902f 100644
--- a/include/ipc-server.h
+++ b/include/ipc-server.h
@@ -21,6 +21,10 @@ void ipc_event_mode(const char *mode);
21 * the name of that modifier. 21 * the name of that modifier.
22 */ 22 */
23void ipc_event_modifier(uint32_t modifier, const char *state); 23void ipc_event_modifier(uint32_t modifier, const char *state);
24/**
25 * Send IPC keyboard binding event.
26 */
27void ipc_event_binding_keyboard(struct sway_binding *sb);
24const char *swayc_type_string(enum swayc_types type); 28const char *swayc_type_string(enum swayc_types type);
25 29
26#endif 30#endif
diff --git a/sway/handlers.c b/sway/handlers.c
index e0acebea..693e11eb 100644
--- a/sway/handlers.c
+++ b/sway/handlers.c
@@ -347,11 +347,14 @@ static bool handle_bindsym(struct sway_binding *binding) {
347 } 347 }
348 348
349 if (match) { 349 if (match) {
350 struct sway_binding *binding_copy = sway_binding_dup(binding);
350 struct cmd_results *res = handle_command(binding->command); 351 struct cmd_results *res = handle_command(binding->command);
351 if (res->status != CMD_SUCCESS) { 352 if (res->status != CMD_SUCCESS) {
352 sway_log(L_ERROR, "Command '%s' failed: %s", res->input, res->error); 353 sway_log(L_ERROR, "Command '%s' failed: %s", res->input, res->error);
353 } 354 }
355 ipc_event_binding_keyboard(binding_copy);
354 free_cmd_results(res); 356 free_cmd_results(res);
357 free_sway_binding(binding_copy);
355 return true; 358 return true;
356 } 359 }
357 360
@@ -362,11 +365,14 @@ static bool handle_bindsym_release(struct sway_binding *binding) {
362 if (binding->keys->length == 1) { 365 if (binding->keys->length == 1) {
363 xkb_keysym_t *key = binding->keys->items[0]; 366 xkb_keysym_t *key = binding->keys->items[0];
364 if (check_released_key(*key)) { 367 if (check_released_key(*key)) {
368 struct sway_binding *binding_copy = sway_binding_dup(binding);
365 struct cmd_results *res = handle_command(binding->command); 369 struct cmd_results *res = handle_command(binding->command);
366 if (res->status != CMD_SUCCESS) { 370 if (res->status != CMD_SUCCESS) {
367 sway_log(L_ERROR, "Command '%s' failed: %s", res->input, res->error); 371 sway_log(L_ERROR, "Command '%s' failed: %s", res->input, res->error);
368 } 372 }
373 ipc_event_binding_keyboard(binding_copy);
369 free_cmd_results(res); 374 free_cmd_results(res);
375 free_sway_binding(binding_copy);
370 return true; 376 return true;
371 } 377 }
372 } 378 }
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
639static 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
650void 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}