mirror of
https://github.com/rad4day/Waybar.git
synced 2023-12-21 10:22:59 +01:00
Update css class when locked/unlocked
This commit is contained in:
parent
642e28166b
commit
40e6360722
@ -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);
|
||||||
|
|
||||||
|
struct {
|
||||||
|
bool state;
|
||||||
|
Gtk::Label& label;
|
||||||
|
const std::string& format;
|
||||||
|
const char* name;
|
||||||
|
} label_states[] = {
|
||||||
|
{(bool) numl, numlock_label_, numlock_format_, "Num"},
|
||||||
|
{(bool) capsl, capslock_label_, capslock_format_, "Caps"},
|
||||||
|
{(bool) scrolll, scrolllock_label_, scrolllock_format_, "Scroll"},
|
||||||
|
};
|
||||||
|
for (auto& label_state : label_states) {
|
||||||
std::string text;
|
std::string text;
|
||||||
text = fmt::format(numlock_format_,
|
text = fmt::format(label_state.format,
|
||||||
fmt::arg("icon", numl ? icon_locked_ : icon_unlocked_),
|
fmt::arg("icon", label_state.state ? icon_locked_ : icon_unlocked_),
|
||||||
fmt::arg("name", "Num"));
|
fmt::arg("name", label_state.name));
|
||||||
numlock_label_.set_markup(text);
|
label_state.label.set_markup(text);
|
||||||
text = fmt::format(capslock_format_,
|
if (label_state.state) {
|
||||||
fmt::arg("icon", capsl ? icon_locked_ : icon_unlocked_),
|
label_state.label.get_style_context()->add_class("locked");
|
||||||
fmt::arg("name", "Caps"));
|
} else {
|
||||||
capslock_label_.set_markup(text);
|
label_state.label.get_style_context()->remove_class("locked");
|
||||||
text = fmt::format(scrolllock_format_,
|
}
|
||||||
fmt::arg("icon", scrolll ? icon_locked_ : icon_unlocked_),
|
}
|
||||||
fmt::arg("name", "Scroll"));
|
|
||||||
scrolllock_label_.set_markup(text);
|
|
||||||
|
|
||||||
AModule::update();
|
AModule::update();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user