aboutsummaryrefslogtreecommitdiffstats
path: root/sway/commands/bar.c
diff options
context:
space:
mode:
authorLibravatar Drew DeVault <sir@cmpwn.com>2018-03-29 17:20:03 -0400
committerLibravatar Drew DeVault <sir@cmpwn.com>2018-03-29 22:11:08 -0400
commitbf7a4cd0ebd465a0597e9eec0142fad222b396de (patch)
treef95c4b8cd8e7d06eaa1b688d3bcbb3249dc21129 /sway/commands/bar.c
parentImplement enough IPC for swaybar to work (diff)
downloadsway-bf7a4cd0ebd465a0597e9eec0142fad222b396de.tar.gz
sway-bf7a4cd0ebd465a0597e9eec0142fad222b396de.tar.zst
sway-bf7a4cd0ebd465a0597e9eec0142fad222b396de.zip
Add bar configuration commands
Diffstat (limited to 'sway/commands/bar.c')
-rw-r--r--sway/commands/bar.c57
1 files changed, 57 insertions, 0 deletions
diff --git a/sway/commands/bar.c b/sway/commands/bar.c
new file mode 100644
index 00000000..548106b3
--- /dev/null
+++ b/sway/commands/bar.c
@@ -0,0 +1,57 @@
1#include <string.h>
2#include <strings.h>
3#include <wlr/util/log.h>
4#include "sway/commands.h"
5#include "sway/config.h"
6#include "util.h"
7
8struct 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 return cmd_results_new(CMD_FAILURE, "bar", "Can only be used in config file.");
30 }
31
32 // Create new bar with default values
33 struct bar_config *bar = default_bar_config();
34 if (!bar) {
35 return cmd_results_new(CMD_FAILURE, "bar", "Unable to allocate bar state");
36 }
37
38 // set bar id
39 int i;
40 for (i = 0; i < config->bars->length; ++i) {
41 if (bar == config->bars->items[i]) {
42 const int len = 5 + numlen(i); // "bar-" + i + \0
43 bar->id = malloc(len * sizeof(char));
44 if (bar->id) {
45 snprintf(bar->id, len, "bar-%d", i);
46 } else {
47 return cmd_results_new(CMD_FAILURE, "bar", "Unable to allocate bar ID");
48 }
49 break;
50 }
51 }
52
53 // Set current bar
54 config->current_bar = bar;
55 wlr_log(L_DEBUG, "Configuring bar %s", bar->id);
56 return cmd_results_new(CMD_BLOCK_BAR, NULL, NULL);
57}