wayland: Expose displays in a deterministic order, and attempt to better handle selecting a primary display.

Wayland can expose displays in any arbitrary order, and doesn't have the native concept of a primary display. However, there are games that presume that the first listed display is the primary, which can lead to problems if that output isn't necessarily the ideal one, as they may use that display to build a resolution list or as the default fullscreen output. This sorts displays by position, then attempts to find the primary display, first by querying the explicit ordering hint, then the GNOME DBus property, then tries to determine the 'best' display according to the criteria that is generally ideal for games and media playback.

The makes the list of displays deterministic, as long as the desktop configuration remains static, with a reasonably appropriate one prioritized as primary, even if there is no explicit way to retrieve the primary display. In the case where a user has a particularly esoteric physical display configuration, the new hint enables explicitly overriding the sorting and selection logic, allowing the entire display order to be customized, if necessary.
This commit is contained in:
Frank Praznik
2024-10-13 14:14:10 -04:00
parent 075ae7db7d
commit 553fc5fe0e
4 changed files with 247 additions and 54 deletions

View File

@@ -3131,6 +3131,28 @@ extern "C" {
*/
#define SDL_HINT_VIDEO_ALLOW_SCREENSAVER "SDL_VIDEO_ALLOW_SCREENSAVER"
/**
* A comma separated list containing the names of the displays that SDL should
* sort to the front of the display list.
*
* When this hint is set, displays with matching name strings will be prioritized in
* the list of displays, as exposed by calling SDL_GetDisplays(), with the first listed
* becoming the primary display. The naming convention can vary depending on the environment,
* but it is usually a connector name (e.g. 'DP-1', 'DP-2', 'HDMI-1', etc...).
*
* On X11 and Wayland desktops, the connector names associated with displays can typically be
* found by using the `xrandr` utility.
*
* This hint is currently supported on the following drivers:
*
* - Wayland (wayland)
*
* This hint should be set before SDL is initialized.
*
* \since This hint is available since SDL 3.1.5.
*/
#define SDL_HINT_VIDEO_DISPLAY_PRIORITY "SDL_VIDEO_DISPLAY_PRIORITY"
/**
* Tell the video driver that we only want a double buffer.
*