aboutsummaryrefslogtreecommitdiffstats
path: root/sway/commands/bind.c
diff options
context:
space:
mode:
authorLibravatar Brian Ashworth <bosrsf04@gmail.com>2019-07-26 12:02:18 -0400
committerLibravatar Simon Ser <contact@emersion.fr>2019-08-01 18:54:58 +0300
commit8ee054b1b95b7466c0dd89bfc9026f4083fb0016 (patch)
treebce2d4bfba93e6889c1aa57085297e4a997af2d8 /sway/commands/bind.c
parentinput/keyboard: don't reset layout for same keymap (diff)
downloadsway-8ee054b1b95b7466c0dd89bfc9026f4083fb0016.tar.gz
sway-8ee054b1b95b7466c0dd89bfc9026f4083fb0016.tar.zst
sway-8ee054b1b95b7466c0dd89bfc9026f4083fb0016.zip
bindsym/code: add group support
This adds support for specifying a binding for a specific group. Any binding without a group listed will be available in all groups. The priority for matching bindings is as follows: input device, group, and locked state. For full compatibility with i3, this also adds Mode_switch as an alias for Group2. Since i3 only supports this for backwards compatibility with older versions of i3, it is implemented here, but not documented.
Diffstat (limited to 'sway/commands/bind.c')
-rw-r--r--sway/commands/bind.c33
1 files changed, 33 insertions, 0 deletions
diff --git a/sway/commands/bind.c b/sway/commands/bind.c
index 767c2fee..5ec89982 100644
--- a/sway/commands/bind.c
+++ b/sway/commands/bind.c
@@ -78,6 +78,10 @@ static bool binding_key_compare(struct sway_binding *binding_a,
78 return false; 78 return false;
79 } 79 }
80 80
81 if (binding_a->group != binding_b->group) {
82 return false;
83 }
84
81 if (binding_a->modifiers ^ binding_b->modifiers) { 85 if (binding_a->modifiers ^ binding_b->modifiers) {
82 return false; 86 return false;
83 } 87 }
@@ -337,6 +341,7 @@ static struct cmd_results *cmd_bindsym_or_bindcode(int argc, char **argv,
337 } 341 }
338 binding->input = strdup("*"); 342 binding->input = strdup("*");
339 binding->keys = create_list(); 343 binding->keys = create_list();
344 binding->group = XKB_LAYOUT_INVALID;
340 binding->modifiers = 0; 345 binding->modifiers = 0;
341 binding->flags = 0; 346 binding->flags = 0;
342 binding->type = bindcode ? BINDING_KEYCODE : BINDING_KEYSYM; 347 binding->type = bindcode ? BINDING_KEYCODE : BINDING_KEYSYM;
@@ -387,6 +392,34 @@ static struct cmd_results *cmd_bindsym_or_bindcode(int argc, char **argv,
387 392
388 list_t *split = split_string(argv[0], "+"); 393 list_t *split = split_string(argv[0], "+");
389 for (int i = 0; i < split->length; ++i) { 394 for (int i = 0; i < split->length; ++i) {
395 // Check for group
396 if (strncmp(split->items[i], "Group", strlen("Group")) == 0) {
397 if (binding->group != XKB_LAYOUT_INVALID) {
398 free_sway_binding(binding);
399 list_free_items_and_destroy(split);
400 return cmd_results_new(CMD_FAILURE,
401 "Only one group can be specified");
402 }
403 char *end;
404 int group = strtol(split->items[i] + strlen("Group"), &end, 10);
405 if (group < 1 || group > 4 || end[0] != '\0') {
406 free_sway_binding(binding);
407 list_free_items_and_destroy(split);
408 return cmd_results_new(CMD_FAILURE, "Invalid group");
409 }
410 binding->group = group - 1;
411 continue;
412 } else if (strcmp(split->items[i], "Mode_switch") == 0) {
413 // For full i3 compatibility, Mode_switch is an alias for Group2
414 if (binding->group != XKB_LAYOUT_INVALID) {
415 free_sway_binding(binding);
416 list_free_items_and_destroy(split);
417 return cmd_results_new(CMD_FAILURE,
418 "Only one group can be specified");
419 }
420 binding->group = 1;
421 }
422
390 // Check for a modifier key 423 // Check for a modifier key
391 uint32_t mod; 424 uint32_t mod;
392 if ((mod = get_modifier_mask_by_name(split->items[i])) > 0) { 425 if ((mod = get_modifier_mask_by_name(split->items[i])) > 0) {