Skip to content

Commit

Permalink
Merge pull request #2915 from haasn/cpu_style
Browse files Browse the repository at this point in the history
Add style class for CPU state
  • Loading branch information
Alexays authored Feb 19, 2024
2 parents bba8da7 + a0bac34 commit 70dc388
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_;

Check warning on line 25 in include/modules/cpu.hpp

View workflow job for this annotation

GitHub Actions / build

include/modules/cpu.hpp:25:15 [readability-identifier-naming]

invalid case style for private member '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 70dc388

Please sign in to comment.