From 4c8621c7a53e7b8fb385bb93dc6c9f5097cc20b8 Mon Sep 17 00:00:00 2001 From: Robinhuett <5955614+Robinhuett@users.noreply.github.com> Date: Tue, 30 Oct 2018 16:23:36 +0100 Subject: [PATCH] Added second warning stage to battery module Also naming is a bit more consistent --- resources/config | 2 ++ src/modules/battery.cpp | 6 ++++++ 2 files changed, 8 insertions(+) diff --git a/resources/config b/resources/config index 1709cc28..43f247ad 100644 --- a/resources/config +++ b/resources/config @@ -43,6 +43,8 @@ "format": "{}% " }, "battery": { + // "warning": 30, // Default value: 30 + // "critical": 15, // Default value: 15 "format": "{capacity}% {icon}", "format-icons": ["", "", "", "", ""] }, diff --git a/src/modules/battery.cpp b/src/modules/battery.cpp index 569ffbed..2828be4e 100644 --- a/src/modules/battery.cpp +++ b/src/modules/battery.cpp @@ -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) {