output: introduce wlr_output_set_name

wlroots picks names for all outputs, but it might be desirable for
compositor to override it.

For instance, Sway will use a headless output as a fallback in
case no outputs are connected. Sway wants to clearly label the
fallback output as such and label "real" headless outputs starting
from HEADLESS-1.
This commit is contained in:
Simon Ser 2021-12-09 15:43:19 +01:00
parent 1fbd13ec79
commit 36a2b19485
6 changed files with 33 additions and 9 deletions

View file

@ -1299,8 +1299,7 @@ void scan_drm_connectors(struct wlr_drm_backend *drm,
wlr_output_init(&wlr_conn->output, &drm->backend, &output_impl, wlr_output_init(&wlr_conn->output, &drm->backend, &output_impl,
drm->display); drm->display);
memcpy(wlr_conn->output.name, wlr_conn->name, wlr_output_set_name(&wlr_conn->output, wlr_conn->name);
sizeof(wlr_conn->output.name));
wlr_conn->output.phys_width = drm_conn->mmWidth; wlr_conn->output.phys_width = drm_conn->mmWidth;
wlr_conn->output.phys_height = drm_conn->mmHeight; wlr_conn->output.phys_height = drm_conn->mmHeight;

View file

@ -116,8 +116,10 @@ struct wlr_output *wlr_headless_add_output(struct wlr_backend *wlr_backend,
output_set_custom_mode(output, width, height, 0); output_set_custom_mode(output, width, height, 0);
strncpy(wlr_output->make, "headless", sizeof(wlr_output->make)); strncpy(wlr_output->make, "headless", sizeof(wlr_output->make));
strncpy(wlr_output->model, "headless", sizeof(wlr_output->model)); strncpy(wlr_output->model, "headless", sizeof(wlr_output->model));
snprintf(wlr_output->name, sizeof(wlr_output->name), "HEADLESS-%zd",
++backend->last_output_num); char name[64];
snprintf(name, sizeof(name), "HEADLESS-%zd", ++backend->last_output_num);
wlr_output_set_name(wlr_output, name);
char description[128]; char description[128];
snprintf(description, sizeof(description), snprintf(description, sizeof(description),

View file

@ -520,8 +520,10 @@ struct wlr_output *wlr_wl_output_create(struct wlr_backend *wlr_backend) {
wlr_output_update_custom_mode(wlr_output, 1280, 720, 0); wlr_output_update_custom_mode(wlr_output, 1280, 720, 0);
strncpy(wlr_output->make, "wayland", sizeof(wlr_output->make)); strncpy(wlr_output->make, "wayland", sizeof(wlr_output->make));
strncpy(wlr_output->model, "wayland", sizeof(wlr_output->model)); strncpy(wlr_output->model, "wayland", sizeof(wlr_output->model));
snprintf(wlr_output->name, sizeof(wlr_output->name), "WL-%zd",
++backend->last_output_num); char name[64];
snprintf(name, sizeof(name), "WL-%zd", ++backend->last_output_num);
wlr_output_set_name(wlr_output, name);
char description[128]; char description[128];
snprintf(description, sizeof(description), snprintf(description, sizeof(description),

View file

@ -512,8 +512,10 @@ struct wlr_output *wlr_x11_output_create(struct wlr_backend *backend) {
wlr_output_update_custom_mode(wlr_output, 1024, 768, 0); wlr_output_update_custom_mode(wlr_output, 1024, 768, 0);
snprintf(wlr_output->name, sizeof(wlr_output->name), "X11-%zd", char name[64];
++x11->last_output_num); snprintf(name, sizeof(name), "X11-%zd", ++x11->last_output_num);
wlr_output_set_name(wlr_output, name);
parse_xcb_setup(wlr_output, x11->xcb); parse_xcb_setup(wlr_output, x11->xcb);
char description[128]; char description[128];

View file

@ -118,7 +118,7 @@ struct wlr_output {
struct wl_global *global; struct wl_global *global;
struct wl_list resources; struct wl_list resources;
char name[24]; char *name;
char *description; // may be NULL char *description; // may be NULL
char make[56]; char make[56];
char model[16]; char model[16];
@ -336,6 +336,17 @@ void wlr_output_set_render_format(struct wlr_output *output, uint32_t format);
void wlr_output_set_scale(struct wlr_output *output, float scale); void wlr_output_set_scale(struct wlr_output *output, float scale);
void wlr_output_set_subpixel(struct wlr_output *output, void wlr_output_set_subpixel(struct wlr_output *output,
enum wl_output_subpixel subpixel); enum wl_output_subpixel subpixel);
/**
* Set the output name.
*
* Output names are subject to the following rules:
*
* - Each output name must be unique.
* - The name cannot change after the output has been advertised to clients.
*
* For more details, see the protocol documentation for wl_output.name.
*/
void wlr_output_set_name(struct wlr_output *output, const char *name);
void wlr_output_set_description(struct wlr_output *output, const char *desc); void wlr_output_set_description(struct wlr_output *output, const char *desc);
/** /**
* Schedule a done event. * Schedule a done event.

View file

@ -324,6 +324,13 @@ void wlr_output_set_subpixel(struct wlr_output *output,
wlr_output_schedule_done(output); wlr_output_schedule_done(output);
} }
void wlr_output_set_name(struct wlr_output *output, const char *name) {
assert(output->global == NULL);
free(output->name);
output->name = strdup(name);
}
void wlr_output_set_description(struct wlr_output *output, const char *desc) { void wlr_output_set_description(struct wlr_output *output, const char *desc) {
if (output->description != NULL && desc != NULL && if (output->description != NULL && desc != NULL &&
strcmp(output->description, desc) == 0) { strcmp(output->description, desc) == 0) {
@ -420,6 +427,7 @@ void wlr_output_destroy(struct wlr_output *output) {
wl_event_source_remove(output->idle_done); wl_event_source_remove(output->idle_done);
} }
free(output->name);
free(output->description); free(output->description);
pixman_region32_fini(&output->pending.damage); pixman_region32_fini(&output->pending.damage);