aboutsummaryrefslogtreecommitdiff
path: root/sway/config.c
diff options
context:
space:
mode:
authorDrew DeVault <sir@cmpwn.com>2015-11-24 07:37:16 -0500
committerDrew DeVault <sir@cmpwn.com>2015-11-24 07:37:16 -0500
commitc671329681550e0b92aabafd284f9c508511714e (patch)
tree894c6b75ae0f5ec4477d703d9c4ad8eec1b67cc4 /sway/config.c
parentcb11364552213e3dbfce8f8b0e90ce562b4e4c1f (diff)
parent9d50f88ceffc44f5ce0b83cc060bbae649ce898b (diff)
downloadsway-c671329681550e0b92aabafd284f9c508511714e.tar.xz
Merge pull request #248 from taiyu-len/master
fix list sorting
Diffstat (limited to 'sway/config.c')
-rw-r--r--sway/config.c20
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) {
int sway_binding_cmp_keys(const void *a, const void *b) {
const struct sway_binding *binda = a, *bindb = b;
- if (binda->modifiers > bindb->modifiers) {
- return 1;
- } else if (binda->modifiers < bindb->modifiers) {
- return -1;
+ // Count keys pressed for this binding. important so we check long before
+ // short ones. for example mod+a+b before mod+a
+ unsigned int moda = 0, modb = 0, i;
+
+ // Count how any modifiers are pressed
+ for (i = 0; i < 8 * sizeof(binda->modifiers); ++i) {
+ moda += (binda->modifiers & 1 << i) != 0;
+ modb += (bindb->modifiers & 1 << i) != 0;
}
-
- if (binda->keys->length > bindb->keys->length) {
- return 1;
- } else if (binda->keys->length < bindb->keys->length) {
- return -1;
+ if (bindb->keys->length + modb != binda->keys->length + moda) {
+ return (bindb->keys->length + modb) - (binda->keys->length + moda);
}
+ // Otherwise compare keys
for (int i = 0; i < binda->keys->length; i++) {
xkb_keysym_t *ka = binda->keys->items[i],
*kb = bindb->keys->items[i];