diff options
author | taiyu <taiyu.len@gmail.com> | 2015-11-24 00:30:02 -0800 |
---|---|---|
committer | taiyu <taiyu.len@gmail.com> | 2015-11-24 00:30:02 -0800 |
commit | 9d50f88ceffc44f5ce0b83cc060bbae649ce898b (patch) | |
tree | 894c6b75ae0f5ec4477d703d9c4ad8eec1b67cc4 /sway | |
parent | Merge pull request #247 from sce/handle_bindsym_duplicates (diff) | |
download | sway-9d50f88ceffc44f5ce0b83cc060bbae649ce898b.tar.gz sway-9d50f88ceffc44f5ce0b83cc060bbae649ce898b.tar.zst sway-9d50f88ceffc44f5ce0b83cc060bbae649ce898b.zip |
fix list sorting
Diffstat (limited to 'sway')
-rw-r--r-- | sway/commands.c | 6 | ||||
-rw-r--r-- | sway/config.c | 20 |
2 files changed, 14 insertions, 12 deletions
diff --git a/sway/commands.c b/sway/commands.c index 5b3b1d0f..f6d56bb4 100644 --- a/sway/commands.c +++ b/sway/commands.c | |||
@@ -1128,9 +1128,9 @@ static struct cmd_results *cmd_scratchpad(int argc, char **argv) { | |||
1128 | 1128 | ||
1129 | // sort in order of longest->shortest | 1129 | // sort in order of longest->shortest |
1130 | static int compare_set(const void *_l, const void *_r) { | 1130 | static int compare_set(const void *_l, const void *_r) { |
1131 | struct sway_variable * const *l = _l; | 1131 | struct sway_variable const *l = _l; |
1132 | struct sway_variable * const *r = _r; | 1132 | struct sway_variable const *r = _r; |
1133 | return strlen((*r)->name) - strlen((*l)->name); | 1133 | return strlen(r->name) - strlen(l->name); |
1134 | } | 1134 | } |
1135 | 1135 | ||
1136 | static struct cmd_results *cmd_set(int argc, char **argv) { | 1136 | static struct cmd_results *cmd_set(int argc, char **argv) { |
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]; |