Add optional headless fallback output

This allows configuring a headless fallback output that
is automatically created whenever there is no other output
around. It is destroyed when a new output is discovered.

It can be enabled by setting the environment variable
LABWC_FALLBACK_OUTPUT to the desired output name.

The feature benefits applications like wayvnc the most
as there is always an output available to connect to.

Co-Authored-By: Simon Long <simon@raspberrypi.com>
This commit is contained in:
Consolatis 2024-03-07 02:11:46 +01:00
parent e00f7cd6db
commit 60aab98e8d
5 changed files with 63 additions and 1 deletions

View file

@ -1,10 +1,14 @@
// SPDX-License-Identifier: GPL-2.0-only
#include <stdlib.h>
#include <wlr/backend/headless.h>
#include <wlr/types/wlr_output.h>
#include "common/string-helpers.h"
#include "labwc.h"
#include "output-virtual.h"
static struct wlr_output *fallback_output = NULL;
void
output_virtual_add(struct server *server, const char *output_name,
struct wlr_output **store_wlr_output)
@ -77,7 +81,8 @@ output_virtual_remove(struct server *server, const char *output_name)
{
struct output *output;
wl_list_for_each(output, &server->outputs, link) {
if (!wlr_output_is_headless(output->wlr_output)) {
if (!wlr_output_is_headless(output->wlr_output)
|| output->wlr_output == fallback_output) {
continue;
}
@ -100,3 +105,32 @@ output_virtual_remove(struct server *server, const char *output_name)
}
}
}
void
output_virtual_update_fallback(struct server *server)
{
struct wl_list *layout_outputs = &server->output_layout->outputs;
const char *fallback_output_name = getenv("LABWC_FALLBACK_OUTPUT");
if (!fallback_output && wl_list_empty(layout_outputs)
&& !string_null_or_empty(fallback_output_name)) {
wlr_log(WLR_DEBUG, "adding fallback output %s", fallback_output_name);
output_virtual_add(server, fallback_output_name, &fallback_output);
} else if (fallback_output && (wl_list_length(layout_outputs) > 1
|| string_null_or_empty(fallback_output_name))) {
wlr_log(WLR_DEBUG, "destroying fallback output %s",
fallback_output->name);
/*
* We must reset fallback_output to NULL before destroying it.
*
* Otherwise we may end up trying to destroy the same wlr_output
* twice due to wlr_output_destroy() removing the output from the
* layout which in turn causes us to be called again.
*/
struct wlr_output *wlr_output = fallback_output;
fallback_output = NULL;
wlr_output_destroy(wlr_output);
}
}