added the thing i was talking about

This commit is contained in:
vaxerski 2022-08-18 18:59:34 +02:00
parent 8881b9a6ef
commit 43c3ca1d38
2 changed files with 39 additions and 1 deletions

View File

@ -18,6 +18,7 @@ private:
void onEvent(const std::string&);
void initLanguage();
std::string getShortFrom(const std::string&);
std::mutex mutex_;
const Bar& bar_;

View File

@ -1,6 +1,8 @@
#include "modules/hyprland/language.hpp"
#include <spdlog/spdlog.h>
#include <xkbcommon/xkbregistry.h>
#include <xkbcommon/xkbcommon.h>
#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, "&", "&amp;");
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