From a0bac34329c88ba84891147d438e596450bbbe01 Mon Sep 17 00:00:00 2001 From: Niklas Haas Date: Tue, 13 Feb 2024 10:49:57 +0100 Subject: [PATCH] Add style class for CPU state Fixes: https://github.com/Alexays/Waybar/issues/2911 --- include/modules/cpu.hpp | 1 + man/waybar-cpu.5.scd | 2 ++ src/modules/cpu.cpp | 6 ++++++ 3 files changed, 9 insertions(+) diff --git a/include/modules/cpu.hpp b/include/modules/cpu.hpp index 7f78c165..449eb1b3 100644 --- a/include/modules/cpu.hpp +++ b/include/modules/cpu.hpp @@ -22,6 +22,7 @@ class Cpu : public ALabel { private: std::vector> prev_times_; + std::string prev_state_; util::SleeperThread thread_; }; diff --git a/man/waybar-cpu.5.scd b/man/waybar-cpu.5.scd index 48479568..64b2bde1 100644 --- a/man/waybar-cpu.5.scd +++ b/man/waybar-cpu.5.scd @@ -121,3 +121,5 @@ CPU usage per core rendered as icons: # STYLE - *#cpu* +- *#cpu.* + - ** can be defined in the *config*. For more information see *states*. diff --git a/src/modules/cpu.cpp b/src/modules/cpu.cpp index 0703eaf7..4fdb6590 100644 --- a/src/modules/cpu.cpp +++ b/src/modules/cpu.cpp @@ -36,6 +36,12 @@ auto waybar::modules::Cpu::update() -> void { format = config_["format-" + state].asString(); } + if (!prev_state_.empty()) { + label_.get_style_context()->remove_class(prev_state_); + } + label_.get_style_context()->add_class(state); + prev_state_ = state; + if (format.empty()) { event_box_.hide(); } else {