module/river: add ‘per-output’ attribute

When set, river tags and seats’ view titles apply to the output yambar
is on, only.

The default is disabled, which implements the old behavior, where
river tags and seats’ view titles represent the union of all
outputs.
This commit is contained in:
Daniel Eklöf 2021-08-02 19:31:01 +02:00
parent 1c6c73928b
commit ba7b9e6244
No known key found for this signature in database
GPG key ID: 5BBD4992C116573F
3 changed files with 41 additions and 12 deletions

View file

@ -17,6 +17,7 @@
individually. `border.width` is now a short-hand for setting all
four borders to the same value
(https://codeberg.org/dnkl/yambar/issues/77).
* river: `per-output: false|true`.
### Changed

View file

@ -12,8 +12,8 @@ about the river tags.
It has an interface similar to the i3/sway module.
The configuration for the river module specifies one _title_ particle,
which will be instantiated with tags representing the currently active
seat and the currently focused view's title.
which will be instantiated once for each seat, with tags representing
the seats' name and the title of the seats' currently focused view.
It also specifies a _content_ template particle, which is instantiated
once for all 32 river tags. This means you probably want to use a
@ -41,10 +41,10 @@ once for all 32 river tags. This means you probably want to use a
: Set to *focused* if _focused_ is true, *unfocused* if _visible_ is true, but _focused_ is false, or *invisible* if the river tag is not visible on any monitors.
| seat
: string
: The name of the currently active seat (*title* particle only, see CONFIGURATION)
: The name of the seat (*title* particle only, see CONFIGURATION)
| title
: string
: The focused view's title (*title* particle only, see CONFIGURATION)
: The seat's focused view's title (*title* particle only, see CONFIGURATION)
# CONFIGURATION
@ -60,6 +60,12 @@ once for all 32 river tags. This means you probably want to use a
: particle
: yes
: Template particle that will be instantiated once for all of the 32 river tags.
| per-output
: bool
: no
: When set to false (the default), tags reflect the union of all
outputs. When set to true, tags reflect river tags and seats for
the output yambar is on only.
# EXAMPLES

View file

@ -48,6 +48,7 @@ struct private {
struct zriver_status_manager_v1 *status_manager;
struct particle *template;
struct particle *title;
bool per_output;
bool is_starting_up;
tll(struct output) outputs;
@ -76,6 +77,8 @@ content(struct module *mod)
{
const struct private *m = mod->private;
const char *output_bar_is_on = mod->bar->output_name(mod->bar);
mtx_lock(&m->mod->lock);
uint32_t output_focused = 0;
@ -85,6 +88,13 @@ content(struct module *mod)
tll_foreach(m->outputs, it) {
const struct output *output = &it->item;
if (m->per_output &&
output_bar_is_on != NULL && output->name != NULL &&
strcmp(output->name, output_bar_is_on) != 0)
{
continue;
}
output_focused |= output->focused;
occupied |= output->occupied;
@ -348,7 +358,6 @@ unfocused_output(void *data, struct zriver_seat_status_v1 *zriver_seat_status_v1
mtx_lock(&mod->lock);
{
struct output *output = NULL;
tll_foreach(m->outputs, it) {
if (it->item.wl_output == wl_output) {
@ -382,6 +391,13 @@ focused_view(void *data, struct zriver_seat_status_v1 *zriver_seat_status_v1,
LOG_DBG("seat: %s: focused view: %s", seat->name, title);
const char *output_bar_is_on = mod->bar->output_name(mod->bar);
if (!seat->m->per_output ||
(output_bar_is_on != NULL &&
seat->output != NULL && seat->output->name != NULL &&
strcmp(output_bar_is_on, seat->output->name) == 0))
{
mtx_lock(&mod->lock);
{
free(seat->title);
@ -390,6 +406,7 @@ focused_view(void *data, struct zriver_seat_status_v1 *zriver_seat_status_v1,
mtx_unlock(&mod->lock);
mod->bar->refresh(mod->bar);
}
}
static const struct zriver_seat_status_v1_listener river_seat_status_listener = {
.focused_output = &focused_output,
@ -646,11 +663,12 @@ out:
}
static struct module *
river_new(struct particle *template, struct particle *title)
river_new(struct particle *template, struct particle *title, bool per_output)
{
struct private *m = calloc(1, sizeof(*m));
m->template = template;
m->title = title;
m->per_output = per_output;
m->is_starting_up = true;
struct module *mod = module_common_new();
@ -668,9 +686,12 @@ from_conf(const struct yml_node *node, struct conf_inherit inherited)
{
const struct yml_node *c = yml_get_value(node, "content");
const struct yml_node *title = yml_get_value(node, "title");
const struct yml_node *per_output = yml_get_value(node, "per-output");
return river_new(
conf_to_particle(c, inherited),
title != NULL ? conf_to_particle(title, inherited) : NULL);
title != NULL ? conf_to_particle(title, inherited) : NULL,
per_output != NULL ? yml_value_as_bool(per_output) : false);
}
static bool
@ -678,6 +699,7 @@ verify_conf(keychain_t *chain, const struct yml_node *node)
{
static const struct attr_info attrs[] = {
{"title", false, &conf_verify_particle},
{"per-output", false, &conf_verify_bool},
MODULE_COMMON_ATTRS,
};