1 #include <string.h>
2 #include "sway/commands.h"
3 #include "sway/input/keyboard.h"
4 #include "log.h"
5 #include "stringop.h"
6 
bar_cmd_modifier(int argc,char ** argv)7 struct cmd_results *bar_cmd_modifier(int argc, char **argv) {
8 	struct cmd_results *error = NULL;
9 	if ((error = checkarg(argc, "modifier", EXPECTED_EQUAL_TO, 1))) {
10 		return error;
11 	}
12 
13 	uint32_t mod = 0;
14 	if (strcmp(argv[0], "none") != 0) {
15 		list_t *split = split_string(argv[0], "+");
16 		for (int i = 0; i < split->length; ++i) {
17 			uint32_t tmp_mod;
18 			if ((tmp_mod = get_modifier_mask_by_name(split->items[i])) > 0) {
19 				mod |= tmp_mod;
20 			} else if (strcmp(split->items[i], "none") == 0) {
21 				error = cmd_results_new(CMD_INVALID,
22 						"none cannot be used along with other modifiers");
23 				list_free_items_and_destroy(split);
24 				return error;
25 			} else {
26 				error = cmd_results_new(CMD_INVALID,
27 					"Unknown modifier '%s'", (char *)split->items[i]);
28 				list_free_items_and_destroy(split);
29 				return error;
30 			}
31 		}
32 		list_free_items_and_destroy(split);
33 	}
34 	config->current_bar->modifier = mod;
35 	sway_log(SWAY_DEBUG,
36 			"Show/Hide the bar when pressing '%s' in hide mode.", argv[0]);
37 	return cmd_results_new(CMD_SUCCESS, NULL);
38 }
39