From c59bb509bd4585af8941db66e357b0bf9b08b2de Mon Sep 17 00:00:00 2001 From: Azazel Date: Mon, 26 Feb 2024 21:00:16 +0000 Subject: [PATCH] fix: hide icon if window is unfocused --- include/modules/hyprland/window.hpp | 1 + src/modules/hyprland/window.cpp | 10 ++++++++++ 2 files changed, 11 insertions(+) diff --git a/include/modules/hyprland/window.hpp b/include/modules/hyprland/window.hpp index 593e3422..f2c266bd 100644 --- a/include/modules/hyprland/window.hpp +++ b/include/modules/hyprland/window.hpp @@ -59,6 +59,7 @@ class Window : public waybar::AAppIconLabel, public EventHandler { bool allFloating_; bool swallowing_; bool fullscreen_; + bool focused_; }; } // namespace waybar::modules::hyprland diff --git a/src/modules/hyprland/window.cpp b/src/modules/hyprland/window.cpp index c7d287e5..ec151a7b 100644 --- a/src/modules/hyprland/window.cpp +++ b/src/modules/hyprland/window.cpp @@ -62,6 +62,12 @@ auto Window::update() -> void { label_.hide(); } + if (focused_) { + image_.show(); + } else { + image_.hide(); + } + setClass("empty", workspace_.windows == 0); setClass("solo", solo_); setClass("floating", allFloating_); @@ -137,13 +143,16 @@ void Window::queryActiveWorkspace() { workspace_ = getActiveWorkspace(); } + focused_ = true; if (workspace_.windows > 0) { const auto clients = gIPC->getSocket1JsonReply("clients"); assert(clients.isArray()); auto activeWindow = std::find_if(clients.begin(), clients.end(), [&](Json::Value window) { return window["address"] == workspace_.last_window; }); + if (activeWindow == std::end(clients)) { + focused_ = false; return; } @@ -185,6 +194,7 @@ void Window::queryActiveWorkspace() { soloClass_ = ""; } } else { + focused_ = false; windowData_ = WindowData{}; allFloating_ = false; swallowing_ = false;