2015-06-21 15:33:46 +00:00
|
|
|
/*
|
|
|
|
Simple DirectMedia Layer
|
2022-01-03 17:40:00 +00:00
|
|
|
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
2015-06-21 15:33:46 +00:00
|
|
|
|
|
|
|
This software is provided 'as-is', without any express or implied
|
|
|
|
warranty. In no event will the authors be held liable for any damages
|
|
|
|
arising from the use of this software.
|
|
|
|
|
|
|
|
Permission is granted to anyone to use this software for any purpose,
|
|
|
|
including commercial applications, and to alter it and redistribute it
|
|
|
|
freely, subject to the following restrictions:
|
|
|
|
|
|
|
|
1. The origin of this software must not be misrepresented; you must not
|
|
|
|
claim that you wrote the original software. If you use this software
|
|
|
|
in a product, an acknowledgment in the product documentation would be
|
|
|
|
appreciated but is not required.
|
|
|
|
2. Altered source versions must be plainly marked as such, and must not be
|
|
|
|
misrepresented as being the original software.
|
|
|
|
3. This notice may not be removed or altered from any source distribution.
|
|
|
|
*/
|
|
|
|
#include "../../SDL_internal.h"
|
|
|
|
|
2022-07-01 20:59:14 +00:00
|
|
|
#if SDL_VIDEO_DRIVER_WINDOWS && !defined(__XBOXONE__) && !defined(__XBOXSERIES__)
|
2015-06-21 15:33:46 +00:00
|
|
|
|
|
|
|
#include "SDL_windowsvideo.h"
|
2021-11-10 16:47:39 +00:00
|
|
|
#include "../../events/SDL_displayevents_c.h"
|
2015-06-21 15:33:46 +00:00
|
|
|
|
|
|
|
/* Windows CE compatibility */
|
|
|
|
#ifndef CDS_FULLSCREEN
|
|
|
|
#define CDS_FULLSCREEN 0
|
|
|
|
#endif
|
|
|
|
|
Fixed bug 3714 - Windows: SDL_WINDOW_FULLSCREEN_DESKTOP broken on 3 monitor setup w/ DPI scaling
Eric Wasylishen 2017-07-26 18:42:58 UTC
I set up an (admittedly exotic) 3-monitor setup, and when I enter fullscreen-desktop on the middle display (#2), the SDL window is off center. (covers half of monitor #2 and most of monitor #3).
The displays are arranged from left to right:
Display #1 (main): 2880x1800, 200% scaling
Display #2: 1920x1200, 150% scaling
Display #3: 1920x1080, 100% scaling
SDL display bounds:
INFO: Bounds: 1440x900 at 0,0
INFO: Bounds: 1281x801 at 1921,0 (these are incorrect)
INFO: Bounds: 1920x1080 at 4800,0
Correct bounds reported by calling EnumDisplayMonitors and printing the LPRECT param of the callback:
1440x900 at (0, 0)
1280x800 at (2880, 0)
1920x1080 at (4800, 0)
It seems like you need 3 displays to reproduce this, and the left two need DPI scaling, and the 3rd display needs to have a different scale factor than the others.
Related: https://bugzilla.libsdl.org/show_bug.cgi?id=3709
SDL: current hg (11235:6a587b9e0ec8)
Windows 10, Version 10.0.15063 Build 15063
Tested with testdraw2 and testgl2, and pressing alt+enter to enter fullscreen desktop.
This patch reworks SDL_windowsmodes.c to use EnumDisplayMonitors instead of EnumDisplayDevices, so we always have an HMONITOR for each SDL display.
With access to an HMONITOR, we can get the monitor bounds in virtual screen coordinates the proper way, by calling GetMonitorInfo. (whereas the original code was doing some calculations - e.g. "data->DeviceMode.dmPosition.x * data->ScaleX" - to try to get virtual screen coordinates. These worked in simple cases, but failed in more complex cases like this bug)
The one potential problem with my patch is, the ChangeDisplaySettingsEx docs say that you're supposed to get the display name from EnumDisplayDevices, but I'm getting the display name from GetMonitorInfo now.
2017-08-11 17:18:45 +00:00
|
|
|
/* #define DEBUG_MODES */
|
2022-06-07 08:01:27 +00:00
|
|
|
/* #define HIGHDPI_DEBUG_VERBOSE */
|
2015-07-30 00:18:56 +00:00
|
|
|
|
2022-11-30 20:51:59 +00:00
|
|
|
static void WIN_UpdateDisplayMode(_THIS, LPCWSTR deviceName, DWORD index, SDL_DisplayMode *mode)
|
2015-06-21 15:33:46 +00:00
|
|
|
{
|
2022-11-30 20:51:59 +00:00
|
|
|
SDL_DisplayModeData *data = (SDL_DisplayModeData *)mode->driverdata;
|
2015-06-21 15:33:46 +00:00
|
|
|
HDC hdc;
|
|
|
|
|
|
|
|
data->DeviceMode.dmFields =
|
|
|
|
(DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT | DM_DISPLAYFREQUENCY |
|
|
|
|
DM_DISPLAYFLAGS);
|
|
|
|
|
2022-12-01 21:07:03 +00:00
|
|
|
/* NOLINTNEXTLINE(bugprone-assignment-in-if-condition): No simple way to extract the assignment */
|
2022-11-30 20:51:59 +00:00
|
|
|
if (index == ENUM_CURRENT_SETTINGS && (hdc = CreateDC(deviceName, NULL, NULL, NULL)) != NULL) {
|
2015-06-21 15:33:46 +00:00
|
|
|
char bmi_data[sizeof(BITMAPINFOHEADER) + 256 * sizeof(RGBQUAD)];
|
|
|
|
LPBITMAPINFO bmi;
|
|
|
|
HBITMAP hbm;
|
2022-11-30 20:51:59 +00:00
|
|
|
int logical_width = GetDeviceCaps(hdc, HORZRES);
|
|
|
|
int logical_height = GetDeviceCaps(hdc, VERTRES);
|
2015-10-07 04:40:50 +00:00
|
|
|
|
2022-06-07 08:01:27 +00:00
|
|
|
/* High-DPI notes:
|
|
|
|
|
|
|
|
If DPI-unaware:
|
|
|
|
- GetDeviceCaps( hdc, HORZRES ) will return the monitor width in points.
|
|
|
|
- DeviceMode.dmPelsWidth is actual pixels (unlike almost all other Windows API's,
|
|
|
|
it's not virtualized when DPI unaware).
|
|
|
|
|
|
|
|
If DPI-aware:
|
|
|
|
- GetDeviceCaps( hdc, HORZRES ) will return pixels, same as DeviceMode.dmPelsWidth */
|
2015-10-07 04:40:50 +00:00
|
|
|
mode->w = logical_width;
|
|
|
|
mode->h = logical_height;
|
2022-11-30 20:51:59 +00:00
|
|
|
|
2019-07-31 02:11:40 +00:00
|
|
|
SDL_zeroa(bmi_data);
|
2022-11-30 20:51:59 +00:00
|
|
|
bmi = (LPBITMAPINFO)bmi_data;
|
2015-06-21 15:33:46 +00:00
|
|
|
bmi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
|
|
|
|
|
|
|
|
hbm = CreateCompatibleBitmap(hdc, 1, 1);
|
|
|
|
GetDIBits(hdc, hbm, 0, 1, NULL, bmi, DIB_RGB_COLORS);
|
|
|
|
GetDIBits(hdc, hbm, 0, 1, NULL, bmi, DIB_RGB_COLORS);
|
|
|
|
DeleteObject(hbm);
|
|
|
|
DeleteDC(hdc);
|
|
|
|
if (bmi->bmiHeader.biCompression == BI_BITFIELDS) {
|
2022-11-30 20:51:59 +00:00
|
|
|
switch (*(Uint32 *)bmi->bmiColors) {
|
2015-06-21 15:33:46 +00:00
|
|
|
case 0x00FF0000:
|
|
|
|
mode->format = SDL_PIXELFORMAT_RGB888;
|
|
|
|
break;
|
|
|
|
case 0x000000FF:
|
|
|
|
mode->format = SDL_PIXELFORMAT_BGR888;
|
|
|
|
break;
|
|
|
|
case 0xF800:
|
|
|
|
mode->format = SDL_PIXELFORMAT_RGB565;
|
|
|
|
break;
|
|
|
|
case 0x7C00:
|
|
|
|
mode->format = SDL_PIXELFORMAT_RGB555;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else if (bmi->bmiHeader.biBitCount == 8) {
|
|
|
|
mode->format = SDL_PIXELFORMAT_INDEX8;
|
|
|
|
} else if (bmi->bmiHeader.biBitCount == 4) {
|
|
|
|
mode->format = SDL_PIXELFORMAT_INDEX4LSB;
|
|
|
|
}
|
2016-03-11 16:33:47 +00:00
|
|
|
} else if (mode->format == SDL_PIXELFORMAT_UNKNOWN) {
|
2015-06-21 15:33:46 +00:00
|
|
|
/* FIXME: Can we tell what this will be? */
|
2016-03-11 16:33:47 +00:00
|
|
|
if ((data->DeviceMode.dmFields & DM_BITSPERPEL) == DM_BITSPERPEL) {
|
|
|
|
switch (data->DeviceMode.dmBitsPerPel) {
|
2015-06-21 15:33:46 +00:00
|
|
|
case 32:
|
|
|
|
mode->format = SDL_PIXELFORMAT_RGB888;
|
|
|
|
break;
|
|
|
|
case 24:
|
|
|
|
mode->format = SDL_PIXELFORMAT_RGB24;
|
|
|
|
break;
|
|
|
|
case 16:
|
|
|
|
mode->format = SDL_PIXELFORMAT_RGB565;
|
|
|
|
break;
|
|
|
|
case 15:
|
|
|
|
mode->format = SDL_PIXELFORMAT_RGB555;
|
|
|
|
break;
|
|
|
|
case 8:
|
|
|
|
mode->format = SDL_PIXELFORMAT_INDEX8;
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
mode->format = SDL_PIXELFORMAT_INDEX4LSB;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-03-11 16:33:47 +00:00
|
|
|
}
|
|
|
|
|
2022-11-30 20:51:59 +00:00
|
|
|
static SDL_DisplayOrientation WIN_GetDisplayOrientation(DEVMODE *mode)
|
2021-11-10 14:03:01 +00:00
|
|
|
{
|
|
|
|
int width = mode->dmPelsWidth;
|
|
|
|
int height = mode->dmPelsHeight;
|
|
|
|
|
|
|
|
/* Use unrotated width/height to guess orientation */
|
|
|
|
if (mode->dmDisplayOrientation == DMDO_90 || mode->dmDisplayOrientation == DMDO_270) {
|
|
|
|
int temp = width;
|
|
|
|
width = height;
|
|
|
|
height = temp;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (width >= height) {
|
|
|
|
switch (mode->dmDisplayOrientation) {
|
|
|
|
case DMDO_DEFAULT:
|
|
|
|
return SDL_ORIENTATION_LANDSCAPE;
|
|
|
|
case DMDO_90:
|
|
|
|
return SDL_ORIENTATION_PORTRAIT;
|
|
|
|
case DMDO_180:
|
|
|
|
return SDL_ORIENTATION_LANDSCAPE_FLIPPED;
|
|
|
|
case DMDO_270:
|
|
|
|
return SDL_ORIENTATION_PORTRAIT_FLIPPED;
|
|
|
|
default:
|
|
|
|
return SDL_ORIENTATION_UNKNOWN;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
switch (mode->dmDisplayOrientation) {
|
|
|
|
case DMDO_DEFAULT:
|
|
|
|
return SDL_ORIENTATION_PORTRAIT;
|
|
|
|
case DMDO_90:
|
|
|
|
return SDL_ORIENTATION_LANDSCAPE_FLIPPED;
|
|
|
|
case DMDO_180:
|
|
|
|
return SDL_ORIENTATION_PORTRAIT_FLIPPED;
|
|
|
|
case DMDO_270:
|
|
|
|
return SDL_ORIENTATION_LANDSCAPE;
|
|
|
|
default:
|
|
|
|
return SDL_ORIENTATION_UNKNOWN;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-30 20:51:59 +00:00
|
|
|
static SDL_bool WIN_GetDisplayMode(_THIS, LPCWSTR deviceName, DWORD index, SDL_DisplayMode *mode, SDL_DisplayOrientation *orientation)
|
2016-03-11 16:33:47 +00:00
|
|
|
{
|
|
|
|
SDL_DisplayModeData *data;
|
|
|
|
DEVMODE devmode;
|
|
|
|
|
|
|
|
devmode.dmSize = sizeof(devmode);
|
|
|
|
devmode.dmDriverExtra = 0;
|
2021-01-05 12:50:10 +00:00
|
|
|
if (!EnumDisplaySettingsW(deviceName, index, &devmode)) {
|
2016-03-11 16:33:47 +00:00
|
|
|
return SDL_FALSE;
|
|
|
|
}
|
|
|
|
|
2022-11-30 20:51:59 +00:00
|
|
|
data = (SDL_DisplayModeData *)SDL_malloc(sizeof(*data));
|
2022-11-27 16:38:43 +00:00
|
|
|
if (data == NULL) {
|
2016-03-11 16:33:47 +00:00
|
|
|
return SDL_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
mode->driverdata = data;
|
|
|
|
data->DeviceMode = devmode;
|
|
|
|
|
|
|
|
mode->format = SDL_PIXELFORMAT_UNKNOWN;
|
|
|
|
mode->w = data->DeviceMode.dmPelsWidth;
|
|
|
|
mode->h = data->DeviceMode.dmPelsHeight;
|
|
|
|
mode->refresh_rate = data->DeviceMode.dmDisplayFrequency;
|
|
|
|
|
|
|
|
/* Fill in the mode information */
|
|
|
|
WIN_UpdateDisplayMode(_this, deviceName, index, mode);
|
2021-11-10 14:03:01 +00:00
|
|
|
|
|
|
|
if (orientation) {
|
|
|
|
*orientation = WIN_GetDisplayOrientation(&devmode);
|
|
|
|
}
|
|
|
|
|
2015-06-21 15:33:46 +00:00
|
|
|
return SDL_TRUE;
|
|
|
|
}
|
|
|
|
|
2022-06-12 19:28:49 +00:00
|
|
|
/* The win32 API calls in this function require Windows Vista or later. */
|
2022-11-30 20:51:59 +00:00
|
|
|
/* *INDENT-OFF* */ /* clang-format off */
|
2022-06-16 06:00:28 +00:00
|
|
|
typedef LONG (WINAPI *SDL_WIN32PROC_GetDisplayConfigBufferSizes)(UINT32 flags, UINT32* numPathArrayElements, UINT32* numModeInfoArrayElements);
|
|
|
|
typedef LONG (WINAPI *SDL_WIN32PROC_QueryDisplayConfig)(UINT32 flags, UINT32* numPathArrayElements, DISPLAYCONFIG_PATH_INFO* pathArray, UINT32* numModeInfoArrayElements, DISPLAYCONFIG_MODE_INFO* modeInfoArray, DISPLAYCONFIG_TOPOLOGY_ID* currentTopologyId);
|
|
|
|
typedef LONG (WINAPI *SDL_WIN32PROC_DisplayConfigGetDeviceInfo)(DISPLAYCONFIG_DEVICE_INFO_HEADER* requestPacket);
|
2022-11-30 20:51:59 +00:00
|
|
|
/* *INDENT-ON* */ /* clang-format on */
|
2022-06-12 19:28:49 +00:00
|
|
|
|
2022-11-30 20:51:59 +00:00
|
|
|
static char *WIN_GetDisplayNameVista(const WCHAR *deviceName)
|
2022-06-12 19:28:49 +00:00
|
|
|
{
|
|
|
|
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");
|
2022-11-27 16:38:43 +00:00
|
|
|
if (dll == NULL) {
|
2022-06-12 19:28:49 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2022-11-30 20:51:59 +00:00
|
|
|
pGetDisplayConfigBufferSizes = (SDL_WIN32PROC_GetDisplayConfigBufferSizes)SDL_LoadFunction(dll, "GetDisplayConfigBufferSizes");
|
|
|
|
pQueryDisplayConfig = (SDL_WIN32PROC_QueryDisplayConfig)SDL_LoadFunction(dll, "QueryDisplayConfig");
|
|
|
|
pDisplayConfigGetDeviceInfo = (SDL_WIN32PROC_DisplayConfigGetDeviceInfo)SDL_LoadFunction(dll, "DisplayConfigGetDeviceInfo");
|
2022-06-12 19:28:49 +00:00
|
|
|
|
2022-11-27 16:38:43 +00:00
|
|
|
if (pGetDisplayConfigBufferSizes == NULL || pQueryDisplayConfig == NULL || pDisplayConfigGetDeviceInfo == NULL) {
|
2022-06-12 19:28:49 +00:00
|
|
|
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);
|
|
|
|
|
2022-11-30 20:51:59 +00:00
|
|
|
paths = (DISPLAYCONFIG_PATH_INFO *)SDL_malloc(sizeof(DISPLAYCONFIG_PATH_INFO) * pathCount);
|
|
|
|
modes = (DISPLAYCONFIG_MODE_INFO *)SDL_malloc(sizeof(DISPLAYCONFIG_MODE_INFO) * modeCount);
|
2022-06-12 19:28:49 +00:00
|
|
|
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;
|
2022-11-30 20:51:59 +00:00
|
|
|
sourceName.header.size = sizeof(sourceName);
|
2022-08-26 01:41:32 +00:00
|
|
|
sourceName.header.id = paths[i].sourceInfo.id;
|
2022-06-12 19:28:49 +00:00
|
|
|
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;
|
2022-11-30 20:51:59 +00:00
|
|
|
targetName.header.size = sizeof(targetName);
|
2022-06-12 19:28:49 +00:00
|
|
|
rc = pDisplayConfigGetDeviceInfo(&targetName.header);
|
|
|
|
if (rc == ERROR_SUCCESS) {
|
|
|
|
retval = WIN_StringToUTF8W(targetName.monitorFriendlyDeviceName);
|
2022-08-10 13:54:49 +00:00
|
|
|
/* if we got an empty string, treat it as failure so we'll fallback
|
|
|
|
to getting the generic name. */
|
|
|
|
if (retval && (*retval == '\0')) {
|
|
|
|
SDL_free(retval);
|
|
|
|
retval = NULL;
|
|
|
|
}
|
2022-06-12 19:28:49 +00:00
|
|
|
}
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2022-12-08 20:46:13 +00:00
|
|
|
static void WIN_AddDisplay(_THIS, HMONITOR hMonitor, const MONITORINFOEXW *info, int *display_index, SDL_bool send_event)
|
2015-06-21 15:33:46 +00:00
|
|
|
{
|
2022-12-08 20:46:13 +00:00
|
|
|
int i, index = *display_index;
|
2015-06-21 15:33:46 +00:00
|
|
|
SDL_VideoDisplay display;
|
|
|
|
SDL_DisplayData *displaydata;
|
|
|
|
SDL_DisplayMode mode;
|
2021-11-10 14:03:01 +00:00
|
|
|
SDL_DisplayOrientation orientation;
|
2015-06-21 15:33:46 +00:00
|
|
|
|
|
|
|
#ifdef DEBUG_MODES
|
2021-01-05 12:50:10 +00:00
|
|
|
SDL_Log("Display: %s\n", WIN_StringToUTF8W(info->szDevice));
|
2015-06-21 15:33:46 +00:00
|
|
|
#endif
|
Fixed bug 3714 - Windows: SDL_WINDOW_FULLSCREEN_DESKTOP broken on 3 monitor setup w/ DPI scaling
Eric Wasylishen 2017-07-26 18:42:58 UTC
I set up an (admittedly exotic) 3-monitor setup, and when I enter fullscreen-desktop on the middle display (#2), the SDL window is off center. (covers half of monitor #2 and most of monitor #3).
The displays are arranged from left to right:
Display #1 (main): 2880x1800, 200% scaling
Display #2: 1920x1200, 150% scaling
Display #3: 1920x1080, 100% scaling
SDL display bounds:
INFO: Bounds: 1440x900 at 0,0
INFO: Bounds: 1281x801 at 1921,0 (these are incorrect)
INFO: Bounds: 1920x1080 at 4800,0
Correct bounds reported by calling EnumDisplayMonitors and printing the LPRECT param of the callback:
1440x900 at (0, 0)
1280x800 at (2880, 0)
1920x1080 at (4800, 0)
It seems like you need 3 displays to reproduce this, and the left two need DPI scaling, and the 3rd display needs to have a different scale factor than the others.
Related: https://bugzilla.libsdl.org/show_bug.cgi?id=3709
SDL: current hg (11235:6a587b9e0ec8)
Windows 10, Version 10.0.15063 Build 15063
Tested with testdraw2 and testgl2, and pressing alt+enter to enter fullscreen desktop.
This patch reworks SDL_windowsmodes.c to use EnumDisplayMonitors instead of EnumDisplayDevices, so we always have an HMONITOR for each SDL display.
With access to an HMONITOR, we can get the monitor bounds in virtual screen coordinates the proper way, by calling GetMonitorInfo. (whereas the original code was doing some calculations - e.g. "data->DeviceMode.dmPosition.x * data->ScaleX" - to try to get virtual screen coordinates. These worked in simple cases, but failed in more complex cases like this bug)
The one potential problem with my patch is, the ChangeDisplaySettingsEx docs say that you're supposed to get the display name from EnumDisplayDevices, but I'm getting the display name from GetMonitorInfo now.
2017-08-11 17:18:45 +00:00
|
|
|
|
2021-11-10 14:03:01 +00:00
|
|
|
if (!WIN_GetDisplayMode(_this, info->szDevice, ENUM_CURRENT_SETTINGS, &mode, &orientation)) {
|
2022-12-08 20:46:13 +00:00
|
|
|
return;
|
2015-06-21 15:33:46 +00:00
|
|
|
}
|
|
|
|
|
2020-10-14 04:08:20 +00:00
|
|
|
// Prevent adding duplicate displays. Do this after we know the display is
|
|
|
|
// ready to be added to allow any displays that we can't fully query to be
|
|
|
|
// removed
|
2022-11-27 16:38:43 +00:00
|
|
|
for (i = 0; i < _this->num_displays; ++i) {
|
2020-10-14 04:08:20 +00:00
|
|
|
SDL_DisplayData *driverdata = (SDL_DisplayData *)_this->displays[i].driverdata;
|
|
|
|
if (SDL_wcscmp(driverdata->DeviceName, info->szDevice) == 0) {
|
2022-12-08 20:46:13 +00:00
|
|
|
SDL_bool moved = (index != i);
|
|
|
|
|
|
|
|
if (moved) {
|
|
|
|
SDL_VideoDisplay tmp;
|
|
|
|
|
|
|
|
SDL_assert(index < _this->num_displays);
|
|
|
|
SDL_memcpy(&tmp, &_this->displays[index], sizeof(tmp));
|
|
|
|
SDL_memcpy(&_this->displays[index], &_this->displays[i], sizeof(tmp));
|
|
|
|
SDL_memcpy(&_this->displays[i], &tmp, sizeof(tmp));
|
|
|
|
i = index;
|
|
|
|
}
|
|
|
|
|
2020-10-14 04:08:20 +00:00
|
|
|
driverdata->MonitorHandle = hMonitor;
|
|
|
|
driverdata->IsValid = SDL_TRUE;
|
2021-11-10 16:47:39 +00:00
|
|
|
|
|
|
|
if (!_this->setting_display_mode) {
|
2022-12-08 20:46:13 +00:00
|
|
|
SDL_Rect bounds;
|
|
|
|
|
2021-11-10 16:47:39 +00:00
|
|
|
SDL_ResetDisplayModes(i);
|
|
|
|
SDL_SetCurrentDisplayMode(&_this->displays[i], &mode);
|
|
|
|
SDL_SetDesktopDisplayMode(&_this->displays[i], &mode);
|
2022-12-08 20:46:13 +00:00
|
|
|
if (WIN_GetDisplayBounds(_this, &_this->displays[i], &bounds) == 0) {
|
|
|
|
if (SDL_memcmp(&driverdata->bounds, &bounds, sizeof(bounds)) != 0 || moved) {
|
|
|
|
SDL_SendDisplayEvent(&_this->displays[i], SDL_DISPLAYEVENT_MOVED, 0);
|
|
|
|
}
|
|
|
|
}
|
2021-11-10 16:47:39 +00:00
|
|
|
SDL_SendDisplayEvent(&_this->displays[i], SDL_DISPLAYEVENT_ORIENTATION, orientation);
|
|
|
|
}
|
2022-12-08 20:46:13 +00:00
|
|
|
goto done;
|
2020-10-14 04:08:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-30 20:51:59 +00:00
|
|
|
displaydata = (SDL_DisplayData *)SDL_calloc(1, sizeof(*displaydata));
|
2022-11-27 16:38:43 +00:00
|
|
|
if (displaydata == NULL) {
|
2022-12-08 20:46:13 +00:00
|
|
|
return;
|
2015-06-21 15:33:46 +00:00
|
|
|
}
|
2022-08-02 00:47:26 +00:00
|
|
|
SDL_memcpy(displaydata->DeviceName, info->szDevice, sizeof(displaydata->DeviceName));
|
Fixed bug 3714 - Windows: SDL_WINDOW_FULLSCREEN_DESKTOP broken on 3 monitor setup w/ DPI scaling
Eric Wasylishen 2017-07-26 18:42:58 UTC
I set up an (admittedly exotic) 3-monitor setup, and when I enter fullscreen-desktop on the middle display (#2), the SDL window is off center. (covers half of monitor #2 and most of monitor #3).
The displays are arranged from left to right:
Display #1 (main): 2880x1800, 200% scaling
Display #2: 1920x1200, 150% scaling
Display #3: 1920x1080, 100% scaling
SDL display bounds:
INFO: Bounds: 1440x900 at 0,0
INFO: Bounds: 1281x801 at 1921,0 (these are incorrect)
INFO: Bounds: 1920x1080 at 4800,0
Correct bounds reported by calling EnumDisplayMonitors and printing the LPRECT param of the callback:
1440x900 at (0, 0)
1280x800 at (2880, 0)
1920x1080 at (4800, 0)
It seems like you need 3 displays to reproduce this, and the left two need DPI scaling, and the 3rd display needs to have a different scale factor than the others.
Related: https://bugzilla.libsdl.org/show_bug.cgi?id=3709
SDL: current hg (11235:6a587b9e0ec8)
Windows 10, Version 10.0.15063 Build 15063
Tested with testdraw2 and testgl2, and pressing alt+enter to enter fullscreen desktop.
This patch reworks SDL_windowsmodes.c to use EnumDisplayMonitors instead of EnumDisplayDevices, so we always have an HMONITOR for each SDL display.
With access to an HMONITOR, we can get the monitor bounds in virtual screen coordinates the proper way, by calling GetMonitorInfo. (whereas the original code was doing some calculations - e.g. "data->DeviceMode.dmPosition.x * data->ScaleX" - to try to get virtual screen coordinates. These worked in simple cases, but failed in more complex cases like this bug)
The one potential problem with my patch is, the ChangeDisplaySettingsEx docs say that you're supposed to get the display name from EnumDisplayDevices, but I'm getting the display name from GetMonitorInfo now.
2017-08-11 17:18:45 +00:00
|
|
|
displaydata->MonitorHandle = hMonitor;
|
2020-10-14 04:08:20 +00:00
|
|
|
displaydata->IsValid = SDL_TRUE;
|
2015-06-21 15:33:46 +00:00
|
|
|
|
|
|
|
SDL_zero(display);
|
2022-06-12 19:28:49 +00:00
|
|
|
display.name = WIN_GetDisplayNameVista(info->szDevice);
|
|
|
|
if (display.name == NULL) {
|
|
|
|
DISPLAY_DEVICEW device;
|
|
|
|
SDL_zero(device);
|
2022-11-30 20:51:59 +00:00
|
|
|
device.cb = sizeof(device);
|
2022-06-12 19:28:49 +00:00
|
|
|
if (EnumDisplayDevicesW(info->szDevice, 0, &device, 0)) {
|
|
|
|
display.name = WIN_StringToUTF8W(device.DeviceString);
|
|
|
|
}
|
2015-06-21 15:33:46 +00:00
|
|
|
}
|
2022-06-12 19:28:49 +00:00
|
|
|
|
2015-06-21 15:33:46 +00:00
|
|
|
display.desktop_mode = mode;
|
|
|
|
display.current_mode = mode;
|
2021-11-10 14:03:01 +00:00
|
|
|
display.orientation = orientation;
|
2022-12-08 20:46:13 +00:00
|
|
|
display.device = _this;
|
2015-06-21 15:33:46 +00:00
|
|
|
display.driverdata = displaydata;
|
2022-12-08 20:46:13 +00:00
|
|
|
WIN_GetDisplayBounds(_this, &display, &displaydata->bounds);
|
|
|
|
index = SDL_AddVideoDisplay(&display, send_event);
|
|
|
|
SDL_assert(index == *display_index);
|
2015-06-21 15:33:46 +00:00
|
|
|
SDL_free(display.name);
|
2022-12-08 20:46:13 +00:00
|
|
|
|
|
|
|
done:
|
|
|
|
*display_index += 1;
|
2015-06-21 15:33:46 +00:00
|
|
|
}
|
|
|
|
|
2022-11-30 20:51:59 +00:00
|
|
|
typedef struct _WIN_AddDisplaysData
|
|
|
|
{
|
Fixed bug 3714 - Windows: SDL_WINDOW_FULLSCREEN_DESKTOP broken on 3 monitor setup w/ DPI scaling
Eric Wasylishen 2017-07-26 18:42:58 UTC
I set up an (admittedly exotic) 3-monitor setup, and when I enter fullscreen-desktop on the middle display (#2), the SDL window is off center. (covers half of monitor #2 and most of monitor #3).
The displays are arranged from left to right:
Display #1 (main): 2880x1800, 200% scaling
Display #2: 1920x1200, 150% scaling
Display #3: 1920x1080, 100% scaling
SDL display bounds:
INFO: Bounds: 1440x900 at 0,0
INFO: Bounds: 1281x801 at 1921,0 (these are incorrect)
INFO: Bounds: 1920x1080 at 4800,0
Correct bounds reported by calling EnumDisplayMonitors and printing the LPRECT param of the callback:
1440x900 at (0, 0)
1280x800 at (2880, 0)
1920x1080 at (4800, 0)
It seems like you need 3 displays to reproduce this, and the left two need DPI scaling, and the 3rd display needs to have a different scale factor than the others.
Related: https://bugzilla.libsdl.org/show_bug.cgi?id=3709
SDL: current hg (11235:6a587b9e0ec8)
Windows 10, Version 10.0.15063 Build 15063
Tested with testdraw2 and testgl2, and pressing alt+enter to enter fullscreen desktop.
This patch reworks SDL_windowsmodes.c to use EnumDisplayMonitors instead of EnumDisplayDevices, so we always have an HMONITOR for each SDL display.
With access to an HMONITOR, we can get the monitor bounds in virtual screen coordinates the proper way, by calling GetMonitorInfo. (whereas the original code was doing some calculations - e.g. "data->DeviceMode.dmPosition.x * data->ScaleX" - to try to get virtual screen coordinates. These worked in simple cases, but failed in more complex cases like this bug)
The one potential problem with my patch is, the ChangeDisplaySettingsEx docs say that you're supposed to get the display name from EnumDisplayDevices, but I'm getting the display name from GetMonitorInfo now.
2017-08-11 17:18:45 +00:00
|
|
|
SDL_VideoDevice *video_device;
|
2022-12-08 20:46:13 +00:00
|
|
|
int display_index;
|
2020-10-14 04:08:20 +00:00
|
|
|
SDL_bool send_event;
|
Fixed bug 3714 - Windows: SDL_WINDOW_FULLSCREEN_DESKTOP broken on 3 monitor setup w/ DPI scaling
Eric Wasylishen 2017-07-26 18:42:58 UTC
I set up an (admittedly exotic) 3-monitor setup, and when I enter fullscreen-desktop on the middle display (#2), the SDL window is off center. (covers half of monitor #2 and most of monitor #3).
The displays are arranged from left to right:
Display #1 (main): 2880x1800, 200% scaling
Display #2: 1920x1200, 150% scaling
Display #3: 1920x1080, 100% scaling
SDL display bounds:
INFO: Bounds: 1440x900 at 0,0
INFO: Bounds: 1281x801 at 1921,0 (these are incorrect)
INFO: Bounds: 1920x1080 at 4800,0
Correct bounds reported by calling EnumDisplayMonitors and printing the LPRECT param of the callback:
1440x900 at (0, 0)
1280x800 at (2880, 0)
1920x1080 at (4800, 0)
It seems like you need 3 displays to reproduce this, and the left two need DPI scaling, and the 3rd display needs to have a different scale factor than the others.
Related: https://bugzilla.libsdl.org/show_bug.cgi?id=3709
SDL: current hg (11235:6a587b9e0ec8)
Windows 10, Version 10.0.15063 Build 15063
Tested with testdraw2 and testgl2, and pressing alt+enter to enter fullscreen desktop.
This patch reworks SDL_windowsmodes.c to use EnumDisplayMonitors instead of EnumDisplayDevices, so we always have an HMONITOR for each SDL display.
With access to an HMONITOR, we can get the monitor bounds in virtual screen coordinates the proper way, by calling GetMonitorInfo. (whereas the original code was doing some calculations - e.g. "data->DeviceMode.dmPosition.x * data->ScaleX" - to try to get virtual screen coordinates. These worked in simple cases, but failed in more complex cases like this bug)
The one potential problem with my patch is, the ChangeDisplaySettingsEx docs say that you're supposed to get the display name from EnumDisplayDevices, but I'm getting the display name from GetMonitorInfo now.
2017-08-11 17:18:45 +00:00
|
|
|
SDL_bool want_primary;
|
|
|
|
} WIN_AddDisplaysData;
|
|
|
|
|
2022-11-30 20:51:59 +00:00
|
|
|
static BOOL CALLBACK WIN_AddDisplaysCallback(HMONITOR hMonitor,
|
|
|
|
HDC hdcMonitor,
|
|
|
|
LPRECT lprcMonitor,
|
|
|
|
LPARAM dwData)
|
2015-06-21 15:33:46 +00:00
|
|
|
{
|
2022-11-30 20:51:59 +00:00
|
|
|
WIN_AddDisplaysData *data = (WIN_AddDisplaysData *)dwData;
|
2020-10-14 04:08:20 +00:00
|
|
|
MONITORINFOEXW info;
|
2015-06-21 15:33:46 +00:00
|
|
|
|
Fixed bug 3714 - Windows: SDL_WINDOW_FULLSCREEN_DESKTOP broken on 3 monitor setup w/ DPI scaling
Eric Wasylishen 2017-07-26 18:42:58 UTC
I set up an (admittedly exotic) 3-monitor setup, and when I enter fullscreen-desktop on the middle display (#2), the SDL window is off center. (covers half of monitor #2 and most of monitor #3).
The displays are arranged from left to right:
Display #1 (main): 2880x1800, 200% scaling
Display #2: 1920x1200, 150% scaling
Display #3: 1920x1080, 100% scaling
SDL display bounds:
INFO: Bounds: 1440x900 at 0,0
INFO: Bounds: 1281x801 at 1921,0 (these are incorrect)
INFO: Bounds: 1920x1080 at 4800,0
Correct bounds reported by calling EnumDisplayMonitors and printing the LPRECT param of the callback:
1440x900 at (0, 0)
1280x800 at (2880, 0)
1920x1080 at (4800, 0)
It seems like you need 3 displays to reproduce this, and the left two need DPI scaling, and the 3rd display needs to have a different scale factor than the others.
Related: https://bugzilla.libsdl.org/show_bug.cgi?id=3709
SDL: current hg (11235:6a587b9e0ec8)
Windows 10, Version 10.0.15063 Build 15063
Tested with testdraw2 and testgl2, and pressing alt+enter to enter fullscreen desktop.
This patch reworks SDL_windowsmodes.c to use EnumDisplayMonitors instead of EnumDisplayDevices, so we always have an HMONITOR for each SDL display.
With access to an HMONITOR, we can get the monitor bounds in virtual screen coordinates the proper way, by calling GetMonitorInfo. (whereas the original code was doing some calculations - e.g. "data->DeviceMode.dmPosition.x * data->ScaleX" - to try to get virtual screen coordinates. These worked in simple cases, but failed in more complex cases like this bug)
The one potential problem with my patch is, the ChangeDisplaySettingsEx docs say that you're supposed to get the display name from EnumDisplayDevices, but I'm getting the display name from GetMonitorInfo now.
2017-08-11 17:18:45 +00:00
|
|
|
SDL_zero(info);
|
|
|
|
info.cbSize = sizeof(info);
|
2015-06-21 15:33:46 +00:00
|
|
|
|
2020-10-14 04:08:20 +00:00
|
|
|
if (GetMonitorInfoW(hMonitor, (LPMONITORINFO)&info) != 0) {
|
Fixed bug 3714 - Windows: SDL_WINDOW_FULLSCREEN_DESKTOP broken on 3 monitor setup w/ DPI scaling
Eric Wasylishen 2017-07-26 18:42:58 UTC
I set up an (admittedly exotic) 3-monitor setup, and when I enter fullscreen-desktop on the middle display (#2), the SDL window is off center. (covers half of monitor #2 and most of monitor #3).
The displays are arranged from left to right:
Display #1 (main): 2880x1800, 200% scaling
Display #2: 1920x1200, 150% scaling
Display #3: 1920x1080, 100% scaling
SDL display bounds:
INFO: Bounds: 1440x900 at 0,0
INFO: Bounds: 1281x801 at 1921,0 (these are incorrect)
INFO: Bounds: 1920x1080 at 4800,0
Correct bounds reported by calling EnumDisplayMonitors and printing the LPRECT param of the callback:
1440x900 at (0, 0)
1280x800 at (2880, 0)
1920x1080 at (4800, 0)
It seems like you need 3 displays to reproduce this, and the left two need DPI scaling, and the 3rd display needs to have a different scale factor than the others.
Related: https://bugzilla.libsdl.org/show_bug.cgi?id=3709
SDL: current hg (11235:6a587b9e0ec8)
Windows 10, Version 10.0.15063 Build 15063
Tested with testdraw2 and testgl2, and pressing alt+enter to enter fullscreen desktop.
This patch reworks SDL_windowsmodes.c to use EnumDisplayMonitors instead of EnumDisplayDevices, so we always have an HMONITOR for each SDL display.
With access to an HMONITOR, we can get the monitor bounds in virtual screen coordinates the proper way, by calling GetMonitorInfo. (whereas the original code was doing some calculations - e.g. "data->DeviceMode.dmPosition.x * data->ScaleX" - to try to get virtual screen coordinates. These worked in simple cases, but failed in more complex cases like this bug)
The one potential problem with my patch is, the ChangeDisplaySettingsEx docs say that you're supposed to get the display name from EnumDisplayDevices, but I'm getting the display name from GetMonitorInfo now.
2017-08-11 17:18:45 +00:00
|
|
|
const SDL_bool is_primary = ((info.dwFlags & MONITORINFOF_PRIMARY) == MONITORINFOF_PRIMARY);
|
2015-06-21 15:33:46 +00:00
|
|
|
|
Fixed bug 3714 - Windows: SDL_WINDOW_FULLSCREEN_DESKTOP broken on 3 monitor setup w/ DPI scaling
Eric Wasylishen 2017-07-26 18:42:58 UTC
I set up an (admittedly exotic) 3-monitor setup, and when I enter fullscreen-desktop on the middle display (#2), the SDL window is off center. (covers half of monitor #2 and most of monitor #3).
The displays are arranged from left to right:
Display #1 (main): 2880x1800, 200% scaling
Display #2: 1920x1200, 150% scaling
Display #3: 1920x1080, 100% scaling
SDL display bounds:
INFO: Bounds: 1440x900 at 0,0
INFO: Bounds: 1281x801 at 1921,0 (these are incorrect)
INFO: Bounds: 1920x1080 at 4800,0
Correct bounds reported by calling EnumDisplayMonitors and printing the LPRECT param of the callback:
1440x900 at (0, 0)
1280x800 at (2880, 0)
1920x1080 at (4800, 0)
It seems like you need 3 displays to reproduce this, and the left two need DPI scaling, and the 3rd display needs to have a different scale factor than the others.
Related: https://bugzilla.libsdl.org/show_bug.cgi?id=3709
SDL: current hg (11235:6a587b9e0ec8)
Windows 10, Version 10.0.15063 Build 15063
Tested with testdraw2 and testgl2, and pressing alt+enter to enter fullscreen desktop.
This patch reworks SDL_windowsmodes.c to use EnumDisplayMonitors instead of EnumDisplayDevices, so we always have an HMONITOR for each SDL display.
With access to an HMONITOR, we can get the monitor bounds in virtual screen coordinates the proper way, by calling GetMonitorInfo. (whereas the original code was doing some calculations - e.g. "data->DeviceMode.dmPosition.x * data->ScaleX" - to try to get virtual screen coordinates. These worked in simple cases, but failed in more complex cases like this bug)
The one potential problem with my patch is, the ChangeDisplaySettingsEx docs say that you're supposed to get the display name from EnumDisplayDevices, but I'm getting the display name from GetMonitorInfo now.
2017-08-11 17:18:45 +00:00
|
|
|
if (is_primary == data->want_primary) {
|
2022-12-08 20:46:13 +00:00
|
|
|
WIN_AddDisplay(data->video_device, hMonitor, &info, &data->display_index, data->send_event);
|
2015-06-21 15:33:46 +00:00
|
|
|
}
|
|
|
|
}
|
Fixed bug 3714 - Windows: SDL_WINDOW_FULLSCREEN_DESKTOP broken on 3 monitor setup w/ DPI scaling
Eric Wasylishen 2017-07-26 18:42:58 UTC
I set up an (admittedly exotic) 3-monitor setup, and when I enter fullscreen-desktop on the middle display (#2), the SDL window is off center. (covers half of monitor #2 and most of monitor #3).
The displays are arranged from left to right:
Display #1 (main): 2880x1800, 200% scaling
Display #2: 1920x1200, 150% scaling
Display #3: 1920x1080, 100% scaling
SDL display bounds:
INFO: Bounds: 1440x900 at 0,0
INFO: Bounds: 1281x801 at 1921,0 (these are incorrect)
INFO: Bounds: 1920x1080 at 4800,0
Correct bounds reported by calling EnumDisplayMonitors and printing the LPRECT param of the callback:
1440x900 at (0, 0)
1280x800 at (2880, 0)
1920x1080 at (4800, 0)
It seems like you need 3 displays to reproduce this, and the left two need DPI scaling, and the 3rd display needs to have a different scale factor than the others.
Related: https://bugzilla.libsdl.org/show_bug.cgi?id=3709
SDL: current hg (11235:6a587b9e0ec8)
Windows 10, Version 10.0.15063 Build 15063
Tested with testdraw2 and testgl2, and pressing alt+enter to enter fullscreen desktop.
This patch reworks SDL_windowsmodes.c to use EnumDisplayMonitors instead of EnumDisplayDevices, so we always have an HMONITOR for each SDL display.
With access to an HMONITOR, we can get the monitor bounds in virtual screen coordinates the proper way, by calling GetMonitorInfo. (whereas the original code was doing some calculations - e.g. "data->DeviceMode.dmPosition.x * data->ScaleX" - to try to get virtual screen coordinates. These worked in simple cases, but failed in more complex cases like this bug)
The one potential problem with my patch is, the ChangeDisplaySettingsEx docs say that you're supposed to get the display name from EnumDisplayDevices, but I'm getting the display name from GetMonitorInfo now.
2017-08-11 17:18:45 +00:00
|
|
|
|
|
|
|
// continue enumeration
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2022-11-30 20:51:59 +00:00
|
|
|
static void WIN_AddDisplays(_THIS, SDL_bool send_event)
|
Fixed bug 3714 - Windows: SDL_WINDOW_FULLSCREEN_DESKTOP broken on 3 monitor setup w/ DPI scaling
Eric Wasylishen 2017-07-26 18:42:58 UTC
I set up an (admittedly exotic) 3-monitor setup, and when I enter fullscreen-desktop on the middle display (#2), the SDL window is off center. (covers half of monitor #2 and most of monitor #3).
The displays are arranged from left to right:
Display #1 (main): 2880x1800, 200% scaling
Display #2: 1920x1200, 150% scaling
Display #3: 1920x1080, 100% scaling
SDL display bounds:
INFO: Bounds: 1440x900 at 0,0
INFO: Bounds: 1281x801 at 1921,0 (these are incorrect)
INFO: Bounds: 1920x1080 at 4800,0
Correct bounds reported by calling EnumDisplayMonitors and printing the LPRECT param of the callback:
1440x900 at (0, 0)
1280x800 at (2880, 0)
1920x1080 at (4800, 0)
It seems like you need 3 displays to reproduce this, and the left two need DPI scaling, and the 3rd display needs to have a different scale factor than the others.
Related: https://bugzilla.libsdl.org/show_bug.cgi?id=3709
SDL: current hg (11235:6a587b9e0ec8)
Windows 10, Version 10.0.15063 Build 15063
Tested with testdraw2 and testgl2, and pressing alt+enter to enter fullscreen desktop.
This patch reworks SDL_windowsmodes.c to use EnumDisplayMonitors instead of EnumDisplayDevices, so we always have an HMONITOR for each SDL display.
With access to an HMONITOR, we can get the monitor bounds in virtual screen coordinates the proper way, by calling GetMonitorInfo. (whereas the original code was doing some calculations - e.g. "data->DeviceMode.dmPosition.x * data->ScaleX" - to try to get virtual screen coordinates. These worked in simple cases, but failed in more complex cases like this bug)
The one potential problem with my patch is, the ChangeDisplaySettingsEx docs say that you're supposed to get the display name from EnumDisplayDevices, but I'm getting the display name from GetMonitorInfo now.
2017-08-11 17:18:45 +00:00
|
|
|
{
|
|
|
|
WIN_AddDisplaysData callback_data;
|
|
|
|
callback_data.video_device = _this;
|
2022-12-08 20:46:13 +00:00
|
|
|
callback_data.display_index = 0;
|
2020-10-14 04:08:20 +00:00
|
|
|
callback_data.send_event = send_event;
|
Fixed bug 3714 - Windows: SDL_WINDOW_FULLSCREEN_DESKTOP broken on 3 monitor setup w/ DPI scaling
Eric Wasylishen 2017-07-26 18:42:58 UTC
I set up an (admittedly exotic) 3-monitor setup, and when I enter fullscreen-desktop on the middle display (#2), the SDL window is off center. (covers half of monitor #2 and most of monitor #3).
The displays are arranged from left to right:
Display #1 (main): 2880x1800, 200% scaling
Display #2: 1920x1200, 150% scaling
Display #3: 1920x1080, 100% scaling
SDL display bounds:
INFO: Bounds: 1440x900 at 0,0
INFO: Bounds: 1281x801 at 1921,0 (these are incorrect)
INFO: Bounds: 1920x1080 at 4800,0
Correct bounds reported by calling EnumDisplayMonitors and printing the LPRECT param of the callback:
1440x900 at (0, 0)
1280x800 at (2880, 0)
1920x1080 at (4800, 0)
It seems like you need 3 displays to reproduce this, and the left two need DPI scaling, and the 3rd display needs to have a different scale factor than the others.
Related: https://bugzilla.libsdl.org/show_bug.cgi?id=3709
SDL: current hg (11235:6a587b9e0ec8)
Windows 10, Version 10.0.15063 Build 15063
Tested with testdraw2 and testgl2, and pressing alt+enter to enter fullscreen desktop.
This patch reworks SDL_windowsmodes.c to use EnumDisplayMonitors instead of EnumDisplayDevices, so we always have an HMONITOR for each SDL display.
With access to an HMONITOR, we can get the monitor bounds in virtual screen coordinates the proper way, by calling GetMonitorInfo. (whereas the original code was doing some calculations - e.g. "data->DeviceMode.dmPosition.x * data->ScaleX" - to try to get virtual screen coordinates. These worked in simple cases, but failed in more complex cases like this bug)
The one potential problem with my patch is, the ChangeDisplaySettingsEx docs say that you're supposed to get the display name from EnumDisplayDevices, but I'm getting the display name from GetMonitorInfo now.
2017-08-11 17:18:45 +00:00
|
|
|
|
|
|
|
callback_data.want_primary = SDL_TRUE;
|
|
|
|
EnumDisplayMonitors(NULL, NULL, WIN_AddDisplaysCallback, (LPARAM)&callback_data);
|
|
|
|
|
|
|
|
callback_data.want_primary = SDL_FALSE;
|
|
|
|
EnumDisplayMonitors(NULL, NULL, WIN_AddDisplaysCallback, (LPARAM)&callback_data);
|
|
|
|
}
|
|
|
|
|
2022-11-30 20:51:59 +00:00
|
|
|
int WIN_InitModes(_THIS)
|
Fixed bug 3714 - Windows: SDL_WINDOW_FULLSCREEN_DESKTOP broken on 3 monitor setup w/ DPI scaling
Eric Wasylishen 2017-07-26 18:42:58 UTC
I set up an (admittedly exotic) 3-monitor setup, and when I enter fullscreen-desktop on the middle display (#2), the SDL window is off center. (covers half of monitor #2 and most of monitor #3).
The displays are arranged from left to right:
Display #1 (main): 2880x1800, 200% scaling
Display #2: 1920x1200, 150% scaling
Display #3: 1920x1080, 100% scaling
SDL display bounds:
INFO: Bounds: 1440x900 at 0,0
INFO: Bounds: 1281x801 at 1921,0 (these are incorrect)
INFO: Bounds: 1920x1080 at 4800,0
Correct bounds reported by calling EnumDisplayMonitors and printing the LPRECT param of the callback:
1440x900 at (0, 0)
1280x800 at (2880, 0)
1920x1080 at (4800, 0)
It seems like you need 3 displays to reproduce this, and the left two need DPI scaling, and the 3rd display needs to have a different scale factor than the others.
Related: https://bugzilla.libsdl.org/show_bug.cgi?id=3709
SDL: current hg (11235:6a587b9e0ec8)
Windows 10, Version 10.0.15063 Build 15063
Tested with testdraw2 and testgl2, and pressing alt+enter to enter fullscreen desktop.
This patch reworks SDL_windowsmodes.c to use EnumDisplayMonitors instead of EnumDisplayDevices, so we always have an HMONITOR for each SDL display.
With access to an HMONITOR, we can get the monitor bounds in virtual screen coordinates the proper way, by calling GetMonitorInfo. (whereas the original code was doing some calculations - e.g. "data->DeviceMode.dmPosition.x * data->ScaleX" - to try to get virtual screen coordinates. These worked in simple cases, but failed in more complex cases like this bug)
The one potential problem with my patch is, the ChangeDisplaySettingsEx docs say that you're supposed to get the display name from EnumDisplayDevices, but I'm getting the display name from GetMonitorInfo now.
2017-08-11 17:18:45 +00:00
|
|
|
{
|
2020-10-14 04:08:20 +00:00
|
|
|
WIN_AddDisplays(_this, SDL_FALSE);
|
Fixed bug 3714 - Windows: SDL_WINDOW_FULLSCREEN_DESKTOP broken on 3 monitor setup w/ DPI scaling
Eric Wasylishen 2017-07-26 18:42:58 UTC
I set up an (admittedly exotic) 3-monitor setup, and when I enter fullscreen-desktop on the middle display (#2), the SDL window is off center. (covers half of monitor #2 and most of monitor #3).
The displays are arranged from left to right:
Display #1 (main): 2880x1800, 200% scaling
Display #2: 1920x1200, 150% scaling
Display #3: 1920x1080, 100% scaling
SDL display bounds:
INFO: Bounds: 1440x900 at 0,0
INFO: Bounds: 1281x801 at 1921,0 (these are incorrect)
INFO: Bounds: 1920x1080 at 4800,0
Correct bounds reported by calling EnumDisplayMonitors and printing the LPRECT param of the callback:
1440x900 at (0, 0)
1280x800 at (2880, 0)
1920x1080 at (4800, 0)
It seems like you need 3 displays to reproduce this, and the left two need DPI scaling, and the 3rd display needs to have a different scale factor than the others.
Related: https://bugzilla.libsdl.org/show_bug.cgi?id=3709
SDL: current hg (11235:6a587b9e0ec8)
Windows 10, Version 10.0.15063 Build 15063
Tested with testdraw2 and testgl2, and pressing alt+enter to enter fullscreen desktop.
This patch reworks SDL_windowsmodes.c to use EnumDisplayMonitors instead of EnumDisplayDevices, so we always have an HMONITOR for each SDL display.
With access to an HMONITOR, we can get the monitor bounds in virtual screen coordinates the proper way, by calling GetMonitorInfo. (whereas the original code was doing some calculations - e.g. "data->DeviceMode.dmPosition.x * data->ScaleX" - to try to get virtual screen coordinates. These worked in simple cases, but failed in more complex cases like this bug)
The one potential problem with my patch is, the ChangeDisplaySettingsEx docs say that you're supposed to get the display name from EnumDisplayDevices, but I'm getting the display name from GetMonitorInfo now.
2017-08-11 17:18:45 +00:00
|
|
|
|
2015-06-21 15:33:46 +00:00
|
|
|
if (_this->num_displays == 0) {
|
|
|
|
return SDL_SetError("No displays available");
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2022-06-07 08:01:27 +00:00
|
|
|
/**
|
2022-11-30 20:51:59 +00:00
|
|
|
* Convert the monitor rect and work rect from pixels to the SDL coordinate system (monitor origins are in pixels,
|
2022-06-07 08:01:27 +00:00
|
|
|
* monitor size in DPI-scaled points).
|
2022-11-30 20:51:59 +00:00
|
|
|
*
|
2022-06-07 08:01:27 +00:00
|
|
|
* No-op if DPI scaling is not enabled.
|
|
|
|
*/
|
2022-11-30 20:51:59 +00:00
|
|
|
static void WIN_MonitorInfoToSDL(const SDL_VideoData *videodata, HMONITOR monitor, MONITORINFO *info)
|
2022-06-07 08:01:27 +00:00
|
|
|
{
|
|
|
|
UINT xdpi, ydpi;
|
|
|
|
|
|
|
|
if (!videodata->dpi_scaling_enabled) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Check for Windows < 8.1*/
|
|
|
|
if (!videodata->GetDpiForMonitor) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (videodata->GetDpiForMonitor(monitor, MDT_EFFECTIVE_DPI, &xdpi, &ydpi) != S_OK) {
|
|
|
|
/* Shouldn't happen? */
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Convert monitor size to points, leaving the monitor position in pixels */
|
|
|
|
info->rcMonitor.right = info->rcMonitor.left + MulDiv(info->rcMonitor.right - info->rcMonitor.left, 96, xdpi);
|
|
|
|
info->rcMonitor.bottom = info->rcMonitor.top + MulDiv(info->rcMonitor.bottom - info->rcMonitor.top, 96, ydpi);
|
|
|
|
|
|
|
|
/* Convert monitor work rect to points */
|
2022-11-30 20:51:59 +00:00
|
|
|
info->rcWork.left = info->rcMonitor.left + MulDiv(info->rcWork.left - info->rcMonitor.left, 96, xdpi);
|
|
|
|
info->rcWork.right = info->rcMonitor.left + MulDiv(info->rcWork.right - info->rcMonitor.left, 96, xdpi);
|
|
|
|
info->rcWork.top = info->rcMonitor.top + MulDiv(info->rcWork.top - info->rcMonitor.top, 96, ydpi);
|
|
|
|
info->rcWork.bottom = info->rcMonitor.top + MulDiv(info->rcWork.bottom - info->rcMonitor.top, 96, ydpi);
|
2022-06-07 08:01:27 +00:00
|
|
|
}
|
|
|
|
|
2022-11-30 20:51:59 +00:00
|
|
|
int WIN_GetDisplayBounds(_THIS, SDL_VideoDisplay *display, SDL_Rect *rect)
|
2015-06-21 15:33:46 +00:00
|
|
|
{
|
Fixed bug 3714 - Windows: SDL_WINDOW_FULLSCREEN_DESKTOP broken on 3 monitor setup w/ DPI scaling
Eric Wasylishen 2017-07-26 18:42:58 UTC
I set up an (admittedly exotic) 3-monitor setup, and when I enter fullscreen-desktop on the middle display (#2), the SDL window is off center. (covers half of monitor #2 and most of monitor #3).
The displays are arranged from left to right:
Display #1 (main): 2880x1800, 200% scaling
Display #2: 1920x1200, 150% scaling
Display #3: 1920x1080, 100% scaling
SDL display bounds:
INFO: Bounds: 1440x900 at 0,0
INFO: Bounds: 1281x801 at 1921,0 (these are incorrect)
INFO: Bounds: 1920x1080 at 4800,0
Correct bounds reported by calling EnumDisplayMonitors and printing the LPRECT param of the callback:
1440x900 at (0, 0)
1280x800 at (2880, 0)
1920x1080 at (4800, 0)
It seems like you need 3 displays to reproduce this, and the left two need DPI scaling, and the 3rd display needs to have a different scale factor than the others.
Related: https://bugzilla.libsdl.org/show_bug.cgi?id=3709
SDL: current hg (11235:6a587b9e0ec8)
Windows 10, Version 10.0.15063 Build 15063
Tested with testdraw2 and testgl2, and pressing alt+enter to enter fullscreen desktop.
This patch reworks SDL_windowsmodes.c to use EnumDisplayMonitors instead of EnumDisplayDevices, so we always have an HMONITOR for each SDL display.
With access to an HMONITOR, we can get the monitor bounds in virtual screen coordinates the proper way, by calling GetMonitorInfo. (whereas the original code was doing some calculations - e.g. "data->DeviceMode.dmPosition.x * data->ScaleX" - to try to get virtual screen coordinates. These worked in simple cases, but failed in more complex cases like this bug)
The one potential problem with my patch is, the ChangeDisplaySettingsEx docs say that you're supposed to get the display name from EnumDisplayDevices, but I'm getting the display name from GetMonitorInfo now.
2017-08-11 17:18:45 +00:00
|
|
|
const SDL_DisplayData *data = (const SDL_DisplayData *)display->driverdata;
|
2022-06-07 08:01:27 +00:00
|
|
|
const SDL_VideoData *videodata = (SDL_VideoData *)display->device->driverdata;
|
Fixed bug 3714 - Windows: SDL_WINDOW_FULLSCREEN_DESKTOP broken on 3 monitor setup w/ DPI scaling
Eric Wasylishen 2017-07-26 18:42:58 UTC
I set up an (admittedly exotic) 3-monitor setup, and when I enter fullscreen-desktop on the middle display (#2), the SDL window is off center. (covers half of monitor #2 and most of monitor #3).
The displays are arranged from left to right:
Display #1 (main): 2880x1800, 200% scaling
Display #2: 1920x1200, 150% scaling
Display #3: 1920x1080, 100% scaling
SDL display bounds:
INFO: Bounds: 1440x900 at 0,0
INFO: Bounds: 1281x801 at 1921,0 (these are incorrect)
INFO: Bounds: 1920x1080 at 4800,0
Correct bounds reported by calling EnumDisplayMonitors and printing the LPRECT param of the callback:
1440x900 at (0, 0)
1280x800 at (2880, 0)
1920x1080 at (4800, 0)
It seems like you need 3 displays to reproduce this, and the left two need DPI scaling, and the 3rd display needs to have a different scale factor than the others.
Related: https://bugzilla.libsdl.org/show_bug.cgi?id=3709
SDL: current hg (11235:6a587b9e0ec8)
Windows 10, Version 10.0.15063 Build 15063
Tested with testdraw2 and testgl2, and pressing alt+enter to enter fullscreen desktop.
This patch reworks SDL_windowsmodes.c to use EnumDisplayMonitors instead of EnumDisplayDevices, so we always have an HMONITOR for each SDL display.
With access to an HMONITOR, we can get the monitor bounds in virtual screen coordinates the proper way, by calling GetMonitorInfo. (whereas the original code was doing some calculations - e.g. "data->DeviceMode.dmPosition.x * data->ScaleX" - to try to get virtual screen coordinates. These worked in simple cases, but failed in more complex cases like this bug)
The one potential problem with my patch is, the ChangeDisplaySettingsEx docs say that you're supposed to get the display name from EnumDisplayDevices, but I'm getting the display name from GetMonitorInfo now.
2017-08-11 17:18:45 +00:00
|
|
|
MONITORINFO minfo;
|
|
|
|
BOOL rc;
|
2015-06-21 15:33:46 +00:00
|
|
|
|
Fixed bug 3714 - Windows: SDL_WINDOW_FULLSCREEN_DESKTOP broken on 3 monitor setup w/ DPI scaling
Eric Wasylishen 2017-07-26 18:42:58 UTC
I set up an (admittedly exotic) 3-monitor setup, and when I enter fullscreen-desktop on the middle display (#2), the SDL window is off center. (covers half of monitor #2 and most of monitor #3).
The displays are arranged from left to right:
Display #1 (main): 2880x1800, 200% scaling
Display #2: 1920x1200, 150% scaling
Display #3: 1920x1080, 100% scaling
SDL display bounds:
INFO: Bounds: 1440x900 at 0,0
INFO: Bounds: 1281x801 at 1921,0 (these are incorrect)
INFO: Bounds: 1920x1080 at 4800,0
Correct bounds reported by calling EnumDisplayMonitors and printing the LPRECT param of the callback:
1440x900 at (0, 0)
1280x800 at (2880, 0)
1920x1080 at (4800, 0)
It seems like you need 3 displays to reproduce this, and the left two need DPI scaling, and the 3rd display needs to have a different scale factor than the others.
Related: https://bugzilla.libsdl.org/show_bug.cgi?id=3709
SDL: current hg (11235:6a587b9e0ec8)
Windows 10, Version 10.0.15063 Build 15063
Tested with testdraw2 and testgl2, and pressing alt+enter to enter fullscreen desktop.
This patch reworks SDL_windowsmodes.c to use EnumDisplayMonitors instead of EnumDisplayDevices, so we always have an HMONITOR for each SDL display.
With access to an HMONITOR, we can get the monitor bounds in virtual screen coordinates the proper way, by calling GetMonitorInfo. (whereas the original code was doing some calculations - e.g. "data->DeviceMode.dmPosition.x * data->ScaleX" - to try to get virtual screen coordinates. These worked in simple cases, but failed in more complex cases like this bug)
The one potential problem with my patch is, the ChangeDisplaySettingsEx docs say that you're supposed to get the display name from EnumDisplayDevices, but I'm getting the display name from GetMonitorInfo now.
2017-08-11 17:18:45 +00:00
|
|
|
SDL_zero(minfo);
|
|
|
|
minfo.cbSize = sizeof(MONITORINFO);
|
|
|
|
rc = GetMonitorInfo(data->MonitorHandle, &minfo);
|
|
|
|
|
|
|
|
if (!rc) {
|
|
|
|
return SDL_SetError("Couldn't find monitor data");
|
|
|
|
}
|
|
|
|
|
2022-06-07 08:01:27 +00:00
|
|
|
WIN_MonitorInfoToSDL(videodata, data->MonitorHandle, &minfo);
|
Fixed bug 3714 - Windows: SDL_WINDOW_FULLSCREEN_DESKTOP broken on 3 monitor setup w/ DPI scaling
Eric Wasylishen 2017-07-26 18:42:58 UTC
I set up an (admittedly exotic) 3-monitor setup, and when I enter fullscreen-desktop on the middle display (#2), the SDL window is off center. (covers half of monitor #2 and most of monitor #3).
The displays are arranged from left to right:
Display #1 (main): 2880x1800, 200% scaling
Display #2: 1920x1200, 150% scaling
Display #3: 1920x1080, 100% scaling
SDL display bounds:
INFO: Bounds: 1440x900 at 0,0
INFO: Bounds: 1281x801 at 1921,0 (these are incorrect)
INFO: Bounds: 1920x1080 at 4800,0
Correct bounds reported by calling EnumDisplayMonitors and printing the LPRECT param of the callback:
1440x900 at (0, 0)
1280x800 at (2880, 0)
1920x1080 at (4800, 0)
It seems like you need 3 displays to reproduce this, and the left two need DPI scaling, and the 3rd display needs to have a different scale factor than the others.
Related: https://bugzilla.libsdl.org/show_bug.cgi?id=3709
SDL: current hg (11235:6a587b9e0ec8)
Windows 10, Version 10.0.15063 Build 15063
Tested with testdraw2 and testgl2, and pressing alt+enter to enter fullscreen desktop.
This patch reworks SDL_windowsmodes.c to use EnumDisplayMonitors instead of EnumDisplayDevices, so we always have an HMONITOR for each SDL display.
With access to an HMONITOR, we can get the monitor bounds in virtual screen coordinates the proper way, by calling GetMonitorInfo. (whereas the original code was doing some calculations - e.g. "data->DeviceMode.dmPosition.x * data->ScaleX" - to try to get virtual screen coordinates. These worked in simple cases, but failed in more complex cases like this bug)
The one potential problem with my patch is, the ChangeDisplaySettingsEx docs say that you're supposed to get the display name from EnumDisplayDevices, but I'm getting the display name from GetMonitorInfo now.
2017-08-11 17:18:45 +00:00
|
|
|
rect->x = minfo.rcMonitor.left;
|
|
|
|
rect->y = minfo.rcMonitor.top;
|
|
|
|
rect->w = minfo.rcMonitor.right - minfo.rcMonitor.left;
|
|
|
|
rect->h = minfo.rcMonitor.bottom - minfo.rcMonitor.top;
|
2015-06-21 15:33:46 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2022-11-30 20:51:59 +00:00
|
|
|
int WIN_GetDisplayDPI(_THIS, SDL_VideoDisplay *display, float *ddpi_out, float *hdpi_out, float *vdpi_out)
|
2015-07-30 00:18:56 +00:00
|
|
|
{
|
Fixed bug 3714 - Windows: SDL_WINDOW_FULLSCREEN_DESKTOP broken on 3 monitor setup w/ DPI scaling
Eric Wasylishen 2017-07-26 18:42:58 UTC
I set up an (admittedly exotic) 3-monitor setup, and when I enter fullscreen-desktop on the middle display (#2), the SDL window is off center. (covers half of monitor #2 and most of monitor #3).
The displays are arranged from left to right:
Display #1 (main): 2880x1800, 200% scaling
Display #2: 1920x1200, 150% scaling
Display #3: 1920x1080, 100% scaling
SDL display bounds:
INFO: Bounds: 1440x900 at 0,0
INFO: Bounds: 1281x801 at 1921,0 (these are incorrect)
INFO: Bounds: 1920x1080 at 4800,0
Correct bounds reported by calling EnumDisplayMonitors and printing the LPRECT param of the callback:
1440x900 at (0, 0)
1280x800 at (2880, 0)
1920x1080 at (4800, 0)
It seems like you need 3 displays to reproduce this, and the left two need DPI scaling, and the 3rd display needs to have a different scale factor than the others.
Related: https://bugzilla.libsdl.org/show_bug.cgi?id=3709
SDL: current hg (11235:6a587b9e0ec8)
Windows 10, Version 10.0.15063 Build 15063
Tested with testdraw2 and testgl2, and pressing alt+enter to enter fullscreen desktop.
This patch reworks SDL_windowsmodes.c to use EnumDisplayMonitors instead of EnumDisplayDevices, so we always have an HMONITOR for each SDL display.
With access to an HMONITOR, we can get the monitor bounds in virtual screen coordinates the proper way, by calling GetMonitorInfo. (whereas the original code was doing some calculations - e.g. "data->DeviceMode.dmPosition.x * data->ScaleX" - to try to get virtual screen coordinates. These worked in simple cases, but failed in more complex cases like this bug)
The one potential problem with my patch is, the ChangeDisplaySettingsEx docs say that you're supposed to get the display name from EnumDisplayDevices, but I'm getting the display name from GetMonitorInfo now.
2017-08-11 17:18:45 +00:00
|
|
|
const SDL_DisplayData *displaydata = (SDL_DisplayData *)display->driverdata;
|
|
|
|
const SDL_VideoData *videodata = (SDL_VideoData *)display->device->driverdata;
|
|
|
|
float hdpi = 0, vdpi = 0, ddpi = 0;
|
2022-11-30 20:51:59 +00:00
|
|
|
|
Fixed bug 3714 - Windows: SDL_WINDOW_FULLSCREEN_DESKTOP broken on 3 monitor setup w/ DPI scaling
Eric Wasylishen 2017-07-26 18:42:58 UTC
I set up an (admittedly exotic) 3-monitor setup, and when I enter fullscreen-desktop on the middle display (#2), the SDL window is off center. (covers half of monitor #2 and most of monitor #3).
The displays are arranged from left to right:
Display #1 (main): 2880x1800, 200% scaling
Display #2: 1920x1200, 150% scaling
Display #3: 1920x1080, 100% scaling
SDL display bounds:
INFO: Bounds: 1440x900 at 0,0
INFO: Bounds: 1281x801 at 1921,0 (these are incorrect)
INFO: Bounds: 1920x1080 at 4800,0
Correct bounds reported by calling EnumDisplayMonitors and printing the LPRECT param of the callback:
1440x900 at (0, 0)
1280x800 at (2880, 0)
1920x1080 at (4800, 0)
It seems like you need 3 displays to reproduce this, and the left two need DPI scaling, and the 3rd display needs to have a different scale factor than the others.
Related: https://bugzilla.libsdl.org/show_bug.cgi?id=3709
SDL: current hg (11235:6a587b9e0ec8)
Windows 10, Version 10.0.15063 Build 15063
Tested with testdraw2 and testgl2, and pressing alt+enter to enter fullscreen desktop.
This patch reworks SDL_windowsmodes.c to use EnumDisplayMonitors instead of EnumDisplayDevices, so we always have an HMONITOR for each SDL display.
With access to an HMONITOR, we can get the monitor bounds in virtual screen coordinates the proper way, by calling GetMonitorInfo. (whereas the original code was doing some calculations - e.g. "data->DeviceMode.dmPosition.x * data->ScaleX" - to try to get virtual screen coordinates. These worked in simple cases, but failed in more complex cases like this bug)
The one potential problem with my patch is, the ChangeDisplaySettingsEx docs say that you're supposed to get the display name from EnumDisplayDevices, but I'm getting the display name from GetMonitorInfo now.
2017-08-11 17:18:45 +00:00
|
|
|
if (videodata->GetDpiForMonitor) {
|
|
|
|
UINT hdpi_uint, vdpi_uint;
|
|
|
|
// Windows 8.1+ codepath
|
|
|
|
if (videodata->GetDpiForMonitor(displaydata->MonitorHandle, MDT_EFFECTIVE_DPI, &hdpi_uint, &vdpi_uint) == S_OK) {
|
|
|
|
// GetDpiForMonitor docs promise to return the same hdpi/vdpi
|
|
|
|
hdpi = (float)hdpi_uint;
|
|
|
|
vdpi = (float)hdpi_uint;
|
|
|
|
ddpi = (float)hdpi_uint;
|
|
|
|
} else {
|
|
|
|
return SDL_SetError("GetDpiForMonitor failed");
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// Window 8.0 and below: same DPI for all monitors.
|
|
|
|
HDC hdc;
|
|
|
|
int hdpi_int, vdpi_int, hpoints, vpoints, hpix, vpix;
|
|
|
|
float hinches, vinches;
|
|
|
|
|
|
|
|
hdc = GetDC(NULL);
|
|
|
|
if (hdc == NULL) {
|
|
|
|
return SDL_SetError("GetDC failed");
|
|
|
|
}
|
|
|
|
hdpi_int = GetDeviceCaps(hdc, LOGPIXELSX);
|
|
|
|
vdpi_int = GetDeviceCaps(hdc, LOGPIXELSY);
|
|
|
|
ReleaseDC(NULL, hdc);
|
2015-07-30 00:18:56 +00:00
|
|
|
|
Fixed bug 3714 - Windows: SDL_WINDOW_FULLSCREEN_DESKTOP broken on 3 monitor setup w/ DPI scaling
Eric Wasylishen 2017-07-26 18:42:58 UTC
I set up an (admittedly exotic) 3-monitor setup, and when I enter fullscreen-desktop on the middle display (#2), the SDL window is off center. (covers half of monitor #2 and most of monitor #3).
The displays are arranged from left to right:
Display #1 (main): 2880x1800, 200% scaling
Display #2: 1920x1200, 150% scaling
Display #3: 1920x1080, 100% scaling
SDL display bounds:
INFO: Bounds: 1440x900 at 0,0
INFO: Bounds: 1281x801 at 1921,0 (these are incorrect)
INFO: Bounds: 1920x1080 at 4800,0
Correct bounds reported by calling EnumDisplayMonitors and printing the LPRECT param of the callback:
1440x900 at (0, 0)
1280x800 at (2880, 0)
1920x1080 at (4800, 0)
It seems like you need 3 displays to reproduce this, and the left two need DPI scaling, and the 3rd display needs to have a different scale factor than the others.
Related: https://bugzilla.libsdl.org/show_bug.cgi?id=3709
SDL: current hg (11235:6a587b9e0ec8)
Windows 10, Version 10.0.15063 Build 15063
Tested with testdraw2 and testgl2, and pressing alt+enter to enter fullscreen desktop.
This patch reworks SDL_windowsmodes.c to use EnumDisplayMonitors instead of EnumDisplayDevices, so we always have an HMONITOR for each SDL display.
With access to an HMONITOR, we can get the monitor bounds in virtual screen coordinates the proper way, by calling GetMonitorInfo. (whereas the original code was doing some calculations - e.g. "data->DeviceMode.dmPosition.x * data->ScaleX" - to try to get virtual screen coordinates. These worked in simple cases, but failed in more complex cases like this bug)
The one potential problem with my patch is, the ChangeDisplaySettingsEx docs say that you're supposed to get the display name from EnumDisplayDevices, but I'm getting the display name from GetMonitorInfo now.
2017-08-11 17:18:45 +00:00
|
|
|
hpoints = GetSystemMetrics(SM_CXVIRTUALSCREEN);
|
|
|
|
vpoints = GetSystemMetrics(SM_CYVIRTUALSCREEN);
|
|
|
|
|
|
|
|
hpix = MulDiv(hpoints, hdpi_int, 96);
|
|
|
|
vpix = MulDiv(vpoints, vdpi_int, 96);
|
|
|
|
|
|
|
|
hinches = (float)hpoints / 96.0f;
|
|
|
|
vinches = (float)vpoints / 96.0f;
|
|
|
|
|
|
|
|
hdpi = (float)hdpi_int;
|
|
|
|
vdpi = (float)vdpi_int;
|
|
|
|
ddpi = SDL_ComputeDiagonalDPI(hpix, vpix, hinches, vinches);
|
2015-10-07 04:40:50 +00:00
|
|
|
}
|
Fixed bug 3714 - Windows: SDL_WINDOW_FULLSCREEN_DESKTOP broken on 3 monitor setup w/ DPI scaling
Eric Wasylishen 2017-07-26 18:42:58 UTC
I set up an (admittedly exotic) 3-monitor setup, and when I enter fullscreen-desktop on the middle display (#2), the SDL window is off center. (covers half of monitor #2 and most of monitor #3).
The displays are arranged from left to right:
Display #1 (main): 2880x1800, 200% scaling
Display #2: 1920x1200, 150% scaling
Display #3: 1920x1080, 100% scaling
SDL display bounds:
INFO: Bounds: 1440x900 at 0,0
INFO: Bounds: 1281x801 at 1921,0 (these are incorrect)
INFO: Bounds: 1920x1080 at 4800,0
Correct bounds reported by calling EnumDisplayMonitors and printing the LPRECT param of the callback:
1440x900 at (0, 0)
1280x800 at (2880, 0)
1920x1080 at (4800, 0)
It seems like you need 3 displays to reproduce this, and the left two need DPI scaling, and the 3rd display needs to have a different scale factor than the others.
Related: https://bugzilla.libsdl.org/show_bug.cgi?id=3709
SDL: current hg (11235:6a587b9e0ec8)
Windows 10, Version 10.0.15063 Build 15063
Tested with testdraw2 and testgl2, and pressing alt+enter to enter fullscreen desktop.
This patch reworks SDL_windowsmodes.c to use EnumDisplayMonitors instead of EnumDisplayDevices, so we always have an HMONITOR for each SDL display.
With access to an HMONITOR, we can get the monitor bounds in virtual screen coordinates the proper way, by calling GetMonitorInfo. (whereas the original code was doing some calculations - e.g. "data->DeviceMode.dmPosition.x * data->ScaleX" - to try to get virtual screen coordinates. These worked in simple cases, but failed in more complex cases like this bug)
The one potential problem with my patch is, the ChangeDisplaySettingsEx docs say that you're supposed to get the display name from EnumDisplayDevices, but I'm getting the display name from GetMonitorInfo now.
2017-08-11 17:18:45 +00:00
|
|
|
|
|
|
|
if (ddpi_out) {
|
|
|
|
*ddpi_out = ddpi;
|
2015-10-07 04:40:50 +00:00
|
|
|
}
|
Fixed bug 3714 - Windows: SDL_WINDOW_FULLSCREEN_DESKTOP broken on 3 monitor setup w/ DPI scaling
Eric Wasylishen 2017-07-26 18:42:58 UTC
I set up an (admittedly exotic) 3-monitor setup, and when I enter fullscreen-desktop on the middle display (#2), the SDL window is off center. (covers half of monitor #2 and most of monitor #3).
The displays are arranged from left to right:
Display #1 (main): 2880x1800, 200% scaling
Display #2: 1920x1200, 150% scaling
Display #3: 1920x1080, 100% scaling
SDL display bounds:
INFO: Bounds: 1440x900 at 0,0
INFO: Bounds: 1281x801 at 1921,0 (these are incorrect)
INFO: Bounds: 1920x1080 at 4800,0
Correct bounds reported by calling EnumDisplayMonitors and printing the LPRECT param of the callback:
1440x900 at (0, 0)
1280x800 at (2880, 0)
1920x1080 at (4800, 0)
It seems like you need 3 displays to reproduce this, and the left two need DPI scaling, and the 3rd display needs to have a different scale factor than the others.
Related: https://bugzilla.libsdl.org/show_bug.cgi?id=3709
SDL: current hg (11235:6a587b9e0ec8)
Windows 10, Version 10.0.15063 Build 15063
Tested with testdraw2 and testgl2, and pressing alt+enter to enter fullscreen desktop.
This patch reworks SDL_windowsmodes.c to use EnumDisplayMonitors instead of EnumDisplayDevices, so we always have an HMONITOR for each SDL display.
With access to an HMONITOR, we can get the monitor bounds in virtual screen coordinates the proper way, by calling GetMonitorInfo. (whereas the original code was doing some calculations - e.g. "data->DeviceMode.dmPosition.x * data->ScaleX" - to try to get virtual screen coordinates. These worked in simple cases, but failed in more complex cases like this bug)
The one potential problem with my patch is, the ChangeDisplaySettingsEx docs say that you're supposed to get the display name from EnumDisplayDevices, but I'm getting the display name from GetMonitorInfo now.
2017-08-11 17:18:45 +00:00
|
|
|
if (hdpi_out) {
|
|
|
|
*hdpi_out = hdpi;
|
|
|
|
}
|
|
|
|
if (vdpi_out) {
|
|
|
|
*vdpi_out = vdpi;
|
2015-10-07 04:40:50 +00:00
|
|
|
}
|
|
|
|
|
Fixed bug 3714 - Windows: SDL_WINDOW_FULLSCREEN_DESKTOP broken on 3 monitor setup w/ DPI scaling
Eric Wasylishen 2017-07-26 18:42:58 UTC
I set up an (admittedly exotic) 3-monitor setup, and when I enter fullscreen-desktop on the middle display (#2), the SDL window is off center. (covers half of monitor #2 and most of monitor #3).
The displays are arranged from left to right:
Display #1 (main): 2880x1800, 200% scaling
Display #2: 1920x1200, 150% scaling
Display #3: 1920x1080, 100% scaling
SDL display bounds:
INFO: Bounds: 1440x900 at 0,0
INFO: Bounds: 1281x801 at 1921,0 (these are incorrect)
INFO: Bounds: 1920x1080 at 4800,0
Correct bounds reported by calling EnumDisplayMonitors and printing the LPRECT param of the callback:
1440x900 at (0, 0)
1280x800 at (2880, 0)
1920x1080 at (4800, 0)
It seems like you need 3 displays to reproduce this, and the left two need DPI scaling, and the 3rd display needs to have a different scale factor than the others.
Related: https://bugzilla.libsdl.org/show_bug.cgi?id=3709
SDL: current hg (11235:6a587b9e0ec8)
Windows 10, Version 10.0.15063 Build 15063
Tested with testdraw2 and testgl2, and pressing alt+enter to enter fullscreen desktop.
This patch reworks SDL_windowsmodes.c to use EnumDisplayMonitors instead of EnumDisplayDevices, so we always have an HMONITOR for each SDL display.
With access to an HMONITOR, we can get the monitor bounds in virtual screen coordinates the proper way, by calling GetMonitorInfo. (whereas the original code was doing some calculations - e.g. "data->DeviceMode.dmPosition.x * data->ScaleX" - to try to get virtual screen coordinates. These worked in simple cases, but failed in more complex cases like this bug)
The one potential problem with my patch is, the ChangeDisplaySettingsEx docs say that you're supposed to get the display name from EnumDisplayDevices, but I'm getting the display name from GetMonitorInfo now.
2017-08-11 17:18:45 +00:00
|
|
|
return ddpi != 0.0f ? 0 : SDL_SetError("Couldn't get DPI");
|
2015-07-30 00:18:56 +00:00
|
|
|
}
|
|
|
|
|
2022-11-30 20:51:59 +00:00
|
|
|
int WIN_GetDisplayUsableBounds(_THIS, SDL_VideoDisplay *display, SDL_Rect *rect)
|
2016-01-05 04:52:40 +00:00
|
|
|
{
|
Fixed bug 3714 - Windows: SDL_WINDOW_FULLSCREEN_DESKTOP broken on 3 monitor setup w/ DPI scaling
Eric Wasylishen 2017-07-26 18:42:58 UTC
I set up an (admittedly exotic) 3-monitor setup, and when I enter fullscreen-desktop on the middle display (#2), the SDL window is off center. (covers half of monitor #2 and most of monitor #3).
The displays are arranged from left to right:
Display #1 (main): 2880x1800, 200% scaling
Display #2: 1920x1200, 150% scaling
Display #3: 1920x1080, 100% scaling
SDL display bounds:
INFO: Bounds: 1440x900 at 0,0
INFO: Bounds: 1281x801 at 1921,0 (these are incorrect)
INFO: Bounds: 1920x1080 at 4800,0
Correct bounds reported by calling EnumDisplayMonitors and printing the LPRECT param of the callback:
1440x900 at (0, 0)
1280x800 at (2880, 0)
1920x1080 at (4800, 0)
It seems like you need 3 displays to reproduce this, and the left two need DPI scaling, and the 3rd display needs to have a different scale factor than the others.
Related: https://bugzilla.libsdl.org/show_bug.cgi?id=3709
SDL: current hg (11235:6a587b9e0ec8)
Windows 10, Version 10.0.15063 Build 15063
Tested with testdraw2 and testgl2, and pressing alt+enter to enter fullscreen desktop.
This patch reworks SDL_windowsmodes.c to use EnumDisplayMonitors instead of EnumDisplayDevices, so we always have an HMONITOR for each SDL display.
With access to an HMONITOR, we can get the monitor bounds in virtual screen coordinates the proper way, by calling GetMonitorInfo. (whereas the original code was doing some calculations - e.g. "data->DeviceMode.dmPosition.x * data->ScaleX" - to try to get virtual screen coordinates. These worked in simple cases, but failed in more complex cases like this bug)
The one potential problem with my patch is, the ChangeDisplaySettingsEx docs say that you're supposed to get the display name from EnumDisplayDevices, but I'm getting the display name from GetMonitorInfo now.
2017-08-11 17:18:45 +00:00
|
|
|
const SDL_DisplayData *data = (const SDL_DisplayData *)display->driverdata;
|
2022-06-07 08:01:27 +00:00
|
|
|
const SDL_VideoData *videodata = (SDL_VideoData *)display->device->driverdata;
|
2016-01-05 04:52:40 +00:00
|
|
|
MONITORINFO minfo;
|
Fixed bug 3714 - Windows: SDL_WINDOW_FULLSCREEN_DESKTOP broken on 3 monitor setup w/ DPI scaling
Eric Wasylishen 2017-07-26 18:42:58 UTC
I set up an (admittedly exotic) 3-monitor setup, and when I enter fullscreen-desktop on the middle display (#2), the SDL window is off center. (covers half of monitor #2 and most of monitor #3).
The displays are arranged from left to right:
Display #1 (main): 2880x1800, 200% scaling
Display #2: 1920x1200, 150% scaling
Display #3: 1920x1080, 100% scaling
SDL display bounds:
INFO: Bounds: 1440x900 at 0,0
INFO: Bounds: 1281x801 at 1921,0 (these are incorrect)
INFO: Bounds: 1920x1080 at 4800,0
Correct bounds reported by calling EnumDisplayMonitors and printing the LPRECT param of the callback:
1440x900 at (0, 0)
1280x800 at (2880, 0)
1920x1080 at (4800, 0)
It seems like you need 3 displays to reproduce this, and the left two need DPI scaling, and the 3rd display needs to have a different scale factor than the others.
Related: https://bugzilla.libsdl.org/show_bug.cgi?id=3709
SDL: current hg (11235:6a587b9e0ec8)
Windows 10, Version 10.0.15063 Build 15063
Tested with testdraw2 and testgl2, and pressing alt+enter to enter fullscreen desktop.
This patch reworks SDL_windowsmodes.c to use EnumDisplayMonitors instead of EnumDisplayDevices, so we always have an HMONITOR for each SDL display.
With access to an HMONITOR, we can get the monitor bounds in virtual screen coordinates the proper way, by calling GetMonitorInfo. (whereas the original code was doing some calculations - e.g. "data->DeviceMode.dmPosition.x * data->ScaleX" - to try to get virtual screen coordinates. These worked in simple cases, but failed in more complex cases like this bug)
The one potential problem with my patch is, the ChangeDisplaySettingsEx docs say that you're supposed to get the display name from EnumDisplayDevices, but I'm getting the display name from GetMonitorInfo now.
2017-08-11 17:18:45 +00:00
|
|
|
BOOL rc;
|
2016-01-05 04:52:40 +00:00
|
|
|
|
Fixed bug 3714 - Windows: SDL_WINDOW_FULLSCREEN_DESKTOP broken on 3 monitor setup w/ DPI scaling
Eric Wasylishen 2017-07-26 18:42:58 UTC
I set up an (admittedly exotic) 3-monitor setup, and when I enter fullscreen-desktop on the middle display (#2), the SDL window is off center. (covers half of monitor #2 and most of monitor #3).
The displays are arranged from left to right:
Display #1 (main): 2880x1800, 200% scaling
Display #2: 1920x1200, 150% scaling
Display #3: 1920x1080, 100% scaling
SDL display bounds:
INFO: Bounds: 1440x900 at 0,0
INFO: Bounds: 1281x801 at 1921,0 (these are incorrect)
INFO: Bounds: 1920x1080 at 4800,0
Correct bounds reported by calling EnumDisplayMonitors and printing the LPRECT param of the callback:
1440x900 at (0, 0)
1280x800 at (2880, 0)
1920x1080 at (4800, 0)
It seems like you need 3 displays to reproduce this, and the left two need DPI scaling, and the 3rd display needs to have a different scale factor than the others.
Related: https://bugzilla.libsdl.org/show_bug.cgi?id=3709
SDL: current hg (11235:6a587b9e0ec8)
Windows 10, Version 10.0.15063 Build 15063
Tested with testdraw2 and testgl2, and pressing alt+enter to enter fullscreen desktop.
This patch reworks SDL_windowsmodes.c to use EnumDisplayMonitors instead of EnumDisplayDevices, so we always have an HMONITOR for each SDL display.
With access to an HMONITOR, we can get the monitor bounds in virtual screen coordinates the proper way, by calling GetMonitorInfo. (whereas the original code was doing some calculations - e.g. "data->DeviceMode.dmPosition.x * data->ScaleX" - to try to get virtual screen coordinates. These worked in simple cases, but failed in more complex cases like this bug)
The one potential problem with my patch is, the ChangeDisplaySettingsEx docs say that you're supposed to get the display name from EnumDisplayDevices, but I'm getting the display name from GetMonitorInfo now.
2017-08-11 17:18:45 +00:00
|
|
|
SDL_zero(minfo);
|
|
|
|
minfo.cbSize = sizeof(MONITORINFO);
|
|
|
|
rc = GetMonitorInfo(data->MonitorHandle, &minfo);
|
2016-01-05 04:52:40 +00:00
|
|
|
|
|
|
|
if (!rc) {
|
|
|
|
return SDL_SetError("Couldn't find monitor data");
|
|
|
|
}
|
|
|
|
|
2022-06-07 08:01:27 +00:00
|
|
|
WIN_MonitorInfoToSDL(videodata, data->MonitorHandle, &minfo);
|
Fixed bug 3714 - Windows: SDL_WINDOW_FULLSCREEN_DESKTOP broken on 3 monitor setup w/ DPI scaling
Eric Wasylishen 2017-07-26 18:42:58 UTC
I set up an (admittedly exotic) 3-monitor setup, and when I enter fullscreen-desktop on the middle display (#2), the SDL window is off center. (covers half of monitor #2 and most of monitor #3).
The displays are arranged from left to right:
Display #1 (main): 2880x1800, 200% scaling
Display #2: 1920x1200, 150% scaling
Display #3: 1920x1080, 100% scaling
SDL display bounds:
INFO: Bounds: 1440x900 at 0,0
INFO: Bounds: 1281x801 at 1921,0 (these are incorrect)
INFO: Bounds: 1920x1080 at 4800,0
Correct bounds reported by calling EnumDisplayMonitors and printing the LPRECT param of the callback:
1440x900 at (0, 0)
1280x800 at (2880, 0)
1920x1080 at (4800, 0)
It seems like you need 3 displays to reproduce this, and the left two need DPI scaling, and the 3rd display needs to have a different scale factor than the others.
Related: https://bugzilla.libsdl.org/show_bug.cgi?id=3709
SDL: current hg (11235:6a587b9e0ec8)
Windows 10, Version 10.0.15063 Build 15063
Tested with testdraw2 and testgl2, and pressing alt+enter to enter fullscreen desktop.
This patch reworks SDL_windowsmodes.c to use EnumDisplayMonitors instead of EnumDisplayDevices, so we always have an HMONITOR for each SDL display.
With access to an HMONITOR, we can get the monitor bounds in virtual screen coordinates the proper way, by calling GetMonitorInfo. (whereas the original code was doing some calculations - e.g. "data->DeviceMode.dmPosition.x * data->ScaleX" - to try to get virtual screen coordinates. These worked in simple cases, but failed in more complex cases like this bug)
The one potential problem with my patch is, the ChangeDisplaySettingsEx docs say that you're supposed to get the display name from EnumDisplayDevices, but I'm getting the display name from GetMonitorInfo now.
2017-08-11 17:18:45 +00:00
|
|
|
rect->x = minfo.rcWork.left;
|
|
|
|
rect->y = minfo.rcWork.top;
|
|
|
|
rect->w = minfo.rcWork.right - minfo.rcWork.left;
|
|
|
|
rect->h = minfo.rcWork.bottom - minfo.rcWork.top;
|
2016-01-05 04:52:40 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2022-06-07 08:01:27 +00:00
|
|
|
/**
|
2022-11-30 20:51:59 +00:00
|
|
|
* Convert a point from the SDL coordinate system (monitor origins are in pixels,
|
2022-06-07 08:01:27 +00:00
|
|
|
* offset within a monitor in DPI-scaled points) to Windows virtual screen coordinates (pixels).
|
2022-11-30 20:51:59 +00:00
|
|
|
*
|
2022-06-07 08:01:27 +00:00
|
|
|
* No-op if DPI scaling is not enabled (returns 96 dpi).
|
2022-11-30 20:51:59 +00:00
|
|
|
*
|
2022-06-07 08:01:27 +00:00
|
|
|
* Returns the DPI of the monitor that was closest to x, y and used for the conversion.
|
|
|
|
*/
|
|
|
|
void WIN_ScreenPointFromSDL(int *x, int *y, int *dpiOut)
|
|
|
|
{
|
|
|
|
const SDL_VideoDevice *videodevice = SDL_GetVideoDevice();
|
|
|
|
const SDL_VideoData *videodata;
|
|
|
|
int displayIndex;
|
|
|
|
SDL_Rect bounds;
|
|
|
|
float ddpi, hdpi, vdpi;
|
|
|
|
int x_sdl, y_sdl;
|
2022-08-08 18:26:52 +00:00
|
|
|
SDL_Point point;
|
2022-11-30 20:51:59 +00:00
|
|
|
point.x = *x;
|
|
|
|
point.y = *y;
|
2022-06-07 08:01:27 +00:00
|
|
|
|
|
|
|
if (dpiOut) {
|
|
|
|
*dpiOut = 96;
|
|
|
|
}
|
|
|
|
|
2022-11-27 16:38:43 +00:00
|
|
|
if (videodevice == NULL || !videodevice->driverdata) {
|
2022-06-07 08:01:27 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
videodata = (SDL_VideoData *)videodevice->driverdata;
|
|
|
|
if (!videodata->dpi_scaling_enabled) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Can't use MonitorFromPoint for this because we currently have SDL coordinates, not pixels */
|
2022-08-08 18:26:52 +00:00
|
|
|
displayIndex = SDL_GetPointDisplayIndex(&point);
|
2022-06-07 08:01:27 +00:00
|
|
|
|
|
|
|
if (displayIndex < 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-11-30 20:51:59 +00:00
|
|
|
if (SDL_GetDisplayBounds(displayIndex, &bounds) < 0 || SDL_GetDisplayDPI(displayIndex, &ddpi, &hdpi, &vdpi) < 0) {
|
2022-06-07 08:01:27 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (dpiOut) {
|
2022-11-30 20:51:59 +00:00
|
|
|
*dpiOut = (int)ddpi;
|
2022-06-07 08:01:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Undo the DPI-scaling within the monitor bounds to convert back to pixels */
|
|
|
|
x_sdl = *x;
|
|
|
|
y_sdl = *y;
|
|
|
|
*x = bounds.x + MulDiv(x_sdl - bounds.x, (int)ddpi, 96);
|
|
|
|
*y = bounds.y + MulDiv(y_sdl - bounds.y, (int)ddpi, 96);
|
|
|
|
|
|
|
|
#ifdef HIGHDPI_DEBUG_VERBOSE
|
|
|
|
SDL_Log("WIN_ScreenPointFromSDL: (%d, %d) points -> (%d x %d) pixels, using %d DPI monitor",
|
2022-11-30 20:51:59 +00:00
|
|
|
x_sdl, y_sdl, *x, *y, (int)ddpi);
|
2022-06-07 08:01:27 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Convert a point from Windows virtual screen coordinates (pixels) to the SDL
|
|
|
|
* coordinate system (monitor origins are in pixels, offset within a monitor in DPI-scaled points).
|
|
|
|
*
|
|
|
|
* No-op if DPI scaling is not enabled.
|
|
|
|
*/
|
|
|
|
void WIN_ScreenPointToSDL(int *x, int *y)
|
|
|
|
{
|
|
|
|
const SDL_VideoDevice *videodevice = SDL_GetVideoDevice();
|
|
|
|
const SDL_VideoData *videodata;
|
|
|
|
POINT point;
|
|
|
|
HMONITOR monitor;
|
|
|
|
int i, displayIndex;
|
|
|
|
SDL_Rect bounds;
|
|
|
|
float ddpi, hdpi, vdpi;
|
|
|
|
int x_pixels, y_pixels;
|
|
|
|
|
2022-11-27 16:38:43 +00:00
|
|
|
if (videodevice == NULL || !videodevice->driverdata) {
|
2022-06-07 08:01:27 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
videodata = (SDL_VideoData *)videodevice->driverdata;
|
|
|
|
if (!videodata->dpi_scaling_enabled) {
|
|
|
|
return;
|
|
|
|
}
|
2022-11-30 20:51:59 +00:00
|
|
|
|
2022-06-07 08:01:27 +00:00
|
|
|
point.x = *x;
|
|
|
|
point.y = *y;
|
|
|
|
monitor = MonitorFromPoint(point, MONITOR_DEFAULTTONEAREST);
|
|
|
|
|
|
|
|
/* Search for the corresponding SDL monitor */
|
|
|
|
displayIndex = -1;
|
|
|
|
for (i = 0; i < videodevice->num_displays; ++i) {
|
|
|
|
SDL_DisplayData *driverdata = (SDL_DisplayData *)videodevice->displays[i].driverdata;
|
|
|
|
if (driverdata->MonitorHandle == monitor) {
|
|
|
|
displayIndex = i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (displayIndex == -1) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Get SDL display properties */
|
2022-11-30 20:51:59 +00:00
|
|
|
if (SDL_GetDisplayBounds(displayIndex, &bounds) < 0 || SDL_GetDisplayDPI(displayIndex, &ddpi, &hdpi, &vdpi) < 0) {
|
2022-06-07 08:01:27 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Convert the point's offset within the monitor from pixels to DPI-scaled points */
|
|
|
|
x_pixels = *x;
|
|
|
|
y_pixels = *y;
|
|
|
|
*x = bounds.x + MulDiv(x_pixels - bounds.x, 96, (int)ddpi);
|
|
|
|
*y = bounds.y + MulDiv(y_pixels - bounds.y, 96, (int)ddpi);
|
|
|
|
|
|
|
|
#ifdef HIGHDPI_DEBUG_VERBOSE
|
|
|
|
SDL_Log("WIN_ScreenPointToSDL: (%d, %d) pixels -> (%d x %d) points, using %d DPI monitor",
|
2022-11-30 20:51:59 +00:00
|
|
|
x_pixels, y_pixels, *x, *y, (int)ddpi);
|
2022-06-07 08:01:27 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2022-11-30 20:51:59 +00:00
|
|
|
void WIN_GetDisplayModes(_THIS, SDL_VideoDisplay *display)
|
2015-06-21 15:33:46 +00:00
|
|
|
{
|
2022-11-30 20:51:59 +00:00
|
|
|
SDL_DisplayData *data = (SDL_DisplayData *)display->driverdata;
|
2015-06-21 15:33:46 +00:00
|
|
|
DWORD i;
|
|
|
|
SDL_DisplayMode mode;
|
|
|
|
|
2022-11-30 20:51:59 +00:00
|
|
|
for (i = 0;; ++i) {
|
2021-11-10 14:03:01 +00:00
|
|
|
if (!WIN_GetDisplayMode(_this, data->DeviceName, i, &mode, NULL)) {
|
2015-06-21 15:33:46 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (SDL_ISPIXELFORMAT_INDEXED(mode.format)) {
|
|
|
|
/* We don't support palettized modes now */
|
|
|
|
SDL_free(mode.driverdata);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (mode.format != SDL_PIXELFORMAT_UNKNOWN) {
|
|
|
|
if (!SDL_AddDisplayMode(display, &mode)) {
|
|
|
|
SDL_free(mode.driverdata);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
SDL_free(mode.driverdata);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-07 08:01:27 +00:00
|
|
|
#ifdef DEBUG_MODES
|
2022-11-30 20:51:59 +00:00
|
|
|
static void WIN_LogMonitor(_THIS, HMONITOR mon)
|
2022-06-07 08:01:27 +00:00
|
|
|
{
|
|
|
|
const SDL_VideoData *vid_data = (const SDL_VideoData *)_this->driverdata;
|
|
|
|
MONITORINFOEX minfo;
|
|
|
|
UINT xdpi = 0, ydpi = 0;
|
|
|
|
char *name_utf8;
|
|
|
|
|
|
|
|
if (vid_data->GetDpiForMonitor) {
|
|
|
|
vid_data->GetDpiForMonitor(mon, MDT_EFFECTIVE_DPI, &xdpi, &ydpi);
|
|
|
|
}
|
|
|
|
|
|
|
|
SDL_zero(minfo);
|
|
|
|
minfo.cbSize = sizeof(minfo);
|
|
|
|
GetMonitorInfo(mon, (LPMONITORINFO)&minfo);
|
|
|
|
|
|
|
|
name_utf8 = WIN_StringToUTF8(minfo.szDevice);
|
|
|
|
|
|
|
|
SDL_Log("WIN_LogMonitor: monitor \"%s\": dpi: %d windows screen coordinates: %d, %d, %dx%d",
|
2022-11-30 20:51:59 +00:00
|
|
|
name_utf8,
|
|
|
|
xdpi,
|
|
|
|
minfo.rcMonitor.left,
|
|
|
|
minfo.rcMonitor.top,
|
|
|
|
minfo.rcMonitor.right - minfo.rcMonitor.left,
|
|
|
|
minfo.rcMonitor.bottom - minfo.rcMonitor.top);
|
2022-06-07 08:01:27 +00:00
|
|
|
|
|
|
|
SDL_free(name_utf8);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2022-11-30 20:51:59 +00:00
|
|
|
int WIN_SetDisplayMode(_THIS, SDL_VideoDisplay *display, SDL_DisplayMode *mode)
|
2015-06-21 15:33:46 +00:00
|
|
|
{
|
2022-11-30 20:51:59 +00:00
|
|
|
SDL_DisplayData *displaydata = (SDL_DisplayData *)display->driverdata;
|
|
|
|
SDL_DisplayModeData *data = (SDL_DisplayModeData *)mode->driverdata;
|
2015-06-21 15:33:46 +00:00
|
|
|
LONG status;
|
|
|
|
|
2022-06-07 08:01:27 +00:00
|
|
|
#ifdef DEBUG_MODES
|
|
|
|
SDL_Log("WIN_SetDisplayMode: monitor state before mode change:");
|
|
|
|
WIN_LogMonitor(_this, displaydata->MonitorHandle);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* High-DPI notes:
|
|
|
|
|
|
|
|
- ChangeDisplaySettingsEx always takes pixels.
|
|
|
|
- e.g. if the display is set to 2880x1800 with 200% scaling in Display Settings
|
|
|
|
- calling ChangeDisplaySettingsEx with a dmPelsWidth/Height other than 2880x1800 will
|
|
|
|
change the monitor DPI to 96. (100% scaling)
|
|
|
|
- calling ChangeDisplaySettingsEx with a dmPelsWidth/Height of 2880x1800 (or a NULL DEVMODE*) will
|
|
|
|
reset the monitor DPI to 192. (200% scaling)
|
|
|
|
|
|
|
|
NOTE: these are temporary changes in DPI, not modifications to the Control Panel setting. */
|
2015-06-21 15:33:46 +00:00
|
|
|
if (mode->driverdata == display->desktop_mode.driverdata) {
|
2022-06-07 08:01:27 +00:00
|
|
|
#ifdef DEBUG_MODES
|
|
|
|
SDL_Log("WIN_SetDisplayMode: resetting to original resolution");
|
|
|
|
#endif
|
2021-01-05 12:50:10 +00:00
|
|
|
status = ChangeDisplaySettingsExW(displaydata->DeviceName, NULL, NULL, CDS_FULLSCREEN, NULL);
|
2015-06-21 15:33:46 +00:00
|
|
|
} else {
|
2022-06-07 08:01:27 +00:00
|
|
|
#ifdef DEBUG_MODES
|
|
|
|
SDL_Log("WIN_SetDisplayMode: changing to %dx%d pixels", data->DeviceMode.dmPelsWidth, data->DeviceMode.dmPelsHeight);
|
|
|
|
#endif
|
2021-01-05 12:50:10 +00:00
|
|
|
status = ChangeDisplaySettingsExW(displaydata->DeviceName, &data->DeviceMode, NULL, CDS_FULLSCREEN, NULL);
|
2015-06-21 15:33:46 +00:00
|
|
|
}
|
|
|
|
if (status != DISP_CHANGE_SUCCESSFUL) {
|
|
|
|
const char *reason = "Unknown reason";
|
|
|
|
switch (status) {
|
|
|
|
case DISP_CHANGE_BADFLAGS:
|
|
|
|
reason = "DISP_CHANGE_BADFLAGS";
|
|
|
|
break;
|
|
|
|
case DISP_CHANGE_BADMODE:
|
|
|
|
reason = "DISP_CHANGE_BADMODE";
|
|
|
|
break;
|
|
|
|
case DISP_CHANGE_BADPARAM:
|
|
|
|
reason = "DISP_CHANGE_BADPARAM";
|
|
|
|
break;
|
|
|
|
case DISP_CHANGE_FAILED:
|
|
|
|
reason = "DISP_CHANGE_FAILED";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return SDL_SetError("ChangeDisplaySettingsEx() failed: %s", reason);
|
|
|
|
}
|
2022-06-07 08:01:27 +00:00
|
|
|
|
|
|
|
#ifdef DEBUG_MODES
|
|
|
|
SDL_Log("WIN_SetDisplayMode: monitor state after mode change:");
|
|
|
|
WIN_LogMonitor(_this, displaydata->MonitorHandle);
|
|
|
|
#endif
|
|
|
|
|
2021-01-05 12:50:10 +00:00
|
|
|
EnumDisplaySettingsW(displaydata->DeviceName, ENUM_CURRENT_SETTINGS, &data->DeviceMode);
|
2016-03-11 16:33:47 +00:00
|
|
|
WIN_UpdateDisplayMode(_this, displaydata->DeviceName, ENUM_CURRENT_SETTINGS, mode);
|
2015-06-21 15:33:46 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2022-11-30 20:51:59 +00:00
|
|
|
void WIN_RefreshDisplays(_THIS)
|
2020-10-14 04:08:20 +00:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
// Mark all displays as potentially invalid to detect
|
|
|
|
// entries that have actually been removed
|
|
|
|
for (i = 0; i < _this->num_displays; ++i) {
|
|
|
|
SDL_DisplayData *driverdata = (SDL_DisplayData *)_this->displays[i].driverdata;
|
|
|
|
driverdata->IsValid = SDL_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Enumerate displays to add any new ones and mark still
|
|
|
|
// connected entries as valid
|
|
|
|
WIN_AddDisplays(_this, SDL_TRUE);
|
|
|
|
|
|
|
|
// Delete any entries still marked as invalid, iterate
|
|
|
|
// in reverse as each delete takes effect immediately
|
|
|
|
for (i = _this->num_displays - 1; i >= 0; --i) {
|
|
|
|
SDL_DisplayData *driverdata = (SDL_DisplayData *)_this->displays[i].driverdata;
|
|
|
|
if (driverdata->IsValid == SDL_FALSE) {
|
|
|
|
SDL_DelVideoDisplay(i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-30 20:51:59 +00:00
|
|
|
void WIN_QuitModes(_THIS)
|
2015-06-21 15:33:46 +00:00
|
|
|
{
|
|
|
|
/* All fullscreen windows should have restored modes by now */
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* SDL_VIDEO_DRIVER_WINDOWS */
|
|
|
|
|
|
|
|
/* vi: set ts=4 sw=4 expandtab: */
|