module/river: add support for ‘layout’ events

This commit is contained in:
Daniel Eklöf 2023-01-12 18:15:16 +01:00
parent f75168796a
commit 134ae847dc
No known key found for this signature in database
GPG key ID: 5BBD4992C116573F
4 changed files with 79 additions and 10 deletions

View file

@ -13,7 +13,8 @@
## Unreleased
### Added
* field width tag format option ([#246][246])
* Field width tag format option ([#246][246])
* river: support for layout events.
[246]: https://codeberg.org/dnkl/yambar/issues/246

View file

@ -54,14 +54,16 @@ once for all 32 river tags. This means you probably want to use a
:< *Description*
| seat
: string
: The name of the seat (*title* particle only, see CONFIGURATION)
: The name of the seat.
| title
: string
: The seat's focused view's title (*title* particle only, see CONFIGURATION)
: The seat's focused view's title.
| mode
: string
: The seat's current mode (entered with e.g. *riverctl enter-mode foobar*)
: The seat's current mode (entered with e.g. *riverctl enter-mode foobar*).
| layout
: string
: Current layout of the output currently focused by the seat.
# CONFIGURATION
@ -90,7 +92,7 @@ once for all 32 river tags. This means you probably want to use a
bar:
left:
- river:
title: {string: { text: "{seat} - {title} ({mode})" }}
title: {string: { text: "{seat} - {title} ({layout}/{mode})" }}
content:
map:
conditions:

View file

@ -16,7 +16,7 @@
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
</copyright>
<interface name="zriver_status_manager_v1" version="3">
<interface name="zriver_status_manager_v1" version="4">
<description summary="manage river status objects">
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 @@
</request>
</interface>
<interface name="zriver_output_status_v1" version="2">
<interface name="zriver_output_status_v1" version="4">
<description summary="track output tags and focus">
This interface allows clients to receive information about the current
windowing state of an output.
@ -83,6 +83,21 @@
</description>
<arg name="tags" type="uint" summary="32-bit bitfield"/>
</event>
<event name="layout_name" since="4">
<description summary="name of the layout">
Sent once on binding the interface should a layout name exist and again
whenever the name changes.
</description>
<arg name="name" type="string" summary="layout name"/>
</event>
<event name="layout_name_clear" since="4">
<description summary="name of the layout">
Sent when the current layout name has been removed without a new one
being set, for example when the active layout generator disconnects.
</description>
</event>
</interface>
<interface name="zriver_seat_status_v1" version="3">

View file

@ -32,6 +32,9 @@ struct output {
uint32_t occupied;
uint32_t focused;
uint32_t urgent;
/* Layout */
char *layout;
};
struct seat {
@ -154,14 +157,19 @@ content(struct module *mod)
size_t i = 32;
tll_foreach(m->seats, it) {
const struct seat *seat = &it->item;
const char *layout =
seat->output != NULL && seat->output->layout != NULL
? seat->output->layout
: "";
struct tag_set tags = {
.tags = (struct tag *[]){
tag_new_string(mod, "seat", seat->name),
tag_new_string(mod, "title", seat->title),
tag_new_string(mod, "mode", seat->mode),
tag_new_string(mod, "layout", layout),
},
.count = 3,
.count = 4,
};
tag_parts[i++] = m->title->instantiate(m->title, &tags);
@ -193,6 +201,7 @@ output_destroy(struct output *output)
seat->output = NULL;
}
free(output->name);
free(output->layout);
if (output->status != NULL)
zriver_output_status_v1_destroy(output->status);
if (output->xdg_output != NULL)
@ -270,11 +279,53 @@ urgent_tags(void *data, struct zriver_output_status_v1 *zriver_output_status_v1,
mod->bar->refresh(mod->bar);
}
#if defined(ZRIVER_OUTPUT_STATUS_V1_LAYOUT_NAME_SINCE_VERSION)
static void
layout_name(void *data,
struct zriver_output_status_v1 *zriver_output_status_v1,
const char *name)
{
struct output *output = data;
struct module *mod = output->m->mod;
mtx_lock(&mod->lock);
{
free(output->layout);
output->layout = name != NULL ? strdup(name) : NULL;
}
mtx_unlock(&mod->lock);
mod->bar->refresh(mod->bar);
}
#endif
#if defined(ZRIVER_OUTPUT_STATUS_V1_LAYOUT_NAME_CLEAR_SINCE_VERSION)
static void
layout_name_clear(void *data,
struct zriver_output_status_v1 *zriver_output_status_v1)
{
struct output *output = data;
struct module *mod = output->m->mod;
mtx_lock(&mod->lock);
{
free(output->layout);
output->layout = NULL;
}
mtx_unlock(&mod->lock);
mod->bar->refresh(mod->bar);
}
#endif
static const struct zriver_output_status_v1_listener river_status_output_listener = {
.focused_tags = &focused_tags,
.view_tags = &view_tags,
.urgent_tags = &urgent_tags,
#if defined(ZRIVER_OUTPUT_STATUS_V1_LAYOUT_NAME_SINCE_VERSION)
.layout_name = &layout_name,
#endif
#if defined(ZRIVER_OUTPUT_STATUS_V1_LAYOUT_NAME_CLEAR_SINCE_VERSION)
.layout_name_clear = &layout_name_clear,
#endif
};
static void
@ -599,7 +650,7 @@ handle_global(void *data, struct wl_registry *registry,
return;
m->status_manager = wl_registry_bind(
registry, name, &zriver_status_manager_v1_interface, min(version, 3));
registry, name, &zriver_status_manager_v1_interface, min(version, 4));
mtx_lock(&m->mod->lock);
tll_foreach(m->outputs, it)