Approach to dry pattern - separate remove/add css-classes logic to methods
This commit is contained in:
@@ -30,7 +30,9 @@ class Language : public waybar::ALabel, public EventHandler {
|
|||||||
std::string short_description;
|
std::string short_description;
|
||||||
};
|
};
|
||||||
|
|
||||||
auto getLayout(const std::string&) -> Layout;
|
auto removeXkbLayoutCssClass() -> void;
|
||||||
|
auto addXkbLayoutCssClass() -> void;
|
||||||
|
static auto getLayout(const std::string&) -> Layout;
|
||||||
|
|
||||||
std::mutex mutex_;
|
std::mutex mutex_;
|
||||||
const Bar& bar_;
|
const Bar& bar_;
|
||||||
|
|||||||
@@ -82,11 +82,9 @@ void Language::onEvent(const std::string& ev) {
|
|||||||
|
|
||||||
layoutName = waybar::util::sanitize_string(layoutName);
|
layoutName = waybar::util::sanitize_string(layoutName);
|
||||||
|
|
||||||
label_.get_style_context()->remove_class(layout_.short_name);
|
removeXkbLayoutCssClass();
|
||||||
spdlog::debug("hyprland language try to remove currently short_name css class {}", layout_.short_name);
|
|
||||||
layout_ = getLayout(layoutName);
|
layout_ = getLayout(layoutName);
|
||||||
label_.get_style_context()->add_class(layout_.short_name);
|
addXkbLayoutCssClass();
|
||||||
spdlog::debug("hyprland language add new short_name css class {}", layout_.short_name);
|
|
||||||
|
|
||||||
spdlog::debug("hyprland language onevent with {}", layoutName);
|
spdlog::debug("hyprland language onevent with {}", layoutName);
|
||||||
|
|
||||||
@@ -107,11 +105,9 @@ void Language::initLanguage() {
|
|||||||
|
|
||||||
searcher = waybar::util::sanitize_string(searcher);
|
searcher = waybar::util::sanitize_string(searcher);
|
||||||
|
|
||||||
label_.get_style_context()->remove_class(layout_.short_name);
|
removeXkbLayoutCssClass();
|
||||||
spdlog::debug("hyprland language try to remove currently short_name css class {}", layout_.short_name);
|
|
||||||
layout_ = getLayout(searcher);
|
layout_ = getLayout(searcher);
|
||||||
label_.get_style_context()->add_class(layout_.short_name);
|
addXkbLayoutCssClass();
|
||||||
spdlog::debug("hyprland language add new short_name css class {}", layout_.short_name);
|
|
||||||
|
|
||||||
spdlog::debug("hyprland language initLanguage found {}", layout_.full_name);
|
spdlog::debug("hyprland language initLanguage found {}", layout_.full_name);
|
||||||
|
|
||||||
@@ -121,6 +117,15 @@ void Language::initLanguage() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
auto Language::removeXkbLayoutCssClass() -> void {
|
||||||
|
label_.get_style_context()->remove_class(layout_.short_name);
|
||||||
|
spdlog::debug("hyprland language try to remove currently short_name css class {}", layout_.short_name);
|
||||||
|
}
|
||||||
|
auto Language::addXkbLayoutCssClass() -> void {
|
||||||
|
label_.get_style_context()->add_class(layout_.short_name);
|
||||||
|
spdlog::debug("hyprland language add new short_name css class {}", layout_.short_name);
|
||||||
|
}
|
||||||
|
|
||||||
auto Language::getLayout(const std::string& fullName) -> Layout {
|
auto Language::getLayout(const std::string& fullName) -> Layout {
|
||||||
auto* const context = rxkb_context_new(RXKB_CONTEXT_LOAD_EXOTIC_RULES);
|
auto* const context = rxkb_context_new(RXKB_CONTEXT_LOAD_EXOTIC_RULES);
|
||||||
rxkb_context_parse_default_ruleset(context);
|
rxkb_context_parse_default_ruleset(context);
|
||||||
|
|||||||
Reference in New Issue
Block a user