mirror of
https://github.com/rad4day/Waybar.git
synced 2023-12-21 10:22:59 +01:00
Merge pull request #2064 from en3wton/hyprland-language-format-replacements
This commit is contained in:
@ -6,7 +6,7 @@
|
||||
|
||||
#include <util/sanitize_str.hpp>
|
||||
|
||||
#include "modules/hyprland/backend.hpp"
|
||||
#include "util/string.hpp"
|
||||
|
||||
namespace waybar::modules::hyprland {
|
||||
|
||||
@ -37,9 +37,20 @@ Language::~Language() {
|
||||
auto Language::update() -> void {
|
||||
std::lock_guard<std::mutex> lg(mutex_);
|
||||
|
||||
std::string layoutName = std::string{};
|
||||
if (config_.isMember("format-" + layout_.short_description)) {
|
||||
const auto propName = "format-" + layout_.short_description;
|
||||
layoutName = fmt::format(fmt::runtime(format_), config_[propName].asString());
|
||||
} else {
|
||||
layoutName = trim(fmt::format(fmt::runtime(format_), fmt::arg("long", layout_.full_name),
|
||||
fmt::arg("short", layout_.short_name),
|
||||
fmt::arg("shortDescription", layout_.short_description),
|
||||
fmt::arg("variant", layout_.variant)));
|
||||
}
|
||||
|
||||
if (!format_.empty()) {
|
||||
label_.show();
|
||||
label_.set_markup(layoutName_);
|
||||
label_.set_markup(layoutName);
|
||||
} else {
|
||||
label_.hide();
|
||||
}
|
||||
@ -57,18 +68,7 @@ void Language::onEvent(const std::string& ev) {
|
||||
|
||||
layoutName = waybar::util::sanitize_string(layoutName);
|
||||
|
||||
const auto briefName = getShortFrom(layoutName);
|
||||
|
||||
if (config_.isMember("format-" + briefName)) {
|
||||
const auto propName = "format-" + briefName;
|
||||
layoutName = fmt::format(fmt::runtime(format_), config_[propName].asString());
|
||||
} else {
|
||||
layoutName = fmt::format(fmt::runtime(format_), layoutName);
|
||||
}
|
||||
|
||||
if (layoutName == layoutName_) return;
|
||||
|
||||
layoutName_ = layoutName;
|
||||
layout_ = getLayout(layoutName);
|
||||
|
||||
spdlog::debug("hyprland language onevent with {}", layoutName);
|
||||
|
||||
@ -89,19 +89,9 @@ void Language::initLanguage() {
|
||||
|
||||
searcher = waybar::util::sanitize_string(searcher);
|
||||
|
||||
auto layoutName = std::string{};
|
||||
const auto briefName = getShortFrom(searcher);
|
||||
layout_ = getLayout(searcher);
|
||||
|
||||
if (config_.isMember("format-" + briefName)) {
|
||||
const auto propName = "format-" + briefName;
|
||||
layoutName = fmt::format(fmt::runtime(format_), config_[propName].asString());
|
||||
} else {
|
||||
layoutName = fmt::format(fmt::runtime(format_), searcher);
|
||||
}
|
||||
|
||||
layoutName_ = layoutName;
|
||||
|
||||
spdlog::debug("hyprland language initLanguage found {}", layoutName_);
|
||||
spdlog::debug("hyprland language initLanguage found {}", layout_.full_name);
|
||||
|
||||
dp.emit();
|
||||
|
||||
@ -110,11 +100,10 @@ void Language::initLanguage() {
|
||||
}
|
||||
}
|
||||
|
||||
std::string Language::getShortFrom(const std::string& fullName) {
|
||||
auto Language::getLayout(const std::string& fullName) -> Layout {
|
||||
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);
|
||||
@ -124,16 +113,26 @@ std::string Language::getShortFrom(const std::string& fullName) {
|
||||
continue;
|
||||
}
|
||||
|
||||
std::string briefName = rxkb_layout_get_brief(layout);
|
||||
auto name = std::string(rxkb_layout_get_name(layout));
|
||||
auto variant_ = rxkb_layout_get_variant(layout);
|
||||
std::string variant = variant_ == nullptr ? "" : std::string(variant_);
|
||||
|
||||
auto short_description_ = rxkb_layout_get_brief(layout);
|
||||
std::string short_description =
|
||||
short_description_ == nullptr ? "" : std::string(short_description_);
|
||||
|
||||
Layout info = Layout{nameOfLayout, name, variant, short_description};
|
||||
|
||||
rxkb_context_unref(CONTEXT);
|
||||
|
||||
return briefName;
|
||||
return info;
|
||||
}
|
||||
|
||||
rxkb_context_unref(CONTEXT);
|
||||
|
||||
return "";
|
||||
spdlog::debug("hyprland language didn't find matching layout");
|
||||
|
||||
return Layout {"", "", "", ""};
|
||||
}
|
||||
|
||||
} // namespace waybar::modules::hyprland
|
||||
|
Reference in New Issue
Block a user