From ab583b08cdf6c34ff4d6013c8dd5ab3d16c4b30b Mon Sep 17 00:00:00 2001
From: patrick96
Date: Sun, 14 Apr 2024 19:52:02 +0200
Subject: [PATCH] fix(tray): Clients not being removed properly
The vector::erase call needs to be supplied with the end of the range,
otherwise only a single element is removed.
Fixes #3111
---
CHANGELOG.md | 1 +
src/x11/tray_manager.cpp | 6 ++++--
2 files changed, 5 insertions(+), 2 deletions(-)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 519fef59..b85e9cfa 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Token min-length calculations would behave differently when non-ASCII characters appear in the token ([`#3074`](https://github.com/polybar/polybar/issues/3074), [`#3087`](https://github.com/polybar/polybar/pull/3087)) by [@nklloyd](https://github.com/nklloyd)
- i3: Fix duplicated rendering for non-full-width bars ([`#3091`](https://github.com/polybar/polybar/pull/3091), [`#3060`](https://github.com/polybar/polybar/issues/3060))
- `internal/backlight`: Module could display the literal `%percentage%` token if the backlight reports a value of 0 at startup ([`#3081`](https://github.com/polybar/polybar/pull/3081)) by [@unclechu](https://github.com/unclechu)
+- `internal/tray`: Fix crash during restarting, when tray icons were not removed proberly ([`#3111`](https://github.com/polybar/polybar/issues/3111), [`#3112`](https://github.com/polybar/polybar/pull/3112))
## [3.7.1] - 2023-11-27
### Build
diff --git a/src/x11/tray_manager.cpp b/src/x11/tray_manager.cpp
index 058d04f1..3a47c1fe 100644
--- a/src/x11/tray_manager.cpp
+++ b/src/x11/tray_manager.cpp
@@ -502,7 +502,8 @@ void manager::remove_client(const client& c) {
void manager::remove_client(xcb_window_t win) {
auto old_size = m_clients.size();
m_clients.erase(
- std::remove_if(m_clients.begin(), m_clients.end(), [win](const auto& client) { return client->match(win); }));
+ std::remove_if(m_clients.begin(), m_clients.end(), [win](const auto& client) { return client->match(win); }),
+ m_clients.end());
if (old_size != m_clients.size()) {
reconfigure();
@@ -518,7 +519,8 @@ void manager::remove_client(xcb_window_t win) {
*/
void manager::clean_clients() {
m_clients.erase(
- std::remove_if(m_clients.begin(), m_clients.end(), [](const auto& client) { return client.get() == nullptr; }));
+ std::remove_if(m_clients.begin(), m_clients.end(), [](const auto& client) { return client.get() == nullptr; }),
+ m_clients.end());
}
bool manager::change_visibility(bool visible) {