feat(niri/language): add CSS classes

This commit is contained in:
workflow
2025-09-29 17:35:06 +03:00
parent 41de8964f1
commit 862ba2f568
3 changed files with 20 additions and 0 deletions

View File

@ -33,6 +33,7 @@ class Language : public ALabel, public EventHandler {
std::vector<Layout> layouts_; std::vector<Layout> layouts_;
unsigned current_idx_; unsigned current_idx_;
std::string last_short_name_;
}; };
} // namespace waybar::modules::niri } // namespace waybar::modules::niri

View File

@ -61,3 +61,12 @@ Addressed by *niri/language*
# STYLE # STYLE
- *#language* - *#language*
Additionally, a CSS class matching the current layout's short name is added to the widget. This
allows per-language styling, for example:
```
#language.us { color: #00ff00; }
#language.de { color: #ff0000; }
#language.fr { color: #0000ff; }
```

View File

@ -58,6 +58,16 @@ void Language::doUpdate() {
spdlog::debug("niri language update with short description {}", layout.short_description); spdlog::debug("niri language update with short description {}", layout.short_description);
spdlog::debug("niri language update with variant {}", layout.variant); spdlog::debug("niri language update with variant {}", layout.variant);
if (!last_short_name_.empty()) {
label_.get_style_context()->remove_class(last_short_name_);
}
if (!layout.short_name.empty()) {
label_.get_style_context()->add_class(layout.short_name);
last_short_name_ = layout.short_name;
} else {
last_short_name_.clear();
}
std::string layoutName = std::string{}; std::string layoutName = std::string{};
if (config_.isMember("format-" + layout.short_description + "-" + layout.variant)) { if (config_.isMember("format-" + layout.short_description + "-" + layout.variant)) {
const auto propName = "format-" + layout.short_description + "-" + layout.variant; const auto propName = "format-" + layout.short_description + "-" + layout.variant;