wayland: Use the output descriptions from xdg-output when available

Some compositors will provide 'nicer' / 'human readable' output descriptions via the xdg-output protocol. Use these description strings, when available, instead of the model name provided by wl-output.  On compositors such as GNOME where this is provided, the display names provided to applications by SDL will now match those in the desktop display settings panel.  On compositors where this data isn't provided, the old behavior of using the model string provided by wl-output will remain unchanged.

Additionally, per the protocol spec, output data provided by xdg-output should supersede wl-output data, so this is the recommended behavior in general.
This commit is contained in:
Frank Praznik 2022-06-14 10:41:18 -04:00 committed by Ethan Lee
parent 714502d373
commit e427e80bfe
1 changed files with 13 additions and 1 deletions

View File

@ -354,6 +354,16 @@ static void
xdg_output_handle_description(void *data, struct zxdg_output_v1 *xdg_output, xdg_output_handle_description(void *data, struct zxdg_output_v1 *xdg_output,
const char *description) const char *description)
{ {
SDL_WaylandOutputData* driverdata = data;
if (driverdata->index == -1) {
/* xdg-output descriptions, if available, supersede wl-output model names. */
if (driverdata->placeholder.name != NULL) {
SDL_free(driverdata->placeholder.name);
}
driverdata->placeholder.name = SDL_strdup(description);
}
} }
static const struct zxdg_output_v1_listener xdg_output_listener = { static const struct zxdg_output_v1_listener xdg_output_listener = {
@ -477,7 +487,9 @@ display_handle_geometry(void *data,
} }
driverdata->physical_width = physical_width; driverdata->physical_width = physical_width;
driverdata->physical_height = physical_height; driverdata->physical_height = physical_height;
if (driverdata->index == -1) {
/* The output name is only set if xdg-output hasn't provided a description. */
if (driverdata->index == -1 && driverdata->placeholder.name == NULL) {
driverdata->placeholder.name = SDL_strdup(model); driverdata->placeholder.name = SDL_strdup(model);
} }