diff --git a/include/modules/hyprland/language.hpp b/include/modules/hyprland/language.hpp index b8afc9c..9e7193e 100644 --- a/include/modules/hyprland/language.hpp +++ b/include/modules/hyprland/language.hpp @@ -18,6 +18,7 @@ private: void onEvent(const std::string&); void initLanguage(); + std::string getShortFrom(const std::string&); std::mutex mutex_; const Bar& bar_; diff --git a/src/modules/hyprland/language.cpp b/src/modules/hyprland/language.cpp index 7006a95..067730d 100644 --- a/src/modules/hyprland/language.cpp +++ b/src/modules/hyprland/language.cpp @@ -1,6 +1,8 @@ #include "modules/hyprland/language.hpp" #include +#include +#include #include "modules/hyprland/backend.hpp" @@ -30,7 +32,7 @@ auto Language::update() -> void { if (!format_.empty()) { label_.show(); - label_.set_markup(fmt::format(format_, layoutName_)); + label_.set_markup(layoutName_); } else { label_.hide(); } @@ -57,6 +59,15 @@ void Language::onEvent(const std::string& ev) { return str; }; + const auto BRIEFNAME = getShortFrom(layoutName); + + if (config_.isMember("format-" + BRIEFNAME)) { + const auto PROPNAME = "format-" + BRIEFNAME; + layoutName = fmt::format(format_, config_[PROPNAME].asString()); + } else { + layoutName = fmt::format(format_, layoutName); + } + layoutName = replaceAll(layoutName, "&", "&"); if (layoutName == layoutName_) return; @@ -92,4 +103,30 @@ void Language::initLanguage() { } } +std::string Language::getShortFrom(const std::string& fullName) { + const auto CONTEXT = rxkb_context_new(RXKB_CONTEXT_LOAD_EXOTIC_RULES); + rxkb_context_parse_default_ruleset(CONTEXT); + + std::string foundName = ""; + rxkb_layout* layout = rxkb_layout_first(CONTEXT); + while (layout) { + std::string nameOfLayout = rxkb_layout_get_description(layout); + + if (nameOfLayout != fullName) { + layout = rxkb_layout_next(layout); + continue; + } + + std::string briefName = rxkb_layout_get_brief(layout); + + rxkb_context_unref(CONTEXT); + + return briefName; + } + + rxkb_context_unref(CONTEXT); + + return ""; +} + } // namespace waybar::modules::hyprland \ No newline at end of file