diff options
author | Ian Fan <ianfan0@gmail.com> | 2018-12-09 15:10:41 +0000 |
---|---|---|
committer | Ian Fan <ianfan0@gmail.com> | 2018-12-31 20:40:18 +0000 |
commit | 6b03c68775c9c638def342c82b1fa3beffa52645 (patch) | |
tree | a3b18d948f8e2a51151f24aab47c552f28a17f70 /sway/commands/bar | |
parent | swaybar: add StatusNotifierItem to tray (diff) | |
download | sway-6b03c68775c9c638def342c82b1fa3beffa52645.tar.gz sway-6b03c68775c9c638def342c82b1fa3beffa52645.tar.zst sway-6b03c68775c9c638def342c82b1fa3beffa52645.zip |
swaybar: implement tray config
Diffstat (limited to 'sway/commands/bar')
-rw-r--r-- | sway/commands/bar/activate_button.c | 8 | ||||
-rw-r--r-- | sway/commands/bar/context_button.c | 8 | ||||
-rw-r--r-- | sway/commands/bar/icon_theme.c | 25 | ||||
-rw-r--r-- | sway/commands/bar/secondary_button.c | 8 | ||||
-rw-r--r-- | sway/commands/bar/tray_bindsym.c | 55 | ||||
-rw-r--r-- | sway/commands/bar/tray_output.c | 39 | ||||
-rw-r--r-- | sway/commands/bar/tray_padding.c | 37 |
7 files changed, 150 insertions, 30 deletions
diff --git a/sway/commands/bar/activate_button.c b/sway/commands/bar/activate_button.c deleted file mode 100644 index 7310e7ec..00000000 --- a/sway/commands/bar/activate_button.c +++ /dev/null | |||
@@ -1,8 +0,0 @@ | |||
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 | // TODO TRAY | ||
7 | return cmd_results_new(CMD_INVALID, "activate_button", "TODO TRAY"); | ||
8 | } | ||
diff --git a/sway/commands/bar/context_button.c b/sway/commands/bar/context_button.c deleted file mode 100644 index 3b76885a..00000000 --- a/sway/commands/bar/context_button.c +++ /dev/null | |||
@@ -1,8 +0,0 @@ | |||
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 | // TODO TRAY | ||
7 | return cmd_results_new(CMD_INVALID, "context_button", "TODO TRAY"); | ||
8 | } | ||
diff --git a/sway/commands/bar/icon_theme.c b/sway/commands/bar/icon_theme.c index 0e30409b..9d3b6040 100644 --- a/sway/commands/bar/icon_theme.c +++ b/sway/commands/bar/icon_theme.c | |||
@@ -1,7 +1,28 @@ | |||
1 | #define _POSIX_C_SOURCE 200809L | ||
1 | #include <string.h> | 2 | #include <string.h> |
3 | #include "config.h" | ||
2 | #include "sway/commands.h" | 4 | #include "sway/commands.h" |
5 | #include "sway/config.h" | ||
6 | #include "log.h" | ||
3 | 7 | ||
4 | struct cmd_results *bar_cmd_icon_theme(int argc, char **argv) { | 8 | struct cmd_results *bar_cmd_icon_theme(int argc, char **argv) { |
5 | // TODO TRAY | 9 | #if HAVE_TRAY |
6 | return cmd_results_new(CMD_INVALID, "icon_theme", "TODO TRAY"); | 10 | struct cmd_results *error = NULL; |
11 | if ((error = checkarg(argc, "icon_theme", EXPECTED_EQUAL_TO, 1))) { | ||
12 | return error; | ||
13 | } | ||
14 | |||
15 | if (!config->current_bar) { | ||
16 | return cmd_results_new(CMD_FAILURE, "tray_padding", "No bar defined."); | ||
17 | } | ||
18 | |||
19 | wlr_log(WLR_DEBUG, "[Bar %s] Setting icon theme to %s", | ||
20 | config->current_bar->id, argv[0]); | ||
21 | free(config->current_bar->icon_theme); | ||
22 | config->current_bar->icon_theme = strdup(argv[0]); | ||
23 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
24 | #else | ||
25 | return cmd_results_new(CMD_INVALID, "icon_theme", | ||
26 | "Sway has been compiled without tray support"); | ||
27 | #endif | ||
7 | } | 28 | } |
diff --git a/sway/commands/bar/secondary_button.c b/sway/commands/bar/secondary_button.c deleted file mode 100644 index 449124cb..00000000 --- a/sway/commands/bar/secondary_button.c +++ /dev/null | |||
@@ -1,8 +0,0 @@ | |||
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 | // TODO TRAY | ||
7 | return cmd_results_new(CMD_INVALID, "secondary_button", "TODO TRAY"); | ||
8 | } | ||
diff --git a/sway/commands/bar/tray_bindsym.c b/sway/commands/bar/tray_bindsym.c new file mode 100644 index 00000000..ad413446 --- /dev/null +++ b/sway/commands/bar/tray_bindsym.c | |||
@@ -0,0 +1,55 @@ | |||
1 | #include <strings.h> | ||
2 | #include "config.h" | ||
3 | #include "sway/commands.h" | ||
4 | #include "sway/config.h" | ||
5 | #include "log.h" | ||
6 | |||
7 | struct cmd_results *bar_cmd_tray_bindsym(int argc, char **argv) { | ||
8 | #if HAVE_TRAY | ||
9 | struct cmd_results *error = NULL; | ||
10 | if ((error = checkarg(argc, "tray_bindsym", EXPECTED_EQUAL_TO, 2))) { | ||
11 | return error; | ||
12 | } | ||
13 | |||
14 | if (!config->current_bar) { | ||
15 | return cmd_results_new(CMD_FAILURE, "tray_bindsym", "No bar defined."); | ||
16 | } | ||
17 | |||
18 | int button = 0; | ||
19 | if (strncasecmp(argv[0], "button", strlen("button")) == 0 && | ||
20 | strlen(argv[0]) == strlen("button0")) { | ||
21 | button = argv[0][strlen("button")] - '0'; | ||
22 | } | ||
23 | if (button < 1 || button > 9) { | ||
24 | return cmd_results_new(CMD_FAILURE, "tray_bindsym", | ||
25 | "[Bar %s] Only buttons 1 to 9 are supported", | ||
26 | config->current_bar->id); | ||
27 | } | ||
28 | |||
29 | static const char *commands[] = { | ||
30 | "ContextMenu", | ||
31 | "Activate", | ||
32 | "SecondaryActivate", | ||
33 | "ScrollDown", | ||
34 | "ScrollLeft", | ||
35 | "ScrollRight", | ||
36 | "ScrollUp", | ||
37 | "nop" | ||
38 | }; | ||
39 | |||
40 | for (size_t i = 0; i < sizeof(commands) / sizeof(commands[0]); ++i) { | ||
41 | if (strcasecmp(argv[1], commands[i]) == 0) { | ||
42 | wlr_log(WLR_DEBUG, "[Bar %s] Binding button %d to %s", | ||
43 | config->current_bar->id, button, commands[i]); | ||
44 | config->current_bar->tray_bindings[button] = commands[i]; | ||
45 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
46 | } | ||
47 | } | ||
48 | |||
49 | return cmd_results_new(CMD_INVALID, "tray_bindsym", | ||
50 | "[Bar %s] Invalid command %s", config->current_bar->id, argv[1]); | ||
51 | #else | ||
52 | return cmd_results_new(CMD_INVALID, "tray_bindsym", | ||
53 | "Sway has been compiled without tray support"); | ||
54 | #endif | ||
55 | } | ||
diff --git a/sway/commands/bar/tray_output.c b/sway/commands/bar/tray_output.c index e6c77128..19ecc5c1 100644 --- a/sway/commands/bar/tray_output.c +++ b/sway/commands/bar/tray_output.c | |||
@@ -1,7 +1,42 @@ | |||
1 | #define _POSIX_C_SOURCE 200809L | ||
1 | #include <string.h> | 2 | #include <string.h> |
3 | #include "config.h" | ||
2 | #include "sway/commands.h" | 4 | #include "sway/commands.h" |
5 | #include "sway/config.h" | ||
6 | #include "list.h" | ||
7 | #include "log.h" | ||
3 | 8 | ||
4 | struct cmd_results *bar_cmd_tray_output(int argc, char **argv) { | 9 | struct cmd_results *bar_cmd_tray_output(int argc, char **argv) { |
5 | // TODO TRAY | 10 | #if HAVE_TRAY |
6 | return cmd_results_new(CMD_INVALID, "tray_output", "TODO TRAY"); | 11 | struct cmd_results *error = NULL; |
12 | if ((error = checkarg(argc, "tray_output", EXPECTED_EQUAL_TO, 1))) { | ||
13 | return error; | ||
14 | } | ||
15 | |||
16 | if (!config->current_bar) { | ||
17 | return cmd_results_new(CMD_FAILURE, "tray_output", "No bar defined."); | ||
18 | } | ||
19 | |||
20 | list_t *outputs = config->current_bar->tray_outputs; | ||
21 | if (!outputs) { | ||
22 | config->current_bar->tray_outputs = outputs = create_list(); | ||
23 | } | ||
24 | |||
25 | if (strcmp(argv[0], "none") == 0) { | ||
26 | wlr_log(WLR_DEBUG, "Hiding tray on bar: %s", config->current_bar->id); | ||
27 | for (int i = 0; i < outputs->length; ++i) { | ||
28 | free(outputs->items[i]); | ||
29 | } | ||
30 | outputs->length = 0; | ||
31 | } else { | ||
32 | wlr_log(WLR_DEBUG, "Showing tray on output '%s' for bar: %s", argv[0], | ||
33 | config->current_bar->id); | ||
34 | list_add(outputs, strdup(argv[0])); | ||
35 | } | ||
36 | |||
37 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
38 | #else | ||
39 | return cmd_results_new(CMD_INVALID, "tray_output", | ||
40 | "Sway has been compiled without tray support"); | ||
41 | #endif | ||
7 | } | 42 | } |
diff --git a/sway/commands/bar/tray_padding.c b/sway/commands/bar/tray_padding.c index 91c56f19..eb795b00 100644 --- a/sway/commands/bar/tray_padding.c +++ b/sway/commands/bar/tray_padding.c | |||
@@ -1,9 +1,42 @@ | |||
1 | #include <stdlib.h> | 1 | #include <stdlib.h> |
2 | #include <strings.h> | 2 | #include <strings.h> |
3 | #include "config.h" | ||
3 | #include "sway/commands.h" | 4 | #include "sway/commands.h" |
5 | #include "sway/config.h" | ||
4 | #include "log.h" | 6 | #include "log.h" |
5 | 7 | ||
6 | struct cmd_results *bar_cmd_tray_padding(int argc, char **argv) { | 8 | struct cmd_results *bar_cmd_tray_padding(int argc, char **argv) { |
7 | // TODO TRAY | 9 | #if HAVE_TRAY |
8 | return cmd_results_new(CMD_INVALID, "tray_padding", "TODO TRAY"); | 10 | struct cmd_results *error = NULL; |
11 | if ((error = checkarg(argc, "tray_padding", EXPECTED_AT_LEAST, 1))) { | ||
12 | return error; | ||
13 | } | ||
14 | if ((error = checkarg(argc, "tray_padding", EXPECTED_AT_MOST, 2))) { | ||
15 | return error; | ||
16 | } | ||
17 | |||
18 | if (!config->current_bar) { | ||
19 | return cmd_results_new(CMD_FAILURE, "tray_padding", "No bar defined."); | ||
20 | } | ||
21 | struct bar_config *bar = config->current_bar; | ||
22 | |||
23 | char *end; | ||
24 | int padding = strtol(argv[0], &end, 10); | ||
25 | if (padding < 0 || (*end != '\0' && strcasecmp(end, "px") != 0)) { | ||
26 | return cmd_results_new(CMD_INVALID, "tray_padding", | ||
27 | "[Bar %s] Invalid tray padding value: %s", bar->id, argv[0]); | ||
28 | } | ||
29 | |||
30 | if (argc == 2 && strcasecmp(argv[1], "px") != 0) { | ||
31 | return cmd_results_new(CMD_INVALID, "tray_padding", | ||
32 | "Expected 'tray_padding <px> [px]'"); | ||
33 | } | ||
34 | |||
35 | wlr_log(WLR_DEBUG, "[Bar %s] Setting tray padding to %d", bar->id, padding); | ||
36 | config->current_bar->tray_padding = padding; | ||
37 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
38 | #else | ||
39 | return cmd_results_new(CMD_INVALID, "tray_padding", | ||
40 | "Sway has been compiled without tray support"); | ||
41 | #endif | ||
9 | } | 42 | } |