From f4f43d9501876697d7c6e88fa8759921025f5923 Mon Sep 17 00:00:00 2001 From: "kyns.one" <137704342+kyns-one@users.noreply.github.com> Date: Thu, 21 Dec 2023 01:34:53 +0100 Subject: [PATCH] Fix screen resolution always tied to the main monitor on win32 platforms. (#15897) --- gfx/common/win32_common.c | 10 +++++++--- gfx/display_servers/dispserv_win32.c | 8 ++++++-- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/gfx/common/win32_common.c b/gfx/common/win32_common.c index e22f266d08d..e422f69a17f 100644 --- a/gfx/common/win32_common.c +++ b/gfx/common/win32_common.c @@ -2680,16 +2680,20 @@ void win32_get_video_output_next( } #if defined(_WIN32_WINNT) && _WIN32_WINNT >= 0x0500 /* 2K */ -#define WIN32_GET_VIDEO_OUTPUT(iModeNum, dm) EnumDisplaySettingsEx(NULL, iModeNum, dm, EDS_ROTATEDMODE) +#define WIN32_GET_VIDEO_OUTPUT(devName, iModeNum, dm) EnumDisplaySettingsEx(devName, iModeNum, dm, EDS_ROTATEDMODE) #else -#define WIN32_GET_VIDEO_OUTPUT(iModeNum, dm) EnumDisplaySettings(NULL, iModeNum, dm) +#define WIN32_GET_VIDEO_OUTPUT(devName, iModeNum, dm) EnumDisplaySettings(devName, iModeNum, dm) #endif bool win32_get_video_output(DEVMODE *dm, int mode, size_t len) { + MONITORINFOEX current_mon; + HMONITOR hm_to_use = NULL; + unsigned mon_id = 0; memset(dm, 0, len); dm->dmSize = len; - if (WIN32_GET_VIDEO_OUTPUT((mode == -1) + win32_monitor_info(¤t_mon, &hm_to_use, &mon_id); + if (WIN32_GET_VIDEO_OUTPUT(¤t_mon.szDevice, (mode == -1) ? ENUM_CURRENT_SETTINGS : (DWORD)mode, dm) == 0) diff --git a/gfx/display_servers/dispserv_win32.c b/gfx/display_servers/dispserv_win32.c index 83e4855e5f7..f528a90d505 100644 --- a/gfx/display_servers/dispserv_win32.c +++ b/gfx/display_servers/dispserv_win32.c @@ -228,6 +228,9 @@ static bool win32_display_server_set_window_decorations(void *data, bool on) static bool win32_display_server_set_resolution(void *data, unsigned width, unsigned height, int int_hz, float hz, int center, int monitor_index, int xoffset, int padjust) { + MONITORINFOEX current_mon; + HMONITOR hm_to_use = NULL; + unsigned mon_id = 0; DEVMODE dm = {0}; LONG res = 0; unsigned i = 0; @@ -288,12 +291,13 @@ static bool win32_display_server_set_resolution(void *data, dm.dmFields |= DM_DISPLAYORIENTATION; #endif - res = win32_change_display_settings(NULL, &dm, CDS_TEST); + win32_monitor_info(¤t_mon, &hm_to_use, &mon_id); + res = win32_change_display_settings(¤t_mon.szDevice, &dm, CDS_TEST); switch (res) { case DISP_CHANGE_SUCCESSFUL: - res = win32_change_display_settings(NULL, &dm, 0); + res = win32_change_display_settings(¤t_mon.szDevice, &dm, 0); switch (res) { case DISP_CHANGE_SUCCESSFUL: