diff --git a/include/modules/hyprland/window.hpp b/include/modules/hyprland/window.hpp index e21426a..e844655 100644 --- a/include/modules/hyprland/window.hpp +++ b/include/modules/hyprland/window.hpp @@ -14,9 +14,12 @@ public: Window(const std::string&, const waybar::Bar&, const Json::Value&); ~Window() = default; + auto update() -> void; + private: void onEvent(const std::string&); + std::mutex mutex_; const Bar& bar_; util::JsonParser parser_; std::string lastView; diff --git a/src/modules/hyprland/window.cpp b/src/modules/hyprland/window.cpp index 96d07bd..f0462a0 100644 --- a/src/modules/hyprland/window.cpp +++ b/src/modules/hyprland/window.cpp @@ -20,10 +20,24 @@ Window::Window(const std::string& id, const Bar& bar, const Json::Value& config) gIPC->registerForIPC("activewindow", [&](const std::string& ev) { this->onEvent(ev); }); } +auto Window::update() -> void { + // fix ampersands + std::lock_guard lg(mutex_); + + if (!format_.empty()) { + label_.show(); + label_.set_markup(fmt::format(format_, lastView)); + } else { + label_.hide(); + } + + ALabel::update(); +} + void Window::onEvent(const std::string& ev) { + std::lock_guard lg(mutex_); auto windowName = ev.substr(ev.find_first_of(',') + 1).substr(0, 256); - // fix ampersands auto replaceAll = [](std::string str, const std::string& from, const std::string& to) -> std::string { size_t start_pos = 0; @@ -42,13 +56,6 @@ void Window::onEvent(const std::string& ev) { spdlog::debug("hyprland window onevent with {}", windowName); - if (!format_.empty()) { - label_.show(); - label_.set_markup(fmt::format(format_, windowName)); - } else { - label_.hide(); - } - - ALabel::update(); + dp.emit(); } } \ No newline at end of file