tray: Replace tray-maxsize module setting with tray-size

The size accepts a percentage with offset relative to the bar height and
determines the width and height of tray icons.

Defaults to 66%

Does not affect spacing
This commit is contained in:
patrick96 2023-03-28 14:00:20 +02:00 committed by Patrick Ziegler
parent 4e66b1f4b8
commit b5f8466117
2 changed files with 24 additions and 7 deletions

View File

@ -12,6 +12,7 @@
#include "events/signal_fwd.hpp" #include "events/signal_fwd.hpp"
#include "events/signal_receiver.hpp" #include "events/signal_receiver.hpp"
#include "utils/concurrency.hpp" #include "utils/concurrency.hpp"
#include "utils/mixins.hpp"
#include "x11/atoms.hpp" #include "x11/atoms.hpp"
#include "x11/connection.hpp" #include "x11/connection.hpp"
#include "x11/tray_client.hpp" #include "x11/tray_client.hpp"
@ -45,7 +46,19 @@ struct tray_settings {
* Number of pixels added between tray icons * Number of pixels added between tray icons
*/ */
unsigned spacing{0U}; unsigned spacing{0U};
/**
* Background color used in the client wrapper window
*
* If transparent, pseudo-transparency is used for the icon.
*/
rgba background{}; rgba background{};
/**
* Used for `_NET_SYSTEM_TRAY_COLORS` atom
*
* Is only a hint to the tray applications.
*/
rgba foreground{}; rgba foreground{};
/** /**
@ -62,7 +75,9 @@ class manager : public xpp::event::sink<evt::expose, evt::client_message, evt::c
evt::selection_clear, evt::property_notify, evt::reparent_notify, evt::destroy_notify, evt::selection_clear, evt::property_notify, evt::reparent_notify, evt::destroy_notify,
evt::map_notify, evt::unmap_notify>, evt::map_notify, evt::unmap_notify>,
public signal_receiver<SIGN_PRIORITY_TRAY, signals::ui::update_background, public signal_receiver<SIGN_PRIORITY_TRAY, signals::ui::update_background,
signals::ui_tray::tray_pos_change, signals::ui_tray::tray_visibility> { signals::ui_tray::tray_pos_change, signals::ui_tray::tray_visibility>,
non_copyable_mixin,
non_movable_mixin {
public: public:
explicit manager(connection& conn, signal_emitter& emitter, const logger& logger, const bar_settings& bar_opts, explicit manager(connection& conn, signal_emitter& emitter, const logger& logger, const bar_settings& bar_opts,
on_update on_update); on_update on_update);

View File

@ -50,15 +50,17 @@ manager::~manager() {
} }
void manager::setup(const config& conf, const string& section_name) { void manager::setup(const config& conf, const string& section_name) {
unsigned client_height = m_bar_opts.inner_area().height; unsigned bar_height = m_bar_opts.inner_area().height;
// Add user-defined padding // Add user-defined padding
m_opts.spacing = conf.get<unsigned>(section_name, "tray-padding", 0); m_opts.spacing = conf.get<unsigned>(section_name, "tray-padding", 0);
auto maxsize = conf.get<unsigned>(section_name, "tray-maxsize", 16); auto size = conf.get(section_name, "tray-size", percentage_with_offset{66., ZERO_PX_EXTENT});
if (client_height > maxsize) { unsigned client_height = std::min(
m_opts.spacing += (client_height - maxsize) / 2; bar_height, units_utils::percentage_with_offset_to_pixel_nonnegative(size, bar_height, m_bar_opts.dpi_y));
client_height = maxsize;
if (client_height == 0) {
m_log.warn("tray: tray-size has an effective value of 0px, you will not see any tray icons");
} }
m_opts.client_size = {client_height, client_height}; m_opts.client_size = {client_height, client_height};
@ -293,7 +295,7 @@ void manager::query_atom() {
} }
/** /**
* Set color atom used by clients when determing icon theme * Set _NET_SYSTEM_TRAY_COLORS atom used by clients when determing icon theme
*/ */
void manager::set_tray_colors() { void manager::set_tray_colors() {
m_log.trace("tray: Set _NET_SYSTEM_TRAY_COLORS to 0x%08x", m_opts.foreground); m_log.trace("tray: Set _NET_SYSTEM_TRAY_COLORS to 0x%08x", m_opts.foreground);