diff --git a/include/modules/hyprland/submap.hpp b/include/modules/hyprland/submap.hpp index 7e3425ef..0dcb5d5a 100644 --- a/include/modules/hyprland/submap.hpp +++ b/include/modules/hyprland/submap.hpp @@ -26,6 +26,7 @@ class Submap : public waybar::ALabel, public EventHandler { const Bar& bar_; util::JsonParser parser_; std::string submap_; + std::string prev_submap_; bool always_on_ = false; std::string default_submap_ = "Default"; diff --git a/src/modules/hyprland/submap.cpp b/src/modules/hyprland/submap.cpp index eb9b1de8..5d587d02 100644 --- a/src/modules/hyprland/submap.cpp +++ b/src/modules/hyprland/submap.cpp @@ -44,6 +44,17 @@ auto Submap::parseConfig(const Json::Value& config) -> void { auto Submap::update() -> void { std::lock_guard lg(mutex_); + // Handle style class changes + if (!prev_submap_.empty()) { + label_.get_style_context()->remove_class(prev_submap_); + } + + if (!submap_.empty()) { + label_.get_style_context()->add_class(submap_); + } + + prev_submap_ = submap_; + if (submap_.empty()) { event_box_.hide(); } else { @@ -66,18 +77,12 @@ void Submap::onEvent(const std::string& ev) { auto submapName = ev.substr(ev.find_first_of('>') + 2); - if (!submap_.empty()) { - label_.get_style_context()->remove_class(submap_); - } - submap_ = submapName; if (submap_.empty() && always_on_) { submap_ = default_submap_; } - label_.get_style_context()->add_class(submap_); - spdlog::debug("hyprland submap onevent with {}", submap_); dp.emit(); diff --git a/src/modules/hyprland/window.cpp b/src/modules/hyprland/window.cpp index 23437c5f..e02a7691 100644 --- a/src/modules/hyprland/window.cpp +++ b/src/modules/hyprland/window.cpp @@ -45,6 +45,8 @@ Window::~Window() { auto Window::update() -> void { std::shared_lock windowIpcShareLock(windowIpcSmtx); + queryActiveWorkspace(); + std::string windowName = waybar::util::sanitize_string(workspace_.last_window_title); std::string windowAddress = workspace_.last_window; @@ -236,8 +238,6 @@ void Window::queryActiveWorkspace() { } void Window::onEvent(const std::string& ev) { - queryActiveWorkspace(); - dp.emit(); } diff --git a/src/modules/hyprland/windowcount.cpp b/src/modules/hyprland/windowcount.cpp index b2721aea..91589189 100644 --- a/src/modules/hyprland/windowcount.cpp +++ b/src/modules/hyprland/windowcount.cpp @@ -37,7 +37,7 @@ WindowCount::~WindowCount() { } auto WindowCount::update() -> void { - std::lock_guard lg(mutex_); + queryActiveWorkspace(); std::string format = config_["format"].asString(); std::string formatEmpty = config_["format-empty"].asString(); @@ -126,7 +126,6 @@ void WindowCount::queryActiveWorkspace() { } void WindowCount::onEvent(const std::string& ev) { - queryActiveWorkspace(); dp.emit(); }