Skip to content

Commit

Permalink
Add style class for CPU state
Browse files Browse the repository at this point in the history
Fixes: #2911
  • Loading branch information
haasn committed Feb 13, 2024
1 parent 2c244b5 commit a0bac34
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 0 deletions.
1 change: 1 addition & 0 deletions include/modules/cpu.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class Cpu : public ALabel {

private:
std::vector<std::tuple<size_t, size_t>> prev_times_;
std::string prev_state_;

util::SleeperThread thread_;
};
Expand Down
2 changes: 2 additions & 0 deletions man/waybar-cpu.5.scd
Original file line number Diff line number Diff line change
Expand Up @@ -121,3 +121,5 @@ CPU usage per core rendered as icons:
# STYLE

- *#cpu*
- *#cpu.<state>*
- *<state>* can be defined in the *config*. For more information see *states*.
6 changes: 6 additions & 0 deletions src/modules/cpu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit a0bac34

Please sign in to comment.