diff options
-rw-r--r-- | sway/handlers.c | 48 |
1 files changed, 38 insertions, 10 deletions
diff --git a/sway/handlers.c b/sway/handlers.c index d992a7b6..cec63192 100644 --- a/sway/handlers.c +++ b/sway/handlers.c | |||
@@ -405,7 +405,28 @@ static void handle_binding_command(struct sway_binding *binding) { | |||
405 | free_cmd_results(res); | 405 | free_cmd_results(res); |
406 | } | 406 | } |
407 | 407 | ||
408 | static bool handle_bindsym(struct sway_binding *binding) { | 408 | static bool handle_bindsym(struct sway_binding *binding, uint32_t keysym, uint32_t keycode) { |
409 | int i; | ||
410 | for (i = 0; i < binding->keys->length; ++i) { | ||
411 | if (binding->bindcode) { | ||
412 | xkb_keycode_t *key = binding->keys->items[i]; | ||
413 | if (keycode == *key) { | ||
414 | handle_binding_command(binding); | ||
415 | return true; | ||
416 | } | ||
417 | } else { | ||
418 | xkb_keysym_t *key = binding->keys->items[i]; | ||
419 | if (keysym == *key) { | ||
420 | handle_binding_command(binding); | ||
421 | return true; | ||
422 | } | ||
423 | } | ||
424 | } | ||
425 | |||
426 | return false; | ||
427 | } | ||
428 | |||
429 | static bool valid_bindsym(struct sway_binding *binding) { | ||
409 | bool match = false; | 430 | bool match = false; |
410 | int i; | 431 | int i; |
411 | for (i = 0; i < binding->keys->length; ++i) { | 432 | for (i = 0; i < binding->keys->length; ++i) { |
@@ -422,12 +443,7 @@ static bool handle_bindsym(struct sway_binding *binding) { | |||
422 | } | 443 | } |
423 | } | 444 | } |
424 | 445 | ||
425 | if (match) { | 446 | return match; |
426 | handle_binding_command(binding); | ||
427 | return true; | ||
428 | } | ||
429 | |||
430 | return false; | ||
431 | } | 447 | } |
432 | 448 | ||
433 | static bool handle_bindsym_release(struct sway_binding *binding) { | 449 | static bool handle_bindsym_release(struct sway_binding *binding) { |
@@ -489,18 +505,19 @@ static bool handle_key(wlc_handle view, uint32_t time, const struct wlc_modifier | |||
489 | modifiers_state_update(modifiers->mods); | 505 | modifiers_state_update(modifiers->mods); |
490 | 506 | ||
491 | // handle bindings | 507 | // handle bindings |
508 | list_t *candidates = create_list(); | ||
492 | for (i = 0; i < mode->bindings->length; ++i) { | 509 | for (i = 0; i < mode->bindings->length; ++i) { |
493 | struct sway_binding *binding = mode->bindings->items[i]; | 510 | struct sway_binding *binding = mode->bindings->items[i]; |
494 | if ((modifiers->mods ^ binding->modifiers) == 0) { | 511 | if ((modifiers->mods ^ binding->modifiers) == 0) { |
495 | switch (state) { | 512 | switch (state) { |
496 | case WLC_KEY_STATE_PRESSED: { | 513 | case WLC_KEY_STATE_PRESSED: { |
497 | if (!binding->release && handle_bindsym(binding)) { | 514 | if (!binding->release && valid_bindsym(binding)) { |
498 | return EVENT_HANDLED; | 515 | list_add(candidates, binding); |
499 | } | 516 | } |
500 | break; | ||
501 | } | 517 | } |
502 | case WLC_KEY_STATE_RELEASED: | 518 | case WLC_KEY_STATE_RELEASED: |
503 | if (binding->release && handle_bindsym_release(binding)) { | 519 | if (binding->release && handle_bindsym_release(binding)) { |
520 | list_free(candidates); | ||
504 | return EVENT_HANDLED; | 521 | return EVENT_HANDLED; |
505 | } | 522 | } |
506 | break; | 523 | break; |
@@ -508,6 +525,17 @@ static bool handle_key(wlc_handle view, uint32_t time, const struct wlc_modifier | |||
508 | } | 525 | } |
509 | } | 526 | } |
510 | 527 | ||
528 | for (i = 0; i < candidates->length; ++i) { | ||
529 | struct sway_binding *binding = candidates->items[i]; | ||
530 | if (state == WLC_KEY_STATE_PRESSED) { | ||
531 | if (!binding->release && handle_bindsym(binding, sym, key)) { | ||
532 | list_free(candidates); | ||
533 | return EVENT_HANDLED; | ||
534 | } | ||
535 | } | ||
536 | } | ||
537 | |||
538 | list_free(candidates); | ||
511 | return EVENT_PASSTHROUGH; | 539 | return EVENT_PASSTHROUGH; |
512 | } | 540 | } |
513 | 541 | ||