diff options
Diffstat (limited to 'sway/commands.c')
-rw-r--r-- | sway/commands.c | 58 |
1 files changed, 17 insertions, 41 deletions
diff --git a/sway/commands.c b/sway/commands.c index 9cc33b9c..4e5bc712 100644 --- a/sway/commands.c +++ b/sway/commands.c | |||
@@ -99,22 +99,6 @@ static sway_cmd bar_colors_cmd_urgent_workspace; | |||
99 | swayc_t *sp_view; | 99 | swayc_t *sp_view; |
100 | int sp_index = 0; | 100 | int sp_index = 0; |
101 | 101 | ||
102 | static struct modifier_key { | ||
103 | char *name; | ||
104 | uint32_t mod; | ||
105 | } modifiers[] = { | ||
106 | { XKB_MOD_NAME_SHIFT, WLC_BIT_MOD_SHIFT }, | ||
107 | { XKB_MOD_NAME_CAPS, WLC_BIT_MOD_CAPS }, | ||
108 | { XKB_MOD_NAME_CTRL, WLC_BIT_MOD_CTRL }, | ||
109 | { "Ctrl", WLC_BIT_MOD_CTRL }, | ||
110 | { XKB_MOD_NAME_ALT, WLC_BIT_MOD_ALT }, | ||
111 | { "Alt", WLC_BIT_MOD_ALT }, | ||
112 | { XKB_MOD_NAME_NUM, WLC_BIT_MOD_MOD2 }, | ||
113 | { "Mod3", WLC_BIT_MOD_MOD3 }, | ||
114 | { XKB_MOD_NAME_LOGO, WLC_BIT_MOD_LOGO }, | ||
115 | { "Mod5", WLC_BIT_MOD_MOD5 }, | ||
116 | }; | ||
117 | |||
118 | static char *bg_options[] = { | 102 | static char *bg_options[] = { |
119 | "stretch", | 103 | "stretch", |
120 | "center", | 104 | "center", |
@@ -187,16 +171,11 @@ static struct cmd_results *cmd_bindsym(int argc, char **argv) { | |||
187 | list_t *split = split_string(argv[0], "+"); | 171 | list_t *split = split_string(argv[0], "+"); |
188 | for (int i = 0; i < split->length; ++i) { | 172 | for (int i = 0; i < split->length; ++i) { |
189 | // Check for a modifier key | 173 | // Check for a modifier key |
190 | int j; | 174 | uint32_t mod; |
191 | bool is_mod = false; | 175 | if ((mod = get_modifier_mask_by_name(split->items[i])) > 0) { |
192 | for (j = 0; j < (int)(sizeof(modifiers) / sizeof(struct modifier_key)); ++j) { | 176 | binding->modifiers |= mod; |
193 | if (strcasecmp(modifiers[j].name, split->items[i]) == 0) { | 177 | continue; |
194 | binding->modifiers |= modifiers[j].mod; | ||
195 | is_mod = true; | ||
196 | break; | ||
197 | } | ||
198 | } | 178 | } |
199 | if (is_mod) continue; | ||
200 | // Check for xkb key | 179 | // Check for xkb key |
201 | xkb_keysym_t sym = xkb_keysym_from_name(split->items[i], XKB_KEYSYM_CASE_INSENSITIVE); | 180 | xkb_keysym_t sym = xkb_keysym_from_name(split->items[i], XKB_KEYSYM_CASE_INSENSITIVE); |
202 | if (!sym) { | 181 | if (!sym) { |
@@ -408,17 +387,13 @@ static struct cmd_results *cmd_floating_mod(int argc, char **argv) { | |||
408 | if ((error = checkarg(argc, "floating_modifier", EXPECTED_AT_LEAST, 1))) { | 387 | if ((error = checkarg(argc, "floating_modifier", EXPECTED_AT_LEAST, 1))) { |
409 | return error; | 388 | return error; |
410 | } | 389 | } |
411 | int i, j; | 390 | int i; |
412 | list_t *split = split_string(argv[0], "+"); | 391 | list_t *split = split_string(argv[0], "+"); |
413 | config->floating_mod = 0; | 392 | config->floating_mod = 0; |
414 | 393 | ||
415 | // set modifier keys | 394 | // set modifier keys |
416 | for (i = 0; i < split->length; ++i) { | 395 | for (i = 0; i < split->length; ++i) { |
417 | for (j = 0; j < (int)(sizeof(modifiers) / sizeof(struct modifier_key)); ++j) { | 396 | config->floating_mod |= get_modifier_mask_by_name(split->items[i]); |
418 | if (strcasecmp(modifiers[j].name, split->items[i]) == 0) { | ||
419 | config->floating_mod |= modifiers[j].mod; | ||
420 | } | ||
421 | } | ||
422 | } | 397 | } |
423 | free_flat_list(split); | 398 | free_flat_list(split); |
424 | if (!config->floating_mod) { | 399 | if (!config->floating_mod) { |
@@ -1776,6 +1751,9 @@ static struct cmd_results *bar_cmd_hidden_state(int argc, char **argv) { | |||
1776 | } | 1751 | } |
1777 | } | 1752 | } |
1778 | 1753 | ||
1754 | // active bar modifiers might have changed. | ||
1755 | update_active_bar_modifiers(); | ||
1756 | |||
1779 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | 1757 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); |
1780 | } | 1758 | } |
1781 | 1759 | ||
@@ -1800,6 +1778,9 @@ static struct cmd_results *bar_set_mode(struct bar_config *bar, const char *mode | |||
1800 | if (strcmp(old_mode, bar->mode) != 0) { | 1778 | if (strcmp(old_mode, bar->mode) != 0) { |
1801 | if (!config->reading) { | 1779 | if (!config->reading) { |
1802 | ipc_event_barconfig_update(bar); | 1780 | ipc_event_barconfig_update(bar); |
1781 | |||
1782 | // active bar modifiers might have changed. | ||
1783 | update_active_bar_modifiers(); | ||
1803 | } | 1784 | } |
1804 | sway_log(L_DEBUG, "Setting mode: '%s' for bar: %s", bar->mode, bar->id); | 1785 | sway_log(L_DEBUG, "Setting mode: '%s' for bar: %s", bar->mode, bar->id); |
1805 | } | 1786 | } |
@@ -1893,16 +1874,11 @@ static struct cmd_results *bar_cmd_modifier(int argc, char **argv) { | |||
1893 | 1874 | ||
1894 | list_t *split = split_string(argv[0], "+"); | 1875 | list_t *split = split_string(argv[0], "+"); |
1895 | for (int i = 0; i < split->length; ++i) { | 1876 | for (int i = 0; i < split->length; ++i) { |
1896 | int j; | 1877 | uint32_t tmp_mod; |
1897 | bool is_mod = false; | 1878 | if ((tmp_mod = get_modifier_mask_by_name(split->items[i])) > 0) { |
1898 | for (j = 0; j < (int)(sizeof(modifiers) / sizeof(struct modifier_key)); ++j) { | 1879 | mod |= tmp_mod; |
1899 | if (strcasecmp(modifiers[j].name, split->items[i]) == 0) { | 1880 | continue; |
1900 | mod |= modifiers[j].mod; | 1881 | } else { |
1901 | is_mod = true; | ||
1902 | break; | ||
1903 | } | ||
1904 | } | ||
1905 | if (!is_mod) { | ||
1906 | free_flat_list(split); | 1882 | free_flat_list(split); |
1907 | return cmd_results_new(CMD_INVALID, "modifier", "Unknown modifier '%s'", split->items[i]); | 1883 | return cmd_results_new(CMD_INVALID, "modifier", "Unknown modifier '%s'", split->items[i]); |
1908 | } | 1884 | } |