From 43c3ca1d38112ce684567ba84488c9db3431605b Mon Sep 17 00:00:00 2001 From: vaxerski Date: Thu, 18 Aug 2022 18:59:34 +0200 Subject: [PATCH] added the thing i was talking about --- include/modules/hyprland/language.hpp | 1 + src/modules/hyprland/language.cpp | 39 ++++++++++++++++++++++++++- 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/include/modules/hyprland/language.hpp b/include/modules/hyprland/language.hpp index b8afc9c6..9e7193e2 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 7006a95f..067730d1 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