Merge pull request #2258 from Anakael/pr/anakael/hide-empty-taskbar

[wrl/taskbare] fix: use empty class for empty taskbar
pull/2265/head
Alexis Rouillard 2023-06-27 08:58:54 +02:00 committed by GitHub
commit 0fff38c751
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 18 deletions

View File

@ -4,12 +4,12 @@
#include <algorithm> #include <algorithm>
#include <regex> #include <regex>
#include <util/sanitize_str.hpp>
#include <vector> #include <vector>
#include "modules/hyprland/backend.hpp" #include "modules/hyprland/backend.hpp"
#include "util/json.hpp" #include "util/json.hpp"
#include "util/rewrite_string.hpp" #include "util/rewrite_string.hpp"
#include <util/sanitize_str.hpp>
namespace waybar::modules::hyprland { namespace waybar::modules::hyprland {
@ -54,7 +54,6 @@ auto Window::update() -> void {
last_title_ = window_name; last_title_ = window_name;
} }
if (!format_.empty()) { if (!format_.empty()) {
label_.show(); label_.show();
label_.set_markup(fmt::format(fmt::runtime(format_), label_.set_markup(fmt::format(fmt::runtime(format_),
@ -63,7 +62,6 @@ auto Window::update() -> void {
label_.hide(); label_.hide();
} }
setClass("empty", workspace_.windows == 0); setClass("empty", workspace_.windows == 0);
setClass("solo", solo_); setClass("solo", solo_);
setClass("fullscreen", fullscreen_); 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 { auto Window::Workspace::parse(const Json::Value& value) -> Window::Workspace {
return Workspace{ return Workspace{value["id"].asInt(), value["windows"].asInt(), value["lastwindow"].asString(),
value["id"].asInt(), value["lastwindowtitle"].asString()};
value["windows"].asInt(),
value["lastwindow"].asString(),
value["lastwindowtitle"].asString()
};
} }
void Window::queryActiveWorkspace() { void Window::queryActiveWorkspace() {
@ -134,13 +128,13 @@ void Window::queryActiveWorkspace() {
workspace_ = getActiveWorkspace(); workspace_ = getActiveWorkspace();
} }
if (workspace_.windows > 0) { if (workspace_.windows > 0) {
const auto clients = gIPC->getSocket1Reply("j/clients"); const auto clients = gIPC->getSocket1Reply("j/clients");
Json::Value json = parser_.parse(clients); Json::Value json = parser_.parse(clients);
assert(json.isArray()); assert(json.isArray());
auto active_window = std::find_if(json.begin(), json.end(), auto active_window = std::find_if(json.begin(), json.end(), [&](Json::Value window) {
[&](Json::Value window) { return window["address"] == workspace_.last_window; }); return window["address"] == workspace_.last_window;
});
if (active_window == std::end(json)) { if (active_window == std::end(json)) {
return; return;
} }
@ -152,8 +146,9 @@ void Window::queryActiveWorkspace() {
} }
std::vector<Json::Value> workspace_windows; std::vector<Json::Value> workspace_windows;
std::copy_if(json.begin(), json.end(), std::back_inserter(workspace_windows), std::copy_if(json.begin(), json.end(), std::back_inserter(workspace_windows),
[&](Json::Value window) { return window["workspace"]["id"] == workspace_.id && [&](Json::Value window) {
window["mapped"].asBool(); }); return window["workspace"]["id"] == workspace_.id && window["mapped"].asBool();
});
solo_ = 1 == std::count_if(workspace_windows.begin(), workspace_windows.end(), solo_ = 1 == std::count_if(workspace_windows.begin(), workspace_windows.end(),
[&](Json::Value window) { return !window["floating"].asBool(); }); [&](Json::Value window) { return !window["floating"].asBool(); });
all_floating_ = std::all_of(workspace_windows.begin(), workspace_windows.end(), all_floating_ = std::all_of(workspace_windows.begin(), workspace_windows.end(),
@ -173,7 +168,6 @@ void Window::onEvent(const std::string& ev) {
dp.emit(); dp.emit();
} }
void Window::setClass(const std::string& classname, bool enable) { void Window::setClass(const std::string& classname, bool enable) {
if (enable) { if (enable) {
if (!bar_.window.get_style_context()->has_class(classname)) { if (!bar_.window.get_style_context()->has_class(classname)) {

View File

@ -506,11 +506,11 @@ void Task::handle_closed() {
spdlog::debug("{} closed", repr()); spdlog::debug("{} closed", repr());
zwlr_foreign_toplevel_handle_v1_destroy(handle_); zwlr_foreign_toplevel_handle_v1_destroy(handle_);
handle_ = nullptr; handle_ = nullptr;
tbar_->remove_task(id_);
if (button_visible_) { if (button_visible_) {
tbar_->remove_button(button); tbar_->remove_button(button);
button_visible_ = false; button_visible_ = false;
} }
tbar_->remove_task(id_);
} }
bool Task::handle_clicked(GdkEventButton *bt) { 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()) { if (!id.empty()) {
box_.get_style_context()->add_class(id); box_.get_style_context()->add_class(id);
} }
box_.get_style_context()->add_class("empty");
event_box_.add(box_); event_box_.add(box_);
struct wl_display *display = Client::inst()->wl_display; struct wl_display *display = Client::inst()->wl_display;
@ -862,11 +863,19 @@ void Taskbar::handle_finished() {
manager_ = nullptr; 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::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) { void Taskbar::remove_task(uint32_t id) {
auto it = std::find_if(std::begin(tasks_), std::end(tasks_), auto it = std::find_if(std::begin(tasks_), std::end(tasks_),