aboutsummaryrefslogtreecommitdiffstats
path: root/sway/commands/bar/mode.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/mode.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/mode.c')
-rw-r--r--sway/commands/bar/mode.c78
1 files changed, 78 insertions, 0 deletions
diff --git a/sway/commands/bar/mode.c b/sway/commands/bar/mode.c
new file mode 100644
index 00000000..7d346956
--- /dev/null
+++ b/sway/commands/bar/mode.c
@@ -0,0 +1,78 @@
1#define _XOPEN_SOURCE 500
2#include <string.h>
3#include <strings.h>
4#include "sway/commands.h"
5#include "sway/config.h"
6#include "sway/ipc-server.h"
7#include "log.h"
8
9static struct cmd_results *bar_set_mode(struct bar_config *bar, const char *mode) {
10 char *old_mode = bar->mode;
11 if (strcasecmp("toggle", mode) == 0 && !config->reading) {
12 if (strcasecmp("dock", bar->mode) == 0) {
13 bar->mode = strdup("hide");
14 } else if (strcasecmp("hide", bar->mode) == 0) {
15 bar->mode = strdup("dock");
16 }
17 } else if (strcasecmp("dock", mode) == 0) {
18 bar->mode = strdup("dock");
19 } else if (strcasecmp("hide", mode) == 0) {
20 bar->mode = strdup("hide");
21 } else if (strcasecmp("invisible", mode) == 0) {
22 bar->mode = strdup("invisible");
23 } else {
24 return cmd_results_new(CMD_INVALID, "mode", "Invalid value %s", mode);
25 }
26
27 if (strcmp(old_mode, bar->mode) != 0) {
28 if (!config->reading) {
29 ipc_event_barconfig_update(bar);
30 }
31 wlr_log(L_DEBUG, "Setting mode: '%s' for bar: %s", bar->mode, bar->id);
32 }
33
34 // free old mode
35 free(old_mode);
36 return cmd_results_new(CMD_SUCCESS, NULL, NULL);
37}
38
39struct cmd_results *bar_cmd_mode(int argc, char **argv) {
40 struct cmd_results *error = NULL;
41 if ((error = checkarg(argc, "mode", EXPECTED_AT_LEAST, 1))) {
42 return error;
43 }
44 if ((error = checkarg(argc, "mode", EXPECTED_LESS_THAN, 3))) {
45 return error;
46 }
47
48 if (config->reading && argc > 1) {
49 return cmd_results_new(CMD_INVALID, "mode", "Unexpected value %s in config mode", argv[1]);
50 }
51
52 const char *mode = argv[0];
53
54 if (config->reading) {
55 return bar_set_mode(config->current_bar, mode);
56 }
57
58 const char *id = NULL;
59 if (argc == 2) {
60 id = argv[1];
61 }
62
63 int i;
64 struct bar_config *bar;
65 for (i = 0; i < config->bars->length; ++i) {
66 bar = config->bars->items[i];
67 if (id && strcmp(id, bar->id) == 0) {
68 return bar_set_mode(bar, mode);
69 }
70
71 error = bar_set_mode(bar, mode);
72 if (error) {
73 return error;
74 }
75 }
76
77 return cmd_results_new(CMD_SUCCESS, NULL, NULL);
78}