Implement tray-reversed option (#3182)

* implement tray-reversed option

* update changelog

* Update src/x11/tray_manager.cpp

Co-authored-by: Patrick Ziegler <p.ziegler96@gmail.com>

* Update CHANGELOG.md

---------

Co-authored-by: Patrick Ziegler <p.ziegler96@gmail.com>
This commit is contained in:
Flexlolo 2024-10-31 04:13:34 +07:00 committed by GitHub
parent f59f509923
commit 9476ad80b8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 18 additions and 1 deletions

View File

@ -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)

View File

@ -66,6 +66,11 @@ struct tray_settings {
*/
rgba foreground{};
/**
* Reverse the order of tray icons
*/
bool reversed{false};
/**
* Window ID of tray selection owner.
*

View File

@ -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) {