From bbcfb5e138f8a3f7e180ee2684016513ccee5d8a Mon Sep 17 00:00:00 2001 From: en3wton Date: Tue, 21 Mar 2023 19:30:35 +0000 Subject: [PATCH] remove use of new on Layout --- include/modules/hyprland/language.hpp | 2 +- src/modules/hyprland/language.cpp | 12 +++++++----- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/include/modules/hyprland/language.hpp b/include/modules/hyprland/language.hpp index b12504c..30789d0 100644 --- a/include/modules/hyprland/language.hpp +++ b/include/modules/hyprland/language.hpp @@ -26,7 +26,7 @@ class Language : public waybar::ALabel, public EventHandler { std::string short_description; }; - auto getLayout(const std::string&) -> Layout*; + auto getLayout(const std::string&) -> Layout; std::mutex mutex_; const Bar& bar_; diff --git a/src/modules/hyprland/language.cpp b/src/modules/hyprland/language.cpp index 832516a..cfc24f8 100644 --- a/src/modules/hyprland/language.cpp +++ b/src/modules/hyprland/language.cpp @@ -68,7 +68,7 @@ void Language::onEvent(const std::string& ev) { layoutName = waybar::util::sanitize_string(layoutName); - layout_ = *getLayout(layoutName); + layout_ = getLayout(layoutName); spdlog::debug("hyprland language onevent with {}", layoutName); @@ -89,7 +89,7 @@ void Language::initLanguage() { searcher = waybar::util::sanitize_string(searcher); - layout_ = *getLayout(searcher); + layout_ = getLayout(searcher); spdlog::debug("hyprland language initLanguage found {}", layout_.full_name); @@ -100,7 +100,7 @@ void Language::initLanguage() { } } -auto Language::getLayout(const std::string& fullName) -> Layout* { +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); @@ -121,7 +121,7 @@ auto Language::getLayout(const std::string& fullName) -> Layout* { std::string short_description = short_description_ == nullptr ? "" : std::string(short_description_); - Layout* info = new Layout{nameOfLayout, name, variant, short_description}; + Layout info = Layout{nameOfLayout, name, variant, short_description}; rxkb_context_unref(CONTEXT); @@ -130,7 +130,9 @@ auto Language::getLayout(const std::string& fullName) -> Layout* { rxkb_context_unref(CONTEXT); - return NULL; + spdlog::debug("hyprland language didn't find matching layout"); + + return Layout {"", "", "", ""}; } } // namespace waybar::modules::hyprland