diff options
Diffstat (limited to 'sway/commands.c')
-rw-r--r-- | sway/commands.c | 30 |
1 files changed, 10 insertions, 20 deletions
diff --git a/sway/commands.c b/sway/commands.c index 6e9137c0..5b3b1d0f 100644 --- a/sway/commands.c +++ b/sway/commands.c | |||
@@ -132,19 +132,6 @@ static struct cmd_results *checkarg(int argc, const char *name, enum expected_ar | |||
132 | return error; | 132 | return error; |
133 | } | 133 | } |
134 | 134 | ||
135 | static int bindsym_sort(const void *_lbind, const void *_rbind) { | ||
136 | const struct sway_binding *lbind = *(void **)_lbind; | ||
137 | const struct sway_binding *rbind = *(void **)_rbind; | ||
138 | unsigned int lmod = 0, rmod = 0, i; | ||
139 | |||
140 | // Count how any modifiers are pressed | ||
141 | for (i = 0; i < 8 * sizeof(lbind->modifiers); ++i) { | ||
142 | lmod += lbind->modifiers & 1 << i; | ||
143 | rmod += rbind->modifiers & 1 << i; | ||
144 | } | ||
145 | return (rbind->keys->length + rmod) - (lbind->keys->length + lmod); | ||
146 | } | ||
147 | |||
148 | static struct cmd_results *cmd_bindsym(int argc, char **argv) { | 135 | static struct cmd_results *cmd_bindsym(int argc, char **argv) { |
149 | struct cmd_results *error = NULL; | 136 | struct cmd_results *error = NULL; |
150 | if ((error = checkarg(argc, "bindsym", EXPECTED_MORE_THAN, 1))) { | 137 | if ((error = checkarg(argc, "bindsym", EXPECTED_MORE_THAN, 1))) { |
@@ -159,8 +146,7 @@ static struct cmd_results *cmd_bindsym(int argc, char **argv) { | |||
159 | binding->command = join_args(argv + 1, argc - 1); | 146 | binding->command = join_args(argv + 1, argc - 1); |
160 | 147 | ||
161 | list_t *split = split_string(argv[0], "+"); | 148 | list_t *split = split_string(argv[0], "+"); |
162 | int i; | 149 | for (int i = 0; i < split->length; ++i) { |
163 | for (i = 0; i < split->length; ++i) { | ||
164 | // Check for a modifier key | 150 | // Check for a modifier key |
165 | int j; | 151 | int j; |
166 | bool is_mod = false; | 152 | bool is_mod = false; |
@@ -176,9 +162,7 @@ static struct cmd_results *cmd_bindsym(int argc, char **argv) { | |||
176 | xkb_keysym_t sym = xkb_keysym_from_name(split->items[i], XKB_KEYSYM_CASE_INSENSITIVE); | 162 | xkb_keysym_t sym = xkb_keysym_from_name(split->items[i], XKB_KEYSYM_CASE_INSENSITIVE); |
177 | if (!sym) { | 163 | if (!sym) { |
178 | error = cmd_results_new(CMD_INVALID, "bindsym", "Unknown key '%s'", (char *)split->items[i]); | 164 | error = cmd_results_new(CMD_INVALID, "bindsym", "Unknown key '%s'", (char *)split->items[i]); |
179 | list_free(binding->keys); | 165 | free_sway_binding(binding); |
180 | free(binding->command); | ||
181 | free(binding); | ||
182 | list_free(split); | 166 | list_free(split); |
183 | return error; | 167 | return error; |
184 | } | 168 | } |
@@ -188,10 +172,16 @@ static struct cmd_results *cmd_bindsym(int argc, char **argv) { | |||
188 | } | 172 | } |
189 | free_flat_list(split); | 173 | free_flat_list(split); |
190 | 174 | ||
191 | // TODO: Check if there are other commands with this key binding | ||
192 | struct sway_mode *mode = config->current_mode; | 175 | struct sway_mode *mode = config->current_mode; |
176 | int i = list_seq_find(mode->bindings, sway_binding_cmp_keys, binding); | ||
177 | if (i > -1) { | ||
178 | sway_log(L_DEBUG, "bindsym - '%s' already exists, overwriting", argv[0]); | ||
179 | struct sway_binding *dup = mode->bindings->items[i]; | ||
180 | free_sway_binding(dup); | ||
181 | list_del(mode->bindings, i); | ||
182 | } | ||
193 | list_add(mode->bindings, binding); | 183 | list_add(mode->bindings, binding); |
194 | list_sort(mode->bindings, bindsym_sort); | 184 | list_sort(mode->bindings, sway_binding_cmp); |
195 | 185 | ||
196 | sway_log(L_DEBUG, "bindsym - Bound %s to command %s", argv[0], binding->command); | 186 | sway_log(L_DEBUG, "bindsym - Bound %s to command %s", argv[0], binding->command); |
197 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | 187 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); |