From 767d9dd5b424b581f9fded5872ebcc94926ffc8a Mon Sep 17 00:00:00 2001 From: Alexis Date: Wed, 15 Aug 2018 14:30:01 +0200 Subject: [PATCH] fix(workspaces): buttons iterator --- src/modules/workspaces.cpp | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/modules/workspaces.cpp b/src/modules/workspaces.cpp index 879a7ba2..b664a97d 100644 --- a/src/modules/workspaces.cpp +++ b/src/modules/workspaces.cpp @@ -34,13 +34,14 @@ auto waybar::modules::Workspaces::update() -> void { std::lock_guard lock(_mutex); bool needReorder = false; - for (auto it = _buttons.begin(); it != _buttons.end(); ++it) { + for (auto it = _buttons.begin(); it != _buttons.end();) { auto ws = std::find_if(_workspaces.begin(), _workspaces.end(), [it](auto node) -> bool { return node["num"].asInt() == it->first; }); if (ws == _workspaces.end()) { it = _buttons.erase(it); needReorder = true; - } + } else + ++it; } for (auto node : _workspaces) { if (_bar.outputName != node["output"].asString()) @@ -51,12 +52,10 @@ auto waybar::modules::Workspaces::update() -> void needReorder = true; } else { auto &button = it->second; - bool isCurrent = node["focused"].asBool(); - if (!isCurrent) { - button.get_style_context()->remove_class("current"); - } else if (isCurrent) { + if (node["focused"].asBool()) button.get_style_context()->add_class("current"); - } + else + button.get_style_context()->remove_class("current"); if (needReorder) _box.reorder_child(button, node["num"].asInt()); button.show();