From 9476ad80b80ae1b5ad29717907bd328becf8f502 Mon Sep 17 00:00:00 2001
From: Flexlolo <43651714+Flexlolo@users.noreply.github.com>
Date: Thu, 31 Oct 2024 04:13:34 +0700
Subject: [PATCH] Implement tray-reversed option (#3182)
* implement tray-reversed option
* update changelog
* Update src/x11/tray_manager.cpp
Co-authored-by: Patrick Ziegler
* Update CHANGELOG.md
---------
Co-authored-by: Patrick Ziegler
---
CHANGELOG.md | 1 +
include/x11/tray_manager.hpp | 5 +++++
src/x11/tray_manager.cpp | 13 ++++++++++++-
3 files changed, 18 insertions(+), 1 deletion(-)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 24633385..4711a81b 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- `internal/battery`: Added `ramp-charging` tag.
([`#3172`](https://github.com/polybar/polybar/pull/3172))
by [@stringlapse](https://github.com/stringlapse).
+- Added tray-reversed = false option to tray module. Makes tray icons order reversed. ([`#3181`](https://github.com/polybar/polybar/discussions/3181))
### Changed
- `internal/pulseaudio`: Volume adjustments now preserve balance instead of volume ratios ([`#3123`](https://github.com/polybar/polybar/issues/3123), [`#3169`](https://github.com/polybar/polybar/pull/3169)) by [`@parmort`](https://github.com/parmort)
diff --git a/include/x11/tray_manager.hpp b/include/x11/tray_manager.hpp
index 08129c02..3107a771 100644
--- a/include/x11/tray_manager.hpp
+++ b/include/x11/tray_manager.hpp
@@ -66,6 +66,11 @@ struct tray_settings {
*/
rgba foreground{};
+ /**
+ * Reverse the order of tray icons
+ */
+ bool reversed{false};
+
/**
* Window ID of tray selection owner.
*
diff --git a/src/x11/tray_manager.cpp b/src/x11/tray_manager.cpp
index 3a47c1fe..238d540b 100644
--- a/src/x11/tray_manager.cpp
+++ b/src/x11/tray_manager.cpp
@@ -75,6 +75,7 @@ void manager::setup(const config& conf, const string& section_name) {
m_opts.foreground = conf.get(section_name, "tray-foreground", m_bar_opts.foreground);
m_opts.selection_owner = m_bar_opts.x_data.window;
+ m_opts.reversed = conf.get(section_name, "tray-reversed", m_opts.reversed);
m_log.info("tray: spacing=%upx padding=%upx size=%upx", m_opts.spacing, m_opts.padding, client_height);
@@ -250,7 +251,7 @@ void manager::reconfigure_clients() {
unsigned count = 0;
- for (auto& client : m_clients) {
+ auto reconfigure_client = [&] (auto& client) {
try {
client->ensure_state();
@@ -267,6 +268,16 @@ void manager::reconfigure_clients() {
client.reset();
has_error = true;
}
+ };
+
+ if (m_opts.reversed) {
+ for (auto it = m_clients.rbegin(); it != m_clients.rend(); ++it) {
+ reconfigure_client(*it);
+ }
+ } else {
+ for (auto it = m_clients.begin(); it != m_clients.end(); ++it) {
+ reconfigure_client(*it);
+ }
}
if (has_error) {