aboutsummaryrefslogtreecommitdiffstats
path: root/sway/old/commands/bar/mode.c
diff options
context:
space:
mode:
Diffstat (limited to 'sway/old/commands/bar/mode.c')
-rw-r--r--sway/old/commands/bar/mode.c81
1 files changed, 81 insertions, 0 deletions
diff --git a/sway/old/commands/bar/mode.c b/sway/old/commands/bar/mode.c
new file mode 100644
index 00000000..36816b93
--- /dev/null
+++ b/sway/old/commands/bar/mode.c
@@ -0,0 +1,81 @@
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 // active bar modifiers might have changed.
32 update_active_bar_modifiers();
33 }
34 sway_log(L_DEBUG, "Setting mode: '%s' for bar: %s", bar->mode, bar->id);
35 }
36
37 // free old mode
38 free(old_mode);
39 return cmd_results_new(CMD_SUCCESS, NULL, NULL);
40}
41
42struct cmd_results *bar_cmd_mode(int argc, char **argv) {
43 struct cmd_results *error = NULL;
44 if ((error = checkarg(argc, "mode", EXPECTED_AT_LEAST, 1))) {
45 return error;
46 }
47 if ((error = checkarg(argc, "mode", EXPECTED_LESS_THAN, 3))) {
48 return error;
49 }
50
51 if (config->reading && argc > 1) {
52 return cmd_results_new(CMD_INVALID, "mode", "Unexpected value %s in config mode", argv[1]);
53 }
54
55 const char *mode = argv[0];
56
57 if (config->reading) {
58 return bar_set_mode(config->current_bar, mode);
59 }
60
61 const char *id = NULL;
62 if (argc == 2) {
63 id = argv[1];
64 }
65
66 int i;
67 struct bar_config *bar;
68 for (i = 0; i < config->bars->length; ++i) {
69 bar = config->bars->items[i];
70 if (id && strcmp(id, bar->id) == 0) {
71 return bar_set_mode(bar, mode);
72 }
73
74 error = bar_set_mode(bar, mode);
75 if (error) {
76 return error;
77 }
78 }
79
80 return cmd_results_new(CMD_SUCCESS, NULL, NULL);
81}