Merge pull request #3925 from casKd-dev/dwl/hide-vacant

dwl/tags: add hide-vacant option
This commit is contained in:
Alexis Rouillard
2026-07-03 23:42:17 +02:00
committed by GitHub
3 changed files with 36 additions and 21 deletions
+1
View File
@@ -30,6 +30,7 @@ class Tags : public waybar::AModule {
const waybar::Bar& bar_; const waybar::Bar& bar_;
Gtk::Box box_; Gtk::Box box_;
std::vector<Gtk::Button> buttons_; std::vector<Gtk::Button> buttons_;
bool hide_vacant_;
struct zdwl_ipc_output_v2* output_status_; struct zdwl_ipc_output_v2* output_status_;
}; };
+5
View File
@@ -21,6 +21,11 @@ Addressed by *dwl/tags*
typeof: array ++ typeof: array ++
The label to display for each tag. The label to display for each tag.
*hide-vacant*: ++
typeof: bool ++
default: false ++
If set to true, tags without clients and that are not active will be hidden.
*disable-click*: ++ *disable-click*: ++
typeof: bool ++ typeof: bool ++
default: false ++ default: false ++
+17 -8
View File
@@ -70,20 +70,19 @@ static const zdwl_ipc_output_v2_listener output_status_listener_impl{
static void handle_global(void* data, struct wl_registry* registry, uint32_t name, static void handle_global(void* data, struct wl_registry* registry, uint32_t name,
const char* interface, uint32_t version) { const char* interface, uint32_t version) {
if (std::strcmp(interface, zdwl_ipc_manager_v2_interface.name) == 0) {
if (std::strcmp(interface, zdwl_ipc_manager_v2_interface.name) == 0) {
auto* self = static_cast<Tags*>(data); auto* self = static_cast<Tags*>(data);
if (self->status_manager_) { if (self->status_manager_) {
zdwl_ipc_manager_v2_destroy(self->status_manager_); zdwl_ipc_manager_v2_destroy(self->status_manager_);
self->status_manager_ = nullptr; self->status_manager_ = nullptr;
} }
self->status_manager_ = static_cast<struct zdwl_ipc_manager_v2*>( self->status_manager_ = static_cast<struct zdwl_ipc_manager_v2*>(
wl_registry_bind(registry, name, &zdwl_ipc_manager_v2_interface, 1)); wl_registry_bind(registry, name, &zdwl_ipc_manager_v2_interface, 1));
} }
if (std::strcmp(interface, wl_seat_interface.name) == 0) { if (std::strcmp(interface, wl_seat_interface.name) == 0) {
auto* self = static_cast<Tags*>(data); auto* self = static_cast<Tags*>(data);
if (self->seat_) { if (self->seat_) {
@@ -93,9 +92,9 @@ if (std::strcmp(interface, wl_seat_interface.name) == 0) {
version = std::min<uint32_t>(version, 1); version = std::min<uint32_t>(version, 1);
self->seat_ = static_cast<struct wl_seat*>( self->seat_ =
wl_registry_bind(registry, name, &wl_seat_interface, version)); static_cast<struct wl_seat*>(wl_registry_bind(registry, name, &wl_seat_interface, version));
} }
} }
static void handle_global_remove(void* data, struct wl_registry* registry, uint32_t name) { static void handle_global_remove(void* data, struct wl_registry* registry, uint32_t name) {
/* Ignore event */ /* Ignore event */
@@ -110,7 +109,11 @@ Tags::Tags(const std::string& id, const waybar::Bar& bar, const Json::Value& con
seat_{nullptr}, seat_{nullptr},
bar_(bar), bar_(bar),
box_{bar.orientation, 0}, box_{bar.orientation, 0},
hide_vacant_(false),
output_status_{nullptr} { output_status_{nullptr} {
if (config_["hide-vacant"].asBool()) {
hide_vacant_ = config_["hide-vacant"].asBool();
}
struct wl_display* display = Client::inst()->wl_display; struct wl_display* display = Client::inst()->wl_display;
struct wl_registry* registry = wl_display_get_registry(display); struct wl_registry* registry = wl_display_get_registry(display);
@@ -221,6 +224,12 @@ void Tags::handle_view_tags(uint32_t tag, uint32_t state, uint32_t clients, uint
} else { } else {
button.get_style_context()->remove_class("urgent"); button.get_style_context()->remove_class("urgent");
} }
if (hide_vacant_ && !clients && !(state & TAG_ACTIVE)) {
button.set_visible(false);
} else {
button.set_visible(true);
}
} }
void Tags::handle_active_output(zdwl_ipc_output_v2* zdwl_output_v2, uint32_t active) { void Tags::handle_active_output(zdwl_ipc_output_v2* zdwl_output_v2, uint32_t active) {