diff --git a/include/modules/dwl/tags.hpp b/include/modules/dwl/tags.hpp index 45a6f01f..4fee30fb 100644 --- a/include/modules/dwl/tags.hpp +++ b/include/modules/dwl/tags.hpp @@ -30,6 +30,7 @@ class Tags : public waybar::AModule { const waybar::Bar& bar_; Gtk::Box box_; std::vector buttons_; + bool hide_vacant_; struct zdwl_ipc_output_v2* output_status_; }; diff --git a/man/waybar-dwl-tags.5.scd b/man/waybar-dwl-tags.5.scd index f775b742..c301f49a 100644 --- a/man/waybar-dwl-tags.5.scd +++ b/man/waybar-dwl-tags.5.scd @@ -21,6 +21,11 @@ Addressed by *dwl/tags* typeof: array ++ 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*: ++ typeof: bool ++ default: false ++ diff --git a/src/modules/dwl/tags.cpp b/src/modules/dwl/tags.cpp index 52554707..3e6696af 100644 --- a/src/modules/dwl/tags.cpp +++ b/src/modules/dwl/tags.cpp @@ -70,32 +70,31 @@ static const zdwl_ipc_output_v2_listener output_status_listener_impl{ static void handle_global(void* data, struct wl_registry* registry, uint32_t name, const char* interface, uint32_t version) { - -if (std::strcmp(interface, zdwl_ipc_manager_v2_interface.name) == 0) { - auto* self = static_cast(data); + if (std::strcmp(interface, zdwl_ipc_manager_v2_interface.name) == 0) { + auto* self = static_cast(data); - if (self->status_manager_) { - zdwl_ipc_manager_v2_destroy(self->status_manager_); - self->status_manager_ = nullptr; -} + if (self->status_manager_) { + zdwl_ipc_manager_v2_destroy(self->status_manager_); + self->status_manager_ = nullptr; + } - self->status_manager_ = static_cast( - wl_registry_bind(registry, name, &zdwl_ipc_manager_v2_interface, 1)); -} - -if (std::strcmp(interface, wl_seat_interface.name) == 0) { - auto* self = static_cast(data); - - if (self->seat_) { - wl_seat_destroy(self->seat_); - self->seat_ = nullptr; + self->status_manager_ = static_cast( + wl_registry_bind(registry, name, &zdwl_ipc_manager_v2_interface, 1)); } - version = std::min(version, 1); + if (std::strcmp(interface, wl_seat_interface.name) == 0) { + auto* self = static_cast(data); - self->seat_ = static_cast( - wl_registry_bind(registry, name, &wl_seat_interface, version)); -} + if (self->seat_) { + wl_seat_destroy(self->seat_); + self->seat_ = nullptr; + } + + version = std::min(version, 1); + + self->seat_ = + static_cast(wl_registry_bind(registry, name, &wl_seat_interface, version)); + } } static void handle_global_remove(void* data, struct wl_registry* registry, uint32_t name) { /* Ignore event */ @@ -110,7 +109,11 @@ Tags::Tags(const std::string& id, const waybar::Bar& bar, const Json::Value& con seat_{nullptr}, bar_(bar), box_{bar.orientation, 0}, + hide_vacant_(false), output_status_{nullptr} { + if (config_["hide-vacant"].asBool()) { + hide_vacant_ = config_["hide-vacant"].asBool(); + } struct wl_display* display = Client::inst()->wl_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 { 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) {