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.
This commit is contained in:
Isaac Freund 2021-08-19 14:59:25 +02:00
parent c413c1ec23
commit 024fd42e27
No known key found for this signature in database
GPG Key ID: 86DED400DDFD7A11
4 changed files with 43 additions and 8 deletions

View File

@ -18,6 +18,7 @@ class Tags : public waybar::AModule {
// Handlers for wayland events // Handlers for wayland events
void handle_focused_tags(uint32_t tags); void handle_focused_tags(uint32_t tags);
void handle_view_tags(struct wl_array *tags); void handle_view_tags(struct wl_array *tags);
void handle_urgent_tags(uint32_t tags);
struct zriver_status_manager_v1 *status_manager_; struct zriver_status_manager_v1 *status_manager_;

View File

@ -15,7 +15,7 @@ Addressed by *river/tags*
*num-tags*: ++ *num-tags*: ++
typeof: uint ++ typeof: uint ++
default: 9 ++ default: 9 ++
The number of tags that should be displayed. The number of tags that should be displayed. Max 32.
*tag-labels*: ++ *tag-labels*: ++
typeof: array ++ typeof: array ++
@ -34,8 +34,10 @@ Addressed by *river/tags*
- *#tags button* - *#tags button*
- *#tags button.occupied* - *#tags button.occupied*
- *#tags button.focused* - *#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 # SEE ALSO

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<protocol name="river_status_unstable_v1"> <protocol name="river_status_unstable_v1">
<copyright> <copyright>
Copyright 2020 Isaac Freund Copyright 2020 The River Developers
Permission to use, copy, modify, and/or distribute this software for any Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above 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. OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
</copyright> </copyright>
<interface name="zriver_status_manager_v1" version="1"> <interface name="zriver_status_manager_v1" version="2">
<description summary="manage river status objects"> <description summary="manage river status objects">
A global factory for objects that receive status information specific A global factory for objects that receive status information specific
to river. It could be used to implement, for example, a status bar. to river. It could be used to implement, for example, a status bar.
@ -47,7 +47,7 @@
</request> </request>
</interface> </interface>
<interface name="zriver_output_status_v1" version="1"> <interface name="zriver_output_status_v1" version="2">
<description summary="track output tags and focus"> <description summary="track output tags and focus">
This interface allows clients to receive information about the current This interface allows clients to receive information about the current
windowing state of an output. windowing state of an output.
@ -75,12 +75,21 @@
</description> </description>
<arg name="tags" type="array" summary="array of 32-bit bitfields"/> <arg name="tags" type="array" summary="array of 32-bit bitfields"/>
</event> </event>
<event name="urgent_tags" since="2">
<description summary="tags of the output with an urgent view">
Sent once on binding the interface and again whenever the set of
tags with at least one urgent view changes.
</description>
<arg name="tags" type="uint" summary="32-bit bitfield"/>
</event>
</interface> </interface>
<interface name="zriver_seat_status_v1" version="1"> <interface name="zriver_seat_status_v1" version="1">
<description summary="track seat focus"> <description summary="track seat focus">
This interface allows clients to receive information about the current 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.
</description> </description>
<request name="destroy" type="destructor"> <request name="destroy" type="destructor">

View File

@ -22,14 +22,24 @@ static void listen_view_tags(void *data, struct zriver_output_status_v1 *zriver_
static_cast<Tags *>(data)->handle_view_tags(tags); static_cast<Tags *>(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<Tags *>(data)->handle_urgent_tags(tags);
}
static const zriver_output_status_v1_listener output_status_listener_impl{ static const zriver_output_status_v1_listener output_status_listener_impl{
.focused_tags = listen_focused_tags, .focused_tags = listen_focused_tags,
.view_tags = listen_view_tags, .view_tags = listen_view_tags,
.urgent_tags = listen_urgent_tags,
}; };
static void handle_global(void *data, struct wl_registry *registry, uint32_t name, static void handle_global(void *data, struct wl_registry *registry, uint32_t name,
const char *interface, uint32_t version) { const char *interface, uint32_t version) {
if (std::strcmp(interface, zriver_status_manager_v1_interface.name) == 0) { if (std::strcmp(interface, zriver_status_manager_v1_interface.name) == 0) {
version = std::min<uint32_t>(version, 2);
if (version < ZRIVER_OUTPUT_STATUS_V1_URGENT_TAGS_SINCE_VERSION) {
spdlog::warn("river server does not support urgent tags");
}
static_cast<Tags *>(data)->status_manager_ = static_cast<struct zriver_status_manager_v1 *>( static_cast<Tags *>(data)->status_manager_ = static_cast<struct zriver_status_manager_v1 *>(
wl_registry_bind(registry, name, &zriver_status_manager_v1_interface, version)); 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_); event_box_.add(box_);
// Default to 9 tags // Default to 9 tags, cap at 32
const uint32_t num_tags = config["num-tags"].isUInt() ? config_["num-tags"].asUInt() : 9; const uint32_t num_tags =
config["num-tags"].isUInt() ? std::min<uint32_t>(32, config_["num-tags"].asUInt()) : 9;
std::vector<std::string> tag_labels(num_tags); std::vector<std::string> tag_labels(num_tags);
for (uint32_t tag = 0; tag < num_tags; ++tag) { 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 */ } /* namespace waybar::modules::river */