diff --git a/CHANGELOG.md b/CHANGELOG.md index 381737b..14bd53c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/doc/yambar-modules-river.5.scd b/doc/yambar-modules-river.5.scd index 7f2920f..3bf3b61 100644 --- a/doc/yambar-modules-river.5.scd +++ b/doc/yambar-modules-river.5.scd @@ -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: diff --git a/external/river-status-unstable-v1.xml b/external/river-status-unstable-v1.xml index 6a74256..e9629dd 100644 --- a/external/river-status-unstable-v1.xml +++ b/external/river-status-unstable-v1.xml @@ -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. @@ -83,6 +83,21 @@ + + + + Sent once on binding the interface should a layout name exist and again + whenever the name changes. + + + + + + + Sent when the current layout name has been removed without a new one + being set, for example when the active layout generator disconnects. + + diff --git a/modules/river.c b/modules/river.c index 059a44e..2273166 100644 --- a/modules/river.c +++ b/modules/river.c @@ -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)