summaryrefslogtreecommitdiffstats
path: root/sway/commands/bar/hidden_state.c
diff options
context:
space:
mode:
Diffstat (limited to 'sway/commands/bar/hidden_state.c')
-rw-r--r--sway/commands/bar/hidden_state.c79
1 files changed, 0 insertions, 79 deletions
diff --git a/sway/commands/bar/hidden_state.c b/sway/commands/bar/hidden_state.c
deleted file mode 100644
index 0b49aa6b..00000000
--- a/sway/commands/bar/hidden_state.c
+++ /dev/null
@@ -1,79 +0,0 @@
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_hidden_state(struct bar_config *bar, const char *hidden_state) {
10 char *old_state = bar->hidden_state;
11 if (strcasecmp("toggle", hidden_state) == 0 && !config->reading) {
12 if (strcasecmp("hide", bar->hidden_state) == 0) {
13 bar->hidden_state = strdup("show");
14 } else if (strcasecmp("show", bar->hidden_state) == 0) {
15 bar->hidden_state = strdup("hide");
16 }
17 } else if (strcasecmp("hide", hidden_state) == 0) {
18 bar->hidden_state = strdup("hide");
19 } else if (strcasecmp("show", hidden_state) == 0) {
20 bar->hidden_state = strdup("show");
21 } else {
22 return cmd_results_new(CMD_INVALID, "hidden_state", "Invalid value %s", hidden_state);
23 }
24
25 if (strcmp(old_state, bar->hidden_state) != 0) {
26 if (!config->reading) {
27 ipc_event_barconfig_update(bar);
28 }
29 sway_log(L_DEBUG, "Setting hidden_state: '%s' for bar: %s", bar->hidden_state, bar->id);
30 }
31
32 // free old mode
33 free(old_state);
34 return cmd_results_new(CMD_SUCCESS, NULL, NULL);
35}
36
37struct cmd_results *bar_cmd_hidden_state(int argc, char **argv) {
38 struct cmd_results *error = NULL;
39 if ((error = checkarg(argc, "hidden_state", EXPECTED_AT_LEAST, 1))) {
40 return error;
41 }
42 if ((error = checkarg(argc, "hidden_state", EXPECTED_LESS_THAN, 3))) {
43 return error;
44 }
45
46 if (config->reading && argc > 1) {
47 return cmd_results_new(CMD_INVALID, "hidden_state", "Unexpected value %s in config mode", argv[1]);
48 }
49
50 const char *state = argv[0];
51
52 if (config->reading) {
53 return bar_set_hidden_state(config->current_bar, state);
54 }
55
56 const char *id = NULL;
57 if (argc == 2) {
58 id = argv[1];
59 }
60
61 int i;
62 struct bar_config *bar;
63 for (i = 0; i < config->bars->length; ++i) {
64 bar = config->bars->items[i];
65 if (id && strcmp(id, bar->id) == 0) {
66 return bar_set_hidden_state(bar, state);
67 }
68
69 error = bar_set_hidden_state(bar, state);
70 if (error) {
71 return error;
72 }
73 }
74
75 // active bar modifiers might have changed.
76 update_active_bar_modifiers();
77
78 return cmd_results_new(CMD_SUCCESS, NULL, NULL);
79}