From 123ce083b46bdff6cf3113347f72c553d3c01425 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lucas=20L=2E=20Treffenst=C3=A4dt?= Date: Fri, 2 Nov 2018 22:08:55 +0100 Subject: [PATCH] fix typo and initialize old_status_ --- include/modules/battery.hpp | 2 +- src/modules/battery.cpp | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/include/modules/battery.hpp b/include/modules/battery.hpp index 5c155d0..093367d 100644 --- a/include/modules/battery.hpp +++ b/include/modules/battery.hpp @@ -29,7 +29,7 @@ class Battery : public ALabel { util::SleeperThread threadTimer_; std::vector batteries_; int fd_; - std::string old_state_; + std::string old_status_; }; } diff --git a/src/modules/battery.cpp b/src/modules/battery.cpp index 06476f3..0986fff 100644 --- a/src/modules/battery.cpp +++ b/src/modules/battery.cpp @@ -34,6 +34,7 @@ waybar::modules::Battery::Battery(const Json::Value& config) for (auto const& bat : batteries_) { inotify_add_watch(fd_, (bat / "uevent").c_str(), IN_ACCESS); } + old_status_ = ""; worker(); } @@ -85,7 +86,7 @@ std::tuple waybar::modules::Battery::getInfos() } } -std::string waybar::modules::Battery::getState(uint16_t capacity, bool charging) +std::string waybar::modules::Battery::getState(uint16_t capacity) { // Get current state std::vector> states; @@ -102,7 +103,7 @@ std::string waybar::modules::Battery::getState(uint16_t capacity, bool charging) }); std::string validState = ""; for (auto state : states) { - if (capacity <= state.second && !charging && validState.empty()) { + if (capacity <= state.second && validState.empty()) { label_.get_style_context()->add_class(state.first); validState = state.first; } else { @@ -118,7 +119,7 @@ auto waybar::modules::Battery::update() -> void label_.set_tooltip_text(status); std::transform(status.begin(), status.end(), status.begin(), ::tolower); auto format = format_; - auto state = getState(capacity, charging); + auto state = getState(capacity); label_.get_style_context()->remove_class(old_status_); label_.get_style_context()->add_class(status); old_status_ = status;