mirror of
https://github.com/rad4day/Waybar.git
synced 2023-12-21 10:22:59 +01:00
Merge branch 'vaxerski:hyprlandLanguage' into hyprlandLanguage
This commit is contained in:
commit
d786f9a0e6
@ -18,6 +18,7 @@ private:
|
|||||||
void onEvent(const std::string&);
|
void onEvent(const std::string&);
|
||||||
|
|
||||||
void initLanguage();
|
void initLanguage();
|
||||||
|
std::string getShortFrom(const std::string&);
|
||||||
|
|
||||||
std::mutex mutex_;
|
std::mutex mutex_;
|
||||||
const Bar& bar_;
|
const Bar& bar_;
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
#include "modules/hyprland/language.hpp"
|
#include "modules/hyprland/language.hpp"
|
||||||
|
|
||||||
#include <spdlog/spdlog.h>
|
#include <spdlog/spdlog.h>
|
||||||
|
#include <xkbcommon/xkbcommon.h>
|
||||||
|
#include <xkbcommon/xkbregistry.h>
|
||||||
|
|
||||||
#include "modules/hyprland/backend.hpp"
|
#include "modules/hyprland/backend.hpp"
|
||||||
|
|
||||||
@ -30,7 +32,7 @@ auto Language::update() -> void {
|
|||||||
|
|
||||||
if (!format_.empty()) {
|
if (!format_.empty()) {
|
||||||
label_.show();
|
label_.show();
|
||||||
label_.set_markup(fmt::format(format_, layoutName_));
|
label_.set_markup(layoutName_);
|
||||||
} else {
|
} else {
|
||||||
label_.hide();
|
label_.hide();
|
||||||
}
|
}
|
||||||
@ -57,6 +59,15 @@ void Language::onEvent(const std::string& ev) {
|
|||||||
return str;
|
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, "&", "&");
|
layoutName = replaceAll(layoutName, "&", "&");
|
||||||
|
|
||||||
if (layoutName == layoutName_) return;
|
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
|
} // namespace waybar::modules::hyprland
|
Loading…
Reference in New Issue
Block a user