aboutsummaryrefslogtreecommitdiffstats
path: root/sway/ipc-server.c
diff options
context:
space:
mode:
authorLibravatar Nathan Rossi <nathan@nathanrossi.com>2020-01-30 23:50:07 +1000
committerLibravatar Simon Ser <contact@emersion.fr>2020-01-30 15:03:54 +0100
commitffbf10d07b19a052e2b6d5ef524f7201fe0012c8 (patch)
treeee95e047733e2d1138dd204d0b69b795c3ecbac0 /sway/ipc-server.c
parentadd danish README (diff)
downloadsway-ffbf10d07b19a052e2b6d5ef524f7201fe0012c8.tar.gz
sway-ffbf10d07b19a052e2b6d5ef524f7201fe0012c8.tar.zst
sway-ffbf10d07b19a052e2b6d5ef524f7201fe0012c8.zip
ipc: Handle unsupported binding event types
Handle binding event types that cannot be encoded gracefully by dropping the event. This prevents issues for binding types like BINDING_SWITCH, where the event would cause a crash.
Diffstat (limited to 'sway/ipc-server.c')
-rw-r--r--sway/ipc-server.c17
1 files changed, 15 insertions, 2 deletions
diff --git a/sway/ipc-server.c b/sway/ipc-server.c
index 9c4f7a64..54b33ca6 100644
--- a/sway/ipc-server.c
+++ b/sway/ipc-server.c
@@ -421,7 +421,8 @@ void ipc_event_binding(struct sway_binding *binding) {
421 json_object *symbols = json_object_new_array(); 421 json_object *symbols = json_object_new_array();
422 json_object *symbol = NULL; 422 json_object *symbol = NULL;
423 423
424 if (binding->type == BINDING_KEYCODE) { // bindcode: populate input_codes 424 switch (binding->type) {
425 case BINDING_KEYCODE:; // bindcode: populate input_codes
425 uint32_t keycode; 426 uint32_t keycode;
426 for (int i = 0; i < binding->keys->length; ++i) { 427 for (int i = 0; i < binding->keys->length; ++i) {
427 keycode = *(uint32_t *)binding->keys->items[i]; 428 keycode = *(uint32_t *)binding->keys->items[i];
@@ -430,7 +431,11 @@ void ipc_event_binding(struct sway_binding *binding) {
430 input_code = keycode; 431 input_code = keycode;
431 } 432 }
432 } 433 }
433 } else { // bindsym/mouse: populate symbols 434 break;
435
436 case BINDING_KEYSYM:
437 case BINDING_MOUSESYM:
438 case BINDING_MOUSECODE:; // bindsym/mouse: populate symbols
434 uint32_t keysym; 439 uint32_t keysym;
435 char buffer[64]; 440 char buffer[64];
436 for (int i = 0; i < binding->keys->length; ++i) { 441 for (int i = 0; i < binding->keys->length; ++i) {
@@ -451,6 +456,14 @@ void ipc_event_binding(struct sway_binding *binding) {
451 json_object_array_add(symbols, str); 456 json_object_array_add(symbols, str);
452 } 457 }
453 } 458 }
459 break;
460
461 default:
462 sway_log(SWAY_DEBUG, "Unsupported ipc binding event");
463 json_object_put(input_codes);
464 json_object_put(symbols);
465 json_object_put(json_binding);
466 return; // do not send any event
454 } 467 }
455 468
456 json_object_object_add(json_binding, "input_codes", input_codes); 469 json_object_object_add(json_binding, "input_codes", input_codes);