From d728de2dd7534dc22a545da57445d86d9abaddbf Mon Sep 17 00:00:00 2001 From: Alexis Date: Fri, 10 Aug 2018 18:02:12 +0200 Subject: [PATCH] fix(battery): check for battries :( --- src/modules/battery.cpp | 5 +++++ src/modules/workspaces.cpp | 8 ++++---- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/modules/battery.cpp b/src/modules/battery.cpp index efab6357..19db47ee 100644 --- a/src/modules/battery.cpp +++ b/src/modules/battery.cpp @@ -14,6 +14,11 @@ waybar::modules::Battery::Battery(Json::Value config) std::cerr << e.what() << std::endl; } + if (!_batteries.size()) { + std::cerr << "No battries." << std::endl; + return; + } + _label.get_style_context()->add_class("battery"); _thread = [this] { diff --git a/src/modules/workspaces.cpp b/src/modules/workspaces.cpp index 80c29bea..44d50504 100644 --- a/src/modules/workspaces.cpp +++ b/src/modules/workspaces.cpp @@ -26,19 +26,20 @@ waybar::modules::Workspaces::Workspaces(Bar &bar) auto waybar::modules::Workspaces::update() -> void { Json::Value workspaces = _getWorkspaces(); - bool hided = false; + bool needReorder = false; for (auto it = _buttons.begin(); it != _buttons.end(); ++it) { auto ws = std::find_if(workspaces.begin(), workspaces.end(), [it](auto node) -> bool { return node["num"].asInt() == it->first; }); if (ws == workspaces.end()) { it->second.hide(); - hided = true; + needReorder = true; } } for (auto node : workspaces) { auto it = _buttons.find(node["num"].asInt()); if (it == _buttons.end()) { _addWorkspace(node); + needReorder = true; } else { auto styleContext = it->second.get_style_context(); bool isCurrent = node["focused"].asBool(); @@ -47,9 +48,8 @@ auto waybar::modules::Workspaces::update() -> void } else if (isCurrent) { styleContext->add_class("current"); } - if (hided) { + if (needReorder) _box->reorder_child(it->second, node["num"].asInt() - 1); - } it->second.show(); } }