diff options
Diffstat (limited to 'sway/config.c')
-rw-r--r-- | sway/config.c | 20 |
1 files changed, 11 insertions, 9 deletions
diff --git a/sway/config.c b/sway/config.c index d70c016a..f2523c1f 100644 --- a/sway/config.c +++ b/sway/config.c | |||
@@ -387,18 +387,20 @@ int workspace_output_cmp_workspace(const void *a, const void *b) { | |||
387 | int sway_binding_cmp_keys(const void *a, const void *b) { | 387 | int sway_binding_cmp_keys(const void *a, const void *b) { |
388 | const struct sway_binding *binda = a, *bindb = b; | 388 | const struct sway_binding *binda = a, *bindb = b; |
389 | 389 | ||
390 | if (binda->modifiers > bindb->modifiers) { | 390 | // Count keys pressed for this binding. important so we check long before |
391 | return 1; | 391 | // short ones. for example mod+a+b before mod+a |
392 | } else if (binda->modifiers < bindb->modifiers) { | 392 | unsigned int moda = 0, modb = 0, i; |
393 | return -1; | 393 | |
394 | // Count how any modifiers are pressed | ||
395 | for (i = 0; i < 8 * sizeof(binda->modifiers); ++i) { | ||
396 | moda += (binda->modifiers & 1 << i) != 0; | ||
397 | modb += (bindb->modifiers & 1 << i) != 0; | ||
394 | } | 398 | } |
395 | 399 | if (bindb->keys->length + modb != binda->keys->length + moda) { | |
396 | if (binda->keys->length > bindb->keys->length) { | 400 | return (bindb->keys->length + modb) - (binda->keys->length + moda); |
397 | return 1; | ||
398 | } else if (binda->keys->length < bindb->keys->length) { | ||
399 | return -1; | ||
400 | } | 401 | } |
401 | 402 | ||
403 | // Otherwise compare keys | ||
402 | for (int i = 0; i < binda->keys->length; i++) { | 404 | for (int i = 0; i < binda->keys->length; i++) { |
403 | xkb_keysym_t *ka = binda->keys->items[i], | 405 | xkb_keysym_t *ka = binda->keys->items[i], |
404 | *kb = bindb->keys->items[i]; | 406 | *kb = bindb->keys->items[i]; |