From 43c3ca1d38112ce684567ba84488c9db3431605b Mon Sep 17 00:00:00 2001 From: vaxerski Date: Thu, 18 Aug 2022 18:59:34 +0200 Subject: [PATCH 1/2] 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 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 From ed6467e785c8a2cee39e1f45f63ac5c8921ce58d Mon Sep 17 00:00:00 2001 From: vaxerski Date: Thu, 18 Aug 2022 19:02:46 +0200 Subject: [PATCH 2/2] fix linter --- src/modules/hyprland/language.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/modules/hyprland/language.cpp b/src/modules/hyprland/language.cpp index 067730d..2ae4967 100644 --- a/src/modules/hyprland/language.cpp +++ b/src/modules/hyprland/language.cpp @@ -1,8 +1,8 @@ #include "modules/hyprland/language.hpp" #include -#include #include +#include #include "modules/hyprland/backend.hpp" @@ -123,7 +123,7 @@ std::string Language::getShortFrom(const std::string& fullName) { return briefName; } - + rxkb_context_unref(CONTEXT); return "";