From f488a889bc8012e7da714be7b9543254ac65cfc4 Mon Sep 17 00:00:00 2001 From: Jeremy Fleischman Date: Wed, 17 Nov 2021 04:41:40 -0600 Subject: [PATCH] Add support for a `tray-foreground` setting. (#2552) This adds a new `tray-foreground` config option, and uses it instead of the `tray-background` setting to build up the `_NET_SYSTEM_TRAY_COLORS` property. I'm pretty sure that the previous behavior was a mistake (this was introduced in 94298741b6de08e79131006504850820bdff9024 which is a pretty large diff). For me and some other people, this results in a black icon being drawn on top of a black background, which is pretty useless! I would say that this diff fixes https://github.com/polybar/polybar/issues/2235. Note: the old code dealt with `unsigned int` and maxed values out at 0xff. The new code deals with `uint16_t` and maxes values out at 0xffff. I haven't found the relevant documentation to justify this change, but from manually testing, I'm pretty confident this is the right change. This all matches pretty closely with this code from i3: [`i3bar/src/xcb.c::init_tray_colors` code](https://github.com/i3/i3/blob/43e805a00d1835db4fc0730ce5003956824b350d/i3bar/src/xcb.c#L1490-L1522), which you can see also uses the bar's foreground color and maxes values out at 0xffff, not 0xff. If you merge this up, I think we should also update https://github.com/polybar/polybar/wiki/Configuration#bar-settings to mention the new settings. Fixes #2235 --- CHANGELOG.md | 3 +++ include/x11/tray_manager.hpp | 1 + src/x11/tray_manager.cpp | 25 +++++++++++++++---------- 3 files changed, 19 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 36893cf0..0314fde0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -135,6 +135,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ([`#2414`](https://github.com/polybar/polybar/issues/2414)) - `custom/ipc`: Add `hook`, `next`, `prev`, `reset` actions to the ipc module ([`#2464`](https://github.com/polybar/polybar/issues/2464)) +- Added a new `tray-foreground` setting to give hints to tray icons about what + color they should be. + ([#2235](https://github.com/polybar/polybar/issues/2235)) ### Changed - Polybar now also reads `config.ini` when searching for config files. diff --git a/include/x11/tray_manager.hpp b/include/x11/tray_manager.hpp index 3f66b024..06370b9b 100644 --- a/include/x11/tray_manager.hpp +++ b/include/x11/tray_manager.hpp @@ -61,6 +61,7 @@ struct tray_settings { unsigned int spacing{0U}; unsigned int sibling{0U}; rgba background{}; + rgba foreground{}; bool transparent{false}; bool detached{false}; }; diff --git a/src/x11/tray_manager.cpp b/src/x11/tray_manager.cpp index 312b6ed3..b46e4f48 100644 --- a/src/x11/tray_manager.cpp +++ b/src/x11/tray_manager.cpp @@ -133,8 +133,9 @@ void tray_manager::setup(const bar_settings& bar_opts) { m_log.warn("tray-transparent is deprecated, the tray always uses pseudo-transparency. Please remove it."); } - // Set user-defined background color + // Set user-defined foreground and background colors. m_opts.background = conf.get(bs, "tray-background", bar_opts.background); + m_opts.foreground = conf.get(bs, "tray-foreground", bar_opts.foreground); if (m_opts.background.alpha_i() != 255) { m_log.trace("tray: enable transparency"); @@ -650,17 +651,21 @@ void tray_manager::set_wm_hints() { * Set color atom used by clients when determing icon theme */ void tray_manager::set_tray_colors() { - m_log.trace("tray: Set _NET_SYSTEM_TRAY_COLORS to %x", m_opts.background); + m_log.trace("tray: Set _NET_SYSTEM_TRAY_COLORS to %x", m_opts.foreground); - auto r = m_opts.background.red_i(); - auto g = m_opts.background.green_i(); - auto b = m_opts.background.blue_i(); + auto r = m_opts.foreground.red_i(); + auto g = m_opts.foreground.green_i(); + auto b = m_opts.foreground.blue_i(); - const unsigned int colors[12] = { - r, g, b, // normal - r, g, b, // error - r, g, b, // warning - r, g, b, // success + const uint16_t r16 = (r << 8) | r; + const uint16_t g16 = (g << 8) | g; + const uint16_t b16 = (b << 8) | b; + + const uint32_t colors[12] = { + r16, g16, b16, // normal + r16, g16, b16, // error + r16, g16, b16, // warning + r16, g16, b16, // success }; m_connection.change_property(