aboutsummaryrefslogtreecommitdiffstats
path: root/sway/commands
diff options
context:
space:
mode:
authorLibravatar Ian Fan <ianfan0@gmail.com>2018-12-09 15:10:41 +0000
committerLibravatar Ian Fan <ianfan0@gmail.com>2018-12-31 20:40:18 +0000
commit6b03c68775c9c638def342c82b1fa3beffa52645 (patch)
treea3b18d948f8e2a51151f24aab47c552f28a17f70 /sway/commands
parentswaybar: add StatusNotifierItem to tray (diff)
downloadsway-6b03c68775c9c638def342c82b1fa3beffa52645.tar.gz
sway-6b03c68775c9c638def342c82b1fa3beffa52645.tar.zst
sway-6b03c68775c9c638def342c82b1fa3beffa52645.zip
swaybar: implement tray config
Diffstat (limited to 'sway/commands')
-rw-r--r--sway/commands/bar.c4
-rw-r--r--sway/commands/bar/activate_button.c8
-rw-r--r--sway/commands/bar/context_button.c8
-rw-r--r--sway/commands/bar/icon_theme.c25
-rw-r--r--sway/commands/bar/secondary_button.c8
-rw-r--r--sway/commands/bar/tray_bindsym.c55
-rw-r--r--sway/commands/bar/tray_output.c39
-rw-r--r--sway/commands/bar/tray_padding.c37
8 files changed, 151 insertions, 33 deletions
diff --git a/sway/commands/bar.c b/sway/commands/bar.c
index 0cf94907..507ee10a 100644
--- a/sway/commands/bar.c
+++ b/sway/commands/bar.c
@@ -8,11 +8,9 @@
8 8
9// Must be in alphabetical order for bsearch 9// Must be in alphabetical order for bsearch
10static struct cmd_handler bar_handlers[] = { 10static struct cmd_handler bar_handlers[] = {
11 { "activate_button", bar_cmd_activate_button },
12 { "binding_mode_indicator", bar_cmd_binding_mode_indicator }, 11 { "binding_mode_indicator", bar_cmd_binding_mode_indicator },
13 { "bindsym", bar_cmd_bindsym }, 12 { "bindsym", bar_cmd_bindsym },
14 { "colors", bar_cmd_colors }, 13 { "colors", bar_cmd_colors },
15 { "context_button", bar_cmd_context_button },
16 { "font", bar_cmd_font }, 14 { "font", bar_cmd_font },
17 { "gaps", bar_cmd_gaps }, 15 { "gaps", bar_cmd_gaps },
18 { "height", bar_cmd_height }, 16 { "height", bar_cmd_height },
@@ -23,11 +21,11 @@ static struct cmd_handler bar_handlers[] = {
23 { "output", bar_cmd_output }, 21 { "output", bar_cmd_output },
24 { "pango_markup", bar_cmd_pango_markup }, 22 { "pango_markup", bar_cmd_pango_markup },
25 { "position", bar_cmd_position }, 23 { "position", bar_cmd_position },
26 { "secondary_button", bar_cmd_secondary_button },
27 { "separator_symbol", bar_cmd_separator_symbol }, 24 { "separator_symbol", bar_cmd_separator_symbol },
28 { "status_command", bar_cmd_status_command }, 25 { "status_command", bar_cmd_status_command },
29 { "strip_workspace_name", bar_cmd_strip_workspace_name }, 26 { "strip_workspace_name", bar_cmd_strip_workspace_name },
30 { "strip_workspace_numbers", bar_cmd_strip_workspace_numbers }, 27 { "strip_workspace_numbers", bar_cmd_strip_workspace_numbers },
28 { "tray_bindsym", bar_cmd_tray_bindsym },
31 { "tray_output", bar_cmd_tray_output }, 29 { "tray_output", bar_cmd_tray_output },
32 { "tray_padding", bar_cmd_tray_padding }, 30 { "tray_padding", bar_cmd_tray_padding },
33 { "workspace_buttons", bar_cmd_workspace_buttons }, 31 { "workspace_buttons", bar_cmd_workspace_buttons },
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
5struct 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
5struct 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
4struct cmd_results *bar_cmd_icon_theme(int argc, char **argv) { 8struct 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
5struct 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
7struct 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
4struct cmd_results *bar_cmd_tray_output(int argc, char **argv) { 9struct 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
6struct cmd_results *bar_cmd_tray_padding(int argc, char **argv) { 8struct 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}