aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--sway/commands/bind.c17
1 files changed, 10 insertions, 7 deletions
diff --git a/sway/commands/bind.c b/sway/commands/bind.c
index 8f8b6b25..01e7cda0 100644
--- a/sway/commands/bind.c
+++ b/sway/commands/bind.c
@@ -674,7 +674,7 @@ static void add_matching_keycodes(struct xkb_keymap *keymap,
}
}
-void cartesian_product_helper(list_t** sets, int n, xkb_keycode_t** current_result, int* curr_size, xkb_keycode_t* current_product, int depth) {
+void cartesian_product_helper(list_t **sets, int n, xkb_keycode_t** current_result, int* curr_size, xkb_keycode_t* current_product, int depth) {
// Conquer
if (depth == n) {
current_result[*curr_size] = malloc(n * sizeof(xkb_keycode_t));
@@ -695,7 +695,7 @@ void cartesian_product_helper(list_t** sets, int n, xkb_keycode_t** current_resu
/**
* Compute the calculate the Cartesian product of `n` sets
*/
-xkb_keycode_t** cartesian_product(list_t** sets, int n) {
+xkb_keycode_t **cartesian_product(list_t **sets, int n) {
int total_combinations = 1;
for (int i = 0; i < n; ++i) {
total_combinations *= sets[i]->length;
@@ -703,8 +703,8 @@ xkb_keycode_t** cartesian_product(list_t** sets, int n) {
// Allocate memory for the current_result
int result_size = 0;
- xkb_keycode_t** result = malloc(total_combinations * sizeof(xkb_keycode_t*));
- xkb_keycode_t* current_product = malloc(n * sizeof(xkb_keycode_t));
+ xkb_keycode_t **result = malloc(total_combinations * sizeof(xkb_keycode_t*));
+ xkb_keycode_t *current_product = malloc(n * sizeof(xkb_keycode_t));
cartesian_product_helper(sets, n, result, &result_size, current_product, 0);
free(current_product);
@@ -724,7 +724,7 @@ bool translate_binding(struct sway_binding *binding) {
}
int num_syms = binding->keys->length;
- list_t ** sym2code = malloc(num_syms * sizeof(list_t*));
+ list_t **sym2code = malloc(num_syms * sizeof(list_t*));
// Collect all keycodes for all keysyms
for (int i = 0; i < num_syms; i++) {
struct keycode_matches matches = {
@@ -752,9 +752,9 @@ bool translate_binding(struct sway_binding *binding) {
}
// If any keycode maps to more than one keysym, use all combinations.
- xkb_keycode_t** combos = cartesian_product(sym2code, num_syms);
+ xkb_keycode_t **combos = cartesian_product(sym2code, num_syms);
- for (int i = 0; i< num_syms; i++) {
+ for (int i = 0; i < num_syms; i++) {
struct sway_binding * copy_binding = malloc(sizeof(struct sway_binding));
binding->type = BINDING_KEYCODE;
*copy_binding = *binding;
@@ -770,6 +770,9 @@ bool translate_binding(struct sway_binding *binding) {
list_qsort(copy_binding->keys, key_qsort_cmp);
binding_add_translated(copy_binding, config->current_mode->keycode_bindings);
}
+ for (int i = 0; i < num_syms; i++) {
+ list_free_items_and_destroy(sym2code[i]);
+ }
return true;
// if any key cannot be translated, the binding revert to keysym binding