fix(battery): check for battries :(

This commit is contained in:
Alexis 2018-08-10 18:02:12 +02:00
parent 4d3879f26f
commit d728de2dd7
2 changed files with 9 additions and 4 deletions

View File

@ -14,6 +14,11 @@ waybar::modules::Battery::Battery(Json::Value config)
std::cerr << e.what() << std::endl; std::cerr << e.what() << std::endl;
} }
if (!_batteries.size()) {
std::cerr << "No battries." << std::endl;
return;
}
_label.get_style_context()->add_class("battery"); _label.get_style_context()->add_class("battery");
_thread = [this] { _thread = [this] {

View File

@ -26,19 +26,20 @@ waybar::modules::Workspaces::Workspaces(Bar &bar)
auto waybar::modules::Workspaces::update() -> void auto waybar::modules::Workspaces::update() -> void
{ {
Json::Value workspaces = _getWorkspaces(); Json::Value workspaces = _getWorkspaces();
bool hided = false; bool needReorder = false;
for (auto it = _buttons.begin(); it != _buttons.end(); ++it) { for (auto it = _buttons.begin(); it != _buttons.end(); ++it) {
auto ws = std::find_if(workspaces.begin(), workspaces.end(), auto ws = std::find_if(workspaces.begin(), workspaces.end(),
[it](auto node) -> bool { return node["num"].asInt() == it->first; }); [it](auto node) -> bool { return node["num"].asInt() == it->first; });
if (ws == workspaces.end()) { if (ws == workspaces.end()) {
it->second.hide(); it->second.hide();
hided = true; needReorder = true;
} }
} }
for (auto node : workspaces) { for (auto node : workspaces) {
auto it = _buttons.find(node["num"].asInt()); auto it = _buttons.find(node["num"].asInt());
if (it == _buttons.end()) { if (it == _buttons.end()) {
_addWorkspace(node); _addWorkspace(node);
needReorder = true;
} else { } else {
auto styleContext = it->second.get_style_context(); auto styleContext = it->second.get_style_context();
bool isCurrent = node["focused"].asBool(); bool isCurrent = node["focused"].asBool();
@ -47,9 +48,8 @@ auto waybar::modules::Workspaces::update() -> void
} else if (isCurrent) { } else if (isCurrent) {
styleContext->add_class("current"); styleContext->add_class("current");
} }
if (hided) { if (needReorder)
_box->reorder_child(it->second, node["num"].asInt() - 1); _box->reorder_child(it->second, node["num"].asInt() - 1);
}
it->second.show(); it->second.show();
} }
} }