From b5f8466117ce492155ecfde88378f12901fc46df Mon Sep 17 00:00:00 2001
From: patrick96
Date: Tue, 28 Mar 2023 14:00:20 +0200
Subject: [PATCH] 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
---
include/x11/tray_manager.hpp | 17 ++++++++++++++++-
src/x11/tray_manager.cpp | 14 ++++++++------
2 files changed, 24 insertions(+), 7 deletions(-)
diff --git a/include/x11/tray_manager.hpp b/include/x11/tray_manager.hpp
index 5469af86..24197203 100644
--- a/include/x11/tray_manager.hpp
+++ b/include/x11/tray_manager.hpp
@@ -12,6 +12,7 @@
#include "events/signal_fwd.hpp"
#include "events/signal_receiver.hpp"
#include "utils/concurrency.hpp"
+#include "utils/mixins.hpp"
#include "x11/atoms.hpp"
#include "x11/connection.hpp"
#include "x11/tray_client.hpp"
@@ -45,7 +46,19 @@ struct tray_settings {
* Number of pixels added between tray icons
*/
unsigned spacing{0U};
+
+ /**
+ * Background color used in the client wrapper window
+ *
+ * If transparent, pseudo-transparency is used for the icon.
+ */
rgba background{};
+
+ /**
+ * Used for `_NET_SYSTEM_TRAY_COLORS` atom
+ *
+ * Is only a hint to the tray applications.
+ */
rgba foreground{};
/**
@@ -62,7 +75,9 @@ class manager : public xpp::event::sink,
public signal_receiver {
+ signals::ui_tray::tray_pos_change, signals::ui_tray::tray_visibility>,
+ non_copyable_mixin,
+ non_movable_mixin {
public:
explicit manager(connection& conn, signal_emitter& emitter, const logger& logger, const bar_settings& bar_opts,
on_update on_update);
diff --git a/src/x11/tray_manager.cpp b/src/x11/tray_manager.cpp
index 9774b501..2c884d52 100644
--- a/src/x11/tray_manager.cpp
+++ b/src/x11/tray_manager.cpp
@@ -50,15 +50,17 @@ manager::~manager() {
}
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
m_opts.spacing = conf.get(section_name, "tray-padding", 0);
- auto maxsize = conf.get(section_name, "tray-maxsize", 16);
- if (client_height > maxsize) {
- m_opts.spacing += (client_height - maxsize) / 2;
- client_height = maxsize;
+ auto size = conf.get(section_name, "tray-size", percentage_with_offset{66., ZERO_PX_EXTENT});
+ unsigned client_height = std::min(
+ bar_height, units_utils::percentage_with_offset_to_pixel_nonnegative(size, bar_height, m_bar_opts.dpi_y));
+
+ 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};
@@ -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() {
m_log.trace("tray: Set _NET_SYSTEM_TRAY_COLORS to 0x%08x", m_opts.foreground);