diff options
Diffstat (limited to 'sway/config.c')
-rw-r--r-- | sway/config.c | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/sway/config.c b/sway/config.c index 2fceb6e2..d70c016a 100644 --- a/sway/config.c +++ b/sway/config.c | |||
@@ -383,3 +383,52 @@ int workspace_output_cmp_workspace(const void *a, const void *b) { | |||
383 | const struct workspace_output *wsa = a, *wsb = b; | 383 | const struct workspace_output *wsa = a, *wsb = b; |
384 | return lenient_strcmp(wsa->workspace, wsb->workspace); | 384 | return lenient_strcmp(wsa->workspace, wsb->workspace); |
385 | } | 385 | } |
386 | |||
387 | int sway_binding_cmp_keys(const void *a, const void *b) { | ||
388 | const struct sway_binding *binda = a, *bindb = b; | ||
389 | |||
390 | if (binda->modifiers > bindb->modifiers) { | ||
391 | return 1; | ||
392 | } else if (binda->modifiers < bindb->modifiers) { | ||
393 | return -1; | ||
394 | } | ||
395 | |||
396 | if (binda->keys->length > bindb->keys->length) { | ||
397 | return 1; | ||
398 | } else if (binda->keys->length < bindb->keys->length) { | ||
399 | return -1; | ||
400 | } | ||
401 | |||
402 | for (int i = 0; i < binda->keys->length; i++) { | ||
403 | xkb_keysym_t *ka = binda->keys->items[i], | ||
404 | *kb = bindb->keys->items[i]; | ||
405 | if (*ka > *kb) { | ||
406 | return 1; | ||
407 | } else if (*ka < *kb) { | ||
408 | return -1; | ||
409 | } | ||
410 | } | ||
411 | return 0; | ||
412 | } | ||
413 | |||
414 | int sway_binding_cmp(const void *a, const void *b) { | ||
415 | int cmp = 0; | ||
416 | if ((cmp = sway_binding_cmp_keys(a, b)) != 0) { | ||
417 | return cmp; | ||
418 | } | ||
419 | const struct sway_binding *binda = a, *bindb = b; | ||
420 | return lenient_strcmp(binda->command, bindb->command); | ||
421 | } | ||
422 | |||
423 | void free_sway_binding(struct sway_binding *binding) { | ||
424 | if (binding->keys) { | ||
425 | for (int i = 0; i < binding->keys->length; i++) { | ||
426 | free(binding->keys->items[i]); | ||
427 | } | ||
428 | list_free(binding->keys); | ||
429 | } | ||
430 | if (binding->command) { | ||
431 | free(binding->command); | ||
432 | } | ||
433 | free(binding); | ||
434 | } | ||