Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

river/tags: Allow river tags to be styled based on monitor focus #3436

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions include/modules/river/tags.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ class Tags : public waybar::AModule {
void handle_focused_tags(uint32_t tags);
void handle_view_tags(struct wl_array *tags);
void handle_urgent_tags(uint32_t tags);
void handle_focused_output(struct wl_output *output);
void handle_unfocused_output(struct wl_output *output);

void handle_primary_clicked(uint32_t tag);
bool handle_button_press(GdkEventButton *event_button, uint32_t tag);
Expand All @@ -30,9 +32,11 @@ class Tags : public waybar::AModule {

private:
const waybar::Bar &bar_;
struct wl_output *output_; // stores the output this module belongs to
Gtk::Box box_;
std::vector<Gtk::Button> buttons_;
struct zriver_output_status_v1 *output_status_;
struct zriver_seat_status_v1 *seat_status_;
};

} /* namespace waybar::modules::river */
5 changes: 4 additions & 1 deletion man/waybar-river-tags.5.scd
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,13 @@ Addressed by *river/tags*
- *#tags button.occupied*
- *#tags button.focused*
- *#tags button.urgent*
- *#tags button.output*

Note that occupied/focused/urgent status may overlap. That is, a tag may be
Note that occupied/focused/urgent/output status may overlap. That is, a tag may be
both occupied and focused at the same time.

The *output* style is applied when the river output (e.g. monitor) of the current bar is focused.

# SEE ALSO

waybar(5), river(1)
58 changes: 55 additions & 3 deletions src/modules/river/tags.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,39 @@ static void listen_urgent_tags(void *data, struct zriver_output_status_v1 *zrive
static_cast<Tags *>(data)->handle_urgent_tags(tags);
}

static void listen_focused_view(void *data, struct zriver_seat_status_v1 *zriver_seat_status_v1,
const char *title) {
// This module doesn't care
}

static void listen_mode(void *data, struct zriver_seat_status_v1 *zriver_seat_status_v1,
const char *mode) {
// This module doesn't care
}

static void listen_focused_output(void *data, struct zriver_seat_status_v1 *zriver_seat_status_v1,
struct wl_output *output) {
static_cast<Tags *>(data)->handle_focused_output(output);
}

static void listen_unfocused_output(void *data, struct zriver_seat_status_v1 *zriver_seat_status_v1,
struct wl_output *output) {
static_cast<Tags *>(data)->handle_unfocused_output(output);
}

static const zriver_output_status_v1_listener output_status_listener_impl{
.focused_tags = listen_focused_tags,
.view_tags = listen_view_tags,
.urgent_tags = listen_urgent_tags,
};

static const zriver_seat_status_v1_listener seat_status_listener_impl{
.focused_output = listen_focused_output,
.unfocused_output = listen_unfocused_output,
.focused_view = listen_focused_view,
.mode = listen_mode,
};

static void listen_command_success(void *data,
struct zriver_command_callback_v1 *zriver_command_callback_v1,
const char *output) {
Expand Down Expand Up @@ -88,12 +115,15 @@ Tags::Tags(const std::string &id, const waybar::Bar &bar, const Json::Value &con
seat_{nullptr},
bar_(bar),
box_{bar.orientation, 0},
output_status_{nullptr} {
output_status_{nullptr},
seat_status_{nullptr} {
struct wl_display *display = Client::inst()->wl_display;
struct wl_registry *registry = wl_display_get_registry(display);
wl_registry_add_listener(registry, &registry_listener_impl, this);
wl_display_roundtrip(display);

output_ = gdk_wayland_monitor_get_wl_output(bar_.output->monitor->gobj());

if (!status_manager_) {
spdlog::error("river_status_manager_v1 not advertised");
return;
Expand Down Expand Up @@ -150,10 +180,12 @@ Tags::Tags(const std::string &id, const waybar::Bar &bar, const Json::Value &con
button.show();
}

struct wl_output *output = gdk_wayland_monitor_get_wl_output(bar_.output->monitor->gobj());
output_status_ = zriver_status_manager_v1_get_river_output_status(status_manager_, output);
output_status_ = zriver_status_manager_v1_get_river_output_status(status_manager_, output_);
zriver_output_status_v1_add_listener(output_status_, &output_status_listener_impl, this);

seat_status_ = zriver_status_manager_v1_get_river_seat_status(status_manager_, seat_);
zriver_seat_status_v1_add_listener(seat_status_, &seat_status_listener_impl, this);

zriver_status_manager_v1_destroy(status_manager_);
}

Expand All @@ -162,6 +194,10 @@ Tags::~Tags() {
zriver_output_status_v1_destroy(output_status_);
}

if (seat_status_) {
zriver_seat_status_v1_destroy(seat_status_);
}

if (control_) {
zriver_control_v1_destroy(control_);
}
Expand Down Expand Up @@ -224,4 +260,20 @@ void Tags::handle_urgent_tags(uint32_t tags) {
}
}

void Tags::handle_focused_output(struct wl_output *output) {
if (output_ == output) {
for (size_t i = 0; i < buttons_.size(); ++i) {
buttons_[i].get_style_context()->add_class("output");
}
}
}

void Tags::handle_unfocused_output(struct wl_output *output) {
if (output_ == output) {
for (size_t i = 0; i < buttons_.size(); ++i) {
buttons_[i].get_style_context()->remove_class("output");
}
}
}

} /* namespace waybar::modules::river */