Fixup headless output names

We use the headless backend to create a special fallback output
used when no other output is connected. However this messes up the
"real" headless output names users have come to expect (e.g.
currently the first headless output will be named "HEADLESS-2"
instead of "HEADLESS-1").

Fix this by setting the output name with [1].

[1]: https://gitlab.freedesktop.org/wlroots/wlroots/-/merge_requests/3395
This commit is contained in:
Simon Ser 2021-12-09 15:55:58 +01:00 committed by Simon Zeni
parent 1eaa61f503
commit 3f58f12617
2 changed files with 11 additions and 0 deletions

View File

@ -5,6 +5,7 @@
#include <time.h> #include <time.h>
#include <wayland-server-core.h> #include <wayland-server-core.h>
#include <wlr/backend/drm.h> #include <wlr/backend/drm.h>
#include <wlr/backend/headless.h>
#include <wlr/render/wlr_renderer.h> #include <wlr/render/wlr_renderer.h>
#include <wlr/types/wlr_buffer.h> #include <wlr/types/wlr_buffer.h>
#include <wlr/types/wlr_drm_lease_v1.h> #include <wlr/types/wlr_drm_lease_v1.h>
@ -833,13 +834,22 @@ static void handle_present(struct wl_listener *listener, void *data) {
output->refresh_nsec = output_event->refresh; output->refresh_nsec = output_event->refresh;
} }
static unsigned int last_headless_num = 0;
void handle_new_output(struct wl_listener *listener, void *data) { void handle_new_output(struct wl_listener *listener, void *data) {
struct sway_server *server = wl_container_of(listener, server, new_output); struct sway_server *server = wl_container_of(listener, server, new_output);
struct wlr_output *wlr_output = data; struct wlr_output *wlr_output = data;
if (wlr_output == root->fallback_output->wlr_output) { if (wlr_output == root->fallback_output->wlr_output) {
return; return;
} }
if (wlr_output_is_headless(wlr_output)) {
char name[64];
snprintf(name, sizeof(name), "HEADLESS-%u", ++last_headless_num);
wlr_output_set_name(wlr_output, name);
}
sway_log(SWAY_DEBUG, "New output %p: %s (non-desktop: %d)", sway_log(SWAY_DEBUG, "New output %p: %s (non-desktop: %d)",
wlr_output, wlr_output->name, wlr_output->non_desktop); wlr_output, wlr_output->name, wlr_output->non_desktop);

View File

@ -227,6 +227,7 @@ bool server_init(struct sway_server *server) {
struct wlr_output *wlr_output = struct wlr_output *wlr_output =
wlr_headless_add_output(server->headless_backend, 800, 600); wlr_headless_add_output(server->headless_backend, 800, 600);
wlr_output_set_name(wlr_output, "FALLBACK");
root->fallback_output = output_create(wlr_output); root->fallback_output = output_create(wlr_output);
// This may have been set already via -Dtxn-timeout // This may have been set already via -Dtxn-timeout