diff --git a/include/modules/river/tags.hpp b/include/modules/river/tags.hpp index c2b1a11..1de4387 100644 --- a/include/modules/river/tags.hpp +++ b/include/modules/river/tags.hpp @@ -33,6 +33,7 @@ class Tags : public waybar::AModule { Gtk::Box box_; std::vector buttons_; struct zriver_output_status_v1 *output_status_; + bool hide_unoccupied; }; } /* namespace waybar::modules::river */ diff --git a/src/modules/river/tags.cpp b/src/modules/river/tags.cpp index ccafc16..cae1a5a 100644 --- a/src/modules/river/tags.cpp +++ b/src/modules/river/tags.cpp @@ -6,6 +6,7 @@ #include #include +#include #include "client.hpp" #include "xdg-output-unstable-v1-client-protocol.h" @@ -107,6 +108,8 @@ Tags::Tags(const std::string &id, const waybar::Bar &bar, const Json::Value &con spdlog::error("wl_seat not advertised"); } + hide_unoccupied = config_["hide-unoccupied"].asBool(); + box_.set_name("tags"); if (!id.empty()) { box_.get_style_context()->add_class(id); @@ -139,7 +142,12 @@ Tags::Tags(const std::string &id, const waybar::Bar &bar, const Json::Value &con button.signal_button_press_event().connect( sigc::bind(sigc::mem_fun(*this, &Tags::handle_button_press), i)); } - button.show(); + if ( hide_unoccupied ) { + button.hide(); + } + else { + button.show(); + } i <<= 1; } @@ -186,8 +194,18 @@ void Tags::handle_focused_tags(uint32_t tags) { for (auto &button : buttons_) { if ((1 << i) & tags) { button.get_style_context()->add_class("focused"); - } else { + button.show(); + } + else { button.get_style_context()->remove_class("focused"); + if (hide_unoccupied) { + if (button.get_style_context()->has_class("occupied")) { + button.show(); + } + else { + button.hide(); + } + } } ++i; } @@ -197,6 +215,9 @@ void Tags::handle_view_tags(struct wl_array *view_tags) { // First clear all occupied state for (auto &button : buttons_) { button.get_style_context()->remove_class("occupied"); + if (hide_unoccupied) { + button.hide(); + } } // Set tags with a view to occupied @@ -206,6 +227,9 @@ void Tags::handle_view_tags(struct wl_array *view_tags) { for (auto &button : buttons_) { if (*tags & (1 << i)) { button.get_style_context()->add_class("occupied"); + if (hide_unoccupied) { + button.show(); + } } ++i; }