feat(river/tags): Allow hiding of unoccupied tags.
This is a very simple attempt at providing the option to hide unoccupied tags in the `river/tags` module. It adds the option `hide-unoccupied` to hide the buttons when a tag is unoccupied. ISSUES: This change currently has an issue due to the way that waybar initialises the bar using the `showall()` function. This causes all the tags to be visible by default until an update operation happens.
This commit is contained in:
parent
1d6cfe7ce6
commit
00e4598c25
|
|
@ -33,6 +33,7 @@ class Tags : public waybar::AModule {
|
||||||
Gtk::Box box_;
|
Gtk::Box box_;
|
||||||
std::vector<Gtk::Button> buttons_;
|
std::vector<Gtk::Button> buttons_;
|
||||||
struct zriver_output_status_v1 *output_status_;
|
struct zriver_output_status_v1 *output_status_;
|
||||||
|
bool hide_unoccupied;
|
||||||
};
|
};
|
||||||
|
|
||||||
} /* namespace waybar::modules::river */
|
} /* namespace waybar::modules::river */
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@
|
||||||
#include <wayland-client.h>
|
#include <wayland-client.h>
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
#include <cstddef>
|
||||||
|
|
||||||
#include "client.hpp"
|
#include "client.hpp"
|
||||||
#include "xdg-output-unstable-v1-client-protocol.h"
|
#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");
|
spdlog::error("wl_seat not advertised");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
hide_unoccupied = config_["hide-unoccupied"].asBool();
|
||||||
|
|
||||||
box_.set_name("tags");
|
box_.set_name("tags");
|
||||||
if (!id.empty()) {
|
if (!id.empty()) {
|
||||||
box_.get_style_context()->add_class(id);
|
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(
|
button.signal_button_press_event().connect(
|
||||||
sigc::bind(sigc::mem_fun(*this, &Tags::handle_button_press), i));
|
sigc::bind(sigc::mem_fun(*this, &Tags::handle_button_press), i));
|
||||||
}
|
}
|
||||||
|
if ( hide_unoccupied ) {
|
||||||
|
button.hide();
|
||||||
|
}
|
||||||
|
else {
|
||||||
button.show();
|
button.show();
|
||||||
|
}
|
||||||
i <<= 1;
|
i <<= 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -186,8 +194,18 @@ void Tags::handle_focused_tags(uint32_t tags) {
|
||||||
for (auto &button : buttons_) {
|
for (auto &button : buttons_) {
|
||||||
if ((1 << i) & tags) {
|
if ((1 << i) & tags) {
|
||||||
button.get_style_context()->add_class("focused");
|
button.get_style_context()->add_class("focused");
|
||||||
} else {
|
button.show();
|
||||||
|
}
|
||||||
|
else {
|
||||||
button.get_style_context()->remove_class("focused");
|
button.get_style_context()->remove_class("focused");
|
||||||
|
if (hide_unoccupied) {
|
||||||
|
if (button.get_style_context()->has_class("occupied")) {
|
||||||
|
button.show();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
button.hide();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
++i;
|
++i;
|
||||||
}
|
}
|
||||||
|
|
@ -197,6 +215,9 @@ void Tags::handle_view_tags(struct wl_array *view_tags) {
|
||||||
// First clear all occupied state
|
// First clear all occupied state
|
||||||
for (auto &button : buttons_) {
|
for (auto &button : buttons_) {
|
||||||
button.get_style_context()->remove_class("occupied");
|
button.get_style_context()->remove_class("occupied");
|
||||||
|
if (hide_unoccupied) {
|
||||||
|
button.hide();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set tags with a view to occupied
|
// 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_) {
|
for (auto &button : buttons_) {
|
||||||
if (*tags & (1 << i)) {
|
if (*tags & (1 << i)) {
|
||||||
button.get_style_context()->add_class("occupied");
|
button.get_style_context()->add_class("occupied");
|
||||||
|
if (hide_unoccupied) {
|
||||||
|
button.show();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
++i;
|
++i;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user