diff options
author | vil <vil@vil.lv> | 2018-06-17 17:37:58 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-06-17 17:37:58 -0400 |
commit | 8884a063c1c11cb1e2370c3f172fcb9ebd59c991 (patch) | |
tree | 7f2fc2f6cd4ba948df2e9e119e2e109973f638db /sway/commands | |
parent | 54a5ee2747c3eae35e4fec400d1efc6ee7509a38 (diff) | |
parent | 7c44ca95f9aef526c6cfa8c2d3704af39755f38b (diff) | |
download | sway-8884a063c1c11cb1e2370c3f172fcb9ebd59c991.tar.xz |
Merge branch 'master' into mark-pool-buffers-busy
Diffstat (limited to 'sway/commands')
-rw-r--r-- | sway/commands/bind.c | 25 |
1 files changed, 14 insertions, 11 deletions
diff --git a/sway/commands/bind.c b/sway/commands/bind.c index d0e3e22f..821f9cd1 100644 --- a/sway/commands/bind.c +++ b/sway/commands/bind.c @@ -32,7 +32,7 @@ void free_sway_binding(struct sway_binding *binding) { * Note that keyboard layout is not considered, so the bindings might actually * not be equivalent on some layouts. */ -bool binding_key_compare(struct sway_binding *binding_a, +static bool binding_key_compare(struct sway_binding *binding_a, struct sway_binding *binding_b) { if (binding_a->release != binding_b->release) { return false; @@ -50,18 +50,12 @@ bool binding_key_compare(struct sway_binding *binding_a, return false; } + // Keys are sorted int keys_len = binding_a->keys->length; for (int i = 0; i < keys_len; ++i) { - uint32_t key_a = *(uint32_t*)binding_a->keys->items[i]; - bool found = false; - for (int j = 0; j < keys_len; ++j) { - uint32_t key_b = *(uint32_t*)binding_b->keys->items[j]; - if (key_b == key_a) { - found = true; - break; - } - } - if (!found) { + uint32_t key_a = *(uint32_t *)binding_a->keys->items[i]; + uint32_t key_b = *(uint32_t *)binding_b->keys->items[i]; + if (key_a != key_b) { return false; } } @@ -69,6 +63,12 @@ bool binding_key_compare(struct sway_binding *binding_a, return true; } +static int key_qsort_cmp(const void *keyp_a, const void *keyp_b) { + uint32_t key_a = **(uint32_t **)keyp_a; + uint32_t key_b = **(uint32_t **)keyp_b; + return (key_a < key_b) ? -1 : ((key_a > key_b) ? 1 : 0); +} + static struct cmd_results *cmd_bindsym_or_bindcode(int argc, char **argv, bool bindcode) { const char *bindtype = bindcode ? "bindcode" : "bindsym"; @@ -169,6 +169,9 @@ static struct cmd_results *cmd_bindsym_or_bindcode(int argc, char **argv, free_flat_list(split); binding->order = binding_order++; + // sort ascending + list_qsort(binding->keys, key_qsort_cmp); + list_t *mode_bindings; if (bindcode) { mode_bindings = config->current_mode->keycode_bindings; |