windows: Get better name for the physical display, for Vista and later. Fixes #5321.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341
diff --git a/src/video/windows/SDL_windowsmodes.c b/src/video/windows/SDL_windowsmodes.c
index 03c2d4a..15d7724 100644
--- a/src/video/windows/SDL_windowsmodes.c
+++ b/src/video/windows/SDL_windowsmodes.c
@@ -196,6 +196,100 @@ WIN_GetDisplayMode(_THIS, LPCWSTR deviceName, DWORD index, SDL_DisplayMode * mod
return SDL_TRUE;
}
+/* The win32 API calls in this function require Windows Vista or later. */
+/* these are normally WINAPI but VS2017 is saying "warning C4229: anachronism used: modifiers on data are ignored" */
+typedef LONG (*SDL_WIN32PROC_GetDisplayConfigBufferSizes)(UINT32 flags, UINT32* numPathArrayElements, UINT32* numModeInfoArrayElements);
+typedef LONG (*SDL_WIN32PROC_QueryDisplayConfig)(UINT32 flags, UINT32* numPathArrayElements, DISPLAYCONFIG_PATH_INFO* pathArray, UINT32* numModeInfoArrayElements, DISPLAYCONFIG_MODE_INFO* modeInfoArray, DISPLAYCONFIG_TOPOLOGY_ID* currentTopologyId);
+typedef LONG (*SDL_WIN32PROC_DisplayConfigGetDeviceInfo)(DISPLAYCONFIG_DEVICE_INFO_HEADER* requestPacket);
+
+static char *
+WIN_GetDisplayNameVista(const WCHAR *deviceName)
+{
+ void *dll;
+ SDL_WIN32PROC_GetDisplayConfigBufferSizes pGetDisplayConfigBufferSizes;
+ SDL_WIN32PROC_QueryDisplayConfig pQueryDisplayConfig;
+ SDL_WIN32PROC_DisplayConfigGetDeviceInfo pDisplayConfigGetDeviceInfo;
+ DISPLAYCONFIG_PATH_INFO *paths = NULL;
+ DISPLAYCONFIG_MODE_INFO *modes = NULL;
+ char *retval = NULL;
+ UINT32 pathCount = 0;
+ UINT32 modeCount = 0;
+ UINT32 i;
+ LONG rc;
+
+ dll = SDL_LoadObject("USER32.DLL");
+ if (!dll) {
+ return NULL;
+ }
+
+ pGetDisplayConfigBufferSizes = (SDL_WIN32PROC_GetDisplayConfigBufferSizes) SDL_LoadFunction(dll, "GetDisplayConfigBufferSizes");
+ pQueryDisplayConfig = (SDL_WIN32PROC_QueryDisplayConfig) SDL_LoadFunction(dll, "QueryDisplayConfig");
+ pDisplayConfigGetDeviceInfo = (SDL_WIN32PROC_DisplayConfigGetDeviceInfo) SDL_LoadFunction(dll, "DisplayConfigGetDeviceInfo");
+
+ if (!pGetDisplayConfigBufferSizes || !pQueryDisplayConfig || !pDisplayConfigGetDeviceInfo) {
+ goto WIN_GetDisplayNameVista_failed;
+ }
+
+ do {
+ rc = pGetDisplayConfigBufferSizes(QDC_ONLY_ACTIVE_PATHS, &pathCount, &modeCount);
+ if (rc != ERROR_SUCCESS) {
+ goto WIN_GetDisplayNameVista_failed;
+ }
+
+ SDL_free(paths);
+ SDL_free(modes);
+
+ paths = (DISPLAYCONFIG_PATH_INFO *) SDL_malloc(sizeof (DISPLAYCONFIG_PATH_INFO) * pathCount);
+ modes = (DISPLAYCONFIG_MODE_INFO *) SDL_malloc(sizeof (DISPLAYCONFIG_MODE_INFO) * modeCount);
+ if ((paths == NULL) || (modes == NULL)) {
+ goto WIN_GetDisplayNameVista_failed;
+ }
+
+ rc = pQueryDisplayConfig(QDC_ONLY_ACTIVE_PATHS, &pathCount, paths, &modeCount, modes, 0);
+ } while (rc == ERROR_INSUFFICIENT_BUFFER);
+
+ if (rc == ERROR_SUCCESS) {
+ for (i = 0; i < pathCount; i++) {
+ DISPLAYCONFIG_SOURCE_DEVICE_NAME sourceName;
+ DISPLAYCONFIG_TARGET_DEVICE_NAME targetName;
+
+ SDL_zero(sourceName);
+ sourceName.header.adapterId = paths[i].targetInfo.adapterId;
+ sourceName.header.type = DISPLAYCONFIG_DEVICE_INFO_GET_SOURCE_NAME;
+ sourceName.header.size = sizeof (sourceName);
+ rc = pDisplayConfigGetDeviceInfo(&sourceName.header);
+ if (rc != ERROR_SUCCESS) {
+ break;
+ } else if (SDL_wcscmp(deviceName, sourceName.viewGdiDeviceName) != 0) {
+ continue;
+ }
+
+ SDL_zero(targetName);
+ targetName.header.adapterId = paths[i].targetInfo.adapterId;
+ targetName.header.id = paths[i].targetInfo.id;
+ targetName.header.type = DISPLAYCONFIG_DEVICE_INFO_GET_TARGET_NAME;
+ targetName.header.size = sizeof (targetName);
+ rc = pDisplayConfigGetDeviceInfo(&targetName.header);
+ if (rc == ERROR_SUCCESS) {
+ retval = WIN_StringToUTF8W(targetName.monitorFriendlyDeviceName);
+ }
+ break;
+ }
+ }
+
+ SDL_free(paths);
+ SDL_free(modes);
+ SDL_UnloadObject(dll);
+ return retval;
+
+WIN_GetDisplayNameVista_failed:
+ SDL_free(retval);
+ SDL_free(paths);
+ SDL_free(modes);
+ SDL_UnloadObject(dll);
+ return NULL;
+}
+
static SDL_bool
WIN_AddDisplay(_THIS, HMONITOR hMonitor, const MONITORINFOEXW *info, SDL_bool send_event)
{
@@ -204,7 +298,6 @@ WIN_AddDisplay(_THIS, HMONITOR hMonitor, const MONITORINFOEXW *info, SDL_bool se
SDL_DisplayData *displaydata;
SDL_DisplayMode mode;
SDL_DisplayOrientation orientation;
- DISPLAY_DEVICEW device;
#ifdef DEBUG_MODES
SDL_Log("Display: %s\n", WIN_StringToUTF8W(info->szDevice));
@@ -243,10 +336,16 @@ WIN_AddDisplay(_THIS, HMONITOR hMonitor, const MONITORINFOEXW *info, SDL_bool se
displaydata->IsValid = SDL_TRUE;
SDL_zero(display);
- device.cb = sizeof(device);
- if (EnumDisplayDevicesW(info->szDevice, 0, &device, 0)) {
- display.name = WIN_StringToUTF8W(device.DeviceString);
+ display.name = WIN_GetDisplayNameVista(info->szDevice);
+ if (display.name == NULL) {
+ DISPLAY_DEVICEW device;
+ SDL_zero(device);
+ device.cb = sizeof (device);
+ if (EnumDisplayDevicesW(info->szDevice, 0, &device, 0)) {
+ display.name = WIN_StringToUTF8W(device.DeviceString);
+ }
}
+
display.desktop_mode = mode;
display.current_mode = mode;
display.orientation = orientation;
diff --git a/src/video/windows/SDL_windowsvideo.h b/src/video/windows/SDL_windowsvideo.h
index f80ffde..50a4371 100644
--- a/src/video/windows/SDL_windowsvideo.h
+++ b/src/video/windows/SDL_windowsvideo.h
@@ -75,6 +75,203 @@ typedef struct _TOUCHINPUT {
DWORD cyContact;
} TOUCHINPUT, *PTOUCHINPUT;
+
+/* More-robust display information in Vista... */
+/* This is a huge amount of data to be stuffing into three API calls. :( */
+typedef struct DISPLAYCONFIG_PATH_SOURCE_INFO
+{
+ LUID adapterId;
+ UINT32 id;
+ union
+ {
+ UINT32 modeInfoIdx;
+ struct
+ {
+ UINT32 cloneGroupId : 16;
+ UINT32 sourceModeInfoIdx : 16;
+ } DUMMYSTRUCTNAME;
+ } DUMMYUNIONNAME;
+
+ UINT32 statusFlags;
+} DISPLAYCONFIG_PATH_SOURCE_INFO;
+
+typedef struct DISPLAYCONFIG_RATIONAL
+{
+ UINT32 Numerator;
+ UINT32 Denominator;
+} DISPLAYCONFIG_RATIONAL;
+
+typedef struct DISPLAYCONFIG_PATH_TARGET_INFO
+{
+ LUID adapterId;
+ UINT32 id;
+ union
+ {
+ UINT32 modeInfoIdx;
+ struct
+ {
+ UINT32 desktopModeInfoIdx : 16;
+ UINT32 targetModeInfoIdx : 16;
+ } DUMMYSTRUCTNAME;
+ } DUMMYUNIONNAME;
+ UINT32 /*DISPLAYCONFIG_VIDEO_OUTPUT_TECHNOLOGY*/ outputTechnology;
+ UINT32 /*DISPLAYCONFIG_ROTATION*/ rotation;
+ UINT32 /*DISPLAYCONFIG_SCALING*/ scaling;
+ DISPLAYCONFIG_RATIONAL refreshRate;
+ UINT32 /*DISPLAYCONFIG_SCANLINE_ORDERING*/ scanLineOrdering;
+ BOOL targetAvailable;
+ UINT32 statusFlags;
+} DISPLAYCONFIG_PATH_TARGET_INFO;
+
+typedef struct DISPLAYCONFIG_PATH_INFO
+{
+ DISPLAYCONFIG_PATH_SOURCE_INFO sourceInfo;
+ DISPLAYCONFIG_PATH_TARGET_INFO targetInfo;
+ UINT32 flags;
+} DISPLAYCONFIG_PATH_INFO;
+
+typedef enum
+{
+ DISPLAYCONFIG_MODE_INFO_TYPE_SOURCE = 1,
+ DISPLAYCONFIG_MODE_INFO_TYPE_TARGET = 2,
+ DISPLAYCONFIG_MODE_INFO_TYPE_DESKTOP_IMAGE = 3,
+ DISPLAYCONFIG_MODE_INFO_TYPE_FORCE_UINT32 = 0xFFFFFFFF
+} DISPLAYCONFIG_MODE_INFO_TYPE;
+
+typedef struct DISPLAYCONFIG_2DREGION
+{
+ UINT32 cx;
+ UINT32 cy;
+} DISPLAYCONFIG_2DREGION;
+
+typedef struct DISPLAYCONFIG_VIDEO_SIGNAL_INFO
+{
+ UINT64 pixelRate;
+ DISPLAYCONFIG_RATIONAL hSyncFreq;
+ DISPLAYCONFIG_RATIONAL vSyncFreq;
+ DISPLAYCONFIG_2DREGION activeSize;
+ DISPLAYCONFIG_2DREGION totalSize;
+
+ union
+ {
+ struct
+ {
+ UINT32 videoStandard : 16;
+
+ // Vertical refresh frequency divider
+ UINT32 vSyncFreqDivider : 6;
+
+ UINT32 reserved : 10;
+ } AdditionalSignalInfo;
+
+ UINT32 videoStandard;
+ } DUMMYUNIONNAME;
+
+ // Scan line ordering (e.g. progressive, interlaced).
+ UINT32 /*DISPLAYCONFIG_SCANLINE_ORDERING*/ scanLineOrdering;
+} DISPLAYCONFIG_VIDEO_SIGNAL_INFO;
+
+typedef struct DISPLAYCONFIG_SOURCE_MODE
+{
+ UINT32 width;
+ UINT32 height;
+ UINT32 /*DISPLAYCONFIG_PIXELFORMAT*/ pixelFormat;
+ POINTL position;
+} DISPLAYCONFIG_SOURCE_MODE;
+
+typedef struct DISPLAYCONFIG_TARGET_MODE
+{
+ DISPLAYCONFIG_VIDEO_SIGNAL_INFO targetVideoSignalInfo;
+} DISPLAYCONFIG_TARGET_MODE;
+
+typedef struct DISPLAYCONFIG_DESKTOP_IMAGE_INFO
+{
+ POINTL PathSourceSize;
+ RECTL DesktopImageRegion;
+ RECTL DesktopImageClip;
+} DISPLAYCONFIG_DESKTOP_IMAGE_INFO;
+
+typedef struct DISPLAYCONFIG_MODE_INFO
+{
+ DISPLAYCONFIG_MODE_INFO_TYPE infoType;
+ UINT32 id;
+ LUID adapterId;
+ union
+ {
+ DISPLAYCONFIG_TARGET_MODE targetMode;
+ DISPLAYCONFIG_SOURCE_MODE sourceMode;
+ DISPLAYCONFIG_DESKTOP_IMAGE_INFO desktopImageInfo;
+ } DUMMYUNIONNAME;
+} DISPLAYCONFIG_MODE_INFO;
+
+typedef enum DISPLAYCONFIG_TOPOLOGY_ID
+{
+ DISPLAYCONFIG_TOPOLOGY_INTERNAL = 0x00000001,
+ DISPLAYCONFIG_TOPOLOGY_CLONE = 0x00000002,
+ DISPLAYCONFIG_TOPOLOGY_EXTEND = 0x00000004,
+ DISPLAYCONFIG_TOPOLOGY_EXTERNAL = 0x00000008,
+ DISPLAYCONFIG_TOPOLOGY_FORCE_UINT32 = 0xFFFFFFFF
+} DISPLAYCONFIG_TOPOLOGY_ID;
+
+typedef enum
+{
+ DISPLAYCONFIG_DEVICE_INFO_GET_SOURCE_NAME = 1,
+ DISPLAYCONFIG_DEVICE_INFO_GET_TARGET_NAME = 2,
+ DISPLAYCONFIG_DEVICE_INFO_GET_TARGET_PREFERRED_MODE = 3,
+ DISPLAYCONFIG_DEVICE_INFO_GET_ADAPTER_NAME = 4,
+ DISPLAYCONFIG_DEVICE_INFO_SET_TARGET_PERSISTENCE = 5,
+ DISPLAYCONFIG_DEVICE_INFO_GET_TARGET_BASE_TYPE = 6,
+ DISPLAYCONFIG_DEVICE_INFO_GET_SUPPORT_VIRTUAL_RESOLUTION = 7,
+ DISPLAYCONFIG_DEVICE_INFO_SET_SUPPORT_VIRTUAL_RESOLUTION = 8,
+ DISPLAYCONFIG_DEVICE_INFO_GET_ADVANCED_COLOR_INFO = 9,
+ DISPLAYCONFIG_DEVICE_INFO_SET_ADVANCED_COLOR_STATE = 10,
+ DISPLAYCONFIG_DEVICE_INFO_GET_SDR_WHITE_LEVEL = 11,
+ DISPLAYCONFIG_DEVICE_INFO_FORCE_UINT32 = 0xFFFFFFFF
+} DISPLAYCONFIG_DEVICE_INFO_TYPE;
+
+typedef struct DISPLAYCONFIG_DEVICE_INFO_HEADER
+{
+ DISPLAYCONFIG_DEVICE_INFO_TYPE type;
+ UINT32 size;
+ LUID adapterId;
+ UINT32 id;
+} DISPLAYCONFIG_DEVICE_INFO_HEADER;
+
+typedef struct DISPLAYCONFIG_SOURCE_DEVICE_NAME
+{
+ DISPLAYCONFIG_DEVICE_INFO_HEADER header;
+ WCHAR viewGdiDeviceName[CCHDEVICENAME];
+} DISPLAYCONFIG_SOURCE_DEVICE_NAME;
+
+typedef struct DISPLAYCONFIG_TARGET_DEVICE_NAME_FLAGS
+{
+ union
+ {
+ struct
+ {
+ UINT32 friendlyNameFromEdid : 1;
+ UINT32 friendlyNameForced : 1;
+ UINT32 edidIdsValid : 1;
+ UINT32 reserved : 29;
+ } DUMMYSTRUCTNAME;
+ UINT32 value;
+ } DUMMYUNIONNAME;
+} DISPLAYCONFIG_TARGET_DEVICE_NAME_FLAGS;
+
+typedef struct DISPLAYCONFIG_TARGET_DEVICE_NAME
+{
+ DISPLAYCONFIG_DEVICE_INFO_HEADER header;
+ DISPLAYCONFIG_TARGET_DEVICE_NAME_FLAGS flags;
+ UINT32 /*DISPLAYCONFIG_VIDEO_OUTPUT_TECHNOLOGY*/ outputTechnology;
+ UINT16 edidManufactureId;
+ UINT16 edidProductCodeId;
+ UINT32 connectorInstance;
+ WCHAR monitorFriendlyDeviceName[64];
+ WCHAR monitorDevicePath[128];
+} DISPLAYCONFIG_TARGET_DEVICE_NAME;
+
+#define QDC_ONLY_ACTIVE_PATHS 0x00000002
+
#endif /* WINVER < 0x0601 */
#if WINVER < 0x0603