···31493149 * prioritized in the list of displays, as exposed by calling
31503150 * SDL_GetDisplays(), with the first listed becoming the primary display. The
31513151 * naming convention can vary depending on the environment, but it is usually
31523152- * a connector name (e.g. 'DP-1', 'DP-2', 'HDMI-1', etc...).
31523152+ * a connector name (e.g. 'DP-1', 'DP-2', 'HDMI-A-1',etc...).
31533153 *
31543154- * On X11 and Wayland desktops, the connector names associated with displays
31543154+ * On Wayland and X11 desktops, the connector names associated with displays
31553155 * can typically be found by using the `xrandr` utility.
31563156 *
31573157 * This hint is currently supported on the following drivers:
31583158 *
31593159+ * - KMSDRM (kmsdrm)
31593160 * - Wayland (wayland)
31603161 *
31613162 * This hint should be set before SDL is initialized.
···799799 SDL_DisplayModeData *modedata = NULL;
800800 drmModeEncoder *encoder = NULL;
801801 drmModeCrtc *crtc = NULL;
802802+ const char *connector_type = NULL;
802803 SDL_DisplayID display_id;
803804 SDL_PropertiesID display_properties;
805805+ char name_fmt[64];
804806 int orientation;
805807 int mode_index;
806808 int i, j;
···963965 KMSDRM_CrtcSetVrr(viddata->drm_fd, crtc->crtc_id, true);
964966 }
965967968968+ // Set the name by the connector type, if possible
969969+ if (KMSDRM_drmModeGetConnectorTypeName) {
970970+ connector_type = KMSDRM_drmModeGetConnectorTypeName(connector->connector_type);
971971+ if (connector_type == NULL) {
972972+ connector_type = "Unknown";
973973+ }
974974+ SDL_snprintf(name_fmt, sizeof(name_fmt), "%s-%u", connector_type, connector->connector_type_id);
975975+ }
976976+966977 /*****************************************/
967978 // Part 2: setup the SDL_Display itself.
968979 /*****************************************/
···984995 CalculateRefreshRate(&dispdata->mode, &display.desktop_mode.refresh_rate_numerator, &display.desktop_mode.refresh_rate_denominator);
985996 display.desktop_mode.format = SDL_PIXELFORMAT_ARGB8888;
986997 display.desktop_mode.internal = modedata;
998998+ if (connector_type) {
999999+ display.name = name_fmt;
10001000+ }
98710019881002 // Add the display to the list of SDL displays.
9891003 display_id = SDL_AddVideoDisplay(&display, false);
···10161030 }
10171031} // NOLINT(clang-analyzer-unix.Malloc): If no error `dispdata` is saved in the display
1018103210331033+static void KMSDRM_SortDisplays(SDL_VideoDevice *_this)
10341034+{
10351035+ const char *name_hint = SDL_GetHint(SDL_HINT_VIDEO_DISPLAY_PRIORITY);
10361036+10371037+ if (name_hint) {
10381038+ char *saveptr;
10391039+ char *str = SDL_strdup(name_hint);
10401040+ SDL_VideoDisplay **sorted_list = SDL_malloc(sizeof(SDL_VideoDisplay *) * _this->num_displays);
10411041+10421042+ if (str && sorted_list) {
10431043+ int sorted_index = 0;
10441044+10451045+ // Sort the requested displays to the front of the list.
10461046+ const char *token = SDL_strtok_r(str, ",", &saveptr);
10471047+ while (token) {
10481048+ for (int i = 0; i < _this->num_displays; ++i) {
10491049+ SDL_VideoDisplay *d = _this->displays[i];
10501050+ if (d && SDL_strcmp(token, d->name) == 0) {
10511051+ sorted_list[sorted_index++] = d;
10521052+ _this->displays[i] = NULL;
10531053+ break;
10541054+ }
10551055+ }
10561056+10571057+ token = SDL_strtok_r(NULL, ",", &saveptr);
10581058+ }
10591059+10601060+ // Append the remaining displays to the end of the list.
10611061+ for (int i = 0; i < _this->num_displays; ++i) {
10621062+ if (_this->displays[i]) {
10631063+ sorted_list[sorted_index++] = _this->displays[i];
10641064+ }
10651065+ }
10661066+10671067+ // Copy the sorted list back to the display list.
10681068+ SDL_memcpy(_this->displays, sorted_list, sizeof(SDL_VideoDisplay *) * _this->num_displays);
10691069+ }
10701070+10711071+ SDL_free(str);
10721072+ SDL_free(sorted_list);
10731073+ }
10741074+}
10751075+10191076/* Initializes the list of SDL displays: we build a new display for each
10201077 connecter connector we find.
10211078 This is to be called early, in VideoInit(), because it gets us
···10771134 result = SDL_SetError("No connected displays found.");
10781135 goto cleanup;
10791136 }
11371137+11381138+ // Sort the displays, if necessary
11391139+ KMSDRM_SortDisplays(_this);
1080114010811141 // Determine if video hardware supports async pageflips.
10821142 if (KMSDRM_drmGetCap(viddata->drm_fd, DRM_CAP_ASYNC_PAGE_FLIP, &async_pageflip) != 0) {