Skip to content

Commit

Permalink
fix(battery): check for battries :(
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexays committed Aug 10, 2018
1 parent 4d3879f commit d728de2
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
5 changes: 5 additions & 0 deletions src/modules/battery.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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] {
Expand Down
8 changes: 4 additions & 4 deletions src/modules/workspaces.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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();
}
}
Expand Down

0 comments on commit d728de2

Please sign in to comment.