diff options
author | Drew DeVault <sir@cmpwn.com> | 2018-03-29 17:20:03 -0400 |
---|---|---|
committer | Drew DeVault <sir@cmpwn.com> | 2018-03-29 22:11:08 -0400 |
commit | bf7a4cd0ebd465a0597e9eec0142fad222b396de (patch) | |
tree | f95c4b8cd8e7d06eaa1b688d3bcbb3249dc21129 /sway/commands/bar | |
parent | Implement enough IPC for swaybar to work (diff) | |
download | sway-bf7a4cd0ebd465a0597e9eec0142fad222b396de.tar.gz sway-bf7a4cd0ebd465a0597e9eec0142fad222b396de.tar.zst sway-bf7a4cd0ebd465a0597e9eec0142fad222b396de.zip |
Add bar configuration commands
Diffstat (limited to 'sway/commands/bar')
24 files changed, 743 insertions, 0 deletions
diff --git a/sway/commands/bar/activate_button.c b/sway/commands/bar/activate_button.c new file mode 100644 index 00000000..0665d2a6 --- /dev/null +++ b/sway/commands/bar/activate_button.c | |||
@@ -0,0 +1,9 @@ | |||
1 | #include <stdlib.h> | ||
2 | #include "sway/commands.h" | ||
3 | #include "log.h" | ||
4 | |||
5 | struct cmd_results *bar_cmd_activate_button(int argc, char **argv) { | ||
6 | const char *cmd_name = "activate_button"; | ||
7 | // TODO TRAY | ||
8 | return cmd_results_new(CMD_INVALID, cmd_name, "TODO TRAY"); | ||
9 | } | ||
diff --git a/sway/commands/bar/binding_mode_indicator.c b/sway/commands/bar/binding_mode_indicator.c new file mode 100644 index 00000000..e11e1033 --- /dev/null +++ b/sway/commands/bar/binding_mode_indicator.c | |||
@@ -0,0 +1,27 @@ | |||
1 | #include <string.h> | ||
2 | #include <strings.h> | ||
3 | #include "sway/commands.h" | ||
4 | #include "log.h" | ||
5 | |||
6 | struct cmd_results *bar_cmd_binding_mode_indicator(int argc, char **argv) { | ||
7 | struct cmd_results *error = NULL; | ||
8 | if ((error = checkarg(argc, "binding_mode_indicator", EXPECTED_EQUAL_TO, 1))) { | ||
9 | return error; | ||
10 | } | ||
11 | |||
12 | if (!config->current_bar) { | ||
13 | return cmd_results_new(CMD_FAILURE, "binding_mode_indicator", "No bar defined."); | ||
14 | } | ||
15 | |||
16 | if (strcasecmp("yes", argv[0]) == 0) { | ||
17 | config->current_bar->binding_mode_indicator = true; | ||
18 | wlr_log(L_DEBUG, "Enabling binding mode indicator on bar: %s", config->current_bar->id); | ||
19 | } else if (strcasecmp("no", argv[0]) == 0) { | ||
20 | config->current_bar->binding_mode_indicator = false; | ||
21 | wlr_log(L_DEBUG, "Disabling binding mode indicator on bar: %s", config->current_bar->id); | ||
22 | } else { | ||
23 | error = cmd_results_new(CMD_INVALID, "binding_mode_indicator", "Invalid value %s", argv[0]); | ||
24 | return error; | ||
25 | } | ||
26 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
27 | } | ||
diff --git a/sway/commands/bar/bindsym.c b/sway/commands/bar/bindsym.c new file mode 100644 index 00000000..ac09a03f --- /dev/null +++ b/sway/commands/bar/bindsym.c | |||
@@ -0,0 +1,11 @@ | |||
1 | #include <stdlib.h> | ||
2 | #include <string.h> | ||
3 | #include "sway/commands.h" | ||
4 | #include "sway/config.h" | ||
5 | #include "list.h" | ||
6 | #include "log.h" | ||
7 | #include "stringop.h" | ||
8 | |||
9 | struct cmd_results *bar_cmd_bindsym(int argc, char **argv) { | ||
10 | return cmd_results_new(CMD_FAILURE, "bindsym", "TODO"); // TODO | ||
11 | } | ||
diff --git a/sway/commands/bar/colors.c b/sway/commands/bar/colors.c new file mode 100644 index 00000000..8b3b0aac --- /dev/null +++ b/sway/commands/bar/colors.c | |||
@@ -0,0 +1,129 @@ | |||
1 | #include <string.h> | ||
2 | #include "sway/commands.h" | ||
3 | |||
4 | static struct cmd_results *parse_single_color(char **color, const char *cmd_name, int argc, char **argv) { | ||
5 | struct cmd_results *error = NULL; | ||
6 | if ((error = checkarg(argc, cmd_name, EXPECTED_EQUAL_TO, 1))) { | ||
7 | return error; | ||
8 | } | ||
9 | |||
10 | if (!*color) { | ||
11 | *color = malloc(10); | ||
12 | if (!*color) { | ||
13 | return cmd_results_new(CMD_FAILURE, cmd_name, "Unable to allocate color"); | ||
14 | } | ||
15 | } | ||
16 | |||
17 | error = add_color(cmd_name, *color, argv[0]); | ||
18 | if (error) { | ||
19 | return error; | ||
20 | } | ||
21 | |||
22 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
23 | } | ||
24 | |||
25 | static struct cmd_results *parse_three_colors(char ***colors, const char *cmd_name, int argc, char **argv) { | ||
26 | struct cmd_results *error = NULL; | ||
27 | if (argc != 3) { | ||
28 | return cmd_results_new(CMD_INVALID, cmd_name, "Requires exactly three color values"); | ||
29 | } | ||
30 | |||
31 | int i; | ||
32 | for (i = 0; i < 3; i++) { | ||
33 | if (!*colors[i]) { | ||
34 | *(colors[i]) = malloc(10); | ||
35 | if (!*(colors[i])) { | ||
36 | return cmd_results_new(CMD_FAILURE, cmd_name, "Unable to allocate color"); | ||
37 | } | ||
38 | } | ||
39 | error = add_color(cmd_name, *(colors[i]), argv[i]); | ||
40 | if (error) { | ||
41 | return error; | ||
42 | } | ||
43 | } | ||
44 | |||
45 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
46 | } | ||
47 | |||
48 | struct cmd_results *bar_cmd_colors(int argc, char **argv) { | ||
49 | struct cmd_results *error = NULL; | ||
50 | if ((error = checkarg(argc, "colors", EXPECTED_EQUAL_TO, 1))) { | ||
51 | return error; | ||
52 | } | ||
53 | |||
54 | if (strcmp("{", argv[0]) != 0) { | ||
55 | return cmd_results_new(CMD_INVALID, "colors", | ||
56 | "Expected '{' at the start of colors config definition."); | ||
57 | } | ||
58 | |||
59 | return cmd_results_new(CMD_BLOCK_BAR_COLORS, NULL, NULL); | ||
60 | } | ||
61 | |||
62 | struct cmd_results *bar_colors_cmd_active_workspace(int argc, char **argv) { | ||
63 | char **colors[3] = { | ||
64 | &(config->current_bar->colors.active_workspace_border), | ||
65 | &(config->current_bar->colors.active_workspace_bg), | ||
66 | &(config->current_bar->colors.active_workspace_text) | ||
67 | }; | ||
68 | return parse_three_colors(colors, "active_workspace", argc, argv); | ||
69 | } | ||
70 | |||
71 | struct cmd_results *bar_colors_cmd_background(int argc, char **argv) { | ||
72 | return parse_single_color(&(config->current_bar->colors.background), "background", argc, argv); | ||
73 | } | ||
74 | |||
75 | struct cmd_results *bar_colors_cmd_focused_background(int argc, char **argv) { | ||
76 | return parse_single_color(&(config->current_bar->colors.focused_background), "focused_background", argc, argv); | ||
77 | } | ||
78 | |||
79 | struct cmd_results *bar_colors_cmd_binding_mode(int argc, char **argv) { | ||
80 | char **colors[3] = { | ||
81 | &(config->current_bar->colors.binding_mode_border), | ||
82 | &(config->current_bar->colors.binding_mode_bg), | ||
83 | &(config->current_bar->colors.binding_mode_text) | ||
84 | }; | ||
85 | return parse_three_colors(colors, "binding_mode", argc, argv); | ||
86 | } | ||
87 | |||
88 | struct cmd_results *bar_colors_cmd_focused_workspace(int argc, char **argv) { | ||
89 | char **colors[3] = { | ||
90 | &(config->current_bar->colors.focused_workspace_border), | ||
91 | &(config->current_bar->colors.focused_workspace_bg), | ||
92 | &(config->current_bar->colors.focused_workspace_text) | ||
93 | }; | ||
94 | return parse_three_colors(colors, "focused_workspace", argc, argv); | ||
95 | } | ||
96 | |||
97 | struct cmd_results *bar_colors_cmd_inactive_workspace(int argc, char **argv) { | ||
98 | char **colors[3] = { | ||
99 | &(config->current_bar->colors.inactive_workspace_border), | ||
100 | &(config->current_bar->colors.inactive_workspace_bg), | ||
101 | &(config->current_bar->colors.inactive_workspace_text) | ||
102 | }; | ||
103 | return parse_three_colors(colors, "inactive_workspace", argc, argv); | ||
104 | } | ||
105 | |||
106 | struct cmd_results *bar_colors_cmd_separator(int argc, char **argv) { | ||
107 | return parse_single_color(&(config->current_bar->colors.separator), "separator", argc, argv); | ||
108 | } | ||
109 | |||
110 | struct cmd_results *bar_colors_cmd_focused_separator(int argc, char **argv) { | ||
111 | return parse_single_color(&(config->current_bar->colors.focused_separator), "focused_separator", argc, argv); | ||
112 | } | ||
113 | |||
114 | struct cmd_results *bar_colors_cmd_statusline(int argc, char **argv) { | ||
115 | return parse_single_color(&(config->current_bar->colors.statusline), "statusline", argc, argv); | ||
116 | } | ||
117 | |||
118 | struct cmd_results *bar_colors_cmd_focused_statusline(int argc, char **argv) { | ||
119 | return parse_single_color(&(config->current_bar->colors.focused_separator), "focused_separator", argc, argv); | ||
120 | } | ||
121 | |||
122 | struct cmd_results *bar_colors_cmd_urgent_workspace(int argc, char **argv) { | ||
123 | char **colors[3] = { | ||
124 | &(config->current_bar->colors.urgent_workspace_border), | ||
125 | &(config->current_bar->colors.urgent_workspace_bg), | ||
126 | &(config->current_bar->colors.urgent_workspace_text) | ||
127 | }; | ||
128 | return parse_three_colors(colors, "urgent_workspace", argc, argv); | ||
129 | } | ||
diff --git a/sway/commands/bar/context_button.c b/sway/commands/bar/context_button.c new file mode 100644 index 00000000..e6d17f10 --- /dev/null +++ b/sway/commands/bar/context_button.c | |||
@@ -0,0 +1,9 @@ | |||
1 | #include <stdlib.h> | ||
2 | #include "sway/commands.h" | ||
3 | #include "log.h" | ||
4 | |||
5 | struct cmd_results *bar_cmd_context_button(int argc, char **argv) { | ||
6 | const char *cmd_name = "context_button"; | ||
7 | // TODO TRAY | ||
8 | return cmd_results_new(CMD_INVALID, cmd_name, "TODO TRAY"); | ||
9 | } | ||
diff --git a/sway/commands/bar/font.c b/sway/commands/bar/font.c new file mode 100644 index 00000000..6d7c533a --- /dev/null +++ b/sway/commands/bar/font.c | |||
@@ -0,0 +1,26 @@ | |||
1 | #include <string.h> | ||
2 | #include "sway/commands.h" | ||
3 | #include "log.h" | ||
4 | #include "stringop.h" | ||
5 | |||
6 | struct 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 | wlr_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..ae0c7834 --- /dev/null +++ b/sway/commands/bar/height.c | |||
@@ -0,0 +1,21 @@ | |||
1 | #include <stdlib.h> | ||
2 | #include <string.h> | ||
3 | #include "sway/commands.h" | ||
4 | #include "log.h" | ||
5 | |||
6 | struct 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 | wlr_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..245d0858 --- /dev/null +++ b/sway/commands/bar/hidden_state.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 | |||
9 | static struct cmd_results *bar_set_hidden_state(struct bar_config *bar, | ||
10 | const char *hidden_state) { | ||
11 | char *old_state = bar->hidden_state; | ||
12 | if (strcasecmp("toggle", hidden_state) == 0 && !config->reading) { | ||
13 | if (strcasecmp("hide", bar->hidden_state) == 0) { | ||
14 | bar->hidden_state = strdup("show"); | ||
15 | } else if (strcasecmp("show", bar->hidden_state) == 0) { | ||
16 | bar->hidden_state = strdup("hide"); | ||
17 | } | ||
18 | } else if (strcasecmp("hide", hidden_state) == 0) { | ||
19 | bar->hidden_state = strdup("hide"); | ||
20 | } else if (strcasecmp("show", hidden_state) == 0) { | ||
21 | bar->hidden_state = strdup("show"); | ||
22 | } else { | ||
23 | return cmd_results_new(CMD_INVALID, "hidden_state", | ||
24 | "Invalid value %s", hidden_state); | ||
25 | } | ||
26 | |||
27 | if (strcmp(old_state, bar->hidden_state) != 0) { | ||
28 | if (!config->reading) { | ||
29 | ipc_event_barconfig_update(bar); | ||
30 | } | ||
31 | wlr_log(L_DEBUG, "Setting hidden_state: '%s' for bar: %s", | ||
32 | bar->hidden_state, bar->id); | ||
33 | } | ||
34 | |||
35 | // free old mode | ||
36 | free(old_state); | ||
37 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
38 | } | ||
39 | |||
40 | struct cmd_results *bar_cmd_hidden_state(int argc, char **argv) { | ||
41 | struct cmd_results *error = NULL; | ||
42 | if ((error = checkarg(argc, "hidden_state", EXPECTED_AT_LEAST, 1))) { | ||
43 | return error; | ||
44 | } | ||
45 | if ((error = checkarg(argc, "hidden_state", EXPECTED_LESS_THAN, 3))) { | ||
46 | return error; | ||
47 | } | ||
48 | |||
49 | if (config->reading && argc > 1) { | ||
50 | return cmd_results_new(CMD_INVALID, "hidden_state", | ||
51 | "Unexpected value %s in config mode", argv[1]); | ||
52 | } | ||
53 | |||
54 | const char *state = argv[0]; | ||
55 | |||
56 | if (config->reading) { | ||
57 | return bar_set_hidden_state(config->current_bar, state); | ||
58 | } | ||
59 | |||
60 | const char *id = NULL; | ||
61 | if (argc == 2) { | ||
62 | id = argv[1]; | ||
63 | } | ||
64 | |||
65 | struct bar_config *bar; | ||
66 | for (int 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_hidden_state(bar, state); | ||
70 | } | ||
71 | |||
72 | error = bar_set_hidden_state(bar, state); | ||
73 | if (error) { | ||
74 | return error; | ||
75 | } | ||
76 | } | ||
77 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
78 | } | ||
diff --git a/sway/commands/bar/icon_theme.c b/sway/commands/bar/icon_theme.c new file mode 100644 index 00000000..c6090b81 --- /dev/null +++ b/sway/commands/bar/icon_theme.c | |||
@@ -0,0 +1,9 @@ | |||
1 | #define _XOPEN_SOURCE 500 | ||
2 | #include <string.h> | ||
3 | #include "sway/commands.h" | ||
4 | |||
5 | struct cmd_results *bar_cmd_icon_theme(int argc, char **argv) { | ||
6 | const char *cmd_name = "tray_output"; | ||
7 | // TODO TRAY | ||
8 | return cmd_results_new(CMD_INVALID, cmd_name, "TODO TRAY"); | ||
9 | } | ||
diff --git a/sway/commands/bar/id.c b/sway/commands/bar/id.c new file mode 100644 index 00000000..d9e7f8df --- /dev/null +++ b/sway/commands/bar/id.c | |||
@@ -0,0 +1,33 @@ | |||
1 | #define _XOPEN_SOURCE 500 | ||
2 | #include <string.h> | ||
3 | #include "sway/commands.h" | ||
4 | #include "log.h" | ||
5 | |||
6 | struct cmd_results *bar_cmd_id(int argc, char **argv) { | ||
7 | struct cmd_results *error = NULL; | ||
8 | if ((error = checkarg(argc, "id", EXPECTED_EQUAL_TO, 1))) { | ||
9 | return error; | ||
10 | } | ||
11 | |||
12 | const char *name = argv[0]; | ||
13 | const char *oldname = config->current_bar->id; | ||
14 | |||
15 | // check if id is used by a previously defined bar | ||
16 | int i; | ||
17 | for (i = 0; i < config->bars->length; ++i) { | ||
18 | struct bar_config *find = config->bars->items[i]; | ||
19 | if (strcmp(name, find->id) == 0 && config->current_bar != find) { | ||
20 | return cmd_results_new(CMD_FAILURE, "id", | ||
21 | "Id '%s' already defined for another bar. Id unchanged (%s).", | ||
22 | name, oldname); | ||
23 | } | ||
24 | } | ||
25 | |||
26 | wlr_log(L_DEBUG, "Renaming bar: '%s' to '%s'", oldname, name); | ||
27 | |||
28 | // free old bar id | ||
29 | free(config->current_bar->id); | ||
30 | |||
31 | config->current_bar->id = strdup(name); | ||
32 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
33 | } | ||
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 | |||
9 | static 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 | |||
39 | struct 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 | } | ||
diff --git a/sway/commands/bar/modifier.c b/sway/commands/bar/modifier.c new file mode 100644 index 00000000..9a1f8b01 --- /dev/null +++ b/sway/commands/bar/modifier.c | |||
@@ -0,0 +1,35 @@ | |||
1 | #include <string.h> | ||
2 | #include "sway/commands.h" | ||
3 | #include "log.h" | ||
4 | #include "stringop.h" | ||
5 | #include "util.h" | ||
6 | |||
7 | struct 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 | wlr_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..034d9ca4 --- /dev/null +++ b/sway/commands/bar/output.c | |||
@@ -0,0 +1,50 @@ | |||
1 | #define _XOPEN_SOURCE 500 | ||
2 | #include <string.h> | ||
3 | #include "sway/commands.h" | ||
4 | #include "list.h" | ||
5 | #include "log.h" | ||
6 | |||
7 | struct cmd_results *bar_cmd_output(int argc, char **argv) { | ||
8 | struct cmd_results *error = NULL; | ||
9 | if ((error = checkarg(argc, "output", EXPECTED_EQUAL_TO, 1))) { | ||
10 | return error; | ||
11 | } | ||
12 | |||
13 | if (!config->current_bar) { | ||
14 | return cmd_results_new(CMD_FAILURE, "output", "No bar defined."); | ||
15 | } | ||
16 | |||
17 | const char *output = argv[0]; | ||
18 | list_t *outputs = config->current_bar->outputs; | ||
19 | if (!outputs) { | ||
20 | outputs = create_list(); | ||
21 | config->current_bar->outputs = outputs; | ||
22 | } | ||
23 | |||
24 | int i; | ||
25 | int add_output = 1; | ||
26 | if (strcmp("*", output) == 0) { | ||
27 | // remove all previous defined outputs and replace with '*' | ||
28 | for (i = 0; i < outputs->length; ++i) { | ||
29 | free(outputs->items[i]); | ||
30 | list_del(outputs, i); | ||
31 | } | ||
32 | } else { | ||
33 | // only add output if not already defined with either the same | ||
34 | // name or as '*' | ||
35 | for (i = 0; i < outputs->length; ++i) { | ||
36 | const char *find = outputs->items[i]; | ||
37 | if (strcmp("*", find) == 0 || strcmp(output, find) == 0) { | ||
38 | add_output = 0; | ||
39 | break; | ||
40 | } | ||
41 | } | ||
42 | } | ||
43 | |||
44 | if (add_output) { | ||
45 | list_add(outputs, strdup(output)); | ||
46 | wlr_log(L_DEBUG, "Adding bar: '%s' to output '%s'", config->current_bar->id, output); | ||
47 | } | ||
48 | |||
49 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
50 | } | ||
diff --git a/sway/commands/bar/pango_markup.c b/sway/commands/bar/pango_markup.c new file mode 100644 index 00000000..34b85e98 --- /dev/null +++ b/sway/commands/bar/pango_markup.c | |||
@@ -0,0 +1,27 @@ | |||
1 | #include <string.h> | ||
2 | #include <strings.h> | ||
3 | #include "sway/commands.h" | ||
4 | #include "log.h" | ||
5 | |||
6 | struct cmd_results *bar_cmd_pango_markup(int argc, char **argv) { | ||
7 | struct cmd_results *error = NULL; | ||
8 | if ((error = checkarg(argc, "pango_markup", EXPECTED_EQUAL_TO, 1))) { | ||
9 | return error; | ||
10 | } | ||
11 | |||
12 | if (!config->current_bar) { | ||
13 | return cmd_results_new(CMD_FAILURE, "pango_markup", "No bar defined."); | ||
14 | } | ||
15 | |||
16 | if (strcasecmp("enabled", argv[0]) == 0) { | ||
17 | config->current_bar->pango_markup = true; | ||
18 | wlr_log(L_DEBUG, "Enabling pango markup for bar: %s", config->current_bar->id); | ||
19 | } else if (strcasecmp("disabled", argv[0]) == 0) { | ||
20 | config->current_bar->pango_markup = false; | ||
21 | wlr_log(L_DEBUG, "Disabling pango markup for bar: %s", config->current_bar->id); | ||
22 | } else { | ||
23 | error = cmd_results_new(CMD_INVALID, "pango_markup", "Invalid value %s", argv[0]); | ||
24 | return error; | ||
25 | } | ||
26 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
27 | } | ||
diff --git a/sway/commands/bar/position.c b/sway/commands/bar/position.c new file mode 100644 index 00000000..efa8c0bc --- /dev/null +++ b/sway/commands/bar/position.c | |||
@@ -0,0 +1,29 @@ | |||
1 | #define _POSIX_C_SOURCE 200809L | ||
2 | #include <string.h> | ||
3 | #include <strings.h> | ||
4 | #include "sway/commands.h" | ||
5 | #include "log.h" | ||
6 | |||
7 | struct cmd_results *bar_cmd_position(int argc, char **argv) { | ||
8 | struct cmd_results *error = NULL; | ||
9 | if ((error = checkarg(argc, "position", EXPECTED_EQUAL_TO, 1))) { | ||
10 | return error; | ||
11 | } | ||
12 | |||
13 | if (!config->current_bar) { | ||
14 | return cmd_results_new(CMD_FAILURE, "position", "No bar defined."); | ||
15 | } | ||
16 | |||
17 | char *valid[] = { "top", "bottom", "left", "right" }; | ||
18 | for (size_t i = 0; i < sizeof(valid) / sizeof(valid[0]); ++i) { | ||
19 | if (strcasecmp(valid[i], argv[0]) == 0) { | ||
20 | wlr_log(L_DEBUG, "Setting bar position '%s' for bar: %s", | ||
21 | argv[0], config->current_bar->id); | ||
22 | config->current_bar->position = strdup(argv[0]); | ||
23 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
24 | } | ||
25 | } | ||
26 | |||
27 | error = cmd_results_new(CMD_INVALID, "position", "Invalid value %s", argv[0]); | ||
28 | return error; | ||
29 | } | ||
diff --git a/sway/commands/bar/secondary_button.c b/sway/commands/bar/secondary_button.c new file mode 100644 index 00000000..46d53e3f --- /dev/null +++ b/sway/commands/bar/secondary_button.c | |||
@@ -0,0 +1,9 @@ | |||
1 | #include <stdlib.h> | ||
2 | #include "sway/commands.h" | ||
3 | #include "log.h" | ||
4 | |||
5 | struct cmd_results *bar_cmd_secondary_button(int argc, char **argv) { | ||
6 | const char *cmd_name = "secondary_button"; | ||
7 | // TODO TRAY | ||
8 | return cmd_results_new(CMD_INVALID, cmd_name, "TODO TRAY"); | ||
9 | } | ||
diff --git a/sway/commands/bar/separator_symbol.c b/sway/commands/bar/separator_symbol.c new file mode 100644 index 00000000..7dc0956b --- /dev/null +++ b/sway/commands/bar/separator_symbol.c | |||
@@ -0,0 +1,21 @@ | |||
1 | #define _XOPEN_SOURCE 500 | ||
2 | #include <string.h> | ||
3 | #include "sway/commands.h" | ||
4 | #include "log.h" | ||
5 | |||
6 | struct cmd_results *bar_cmd_separator_symbol(int argc, char **argv) { | ||
7 | struct cmd_results *error = NULL; | ||
8 | if ((error = checkarg(argc, "separator_symbol", EXPECTED_EQUAL_TO, 1))) { | ||
9 | return error; | ||
10 | } | ||
11 | |||
12 | if (!config->current_bar) { | ||
13 | return cmd_results_new(CMD_FAILURE, "separator_symbol", "No bar defined."); | ||
14 | } | ||
15 | |||
16 | free(config->current_bar->separator_symbol); | ||
17 | config->current_bar->separator_symbol = strdup(argv[0]); | ||
18 | wlr_log(L_DEBUG, "Settings separator_symbol '%s' for bar: %s", config->current_bar->separator_symbol, config->current_bar->id); | ||
19 | |||
20 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
21 | } | ||
diff --git a/sway/commands/bar/status_command.c b/sway/commands/bar/status_command.c new file mode 100644 index 00000000..05377fcc --- /dev/null +++ b/sway/commands/bar/status_command.c | |||
@@ -0,0 +1,21 @@ | |||
1 | #include <string.h> | ||
2 | #include "sway/commands.h" | ||
3 | #include "log.h" | ||
4 | #include "stringop.h" | ||
5 | |||
6 | struct 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 | wlr_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..0558db8f --- /dev/null +++ b/sway/commands/bar/strip_workspace_numbers.c | |||
@@ -0,0 +1,27 @@ | |||
1 | #include <string.h> | ||
2 | #include <strings.h> | ||
3 | #include "sway/commands.h" | ||
4 | #include "log.h" | ||
5 | |||
6 | struct cmd_results *bar_cmd_strip_workspace_numbers(int argc, char **argv) { | ||
7 | struct cmd_results *error = NULL; | ||
8 | if ((error = checkarg(argc, "strip_workspace_numbers", EXPECTED_EQUAL_TO, 1))) { | ||
9 | return error; | ||
10 | } | ||
11 | |||
12 | if (!config->current_bar) { | ||
13 | return cmd_results_new(CMD_FAILURE, "strip_workspace_numbers", "No bar defined."); | ||
14 | } | ||
15 | |||
16 | if (strcasecmp("yes", argv[0]) == 0) { | ||
17 | config->current_bar->strip_workspace_numbers = true; | ||
18 | wlr_log(L_DEBUG, "Stripping workspace numbers on bar: %s", config->current_bar->id); | ||
19 | } else if (strcasecmp("no", argv[0]) == 0) { | ||
20 | config->current_bar->strip_workspace_numbers = false; | ||
21 | wlr_log(L_DEBUG, "Enabling workspace numbers on bar: %s", config->current_bar->id); | ||
22 | } else { | ||
23 | error = cmd_results_new(CMD_INVALID, "strip_workspace_numbers", "Invalid value %s", argv[0]); | ||
24 | return error; | ||
25 | } | ||
26 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
27 | } | ||
diff --git a/sway/commands/bar/swaybar_command.c b/sway/commands/bar/swaybar_command.c new file mode 100644 index 00000000..63d4f29a --- /dev/null +++ b/sway/commands/bar/swaybar_command.c | |||
@@ -0,0 +1,21 @@ | |||
1 | #include <string.h> | ||
2 | #include "sway/commands.h" | ||
3 | #include "log.h" | ||
4 | #include "stringop.h" | ||
5 | |||
6 | struct 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 | wlr_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..2d822146 --- /dev/null +++ b/sway/commands/bar/tray_output.c | |||
@@ -0,0 +1,9 @@ | |||
1 | #define _XOPEN_SOURCE 500 | ||
2 | #include <string.h> | ||
3 | #include "sway/commands.h" | ||
4 | |||
5 | struct cmd_results *bar_cmd_tray_output(int argc, char **argv) { | ||
6 | const char *cmd_name = "tray_output"; | ||
7 | // TODO TRAY | ||
8 | return cmd_results_new(CMD_INVALID, cmd_name, "TODO TRAY"); | ||
9 | } | ||
diff --git a/sway/commands/bar/tray_padding.c b/sway/commands/bar/tray_padding.c new file mode 100644 index 00000000..95b8ad3b --- /dev/null +++ b/sway/commands/bar/tray_padding.c | |||
@@ -0,0 +1,10 @@ | |||
1 | #include <stdlib.h> | ||
2 | #include <strings.h> | ||
3 | #include "sway/commands.h" | ||
4 | #include "log.h" | ||
5 | |||
6 | struct cmd_results *bar_cmd_tray_padding(int argc, char **argv) { | ||
7 | const char *cmd_name = "tray_padding"; | ||
8 | // TODO TRAY | ||
9 | return cmd_results_new(CMD_INVALID, cmd_name, "TODO TRAY"); | ||
10 | } | ||
diff --git a/sway/commands/bar/workspace_buttons.c b/sway/commands/bar/workspace_buttons.c new file mode 100644 index 00000000..1a617eb8 --- /dev/null +++ b/sway/commands/bar/workspace_buttons.c | |||
@@ -0,0 +1,27 @@ | |||
1 | #include <string.h> | ||
2 | #include <strings.h> | ||
3 | #include "sway/commands.h" | ||
4 | #include "log.h" | ||
5 | |||
6 | struct cmd_results *bar_cmd_workspace_buttons(int argc, char **argv) { | ||
7 | struct cmd_results *error = NULL; | ||
8 | if ((error = checkarg(argc, "workspace_buttons", EXPECTED_EQUAL_TO, 1))) { | ||
9 | return error; | ||
10 | } | ||
11 | |||
12 | if (!config->current_bar) { | ||
13 | return cmd_results_new(CMD_FAILURE, "workspace_buttons", "No bar defined."); | ||
14 | } | ||
15 | |||
16 | if (strcasecmp("yes", argv[0]) == 0) { | ||
17 | config->current_bar->workspace_buttons = true; | ||
18 | wlr_log(L_DEBUG, "Enabling workspace buttons on bar: %s", config->current_bar->id); | ||
19 | } else if (strcasecmp("no", argv[0]) == 0) { | ||
20 | config->current_bar->workspace_buttons = false; | ||
21 | wlr_log(L_DEBUG, "Disabling workspace buttons on bar: %s", config->current_bar->id); | ||
22 | } else { | ||
23 | error = cmd_results_new(CMD_INVALID, "workspace_buttons", "Invalid value %s", argv[0]); | ||
24 | return error; | ||
25 | } | ||
26 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
27 | } | ||
diff --git a/sway/commands/bar/wrap_scroll.c b/sway/commands/bar/wrap_scroll.c new file mode 100644 index 00000000..c89dff5f --- /dev/null +++ b/sway/commands/bar/wrap_scroll.c | |||
@@ -0,0 +1,27 @@ | |||
1 | #include <string.h> | ||
2 | #include <strings.h> | ||
3 | #include "sway/commands.h" | ||
4 | #include "log.h" | ||
5 | |||
6 | struct cmd_results *bar_cmd_wrap_scroll(int argc, char **argv) { | ||
7 | struct cmd_results *error = NULL; | ||
8 | if ((error = checkarg(argc, "wrap_scroll", EXPECTED_EQUAL_TO, 1))) { | ||
9 | return error; | ||
10 | } | ||
11 | |||
12 | if (!config->current_bar) { | ||
13 | return cmd_results_new(CMD_FAILURE, "wrap_scroll", "No bar defined."); | ||
14 | } | ||
15 | |||
16 | if (strcasecmp("yes", argv[0]) == 0) { | ||
17 | config->current_bar->wrap_scroll = true; | ||
18 | wlr_log(L_DEBUG, "Enabling wrap scroll on bar: %s", config->current_bar->id); | ||
19 | } else if (strcasecmp("no", argv[0]) == 0) { | ||
20 | config->current_bar->wrap_scroll = false; | ||
21 | wlr_log(L_DEBUG, "Disabling wrap scroll on bar: %s", config->current_bar->id); | ||
22 | } else { | ||
23 | error = cmd_results_new(CMD_INVALID, "wrap_scroll", "Invalid value %s", argv[0]); | ||
24 | return error; | ||
25 | } | ||
26 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
27 | } | ||