From 024fd42e272f79cb08e594eb3af86c93b1446c91 Mon Sep 17 00:00:00 2001 From: Isaac Freund Date: Thu, 19 Aug 2021 14:59:25 +0200 Subject: [PATCH] river/tags: support urgent tags Upstream river has a concept of urgent views/tags as of commit e59c2a73. Introduce a new urgent style to expose this in the waybar module. --- include/modules/river/tags.hpp | 1 + man/waybar-river-tags.5.scd | 6 ++++-- protocol/river-status-unstable-v1.xml | 17 +++++++++++++---- src/modules/river/tags.cpp | 27 +++++++++++++++++++++++++-- 4 files changed, 43 insertions(+), 8 deletions(-) diff --git a/include/modules/river/tags.hpp b/include/modules/river/tags.hpp index f80b3c5..9b75fbd 100644 --- a/include/modules/river/tags.hpp +++ b/include/modules/river/tags.hpp @@ -18,6 +18,7 @@ class Tags : public waybar::AModule { // Handlers for wayland events void handle_focused_tags(uint32_t tags); void handle_view_tags(struct wl_array *tags); + void handle_urgent_tags(uint32_t tags); struct zriver_status_manager_v1 *status_manager_; diff --git a/man/waybar-river-tags.5.scd b/man/waybar-river-tags.5.scd index 0f02724..65b9033 100644 --- a/man/waybar-river-tags.5.scd +++ b/man/waybar-river-tags.5.scd @@ -15,7 +15,7 @@ Addressed by *river/tags* *num-tags*: ++ typeof: uint ++ default: 9 ++ - The number of tags that should be displayed. + The number of tags that should be displayed. Max 32. *tag-labels*: ++ typeof: array ++ @@ -34,8 +34,10 @@ Addressed by *river/tags* - *#tags button* - *#tags button.occupied* - *#tags button.focused* +- *#tags button.urgent* -Note that a tag can be both occupied and focused at the same time. +Note that occupied/focused/urgent status may overlap. That is, a tag may be +both occupied and focused at the same time. # SEE ALSO diff --git a/protocol/river-status-unstable-v1.xml b/protocol/river-status-unstable-v1.xml index a4d6f4e..13affaa 100644 --- a/protocol/river-status-unstable-v1.xml +++ b/protocol/river-status-unstable-v1.xml @@ -1,7 +1,7 @@ - Copyright 2020 Isaac Freund + Copyright 2020 The River Developers Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above @@ -16,7 +16,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - + A global factory for objects that receive status information specific to river. It could be used to implement, for example, a status bar. @@ -47,7 +47,7 @@ - + This interface allows clients to receive information about the current windowing state of an output. @@ -75,12 +75,21 @@ + + + + Sent once on binding the interface and again whenever the set of + tags with at least one urgent view changes. + + + This interface allows clients to receive information about the current - focus of a seat. + focus of a seat. Note that (un)focused_output events will only be sent + if the client has bound the relevant wl_output globals. diff --git a/src/modules/river/tags.cpp b/src/modules/river/tags.cpp index e96b201..2628af2 100644 --- a/src/modules/river/tags.cpp +++ b/src/modules/river/tags.cpp @@ -22,14 +22,24 @@ static void listen_view_tags(void *data, struct zriver_output_status_v1 *zriver_ static_cast(data)->handle_view_tags(tags); } +static void listen_urgent_tags(void *data, struct zriver_output_status_v1 *zriver_output_status_v1, + uint32_t tags) { + static_cast(data)->handle_urgent_tags(tags); +} + 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 void handle_global(void *data, struct wl_registry *registry, uint32_t name, const char *interface, uint32_t version) { if (std::strcmp(interface, zriver_status_manager_v1_interface.name) == 0) { + version = std::min(version, 2); + if (version < ZRIVER_OUTPUT_STATUS_V1_URGENT_TAGS_SINCE_VERSION) { + spdlog::warn("river server does not support urgent tags"); + } static_cast(data)->status_manager_ = static_cast( wl_registry_bind(registry, name, &zriver_status_manager_v1_interface, version)); } @@ -64,8 +74,9 @@ Tags::Tags(const std::string &id, const waybar::Bar &bar, const Json::Value &con } event_box_.add(box_); - // Default to 9 tags - const uint32_t num_tags = config["num-tags"].isUInt() ? config_["num-tags"].asUInt() : 9; + // Default to 9 tags, cap at 32 + const uint32_t num_tags = + config["num-tags"].isUInt() ? std::min(32, config_["num-tags"].asUInt()) : 9; std::vector tag_labels(num_tags); for (uint32_t tag = 0; tag < num_tags; ++tag) { @@ -129,4 +140,16 @@ void Tags::handle_view_tags(struct wl_array *view_tags) { } } +void Tags::handle_urgent_tags(uint32_t tags) { + uint32_t i = 0; + for (auto &button : buttons_) { + if ((1 << i) & tags) { + button.get_style_context()->add_class("urgent"); + } else { + button.get_style_context()->remove_class("urgent"); + } + ++i; + } +} + } /* namespace waybar::modules::river */