Update css class when locked/unlocked

This commit is contained in:
Grant Moyer 2021-02-07 18:57:12 -05:00
parent 642e28166b
commit 40e6360722
1 changed files with 22 additions and 13 deletions

View File

@ -99,19 +99,28 @@ auto waybar::modules::KeyboardState::update() -> void {
int capsl = libevdev_get_event_value(dev_, EV_LED, LED_CAPSL); int capsl = libevdev_get_event_value(dev_, EV_LED, LED_CAPSL);
int scrolll = libevdev_get_event_value(dev_, EV_LED, LED_SCROLLL); int scrolll = libevdev_get_event_value(dev_, EV_LED, LED_SCROLLL);
std::string text; struct {
text = fmt::format(numlock_format_, bool state;
fmt::arg("icon", numl ? icon_locked_ : icon_unlocked_), Gtk::Label& label;
fmt::arg("name", "Num")); const std::string& format;
numlock_label_.set_markup(text); const char* name;
text = fmt::format(capslock_format_, } label_states[] = {
fmt::arg("icon", capsl ? icon_locked_ : icon_unlocked_), {(bool) numl, numlock_label_, numlock_format_, "Num"},
fmt::arg("name", "Caps")); {(bool) capsl, capslock_label_, capslock_format_, "Caps"},
capslock_label_.set_markup(text); {(bool) scrolll, scrolllock_label_, scrolllock_format_, "Scroll"},
text = fmt::format(scrolllock_format_, };
fmt::arg("icon", scrolll ? icon_locked_ : icon_unlocked_), for (auto& label_state : label_states) {
fmt::arg("name", "Scroll")); std::string text;
scrolllock_label_.set_markup(text); text = fmt::format(label_state.format,
fmt::arg("icon", label_state.state ? icon_locked_ : icon_unlocked_),
fmt::arg("name", label_state.name));
label_state.label.set_markup(text);
if (label_state.state) {
label_state.label.get_style_context()->add_class("locked");
} else {
label_state.label.get_style_context()->remove_class("locked");
}
}
AModule::update(); AModule::update();
} }