# XDG_CURRENT_DESKTOP=wlroots
+##
+## This causes a virtual output to be created automatically whenever there
+## are no outputs around. This helps for cases like wayvnc so there is always
+## an output available to connect to. The name can be chosen freely but there
+## must be no duplicate output names, for this reason using VIRTUAL-x or a
+## physical connector name like HDMI-A-1 is not recommended as wlroots may
+## want to create outputs with those names later on which would then fail.
+##
+## Using an output name that starts with NOOP- has the additional benefit
+## that wayvnc will detect it being a virtual output and allow clients to
+## resize the output to match the client resolution.
+##
+
+# LABWC_FALLBACK_OUTPUT=NOOP-fallback
+
// 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)
{
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;
}
}
}
}
+
+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);
+ }
+}
#include "labwc.h"
#include "layers.h"
#include "node.h"
+#include "output-virtual.h"
#include "regions.h"
#include "view.h"
#include "xwayland.h"
{
struct server *server =
wl_container_of(listener, server, output_layout_change);
+
+ /* Prevents unnecessary layout recalculations */
+ server->pending_output_layout_change++;
+ output_virtual_update_fallback(server);
+ server->pending_output_layout_change--;
+
do_output_layout_change(server);
}
#include "labwc.h"
#include "layers.h"
#include "menu/menu.h"
+#include "output-virtual.h"
#include "regions.h"
#include "resize_indicator.h"
#include "theme.h"
{
session_environment_init();
reload_config_and_theme();
+ output_virtual_update_fallback(g_server);
return 0;
}
exit(EXIT_FAILURE);
}
+ /* Potentially set up the initial fallback output */
+ output_virtual_update_fallback(server);
+
if (setenv("WAYLAND_DISPLAY", socket, true) < 0) {
wlr_log_errno(WLR_ERROR, "unable to set WAYLAND_DISPLAY");
} else {