aboutsummaryrefslogtreecommitdiffstats
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
parentswaybar: add StatusNotifierItem to tray (diff)
downloadsway-6b03c68775c9c638def342c82b1fa3beffa52645.tar.gz
sway-6b03c68775c9c638def342c82b1fa3beffa52645.tar.zst
sway-6b03c68775c9c638def342c82b1fa3beffa52645.zip
swaybar: implement tray config
-rw-r--r--include/sway/commands.h4
-rw-r--r--include/sway/config.h8
-rw-r--r--include/swaybar/config.h8
-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
-rw-r--r--sway/config/bar.c9
-rw-r--r--sway/ipc-json.c37
-rw-r--r--sway/meson.build4
-rw-r--r--sway/sway-bar.5.scd25
-rw-r--r--swaybar/bar.c1
-rw-r--r--swaybar/config.c12
-rw-r--r--swaybar/ipc.c34
18 files changed, 271 insertions, 55 deletions
diff --git a/include/sway/commands.h b/include/sway/commands.h
index 7bee2538..0e2d7931 100644
--- a/include/sway/commands.h
+++ b/include/sway/commands.h
@@ -182,11 +182,9 @@ sway_cmd cmd_workspace;
182sway_cmd cmd_ws_auto_back_and_forth; 182sway_cmd cmd_ws_auto_back_and_forth;
183sway_cmd cmd_workspace_layout; 183sway_cmd cmd_workspace_layout;
184 184
185sway_cmd bar_cmd_activate_button;
186sway_cmd bar_cmd_binding_mode_indicator; 185sway_cmd bar_cmd_binding_mode_indicator;
187sway_cmd bar_cmd_bindsym; 186sway_cmd bar_cmd_bindsym;
188sway_cmd bar_cmd_colors; 187sway_cmd bar_cmd_colors;
189sway_cmd bar_cmd_context_button;
190sway_cmd bar_cmd_font; 188sway_cmd bar_cmd_font;
191sway_cmd bar_cmd_gaps; 189sway_cmd bar_cmd_gaps;
192sway_cmd bar_cmd_mode; 190sway_cmd bar_cmd_mode;
@@ -197,13 +195,13 @@ sway_cmd bar_cmd_hidden_state;
197sway_cmd bar_cmd_icon_theme; 195sway_cmd bar_cmd_icon_theme;
198sway_cmd bar_cmd_id; 196sway_cmd bar_cmd_id;
199sway_cmd bar_cmd_position; 197sway_cmd bar_cmd_position;
200sway_cmd bar_cmd_secondary_button;
201sway_cmd bar_cmd_separator_symbol; 198sway_cmd bar_cmd_separator_symbol;
202sway_cmd bar_cmd_status_command; 199sway_cmd bar_cmd_status_command;
203sway_cmd bar_cmd_pango_markup; 200sway_cmd bar_cmd_pango_markup;
204sway_cmd bar_cmd_strip_workspace_numbers; 201sway_cmd bar_cmd_strip_workspace_numbers;
205sway_cmd bar_cmd_strip_workspace_name; 202sway_cmd bar_cmd_strip_workspace_name;
206sway_cmd bar_cmd_swaybar_command; 203sway_cmd bar_cmd_swaybar_command;
204sway_cmd bar_cmd_tray_bindsym;
207sway_cmd bar_cmd_tray_output; 205sway_cmd bar_cmd_tray_output;
208sway_cmd bar_cmd_tray_padding; 206sway_cmd bar_cmd_tray_padding;
209sway_cmd bar_cmd_wrap_scroll; 207sway_cmd bar_cmd_wrap_scroll;
diff --git a/include/sway/config.h b/include/sway/config.h
index 86473e17..f604b054 100644
--- a/include/sway/config.h
+++ b/include/sway/config.h
@@ -6,6 +6,7 @@
6#include <time.h> 6#include <time.h>
7#include <wlr/types/wlr_box.h> 7#include <wlr/types/wlr_box.h>
8#include <xkbcommon/xkbcommon.h> 8#include <xkbcommon/xkbcommon.h>
9#include "../include/config.h"
9#include "list.h" 10#include "list.h"
10#include "swaynag.h" 11#include "swaynag.h"
11#include "tree/container.h" 12#include "tree/container.h"
@@ -253,6 +254,13 @@ struct bar_config {
253 char *binding_mode_bg; 254 char *binding_mode_bg;
254 char *binding_mode_text; 255 char *binding_mode_text;
255 } colors; 256 } colors;
257
258#if HAVE_TRAY
259 char *icon_theme;
260 const char *tray_bindings[10]; // mouse buttons 0-9
261 list_t *tray_outputs; // char *
262 int tray_padding;
263#endif
256}; 264};
257 265
258struct bar_binding { 266struct bar_binding {
diff --git a/include/swaybar/config.h b/include/swaybar/config.h
index fd7c6ec4..def70d5b 100644
--- a/include/swaybar/config.h
+++ b/include/swaybar/config.h
@@ -3,6 +3,7 @@
3#include <stdbool.h> 3#include <stdbool.h>
4#include <stdint.h> 4#include <stdint.h>
5#include <wayland-client.h> 5#include <wayland-client.h>
6#include "../include/config.h"
6#include "list.h" 7#include "list.h"
7#include "util.h" 8#include "util.h"
8 9
@@ -64,6 +65,13 @@ struct swaybar_config {
64 struct box_colors urgent_workspace; 65 struct box_colors urgent_workspace;
65 struct box_colors binding_mode; 66 struct box_colors binding_mode;
66 } colors; 67 } colors;
68
69#if HAVE_TRAY
70 char *icon_theme;
71 char *tray_bindings[10]; // mouse buttons 0-9
72 list_t *tray_outputs; // char *
73 int tray_padding;
74#endif
67}; 75};
68 76
69struct swaybar_config *init_config(void); 77struct swaybar_config *init_config(void);
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}
diff --git a/sway/config/bar.c b/sway/config/bar.c
index 45c9e998..670219f1 100644
--- a/sway/config/bar.c
+++ b/sway/config/bar.c
@@ -12,6 +12,7 @@
12#include <signal.h> 12#include <signal.h>
13#include "sway/config.h" 13#include "sway/config.h"
14#include "sway/output.h" 14#include "sway/output.h"
15#include "config.h"
15#include "stringop.h" 16#include "stringop.h"
16#include "list.h" 17#include "list.h"
17#include "log.h" 18#include "log.h"
@@ -77,6 +78,10 @@ void free_bar_config(struct bar_config *bar) {
77 free(bar->colors.binding_mode_border); 78 free(bar->colors.binding_mode_border);
78 free(bar->colors.binding_mode_bg); 79 free(bar->colors.binding_mode_bg);
79 free(bar->colors.binding_mode_text); 80 free(bar->colors.binding_mode_text);
81#if HAVE_TRAY
82 list_free_items_and_destroy(bar->tray_outputs);
83 free(bar->icon_theme);
84#endif
80 free(bar); 85 free(bar);
81} 86}
82 87
@@ -165,6 +170,10 @@ struct bar_config *default_bar_config(void) {
165 bar->colors.binding_mode_bg = NULL; 170 bar->colors.binding_mode_bg = NULL;
166 bar->colors.binding_mode_text = NULL; 171 bar->colors.binding_mode_text = NULL;
167 172
173#if HAVE_TRAY
174 bar->tray_padding = 2;
175#endif
176
168 list_add(config->bars, bar); 177 list_add(config->bars, bar);
169 return bar; 178 return bar;
170cleanup: 179cleanup:
diff --git a/sway/ipc-json.c b/sway/ipc-json.c
index 96701dc2..53e0e335 100644
--- a/sway/ipc-json.c
+++ b/sway/ipc-json.c
@@ -1,6 +1,7 @@
1#include <json-c/json.h> 1#include <json-c/json.h>
2#include <stdio.h> 2#include <stdio.h>
3#include <ctype.h> 3#include <ctype.h>
4#include "config.h"
4#include "log.h" 5#include "log.h"
5#include "sway/config.h" 6#include "sway/config.h"
6#include "sway/ipc-json.h" 7#include "sway/ipc-json.h"
@@ -785,5 +786,41 @@ json_object *ipc_json_describe_bar_config(struct bar_config *bar) {
785 } 786 }
786 json_object_object_add(json, "outputs", outputs); 787 json_object_object_add(json, "outputs", outputs);
787 } 788 }
789#if HAVE_TRAY
790 // Add tray outputs if defined
791 if (bar->tray_outputs && bar->tray_outputs->length > 0) {
792 json_object *tray_outputs = json_object_new_array();
793 for (int i = 0; i < bar->tray_outputs->length; ++i) {
794 const char *name = bar->tray_outputs->items[i];
795 json_object_array_add(tray_outputs, json_object_new_string(name));
796 }
797 json_object_object_add(json, "tray_outputs", tray_outputs);
798 }
799
800 json_object *tray_bindings = json_object_new_array();
801 for (int i = 0; i < 10; ++i) {
802 if (bar->tray_bindings[i]) {
803 json_object *bind = json_object_new_object();
804 json_object_object_add(bind, "input_code",
805 json_object_new_int(i));
806 json_object_object_add(bind, "command",
807 json_object_new_string(bar->tray_bindings[i]));
808 json_object_array_add(tray_bindings, bind);
809 }
810 }
811 if (json_object_array_length(tray_bindings) > 0) {
812 json_object_object_add(json, "tray_bindings", tray_bindings);
813 } else {
814 json_object_put(tray_bindings);
815 }
816
817 if (bar->icon_theme) {
818 json_object_object_add(json, "icon_theme",
819 json_object_new_string(bar->icon_theme));
820 }
821
822 json_object_object_add(json, "tray_padding",
823 json_object_new_int(bar->tray_padding));
824#endif
788 return json; 825 return json;
789} 826}
diff --git a/sway/meson.build b/sway/meson.build
index 6d446acb..7f739287 100644
--- a/sway/meson.build
+++ b/sway/meson.build
@@ -99,11 +99,9 @@ sway_sources = files(
99 'commands/workspace_layout.c', 99 'commands/workspace_layout.c',
100 'commands/ws_auto_back_and_forth.c', 100 'commands/ws_auto_back_and_forth.c',
101 101
102 'commands/bar/activate_button.c',
103 'commands/bar/binding_mode_indicator.c', 102 'commands/bar/binding_mode_indicator.c',
104 'commands/bar/bindsym.c', 103 'commands/bar/bindsym.c',
105 'commands/bar/colors.c', 104 'commands/bar/colors.c',
106 'commands/bar/context_button.c',
107 'commands/bar/font.c', 105 'commands/bar/font.c',
108 'commands/bar/gaps.c', 106 'commands/bar/gaps.c',
109 'commands/bar/height.c', 107 'commands/bar/height.c',
@@ -115,12 +113,12 @@ sway_sources = files(
115 'commands/bar/output.c', 113 'commands/bar/output.c',
116 'commands/bar/pango_markup.c', 114 'commands/bar/pango_markup.c',
117 'commands/bar/position.c', 115 'commands/bar/position.c',
118 'commands/bar/secondary_button.c',
119 'commands/bar/separator_symbol.c', 116 'commands/bar/separator_symbol.c',
120 'commands/bar/status_command.c', 117 'commands/bar/status_command.c',
121 'commands/bar/strip_workspace_numbers.c', 118 'commands/bar/strip_workspace_numbers.c',
122 'commands/bar/strip_workspace_name.c', 119 'commands/bar/strip_workspace_name.c',
123 'commands/bar/swaybar_command.c', 120 'commands/bar/swaybar_command.c',
121 'commands/bar/tray_bindsym.c',
124 'commands/bar/tray_output.c', 122 'commands/bar/tray_output.c',
125 'commands/bar/tray_padding.c', 123 'commands/bar/tray_padding.c',
126 'commands/bar/workspace_buttons.c', 124 'commands/bar/workspace_buttons.c',
diff --git a/sway/sway-bar.5.scd b/sway/sway-bar.5.scd
index a3c6af2e..2357591d 100644
--- a/sway/sway-bar.5.scd
+++ b/sway/sway-bar.5.scd
@@ -100,27 +100,20 @@ The following commands configure the tray.
100The _button_ argument in all cases is a platform-specific button code. On Linux 100The _button_ argument in all cases is a platform-specific button code. On Linux
101you can find a list of these at linux/input-event-codes.h. 101you can find a list of these at linux/input-event-codes.h.
102 102
103*activate\_button* <button> 103*tray\_bindsym* button<n> ContextMenu|Activate|SecondaryActivate|ScrollDown|ScrollLeft|ScrollRight|ScrollUp|nop
104 Sets the button to be used for the _activate_ (primary click) tray item 104 Binds mouse button _n_ (1 to 9) to the specified action. Use the command
105 event. The default is BTN\_LEFT (0x110). 105 _nop_ to disable the default action (Activate for button 1, ContextMenu for
106 106 button 2 and SecondaryActivate for button 3).
107*context\_button* <button>
108 Sets the button to be used for the _context menu_ (right click) tray item
109 event. The default is BTN\_RIGHT (0x111).
110
111*secondary\_button* <button>
112 Sets the button to be used for the _secondary_ (middle click) tray item
113 event. The default is BTN\_MIDDLE (0x112).
114
115*tray\_output* none|all|<output>
116 Sets the output that the tray will appear on or none. Unlike i3bar, swaybar
117 is able to show icons on any number of bars and outputs without races.
118 The default is _all_.
119 107
120*tray\_padding* <px> [px] 108*tray\_padding* <px> [px]
121 Sets the pixel padding of the system tray. This padding will surround the 109 Sets the pixel padding of the system tray. This padding will surround the
122 tray on all sides and between each item. The default value for _px_ is 2. 110 tray on all sides and between each item. The default value for _px_ is 2.
123 111
112*tray\_output* none|<output>
113 Restrict the tray to a certain output, can be specified multiple times. If
114 omitted, the tray will be displayed on all outputs. Unlike i3bar, swaybar
115 can show icons on any number of bars and outputs without races.
116
124*icon\_theme* <name> 117*icon\_theme* <name>
125 Sets the icon theme that sway will look for item icons in. This option has 118 Sets the icon theme that sway will look for item icons in. This option has
126 no default value, because sway will always default to the fallback theme, 119 no default value, because sway will always default to the fallback theme,
diff --git a/swaybar/bar.c b/swaybar/bar.c
index c26e76ce..668168eb 100644
--- a/swaybar/bar.c
+++ b/swaybar/bar.c
@@ -11,6 +11,7 @@
11#include <wayland-client.h> 11#include <wayland-client.h>
12#include <wayland-cursor.h> 12#include <wayland-cursor.h>
13#include <wlr/util/log.h> 13#include <wlr/util/log.h>
14#include "config.h"
14#include "swaybar/bar.h" 15#include "swaybar/bar.h"
15#include "swaybar/config.h" 16#include "swaybar/config.h"
16#include "swaybar/i3bar.h" 17#include "swaybar/i3bar.h"
diff --git a/swaybar/config.c b/swaybar/config.c
index 10c78c8a..9cafe061 100644
--- a/swaybar/config.c
+++ b/swaybar/config.c
@@ -4,6 +4,7 @@
4#include <wlr/util/log.h> 4#include <wlr/util/log.h>
5#include "swaybar/config.h" 5#include "swaybar/config.h"
6#include "wlr-layer-shell-unstable-v1-client-protocol.h" 6#include "wlr-layer-shell-unstable-v1-client-protocol.h"
7#include "config.h"
7#include "stringop.h" 8#include "stringop.h"
8#include "list.h" 9#include "list.h"
9 10
@@ -73,6 +74,10 @@ struct swaybar_config *init_config(void) {
73 config->colors.binding_mode.background = 0x900000FF; 74 config->colors.binding_mode.background = 0x900000FF;
74 config->colors.binding_mode.text = 0xFFFFFFFF; 75 config->colors.binding_mode.text = 0xFFFFFFFF;
75 76
77#if HAVE_TRAY
78 config->tray_padding = 2;
79#endif
80
76 return config; 81 return config;
77} 82}
78 83
@@ -102,5 +107,12 @@ void free_config(struct swaybar_config *config) {
102 free(coutput->name); 107 free(coutput->name);
103 free(coutput); 108 free(coutput);
104 } 109 }
110#if HAVE_TRAY
111 list_free_items_and_destroy(config->tray_outputs);
112 for (int i = 0; i < 10; ++i) {
113 free(config->tray_bindings[i]);
114 }
115 free(config->icon_theme);
116#endif
105 free(config); 117 free(config);
106} 118}
diff --git a/swaybar/ipc.c b/swaybar/ipc.c
index 2b930786..df0586bf 100644
--- a/swaybar/ipc.c
+++ b/swaybar/ipc.c
@@ -6,6 +6,7 @@
6#include <wlr/util/log.h> 6#include <wlr/util/log.h>
7#include "swaybar/config.h" 7#include "swaybar/config.h"
8#include "swaybar/ipc.h" 8#include "swaybar/ipc.h"
9#include "config.h"
9#include "ipc-client.h" 10#include "ipc-client.h"
10#include "list.h" 11#include "list.h"
11 12
@@ -282,6 +283,39 @@ static bool ipc_parse_config(
282 ipc_parse_colors(config, colors); 283 ipc_parse_colors(config, colors);
283 } 284 }
284 285
286#if HAVE_TRAY
287 json_object *tray_outputs, *tray_padding, *tray_bindings, *icon_theme;
288
289 if ((json_object_object_get_ex(bar_config, "tray_outputs", &tray_outputs))) {
290 config->tray_outputs = create_list();
291 int length = json_object_array_length(tray_outputs);
292 for (int i = 0; i < length; ++i) {
293 json_object *o = json_object_array_get_idx(tray_outputs, i);
294 list_add(config->tray_outputs, strdup(json_object_get_string(o)));
295 }
296 }
297
298 if ((json_object_object_get_ex(bar_config, "tray_padding", &tray_padding))) {
299 config->tray_padding = json_object_get_int(tray_padding);
300 }
301
302 if ((json_object_object_get_ex(bar_config, "tray_bindings", &tray_bindings))) {
303 int length = json_object_array_length(tray_bindings);
304 for (int i = 0; i < length; ++i) {
305 json_object *bind = json_object_array_get_idx(tray_bindings, i);
306 json_object *button, *command;
307 json_object_object_get_ex(bind, "input_code", &button);
308 json_object_object_get_ex(bind, "command", &command);
309 config->tray_bindings[json_object_get_int(button)] =
310 strdup(json_object_get_string(command));
311 }
312 }
313
314 if ((json_object_object_get_ex(bar_config, "icon_theme", &icon_theme))) {
315 config->icon_theme = strdup(json_object_get_string(icon_theme));
316 }
317#endif
318
285 json_object_put(bar_config); 319 json_object_put(bar_config);
286 return true; 320 return true;
287} 321}