aboutsummaryrefslogtreecommitdiffstats
path: root/sway/commands/bar
diff options
context:
space:
mode:
authorLibravatar Zandr Martin <zandrmartin@gmail.com>2016-09-01 21:39:08 -0500
committerLibravatar Zandr Martin <zandrmartin@gmail.com>2016-09-01 21:39:08 -0500
commitb374c35758777f98e5ddbe4b0dc43bd7c80f36d7 (patch)
tree04bb4cfc3da7d2e0de7fbc38db42f65c66d2df4c /sway/commands/bar
parentMerge pull request #874 from yohanesu75/ipc-client-fix (diff)
downloadsway-b374c35758777f98e5ddbe4b0dc43bd7c80f36d7.tar.gz
sway-b374c35758777f98e5ddbe4b0dc43bd7c80f36d7.tar.zst
sway-b374c35758777f98e5ddbe4b0dc43bd7c80f36d7.zip
refactor commands.c
Diffstat (limited to 'sway/commands/bar')
-rw-r--r--sway/commands/bar/binding_mode_indicator.c26
-rw-r--r--sway/commands/bar/bindsym.c45
-rw-r--r--sway/commands/bar/colors.c160
-rw-r--r--sway/commands/bar/font.c26
-rw-r--r--sway/commands/bar/height.c21
-rw-r--r--sway/commands/bar/hidden_state.c77
-rw-r--r--sway/commands/bar/id.c32
-rw-r--r--sway/commands/bar/mode.c79
-rw-r--r--sway/commands/bar/modifier.c35
-rw-r--r--sway/commands/bar/output.c49
-rw-r--r--sway/commands/bar/pango_markup.c26
-rw-r--r--sway/commands/bar/position.c32
-rw-r--r--sway/commands/bar/separator_symbol.c20
-rw-r--r--sway/commands/bar/status_command.c21
-rw-r--r--sway/commands/bar/strip_workspace_numbers.c26
-rw-r--r--sway/commands/bar/swaybar_command.c21
-rw-r--r--sway/commands/bar/tray_output.c7
-rw-r--r--sway/commands/bar/tray_padding.c29
-rw-r--r--sway/commands/bar/workspace_buttons.c26
-rw-r--r--sway/commands/bar/wrap_scroll.c26
20 files changed, 784 insertions, 0 deletions
diff --git a/sway/commands/bar/binding_mode_indicator.c b/sway/commands/bar/binding_mode_indicator.c
new file mode 100644
index 00000000..be72cb9b
--- /dev/null
+++ b/sway/commands/bar/binding_mode_indicator.c
@@ -0,0 +1,26 @@
1#include <string.h>
2#include "commands.h"
3#include "log.h"
4
5struct cmd_results *bar_cmd_binding_mode_indicator(int argc, char **argv) {
6 struct cmd_results *error = NULL;
7 if ((error = checkarg(argc, "binding_mode_indicator", EXPECTED_EQUAL_TO, 1))) {
8 return error;
9 }
10
11 if (!config->current_bar) {
12 return cmd_results_new(CMD_FAILURE, "binding_mode_indicator", "No bar defined.");
13 }
14
15 if (strcasecmp("yes", argv[0]) == 0) {
16 config->current_bar->binding_mode_indicator = true;
17 sway_log(L_DEBUG, "Enabling binding mode indicator on bar: %s", config->current_bar->id);
18 } else if (strcasecmp("no", argv[0]) == 0) {
19 config->current_bar->binding_mode_indicator = false;
20 sway_log(L_DEBUG, "Disabling binding mode indicator on bar: %s", config->current_bar->id);
21 } else {
22 error = cmd_results_new(CMD_INVALID, "binding_mode_indicator", "Invalid value %s", argv[0]);
23 return error;
24 }
25 return cmd_results_new(CMD_SUCCESS, NULL, NULL);
26}
diff --git a/sway/commands/bar/bindsym.c b/sway/commands/bar/bindsym.c
new file mode 100644
index 00000000..4f50e708
--- /dev/null
+++ b/sway/commands/bar/bindsym.c
@@ -0,0 +1,45 @@
1#include <stdlib.h>
2#include <string.h>
3#include "commands.h"
4#include "config.h"
5#include "list.h"
6#include "log.h"
7#include "stringop.h"
8
9struct cmd_results *bar_cmd_bindsym(int argc, char **argv) {
10 struct cmd_results *error = NULL;
11 if ((error = checkarg(argc, "bindsym", EXPECTED_MORE_THAN, 1))) {
12 return error;
13 } else if (!config->reading) {
14 return cmd_results_new(CMD_FAILURE, "bindsym", "Can only be used in config file.");
15 }
16
17 if (!config->current_bar) {
18 return cmd_results_new(CMD_FAILURE, "bindsym", "No bar defined.");
19 }
20
21 if (strlen(argv[1]) != 7) {
22 return cmd_results_new(CMD_INVALID, "bindsym", "Invalid mouse binding %s", argv[1]);
23 }
24 uint32_t numbutton = (uint32_t)atoi(argv[1] + 6);
25 if (numbutton < 1 || numbutton > 5 || strncmp(argv[1], "button", 6) != 0) {
26 return cmd_results_new(CMD_INVALID, "bindsym", "Invalid mouse binding %s", argv[1]);
27 }
28 struct sway_mouse_binding *binding = malloc(sizeof(struct sway_mouse_binding));
29 binding->button = numbutton;
30 binding->command = join_args(argv + 1, argc - 1);
31
32 struct bar_config *bar = config->current_bar;
33 int i = list_seq_find(bar->bindings, sway_mouse_binding_cmp_buttons, binding);
34 if (i > -1) {
35 sway_log(L_DEBUG, "bindsym - '%s' for swaybar already exists, overwriting", argv[0]);
36 struct sway_mouse_binding *dup = bar->bindings->items[i];
37 free_sway_mouse_binding(dup);
38 list_del(bar->bindings, i);
39 }
40 list_add(bar->bindings, binding);
41 list_qsort(bar->bindings, sway_mouse_binding_cmp_qsort);
42
43 sway_log(L_DEBUG, "bindsym - Bound %s to command %s when clicking swaybar", argv[0], binding->command);
44 return cmd_results_new(CMD_SUCCESS, NULL, NULL);
45}
diff --git a/sway/commands/bar/colors.c b/sway/commands/bar/colors.c
new file mode 100644
index 00000000..d33a323e
--- /dev/null
+++ b/sway/commands/bar/colors.c
@@ -0,0 +1,160 @@
1#include <string.h>
2#include "commands.h"
3
4struct cmd_results *bar_cmd_colors(int argc, char **argv) {
5 struct cmd_results *error = NULL;
6 if ((error = checkarg(argc, "colors", EXPECTED_EQUAL_TO, 1))) {
7 return error;
8 }
9
10 if (strcmp("{", argv[0]) != 0) {
11 return cmd_results_new(CMD_INVALID, "colors",
12 "Expected '{' at the start of colors config definition.");
13 }
14
15 return cmd_results_new(CMD_BLOCK_BAR_COLORS, NULL, NULL);
16}
17
18struct cmd_results *bar_colors_cmd_active_workspace(int argc, char **argv) {
19 struct cmd_results *error = NULL;
20 if ((error = checkarg(argc, "active_workspace", EXPECTED_EQUAL_TO, 3))) {
21 return error;
22 }
23
24 if ((error = add_color("active_workspace_border", config->current_bar->colors.active_workspace_border, argv[0]))) {
25 return error;
26 }
27
28 if ((error = add_color("active_workspace_bg", config->current_bar->colors.active_workspace_bg, argv[1]))) {
29 return error;
30 }
31
32 if ((error = add_color("active_workspace_text", config->current_bar->colors.active_workspace_text, argv[2]))) {
33 return error;
34 }
35
36 return cmd_results_new(CMD_SUCCESS, NULL, NULL);
37}
38
39struct cmd_results *bar_colors_cmd_background(int argc, char **argv) {
40 struct cmd_results *error = NULL;
41 if ((error = checkarg(argc, "background", EXPECTED_EQUAL_TO, 1))) {
42 return error;
43 }
44
45 if ((error = add_color("background", config->current_bar->colors.background, argv[0]))) {
46 return error;
47 }
48
49 return cmd_results_new(CMD_SUCCESS, NULL, NULL);
50}
51
52struct cmd_results *bar_colors_cmd_binding_mode(int argc, char **argv) {
53 struct cmd_results *error = NULL;
54 if ((error = checkarg(argc, "binding_mode", EXPECTED_EQUAL_TO, 3))) {
55 return error;
56 }
57
58 if ((error = add_color("binding_mode_border", config->current_bar->colors.binding_mode_border, argv[0]))) {
59 return error;
60 }
61
62 if ((error = add_color("binding_mode_bg", config->current_bar->colors.binding_mode_bg, argv[1]))) {
63 return error;
64 }
65
66 if ((error = add_color("binding_mode_text", config->current_bar->colors.binding_mode_text, argv[2]))) {
67 return error;
68 }
69
70 return cmd_results_new(CMD_SUCCESS, NULL, NULL);
71}
72
73struct cmd_results *bar_colors_cmd_focused_workspace(int argc, char **argv) {
74 struct cmd_results *error = NULL;
75 if ((error = checkarg(argc, "focused_workspace", EXPECTED_EQUAL_TO, 3))) {
76 return error;
77 }
78
79 if ((error = add_color("focused_workspace_border", config->current_bar->colors.focused_workspace_border, argv[0]))) {
80 return error;
81 }
82
83 if ((error = add_color("focused_workspace_bg", config->current_bar->colors.focused_workspace_bg, argv[1]))) {
84 return error;
85 }
86
87 if ((error = add_color("focused_workspace_text", config->current_bar->colors.focused_workspace_text, argv[2]))) {
88 return error;
89 }
90
91 return cmd_results_new(CMD_SUCCESS, NULL, NULL);
92}
93
94struct cmd_results *bar_colors_cmd_inactive_workspace(int argc, char **argv) {
95 struct cmd_results *error = NULL;
96 if ((error = checkarg(argc, "inactive_workspace", EXPECTED_EQUAL_TO, 3))) {
97 return error;
98 }
99
100 if ((error = add_color("inactive_workspace_border", config->current_bar->colors.inactive_workspace_border, argv[0]))) {
101 return error;
102 }
103
104 if ((error = add_color("inactive_workspace_bg", config->current_bar->colors.inactive_workspace_bg, argv[1]))) {
105 return error;
106 }
107
108 if ((error = add_color("inactive_workspace_text", config->current_bar->colors.inactive_workspace_text, argv[2]))) {
109 return error;
110 }
111
112 return cmd_results_new(CMD_SUCCESS, NULL, NULL);
113}
114
115struct cmd_results *bar_colors_cmd_separator(int argc, char **argv) {
116 struct cmd_results *error = NULL;
117 if ((error = checkarg(argc, "separator", EXPECTED_EQUAL_TO, 1))) {
118 return error;
119 }
120
121 if ((error = add_color("separator", config->current_bar->colors.separator, argv[0]))) {
122 return error;
123 }
124
125 return cmd_results_new(CMD_SUCCESS, NULL, NULL);
126}
127
128struct cmd_results *bar_colors_cmd_statusline(int argc, char **argv) {
129 struct cmd_results *error = NULL;
130 if ((error = checkarg(argc, "statusline", EXPECTED_EQUAL_TO, 1))) {
131 return error;
132 }
133
134 if ((error = add_color("statusline", config->current_bar->colors.statusline, argv[0]))) {
135 return error;
136 }
137
138 return cmd_results_new(CMD_SUCCESS, NULL, NULL);
139}
140
141struct cmd_results *bar_colors_cmd_urgent_workspace(int argc, char **argv) {
142 struct cmd_results *error = NULL;
143 if ((error = checkarg(argc, "urgent_workspace", EXPECTED_EQUAL_TO, 3))) {
144 return error;
145 }
146
147 if ((error = add_color("urgent_workspace_border", config->current_bar->colors.urgent_workspace_border, argv[0]))) {
148 return error;
149 }
150
151 if ((error = add_color("urgent_workspace_bg", config->current_bar->colors.urgent_workspace_bg, argv[1]))) {
152 return error;
153 }
154
155 if ((error = add_color("urgent_workspace_text", config->current_bar->colors.urgent_workspace_text, argv[2]))) {
156 return error;
157 }
158
159 return cmd_results_new(CMD_SUCCESS, NULL, NULL);
160}
diff --git a/sway/commands/bar/font.c b/sway/commands/bar/font.c
new file mode 100644
index 00000000..afc542d2
--- /dev/null
+++ b/sway/commands/bar/font.c
@@ -0,0 +1,26 @@
1#include <string.h>
2#include "commands.h"
3#include "log.h"
4#include "stringop.h"
5
6struct cmd_results *bar_cmd_font(int argc, char **argv) {
7 struct cmd_results *error = NULL;
8 if ((error = checkarg(argc, "font", EXPECTED_AT_LEAST, 1))) {
9 return error;
10 }
11
12 if (!config->current_bar) {
13 return cmd_results_new(CMD_FAILURE, "font", "No bar defined.");
14 }
15
16 char *font = join_args(argv, argc);
17 free(config->current_bar->font);
18 if (strlen(font) > 6 && strncmp("pango:", font, 6) == 0) {
19 config->current_bar->font = font;
20 } else {
21 config->current_bar->font = font;
22 }
23
24 sway_log(L_DEBUG, "Settings font '%s' for bar: %s", config->current_bar->font, config->current_bar->id);
25 return cmd_results_new(CMD_SUCCESS, NULL, NULL);
26}
diff --git a/sway/commands/bar/height.c b/sway/commands/bar/height.c
new file mode 100644
index 00000000..9ea0a81a
--- /dev/null
+++ b/sway/commands/bar/height.c
@@ -0,0 +1,21 @@
1#include <stdlib.h>
2#include <string.h>
3#include "commands.h"
4#include "log.h"
5
6struct cmd_results *bar_cmd_height(int argc, char **argv) {
7 struct cmd_results *error = NULL;
8 if ((error = checkarg(argc, "height", EXPECTED_EQUAL_TO, 1))) {
9 return error;
10 }
11
12 int height = atoi(argv[0]);
13 if (height < 0) {
14 return cmd_results_new(CMD_INVALID, "height",
15 "Invalid height value: %s", argv[0]);
16 }
17
18 config->current_bar->height = height;
19 sway_log(L_DEBUG, "Setting bar height to %d on bar: %s", height, config->current_bar->id);
20 return cmd_results_new(CMD_SUCCESS, NULL, NULL);
21}
diff --git a/sway/commands/bar/hidden_state.c b/sway/commands/bar/hidden_state.c
new file mode 100644
index 00000000..22035c98
--- /dev/null
+++ b/sway/commands/bar/hidden_state.c
@@ -0,0 +1,77 @@
1#include <string.h>
2#include "commands.h"
3#include "config.h"
4#include "ipc-server.h"
5#include "log.h"
6
7static struct cmd_results *bar_set_hidden_state(struct bar_config *bar, const char *hidden_state) {
8 char *old_state = bar->hidden_state;
9 if (strcasecmp("toggle", hidden_state) == 0 && !config->reading) {
10 if (strcasecmp("hide", bar->hidden_state) == 0) {
11 bar->hidden_state = strdup("show");
12 } else if (strcasecmp("show", bar->hidden_state) == 0) {
13 bar->hidden_state = strdup("hide");
14 }
15 } else if (strcasecmp("hide", hidden_state) == 0) {
16 bar->hidden_state = strdup("hide");
17 } else if (strcasecmp("show", hidden_state) == 0) {
18 bar->hidden_state = strdup("show");
19 } else {
20 return cmd_results_new(CMD_INVALID, "hidden_state", "Invalid value %s", hidden_state);
21 }
22
23 if (strcmp(old_state, bar->hidden_state) != 0) {
24 if (!config->reading) {
25 ipc_event_barconfig_update(bar);
26 }
27 sway_log(L_DEBUG, "Setting hidden_state: '%s' for bar: %s", bar->hidden_state, bar->id);
28 }
29
30 // free old mode
31 free(old_state);
32 return cmd_results_new(CMD_SUCCESS, NULL, NULL);
33}
34
35struct cmd_results *bar_cmd_hidden_state(int argc, char **argv) {
36 struct cmd_results *error = NULL;
37 if ((error = checkarg(argc, "hidden_state", EXPECTED_AT_LEAST, 1))) {
38 return error;
39 }
40 if ((error = checkarg(argc, "hidden_state", EXPECTED_LESS_THAN, 3))) {
41 return error;
42 }
43
44 if (config->reading && argc > 1) {
45 return cmd_results_new(CMD_INVALID, "hidden_state", "Unexpected value %s in config mode", argv[1]);
46 }
47
48 const char *state = argv[0];
49
50 if (config->reading) {
51 return bar_set_hidden_state(config->current_bar, state);
52 }
53
54 const char *id = NULL;
55 if (argc == 2) {
56 id = argv[1];
57 }
58
59 int i;
60 struct bar_config *bar;
61 for (i = 0; i < config->bars->length; ++i) {
62 bar = config->bars->items[i];
63 if (id && strcmp(id, bar->id) == 0) {
64 return bar_set_hidden_state(bar, state);
65 }
66
67 error = bar_set_hidden_state(bar, state);
68 if (error) {
69 return error;
70 }
71 }
72
73 // active bar modifiers might have changed.
74 update_active_bar_modifiers();
75
76 return cmd_results_new(CMD_SUCCESS, NULL, NULL);
77}
diff --git a/sway/commands/bar/id.c b/sway/commands/bar/id.c
new file mode 100644
index 00000000..6ca9f6b6
--- /dev/null
+++ b/sway/commands/bar/id.c
@@ -0,0 +1,32 @@
1#include <string.h>
2#include "commands.h"
3#include "log.h"
4
5struct cmd_results *bar_cmd_id(int argc, char **argv) {
6 struct cmd_results *error = NULL;
7 if ((error = checkarg(argc, "id", EXPECTED_EQUAL_TO, 1))) {
8 return error;
9 }
10
11 const char *name = argv[0];
12 const char *oldname = config->current_bar->id;
13
14 // check if id is used by a previously defined bar
15 int i;
16 for (i = 0; i < config->bars->length; ++i) {
17 struct bar_config *find = config->bars->items[i];
18 if (strcmp(name, find->id) == 0 && config->current_bar != find) {
19 return cmd_results_new(CMD_FAILURE, "id",
20 "Id '%s' already defined for another bar. Id unchanged (%s).",
21 name, oldname);
22 }
23 }
24
25 sway_log(L_DEBUG, "Renaming bar: '%s' to '%s'", oldname, name);
26
27 // free old bar id
28 free(config->current_bar->id);
29
30 config->current_bar->id = strdup(name);
31 return cmd_results_new(CMD_SUCCESS, NULL, NULL);
32}
diff --git a/sway/commands/bar/mode.c b/sway/commands/bar/mode.c
new file mode 100644
index 00000000..321d5a29
--- /dev/null
+++ b/sway/commands/bar/mode.c
@@ -0,0 +1,79 @@
1#include <string.h>
2#include "commands.h"
3#include "config.h"
4#include "ipc-server.h"
5#include "log.h"
6
7static struct cmd_results *bar_set_mode(struct bar_config *bar, const char *mode) {
8 char *old_mode = bar->mode;
9 if (strcasecmp("toggle", mode) == 0 && !config->reading) {
10 if (strcasecmp("dock", bar->mode) == 0) {
11 bar->mode = strdup("hide");
12 } else if (strcasecmp("hide", bar->mode) == 0) {
13 bar->mode = strdup("dock");
14 }
15 } else if (strcasecmp("dock", mode) == 0) {
16 bar->mode = strdup("dock");
17 } else if (strcasecmp("hide", mode) == 0) {
18 bar->mode = strdup("hide");
19 } else if (strcasecmp("invisible", mode) == 0) {
20 bar->mode = strdup("invisible");
21 } else {
22 return cmd_results_new(CMD_INVALID, "mode", "Invalid value %s", mode);
23 }
24
25 if (strcmp(old_mode, bar->mode) != 0) {
26 if (!config->reading) {
27 ipc_event_barconfig_update(bar);
28
29 // active bar modifiers might have changed.
30 update_active_bar_modifiers();
31 }
32 sway_log(L_DEBUG, "Setting mode: '%s' for bar: %s", bar->mode, bar->id);
33 }
34
35 // free old mode
36 free(old_mode);
37 return cmd_results_new(CMD_SUCCESS, NULL, NULL);
38}
39
40struct cmd_results *bar_cmd_mode(int argc, char **argv) {
41 struct cmd_results *error = NULL;
42 if ((error = checkarg(argc, "mode", EXPECTED_AT_LEAST, 1))) {
43 return error;
44 }
45 if ((error = checkarg(argc, "mode", EXPECTED_LESS_THAN, 3))) {
46 return error;
47 }
48
49 if (config->reading && argc > 1) {
50 return cmd_results_new(CMD_INVALID, "mode", "Unexpected value %s in config mode", argv[1]);
51 }
52
53 const char *mode = argv[0];
54
55 if (config->reading) {
56 return bar_set_mode(config->current_bar, mode);
57 }
58
59 const char *id = NULL;
60 if (argc == 2) {
61 id = argv[1];
62 }
63
64 int i;
65 struct bar_config *bar;
66 for (i = 0; i < config->bars->length; ++i) {
67 bar = config->bars->items[i];
68 if (id && strcmp(id, bar->id) == 0) {
69 return bar_set_mode(bar, mode);
70 }
71
72 error = bar_set_mode(bar, mode);
73 if (error) {
74 return error;
75 }
76 }
77
78 return cmd_results_new(CMD_SUCCESS, NULL, NULL);
79}
diff --git a/sway/commands/bar/modifier.c b/sway/commands/bar/modifier.c
new file mode 100644
index 00000000..7d4501c7
--- /dev/null
+++ b/sway/commands/bar/modifier.c
@@ -0,0 +1,35 @@
1#include <string.h>
2#include "commands.h"
3#include "log.h"
4#include "stringop.h"
5#include "util.h"
6
7struct cmd_results *bar_cmd_modifier(int argc, char **argv) {
8 struct cmd_results *error = NULL;
9 if ((error = checkarg(argc, "modifier", EXPECTED_EQUAL_TO, 1))) {
10 return error;
11 }
12
13 if (!config->current_bar) {
14 return cmd_results_new(CMD_FAILURE, "modifier", "No bar defined.");
15 }
16
17 uint32_t mod = 0;
18
19 list_t *split = split_string(argv[0], "+");
20 for (int i = 0; i < split->length; ++i) {
21 uint32_t tmp_mod;
22 if ((tmp_mod = get_modifier_mask_by_name(split->items[i])) > 0) {
23 mod |= tmp_mod;
24 continue;
25 } else {
26 free_flat_list(split);
27 return cmd_results_new(CMD_INVALID, "modifier", "Unknown modifier '%s'", split->items[i]);
28 }
29 }
30 free_flat_list(split);
31
32 config->current_bar->modifier = mod;
33 sway_log(L_DEBUG, "Show/Hide the bar when pressing '%s' in hide mode.", argv[0]);
34 return cmd_results_new(CMD_SUCCESS, NULL, NULL);
35}
diff --git a/sway/commands/bar/output.c b/sway/commands/bar/output.c
new file mode 100644
index 00000000..9a0d7a73
--- /dev/null
+++ b/sway/commands/bar/output.c
@@ -0,0 +1,49 @@
1#include <string.h>
2#include "commands.h"
3#include "list.h"
4#include "log.h"
5
6struct cmd_results *bar_cmd_output(int argc, char **argv) {
7 struct cmd_results *error = NULL;
8 if ((error = checkarg(argc, "output", EXPECTED_EQUAL_TO, 1))) {
9 return error;
10 }
11
12 if (!config->current_bar) {
13 return cmd_results_new(CMD_FAILURE, "output", "No bar defined.");
14 }
15
16 const char *output = argv[0];
17 list_t *outputs = config->current_bar->outputs;
18 if (!outputs) {
19 outputs = create_list();
20 config->current_bar->outputs = outputs;
21 }
22
23 int i;
24 int add_output = 1;
25 if (strcmp("*", output) == 0) {
26 // remove all previous defined outputs and replace with '*'
27 for (i = 0; i < outputs->length; ++i) {
28 free(outputs->items[i]);
29 list_del(outputs, i);
30 }
31 } else {
32 // only add output if not already defined with either the same
33 // name or as '*'
34 for (i = 0; i < outputs->length; ++i) {
35 const char *find = outputs->items[i];
36 if (strcmp("*", find) == 0 || strcmp(output, find) == 0) {
37 add_output = 0;
38 break;
39 }
40 }
41 }
42
43 if (add_output) {
44 list_add(outputs, strdup(output));
45 sway_log(L_DEBUG, "Adding bar: '%s' to output '%s'", config->current_bar->id, output);
46 }
47
48 return cmd_results_new(CMD_SUCCESS, NULL, NULL);
49}
diff --git a/sway/commands/bar/pango_markup.c b/sway/commands/bar/pango_markup.c
new file mode 100644
index 00000000..fcc38d13
--- /dev/null
+++ b/sway/commands/bar/pango_markup.c
@@ -0,0 +1,26 @@
1#include <string.h>
2#include "commands.h"
3#include "log.h"
4
5struct cmd_results *bar_cmd_pango_markup(int argc, char **argv) {
6 struct cmd_results *error = NULL;
7 if ((error = checkarg(argc, "pango_markup", EXPECTED_EQUAL_TO, 1))) {
8 return error;
9 }
10
11 if (!config->current_bar) {
12 return cmd_results_new(CMD_FAILURE, "pango_markup", "No bar defined.");
13 }
14
15 if (strcasecmp("enabled", argv[0]) == 0) {
16 config->current_bar->pango_markup = true;
17 sway_log(L_DEBUG, "Enabling pango markup for bar: %s", config->current_bar->id);
18 } else if (strcasecmp("disabled", argv[0]) == 0) {
19 config->current_bar->pango_markup = false;
20 sway_log(L_DEBUG, "Disabling pango markup for bar: %s", config->current_bar->id);
21 } else {
22 error = cmd_results_new(CMD_INVALID, "pango_markup", "Invalid value %s", argv[0]);
23 return error;
24 }
25 return cmd_results_new(CMD_SUCCESS, NULL, NULL);
26}
diff --git a/sway/commands/bar/position.c b/sway/commands/bar/position.c
new file mode 100644
index 00000000..6f97062f
--- /dev/null
+++ b/sway/commands/bar/position.c
@@ -0,0 +1,32 @@
1#include <string.h>
2#include "commands.h"
3#include "log.h"
4
5struct cmd_results *bar_cmd_position(int argc, char **argv) {
6 struct cmd_results *error = NULL;
7 if ((error = checkarg(argc, "position", EXPECTED_EQUAL_TO, 1))) {
8 return error;
9 }
10
11 if (!config->current_bar) {
12 return cmd_results_new(CMD_FAILURE, "position", "No bar defined.");
13 }
14
15 if (strcasecmp("top", argv[0]) == 0) {
16 config->current_bar->position = DESKTOP_SHELL_PANEL_POSITION_TOP;
17 } else if (strcasecmp("bottom", argv[0]) == 0) {
18 config->current_bar->position = DESKTOP_SHELL_PANEL_POSITION_BOTTOM;
19 } else if (strcasecmp("left", argv[0]) == 0) {
20 sway_log(L_INFO, "Warning: swaybar currently only supports top and bottom positioning. YMMV");
21 config->current_bar->position = DESKTOP_SHELL_PANEL_POSITION_LEFT;
22 } else if (strcasecmp("right", argv[0]) == 0) {
23 sway_log(L_INFO, "Warning: swaybar currently only supports top and bottom positioning. YMMV");
24 config->current_bar->position = DESKTOP_SHELL_PANEL_POSITION_RIGHT;
25 } else {
26 error = cmd_results_new(CMD_INVALID, "position", "Invalid value %s", argv[0]);
27 return error;
28 }
29
30 sway_log(L_DEBUG, "Setting bar position '%s' for bar: %s", argv[0], config->current_bar->id);
31 return cmd_results_new(CMD_SUCCESS, NULL, NULL);
32}
diff --git a/sway/commands/bar/separator_symbol.c b/sway/commands/bar/separator_symbol.c
new file mode 100644
index 00000000..16c455e7
--- /dev/null
+++ b/sway/commands/bar/separator_symbol.c
@@ -0,0 +1,20 @@
1#include <string.h>
2#include "commands.h"
3#include "log.h"
4
5struct cmd_results *bar_cmd_separator_symbol(int argc, char **argv) {
6 struct cmd_results *error = NULL;
7 if ((error = checkarg(argc, "separator_symbol", EXPECTED_EQUAL_TO, 1))) {
8 return error;
9 }
10
11 if (!config->current_bar) {
12 return cmd_results_new(CMD_FAILURE, "separator_symbol", "No bar defined.");
13 }
14
15 free(config->current_bar->separator_symbol);
16 config->current_bar->separator_symbol = strdup(argv[0]);
17 sway_log(L_DEBUG, "Settings separator_symbol '%s' for bar: %s", config->current_bar->separator_symbol, config->current_bar->id);
18
19 return cmd_results_new(CMD_SUCCESS, NULL, NULL);
20}
diff --git a/sway/commands/bar/status_command.c b/sway/commands/bar/status_command.c
new file mode 100644
index 00000000..ec91e9f7
--- /dev/null
+++ b/sway/commands/bar/status_command.c
@@ -0,0 +1,21 @@
1#include <string.h>
2#include "commands.h"
3#include "log.h"
4#include "stringop.h"
5
6struct cmd_results *bar_cmd_status_command(int argc, char **argv) {
7 struct cmd_results *error = NULL;
8 if ((error = checkarg(argc, "status_command", EXPECTED_AT_LEAST, 1))) {
9 return error;
10 }
11
12 if (!config->current_bar) {
13 return cmd_results_new(CMD_FAILURE, "status_command", "No bar defined.");
14 }
15
16 free(config->current_bar->status_command);
17 config->current_bar->status_command = join_args(argv, argc);
18 sway_log(L_DEBUG, "Feeding bar with status command: %s", config->current_bar->status_command);
19
20 return cmd_results_new(CMD_SUCCESS, NULL, NULL);
21}
diff --git a/sway/commands/bar/strip_workspace_numbers.c b/sway/commands/bar/strip_workspace_numbers.c
new file mode 100644
index 00000000..7a709e4b
--- /dev/null
+++ b/sway/commands/bar/strip_workspace_numbers.c
@@ -0,0 +1,26 @@
1#include <string.h>
2#include "commands.h"
3#include "log.h"
4
5struct cmd_results *bar_cmd_strip_workspace_numbers(int argc, char **argv) {
6 struct cmd_results *error = NULL;
7 if ((error = checkarg(argc, "strip_workspace_numbers", EXPECTED_EQUAL_TO, 1))) {
8 return error;
9 }
10
11 if (!config->current_bar) {
12 return cmd_results_new(CMD_FAILURE, "strip_workspace_numbers", "No bar defined.");
13 }
14
15 if (strcasecmp("yes", argv[0]) == 0) {
16 config->current_bar->strip_workspace_numbers = true;
17 sway_log(L_DEBUG, "Stripping workspace numbers on bar: %s", config->current_bar->id);
18 } else if (strcasecmp("no", argv[0]) == 0) {
19 config->current_bar->strip_workspace_numbers = false;
20 sway_log(L_DEBUG, "Enabling workspace numbers on bar: %s", config->current_bar->id);
21 } else {
22 error = cmd_results_new(CMD_INVALID, "strip_workspace_numbers", "Invalid value %s", argv[0]);
23 return error;
24 }
25 return cmd_results_new(CMD_SUCCESS, NULL, NULL);
26}
diff --git a/sway/commands/bar/swaybar_command.c b/sway/commands/bar/swaybar_command.c
new file mode 100644
index 00000000..1f28184a
--- /dev/null
+++ b/sway/commands/bar/swaybar_command.c
@@ -0,0 +1,21 @@
1#include <string.h>
2#include "commands.h"
3#include "log.h"
4#include "stringop.h"
5
6struct cmd_results *bar_cmd_swaybar_command(int argc, char **argv) {
7 struct cmd_results *error = NULL;
8 if ((error = checkarg(argc, "swaybar_command", EXPECTED_AT_LEAST, 1))) {
9 return error;
10 }
11
12 if (!config->current_bar) {
13 return cmd_results_new(CMD_FAILURE, "swaybar_command", "No bar defined.");
14 }
15
16 free(config->current_bar->swaybar_command);
17 config->current_bar->swaybar_command = join_args(argv, argc);
18 sway_log(L_DEBUG, "Using custom swaybar command: %s", config->current_bar->swaybar_command);
19
20 return cmd_results_new(CMD_SUCCESS, NULL, NULL);
21}
diff --git a/sway/commands/bar/tray_output.c b/sway/commands/bar/tray_output.c
new file mode 100644
index 00000000..39b571d0
--- /dev/null
+++ b/sway/commands/bar/tray_output.c
@@ -0,0 +1,7 @@
1#include "commands.h"
2#include "log.h"
3
4struct cmd_results *bar_cmd_tray_output(int argc, char **argv) {
5 sway_log(L_ERROR, "Warning: tray_output is not supported on wayland");
6 return cmd_results_new(CMD_SUCCESS, NULL, NULL);
7}
diff --git a/sway/commands/bar/tray_padding.c b/sway/commands/bar/tray_padding.c
new file mode 100644
index 00000000..978ce0b7
--- /dev/null
+++ b/sway/commands/bar/tray_padding.c
@@ -0,0 +1,29 @@
1#include <stdlib.h>
2#include <string.h>
3#include "commands.h"
4#include "log.h"
5
6struct cmd_results *bar_cmd_tray_padding(int argc, char **argv) {
7 struct cmd_results *error = NULL;
8 if ((error = checkarg(argc, "tray_padding", EXPECTED_AT_LEAST, 1))) {
9 return error;
10 }
11
12 if (!config->current_bar) {
13 return cmd_results_new(CMD_FAILURE, "tray_padding", "No bar defined.");
14 }
15
16 int padding = atoi(argv[0]);
17 if (padding < 0) {
18 return cmd_results_new(CMD_INVALID, "tray_padding",
19 "Invalid padding value %s, minimum is 0", argv[0]);
20 }
21
22 if (argc > 1 && strcasecmp("px", argv[1]) != 0) {
23 return cmd_results_new(CMD_INVALID, "tray_padding",
24 "Unknown unit %s", argv[1]);
25 }
26 config->current_bar->tray_padding = padding;
27 sway_log(L_DEBUG, "Enabling tray padding of %d px on bar: %s", padding, config->current_bar->id);
28 return cmd_results_new(CMD_SUCCESS, NULL, NULL);
29}
diff --git a/sway/commands/bar/workspace_buttons.c b/sway/commands/bar/workspace_buttons.c
new file mode 100644
index 00000000..ce37fde9
--- /dev/null
+++ b/sway/commands/bar/workspace_buttons.c
@@ -0,0 +1,26 @@
1#include <string.h>
2#include "commands.h"
3#include "log.h"
4
5struct cmd_results *bar_cmd_workspace_buttons(int argc, char **argv) {
6 struct cmd_results *error = NULL;
7 if ((error = checkarg(argc, "workspace_buttons", EXPECTED_EQUAL_TO, 1))) {
8 return error;
9 }
10
11 if (!config->current_bar) {
12 return cmd_results_new(CMD_FAILURE, "workspace_buttons", "No bar defined.");
13 }
14
15 if (strcasecmp("yes", argv[0]) == 0) {
16 config->current_bar->workspace_buttons = true;
17 sway_log(L_DEBUG, "Enabling workspace buttons on bar: %s", config->current_bar->id);
18 } else if (strcasecmp("no", argv[0]) == 0) {
19 config->current_bar->workspace_buttons = false;
20 sway_log(L_DEBUG, "Disabling workspace buttons on bar: %s", config->current_bar->id);
21 } else {
22 error = cmd_results_new(CMD_INVALID, "workspace_buttons", "Invalid value %s", argv[0]);
23 return error;
24 }
25 return cmd_results_new(CMD_SUCCESS, NULL, NULL);
26}
diff --git a/sway/commands/bar/wrap_scroll.c b/sway/commands/bar/wrap_scroll.c
new file mode 100644
index 00000000..0a5fbf93
--- /dev/null
+++ b/sway/commands/bar/wrap_scroll.c
@@ -0,0 +1,26 @@
1#include <string.h>
2#include "commands.h"
3#include "log.h"
4
5struct cmd_results *bar_cmd_wrap_scroll(int argc, char **argv) {
6 struct cmd_results *error = NULL;
7 if ((error = checkarg(argc, "wrap_scroll", EXPECTED_EQUAL_TO, 1))) {
8 return error;
9 }
10
11 if (!config->current_bar) {
12 return cmd_results_new(CMD_FAILURE, "wrap_scroll", "No bar defined.");
13 }
14
15 if (strcasecmp("yes", argv[0]) == 0) {
16 config->current_bar->wrap_scroll = true;
17 sway_log(L_DEBUG, "Enabling wrap scroll on bar: %s", config->current_bar->id);
18 } else if (strcasecmp("no", argv[0]) == 0) {
19 config->current_bar->wrap_scroll = false;
20 sway_log(L_DEBUG, "Disabling wrap scroll on bar: %s", config->current_bar->id);
21 } else {
22 error = cmd_results_new(CMD_INVALID, "wrap_scroll", "Invalid value %s", argv[0]);
23 return error;
24 }
25 return cmd_results_new(CMD_SUCCESS, NULL, NULL);
26}