diff options
Diffstat (limited to 'sway/commands.c')
-rw-r--r-- | sway/commands.c | 37 |
1 files changed, 17 insertions, 20 deletions
diff --git a/sway/commands.c b/sway/commands.c index 7f24f5ab..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); |
@@ -1471,6 +1461,13 @@ struct cmd_results *handle_command(char *_exec) { | |||
1471 | return results; | 1461 | return results; |
1472 | } | 1462 | } |
1473 | 1463 | ||
1464 | // this is like handle_command above, except: | ||
1465 | // 1) it ignores empty commands (empty lines) | ||
1466 | // 2) it does variable substitution | ||
1467 | // 3) it doesn't split commands (because the multiple commands are supposed to | ||
1468 | // be chained together) | ||
1469 | // 4) handle_command handles all state internally while config_command has some | ||
1470 | // state handled outside (notably the block mode, in read_config) | ||
1474 | struct cmd_results *config_command(char *exec) { | 1471 | struct cmd_results *config_command(char *exec) { |
1475 | struct cmd_results *results = NULL; | 1472 | struct cmd_results *results = NULL; |
1476 | int argc; | 1473 | int argc; |