aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar taiyu <taiyu.len@gmail.com>2015-11-24 00:30:02 -0800
committerLibravatar taiyu <taiyu.len@gmail.com>2015-11-24 00:30:02 -0800
commit9d50f88ceffc44f5ce0b83cc060bbae649ce898b (patch)
tree894c6b75ae0f5ec4477d703d9c4ad8eec1b67cc4
parentMerge pull request #247 from sce/handle_bindsym_duplicates (diff)
downloadsway-9d50f88ceffc44f5ce0b83cc060bbae649ce898b.tar.gz
sway-9d50f88ceffc44f5ce0b83cc060bbae649ce898b.tar.zst
sway-9d50f88ceffc44f5ce0b83cc060bbae649ce898b.zip
fix list sorting
-rw-r--r--common/list.c8
-rw-r--r--sway/commands.c6
-rw-r--r--sway/config.c20
3 files changed, 21 insertions, 13 deletions
diff --git a/common/list.c b/common/list.c
index 310296d8..d6f6f2ea 100644
--- a/common/list.c
+++ b/common/list.c
@@ -50,8 +50,14 @@ void list_cat(list_t *list, list_t *source) {
50 } 50 }
51} 51}
52 52
53// pass the pointer of the object we care about to the comparison function
54static int list_cmp(const void *l, const void *r, void *_cmp) {
55 int (*cmp)(const void *, const void *) = _cmp;
56 return cmp(*(void**)l, *(void**)r);
57}
58
53void list_sort(list_t *list, int compare(const void *left, const void *right)) { 59void list_sort(list_t *list, int compare(const void *left, const void *right)) {
54 qsort(list->items, list->length, sizeof(void *), compare); 60 qsort_r(list->items, list->length, sizeof(void *), list_cmp, compare);
55} 61}
56 62
57int list_seq_find(list_t *list, int compare(const void *item, const void *data), const void *data) { 63int list_seq_find(list_t *list, int compare(const void *item, const void *data), const void *data) {
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
1130static int compare_set(const void *_l, const void *_r) { 1130static 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
1136static struct cmd_results *cmd_set(int argc, char **argv) { 1136static 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) {
387int sway_binding_cmp_keys(const void *a, const void *b) { 387int 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];