diff --git a/src/modules/hyprland/window.cpp b/src/modules/hyprland/window.cpp index ba476e93..b122fc9d 100644 --- a/src/modules/hyprland/window.cpp +++ b/src/modules/hyprland/window.cpp @@ -4,12 +4,12 @@ #include #include +#include #include #include "modules/hyprland/backend.hpp" #include "util/json.hpp" #include "util/rewrite_string.hpp" -#include namespace waybar::modules::hyprland { @@ -54,7 +54,6 @@ auto Window::update() -> void { last_title_ = window_name; } - if (!format_.empty()) { label_.show(); label_.set_markup(fmt::format(fmt::runtime(format_), @@ -63,7 +62,6 @@ auto Window::update() -> void { label_.hide(); } - setClass("empty", workspace_.windows == 0); setClass("solo", solo_); setClass("fullscreen", fullscreen_); @@ -117,12 +115,8 @@ auto Window::getActiveWorkspace(const std::string& monitorName) -> Workspace { } auto Window::Workspace::parse(const Json::Value& value) -> Window::Workspace { - return Workspace{ - value["id"].asInt(), - value["windows"].asInt(), - value["lastwindow"].asString(), - value["lastwindowtitle"].asString() - }; + return Workspace{value["id"].asInt(), value["windows"].asInt(), value["lastwindow"].asString(), + value["lastwindowtitle"].asString()}; } void Window::queryActiveWorkspace() { @@ -134,13 +128,13 @@ void Window::queryActiveWorkspace() { workspace_ = getActiveWorkspace(); } - if (workspace_.windows > 0) { const auto clients = gIPC->getSocket1Reply("j/clients"); Json::Value json = parser_.parse(clients); assert(json.isArray()); - auto active_window = std::find_if(json.begin(), json.end(), - [&](Json::Value window) { return window["address"] == workspace_.last_window; }); + auto active_window = std::find_if(json.begin(), json.end(), [&](Json::Value window) { + return window["address"] == workspace_.last_window; + }); if (active_window == std::end(json)) { return; } @@ -152,8 +146,9 @@ void Window::queryActiveWorkspace() { } std::vector workspace_windows; std::copy_if(json.begin(), json.end(), std::back_inserter(workspace_windows), - [&](Json::Value window) { return window["workspace"]["id"] == workspace_.id && - window["mapped"].asBool(); }); + [&](Json::Value window) { + return window["workspace"]["id"] == workspace_.id && window["mapped"].asBool(); + }); solo_ = 1 == std::count_if(workspace_windows.begin(), workspace_windows.end(), [&](Json::Value window) { return !window["floating"].asBool(); }); all_floating_ = std::all_of(workspace_windows.begin(), workspace_windows.end(), @@ -173,7 +168,6 @@ void Window::onEvent(const std::string& ev) { dp.emit(); } - void Window::setClass(const std::string& classname, bool enable) { if (enable) { if (!bar_.window.get_style_context()->has_class(classname)) { diff --git a/src/modules/wlr/taskbar.cpp b/src/modules/wlr/taskbar.cpp index 74b8be5d..0fd44435 100644 --- a/src/modules/wlr/taskbar.cpp +++ b/src/modules/wlr/taskbar.cpp @@ -506,11 +506,11 @@ void Task::handle_closed() { spdlog::debug("{} closed", repr()); zwlr_foreign_toplevel_handle_v1_destroy(handle_); handle_ = nullptr; + tbar_->remove_task(id_); if (button_visible_) { tbar_->remove_button(button); button_visible_ = false; } - tbar_->remove_task(id_); } bool Task::handle_clicked(GdkEventButton *bt) { @@ -710,6 +710,7 @@ Taskbar::Taskbar(const std::string &id, const waybar::Bar &bar, const Json::Valu if (!id.empty()) { box_.get_style_context()->add_class(id); } + box_.get_style_context()->add_class("empty"); event_box_.add(box_); struct wl_display *display = Client::inst()->wl_display; @@ -862,11 +863,19 @@ void Taskbar::handle_finished() { manager_ = nullptr; } -void Taskbar::add_button(Gtk::Button &bt) { box_.pack_start(bt, false, false); } +void Taskbar::add_button(Gtk::Button &bt) { + box_.pack_start(bt, false, false); + box_.get_style_context()->remove_class("empty"); +} void Taskbar::move_button(Gtk::Button &bt, int pos) { box_.reorder_child(bt, pos); } -void Taskbar::remove_button(Gtk::Button &bt) { box_.remove(bt); } +void Taskbar::remove_button(Gtk::Button &bt) { + box_.remove(bt); + if (tasks_.empty()) { + box_.get_style_context()->add_class("empty"); + } +} void Taskbar::remove_task(uint32_t id) { auto it = std::find_if(std::begin(tasks_), std::end(tasks_),