From 03bd0c74c0444dc88685e5f5639145a842ec4bba Mon Sep 17 00:00:00 2001 From: Bonsaiiv Date: Sat, 31 Jan 2026 09:08:19 +0100 Subject: [PATCH 1/3] swaybar: add option to configure tray background --- include/sway/commands.h | 1 + include/sway/config.h | 3 +++ include/swaybar/config.h | 2 ++ sway/commands/bar/colors.c | 10 ++++++++++ sway/config/bar.c | 1 + sway/ipc-json.c | 10 ++++++++++ sway/sway-bar.5.scd | 3 +++ swaybar/config.c | 1 + swaybar/ipc.c | 1 + swaybar/tray/item.c | 3 +++ 10 files changed, 35 insertions(+) diff --git a/include/sway/commands.h b/include/sway/commands.h index 389c382eb..d2b366b78 100644 --- a/include/sway/commands.h +++ b/include/sway/commands.h @@ -245,6 +245,7 @@ sway_cmd bar_colors_cmd_focused_separator; sway_cmd bar_colors_cmd_statusline; sway_cmd bar_colors_cmd_focused_statusline; sway_cmd bar_colors_cmd_urgent_workspace; +sway_cmd bar_colors_cmd_tray_background; sway_cmd input_cmd_seat; sway_cmd input_cmd_accel_profile; diff --git a/include/sway/config.h b/include/sway/config.h index 16b822fea..47dd76d54 100644 --- a/include/sway/config.h +++ b/include/sway/config.h @@ -404,6 +404,9 @@ struct bar_config { char *binding_mode_border; char *binding_mode_bg; char *binding_mode_text; +#if HAVE_TRAY + char *tray_background; +#endif } colors; #if HAVE_TRAY diff --git a/include/swaybar/config.h b/include/swaybar/config.h index ad58b3c3c..a8283bfc1 100644 --- a/include/swaybar/config.h +++ b/include/swaybar/config.h @@ -71,6 +71,8 @@ struct swaybar_config { struct box_colors inactive_workspace; struct box_colors urgent_workspace; struct box_colors binding_mode; + + uint32_t tray_background; } colors; #if HAVE_TRAY diff --git a/sway/commands/bar/colors.c b/sway/commands/bar/colors.c index 275fa3c64..e6aa76ef4 100644 --- a/sway/commands/bar/colors.c +++ b/sway/commands/bar/colors.c @@ -16,6 +16,9 @@ static const struct cmd_handler bar_colors_handlers[] = { { "separator", bar_colors_cmd_separator }, { "statusline", bar_colors_cmd_statusline }, { "urgent_workspace", bar_colors_cmd_urgent_workspace }, +#if HAVE_TRAY + { "tray_background", bar_colors_cmd_tray_background }, +#endif }; static char *hex_to_rgba_hex(const char *hex) { @@ -150,3 +153,10 @@ struct cmd_results *bar_colors_cmd_urgent_workspace(int argc, char **argv) { }; return parse_three_colors(colors, "urgent_workspace", argc, argv); } + +#if HAVE_TRAY +struct cmd_results *bar_colors_cmd_tray_background(int argc, char **argv) { + return parse_single_color(&(config->current_bar->colors.tray_background), + "tray_background", argc, argv); +} +#endif diff --git a/sway/config/bar.c b/sway/config/bar.c index f4efb276c..3dec48803 100644 --- a/sway/config/bar.c +++ b/sway/config/bar.c @@ -171,6 +171,7 @@ struct bar_config *default_bar_config(void) { bar->colors.binding_mode_text = NULL; #if HAVE_TRAY + bar->colors.tray_background = NULL; bar->tray_padding = 2; wl_list_init(&bar->tray_bindings); #endif diff --git a/sway/ipc-json.c b/sway/ipc-json.c index 3b69ad384..b834983c6 100644 --- a/sway/ipc-json.c +++ b/sway/ipc-json.c @@ -1404,6 +1404,16 @@ json_object *ipc_json_describe_bar_config(struct bar_config *bar) { json_object_new_string(bar->colors.urgent_workspace_text)); } +#if HAVE_TRAY + if (bar->colors.tray_background) { + json_object_object_add(colors, "tray_background", + json_object_new_string(bar->colors.tray_background)); + } else { + json_object_object_add(colors, "tray_background", + json_object_new_string(bar->colors.background)); + } +#endif + json_object_object_add(json, "colors", colors); if (bar->bindings->length > 0) { diff --git a/sway/sway-bar.5.scd b/sway/sway-bar.5.scd index a1733aa2b..185f2a518 100644 --- a/sway/sway-bar.5.scd +++ b/sway/sway-bar.5.scd @@ -232,6 +232,9 @@ must be defined in hex: _#RRGGBB_ or _#RRGGBBAA_. Border, background and text color for the binding mode indicator. If not used, the colors will be taken from _urgent_workspace_. +*tray_background* + Background color of the system tray. + # SEE ALSO *sway*(5) *swaybar-protocol*(7) diff --git a/swaybar/config.c b/swaybar/config.c index 55bfcb722..ad274b745 100644 --- a/swaybar/config.c +++ b/swaybar/config.c @@ -77,6 +77,7 @@ struct swaybar_config *init_config(void) { config->colors.binding_mode.text = 0xFFFFFFFF; #if HAVE_TRAY + config->colors.tray_background = 0x000000FF; config->tray_padding = 2; wl_list_init(&config->tray_bindings); #endif diff --git a/swaybar/ipc.c b/swaybar/ipc.c index 68d8dd32d..74834748e 100644 --- a/swaybar/ipc.c +++ b/swaybar/ipc.c @@ -80,6 +80,7 @@ static void ipc_parse_colors( { "binding_mode_border", &config->colors.binding_mode.border }, { "binding_mode_bg", &config->colors.binding_mode.background }, { "binding_mode_text", &config->colors.binding_mode.text }, + { "tray_background", &config->colors.tray_background }, }; for (size_t i = 0; i < sizeof(properties) / sizeof(properties[i]); i++) { diff --git a/swaybar/tray/item.c b/swaybar/tray/item.c index 12929743b..baf69f9fb 100644 --- a/swaybar/tray/item.c +++ b/swaybar/tray/item.c @@ -514,6 +514,9 @@ uint32_t render_sni(cairo_t *cairo, struct swaybar_output *output, double *x, cairo_set_operator(cairo, CAIRO_OPERATOR_OVER); cairo_matrix_t scale_matrix; + cairo_set_source_u32(cairo, output->bar->config->colors.tray_background); + cairo_rectangle(cairo, *x, icon_y, size, size); + cairo_fill(cairo); cairo_pattern_t *icon_pattern = cairo_pattern_create_for_surface(icon); // TODO: check cairo_pattern_status for "ENOMEM" cairo_matrix_init_scale(&scale_matrix, output->scale, output->scale); From 49d8cf1d94a83ecbd8d4dd446cfaf8d8ee3bc3f7 Mon Sep 17 00:00:00 2001 From: Bonsaiiv Date: Sun, 8 Feb 2026 13:33:50 +0100 Subject: [PATCH 2/3] also free tray_background configuration --- sway/config/bar.c | 1 + 1 file changed, 1 insertion(+) diff --git a/sway/config/bar.c b/sway/config/bar.c index 3dec48803..63facdef8 100644 --- a/sway/config/bar.c +++ b/sway/config/bar.c @@ -71,6 +71,7 @@ void free_bar_config(struct bar_config *bar) { free(bar->colors.binding_mode_bg); free(bar->colors.binding_mode_text); #if HAVE_TRAY + free(bar->colors.tray_background); list_free_items_and_destroy(bar->tray_outputs); free(bar->icon_theme); From 0a6027968ad5d0f97c7774ca01b07293b35f06fc Mon Sep 17 00:00:00 2001 From: Bonsaiiv Date: Sat, 14 Feb 2026 18:18:20 +0100 Subject: [PATCH 3/3] use #00000000 as default tray background this ensures, that the tray background is equal to bar background if tray background is not set and background color is neither fully opaque or transparent --- sway/config/bar.c | 4 +++- sway/ipc-json.c | 9 ++------- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/sway/config/bar.c b/sway/config/bar.c index 63facdef8..695ef6762 100644 --- a/sway/config/bar.c +++ b/sway/config/bar.c @@ -172,7 +172,9 @@ struct bar_config *default_bar_config(void) { bar->colors.binding_mode_text = NULL; #if HAVE_TRAY - bar->colors.tray_background = NULL; + if (!(bar->colors.tray_background = strndup("#00000000", 9))) { + goto cleanup; + } bar->tray_padding = 2; wl_list_init(&bar->tray_bindings); #endif diff --git a/sway/ipc-json.c b/sway/ipc-json.c index b834983c6..88faf937d 100644 --- a/sway/ipc-json.c +++ b/sway/ipc-json.c @@ -1405,13 +1405,8 @@ json_object *ipc_json_describe_bar_config(struct bar_config *bar) { } #if HAVE_TRAY - if (bar->colors.tray_background) { - json_object_object_add(colors, "tray_background", - json_object_new_string(bar->colors.tray_background)); - } else { - json_object_object_add(colors, "tray_background", - json_object_new_string(bar->colors.background)); - } + json_object_object_add(colors, "tray_background", + json_object_new_string(bar->colors.tray_background)); #endif json_object_object_add(json, "colors", colors);