diff options
Diffstat (limited to 'sway/commands/bar.c')
-rw-r--r-- | sway/commands/bar.c | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/sway/commands/bar.c b/sway/commands/bar.c new file mode 100644 index 00000000..9e7d6c5c --- /dev/null +++ b/sway/commands/bar.c | |||
@@ -0,0 +1,51 @@ | |||
1 | #include <stdio.h> | ||
2 | #include <string.h> | ||
3 | #include "commands.h" | ||
4 | #include "config.h" | ||
5 | #include "log.h" | ||
6 | #include "util.h" | ||
7 | |||
8 | struct cmd_results *cmd_bar(int argc, char **argv) { | ||
9 | struct cmd_results *error = NULL; | ||
10 | if ((error = checkarg(argc, "bar", EXPECTED_AT_LEAST, 1))) { | ||
11 | return error; | ||
12 | } | ||
13 | |||
14 | if (config->reading && strcmp("{", argv[0]) != 0) { | ||
15 | return cmd_results_new(CMD_INVALID, "bar", | ||
16 | "Expected '{' at start of bar config definition."); | ||
17 | } | ||
18 | |||
19 | if (!config->reading) { | ||
20 | if (argc > 1) { | ||
21 | if (strcasecmp("mode", argv[0]) == 0) { | ||
22 | return bar_cmd_mode(argc-1, argv + 1); | ||
23 | } | ||
24 | |||
25 | if (strcasecmp("hidden_state", argv[0]) == 0) { | ||
26 | return bar_cmd_hidden_state(argc-1, argv + 1); | ||
27 | } | ||
28 | } | ||
29 | |||
30 | return cmd_results_new(CMD_FAILURE, "bar", "Can only be used in config file."); | ||
31 | } | ||
32 | |||
33 | // Create new bar with default values | ||
34 | struct bar_config *bar = default_bar_config(); | ||
35 | |||
36 | // set bar id | ||
37 | int i; | ||
38 | for (i = 0; i < config->bars->length; ++i) { | ||
39 | if (bar == config->bars->items[i]) { | ||
40 | const int len = 5 + numlen(i); // "bar-" + i + \0 | ||
41 | bar->id = malloc(len * sizeof(char)); | ||
42 | snprintf(bar->id, len, "bar-%d", i); | ||
43 | break; | ||
44 | } | ||
45 | } | ||
46 | |||
47 | // Set current bar | ||
48 | config->current_bar = bar; | ||
49 | sway_log(L_DEBUG, "Configuring bar %s", bar->id); | ||
50 | return cmd_results_new(CMD_BLOCK_BAR, NULL, NULL); | ||
51 | } | ||