Merge pull request #71 from Robinhuett/configurable_battery_levels

Added second warning stage to battery module
This commit is contained in:
Alex 2018-10-30 16:31:01 +01:00 committed by GitHub
commit 0e93de9c0a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 0 deletions

View File

@ -43,6 +43,8 @@
"format": "{}% "
},
"battery": {
// "warning": 30, // Default value: 30
// "critical": 15, // Default value: 15
"format": "{capacity}% {icon}",
"format-icons": ["", "", "", "", ""]
},

View File

@ -88,10 +88,16 @@ auto waybar::modules::Battery::update() -> void
} else {
label_.get_style_context()->remove_class("charging");
}
auto warning = config_["warning"].isUInt() ? config_["warning"].asUInt() : 30;
auto critical = config_["critical"].isUInt() ? config_["critical"].asUInt() : 15;
if (capacity <= critical && !charging) {
label_.get_style_context()->add_class("critical");
label_.get_style_context()->remove_class("warning");
} else if (capacity <= warning && !charging) {
label_.get_style_context()->add_class("warning");
label_.get_style_context()->remove_class("critical");
} else {
label_.get_style_context()->remove_class("critical");
label_.get_style_context()->remove_class("warning");
}
} catch (const std::exception& e) {