aboutsummaryrefslogtreecommitdiff
path: root/sway/commands
diff options
context:
space:
mode:
authorfrsfnrrg <frsfnrrg@users.noreply.github.com>2018-06-12 10:37:47 -0400
committerfrsfnrrg <frsfnrrg@users.noreply.github.com>2018-06-12 11:26:24 -0400
commitb23cd827cf934ef7f631b7c448e7afa4147c1936 (patch)
treee08b25504f68e20d95c484b0b57ec2caedf27978 /sway/commands
parent867fb6aedbbe4cd1c7f4817848682609e8489880 (diff)
Sort binding key lists
Sort the list comprising the set of keys for the binding in ascending order. (Keyboard shortcuts depend only on the set of simultaneously pressed keys, not their order, so this change should have no external effect.) This simplifies comparisons between bindings.
Diffstat (limited to 'sway/commands')
-rw-r--r--sway/commands/bind.c25
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;