diff --git a/include/modules/river/tags.hpp b/include/modules/river/tags.hpp index 047ee086..7d5c68dd 100644 --- a/include/modules/river/tags.hpp +++ b/include/modules/river/tags.hpp @@ -30,6 +30,9 @@ class Tags : public waybar::AModule { struct zriver_control_v1 *control_; struct zriver_seat_status_v1 *seat_status_; struct wl_seat *seat_; + // used to make sure the focused view tags are on the correct output + const wl_output *output_; + const wl_output *focused_output_; private: const waybar::Bar &bar_; diff --git a/include/modules/river/window.hpp b/include/modules/river/window.hpp index 32542555..6ed2ce68 100644 --- a/include/modules/river/window.hpp +++ b/include/modules/river/window.hpp @@ -3,6 +3,8 @@ #include #include +#include + #include "ALabel.hpp" #include "bar.hpp" #include "river-status-unstable-v1-client-protocol.h" @@ -25,8 +27,9 @@ class Window : public waybar::ALabel { private: const waybar::Bar &bar_; - struct wl_output *output_; // stores the output this module belongs to - struct wl_output *focused_output_; // stores the currently focused output + std::optional default_format_; // format when there is no window + struct wl_output *output_; // stores the output this module belongs to + struct wl_output *focused_output_; // stores the currently focused output struct zriver_seat_status_v1 *seat_status_; }; diff --git a/man/waybar-river-window.5.scd b/man/waybar-river-window.5.scd index 82eee0a5..e8155612 100644 --- a/man/waybar-river-window.5.scd +++ b/man/waybar-river-window.5.scd @@ -17,6 +17,10 @@ Addressed by *river/window* default: {} ++ The format, how information should be displayed. On {} data gets inserted. +*default-format*: ++ + typeof: string ++ + A string to be show if no window is focused. No formatting is done but markup is supported. + *rotate*: ++ typeof: integer ++ Positive value to rotate the text label (in 90 degree increments). diff --git a/src/modules/river/tags.cpp b/src/modules/river/tags.cpp index 146387bb..c2078180 100644 --- a/src/modules/river/tags.cpp +++ b/src/modules/river/tags.cpp @@ -64,22 +64,21 @@ static const zriver_command_callback_v1_listener command_callback_listener_impl{ static void listen_focused_output(void *data, struct zriver_seat_status_v1 *zriver_seat_status_v1, struct wl_output *output) { - // Intentionally empty + static_cast(data)->focused_output_ = output; } static void listen_unfocused_output(void *data, struct zriver_seat_status_v1 *zriver_seat_status_v1, - struct wl_output *output) { - // Intentionally empty -} + struct wl_output *output) {} static void listen_focused_view(void *data, struct zriver_seat_status_v1 *zriver_seat_status_v1, const char *title, uint32_t tags) { static_cast(data)->handle_focused_view(title, tags); + static_cast(data)->AModule::update(); } static void listen_mode(void *data, struct zriver_seat_status_v1 *zriver_seat_status_v1, const char *mode) { - // Intentionally empty + static_cast(data)->AModule::update(); } static const zriver_seat_status_v1_listener seat_status_listener_impl{ @@ -125,6 +124,8 @@ Tags::Tags(const std::string &id, const waybar::Bar &bar, const Json::Value &con status_manager_{nullptr}, control_{nullptr}, seat_{nullptr}, + output_{nullptr}, + focused_output_{nullptr}, bar_(bar), box_{bar.orientation, 0}, output_status_{nullptr} { @@ -149,6 +150,8 @@ Tags::Tags(const std::string &id, const waybar::Bar &bar, const Json::Value &con 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); + output_ = gdk_wayland_monitor_get_wl_output(bar_.output->monitor->gobj()); + box_.set_name("tags"); if (!id.empty()) { box_.get_style_context()->add_class(id); @@ -317,20 +320,10 @@ void Tags::handle_urgent_tags(uint32_t tags) { } void Tags::handle_focused_view(const char *title, uint32_t tags) { - auto hide_vacant = config_["hide-vacant"].asBool(); for (size_t i = 0; i < buttons_.size(); ++i) { - bool visible = buttons_[i].is_visible(); - bool occupied = buttons_[i].get_style_context()->has_class("occupied"); - bool focused = buttons_[i].get_style_context()->has_class("focused"); - if ((1 << i) & tags) { - if (hide_vacant && !visible) { - buttons_[i].set_visible(true); - } + if ((1 << i) & tags && output_ == focused_output_) { buttons_[i].get_style_context()->add_class("current-view"); } else { - if (hide_vacant && !(occupied || focused)) { - buttons_[i].set_visible(false); - } buttons_[i].get_style_context()->remove_class("current-view"); } } diff --git a/src/modules/river/window.cpp b/src/modules/river/window.cpp index 5c2b5ddd..7005d75f 100644 --- a/src/modules/river/window.cpp +++ b/src/modules/river/window.cpp @@ -65,6 +65,10 @@ Window::Window(const std::string &id, const waybar::Bar &bar, const Json::Value seat_{nullptr}, bar_(bar), seat_status_{nullptr} { + if (config_["default-format"].isString()) { + default_format_ = config_["default-format"].asString(); + } + struct wl_display *display = Client::inst()->wl_display; struct wl_registry *registry = wl_display_get_registry(display); wl_registry_add_listener(registry, ®istry_listener_impl, this); @@ -104,7 +108,16 @@ void Window::handle_focused_view(const char *title, uint32_t tags) { if (focused_output_ != output_) return; if (std::strcmp(title, "") == 0 || format_.empty()) { - label_.hide(); // hide empty labels or labels with empty format + if (default_format_.has_value()) { + label_.show(); + const std::string &default_format = default_format_.value(); + label_.set_markup(default_format); + if (tooltipEnabled()) { + label_.set_tooltip_markup(default_format); + } + } else { + label_.hide(); // hide empty labels or labels with empty format + } } else { label_.show(); auto text = fmt::format(fmt::runtime(format_), Glib::Markup::escape_text(title).raw());