From 4797fbac377fc9f01723c364a331a1cc2f34f553 Mon Sep 17 00:00:00 2001 From: Esme Povirk Date: Thu, 20 Nov 2025 20:27:36 +0000 Subject: [PATCH 1/2] windows: Add property mapping displayID to HMONITOR. --- include/SDL3/SDL_video.h | 6 ++++++ src/video/windows/SDL_windowsmodes.c | 4 ++++ 2 files changed, 10 insertions(+) diff --git a/include/SDL3/SDL_video.h b/include/SDL3/SDL_video.h index f5f92fcd1946b..5d13231dc32db 100644 --- a/include/SDL3/SDL_video.h +++ b/include/SDL3/SDL_video.h @@ -665,6 +665,11 @@ extern SDL_DECLSPEC SDL_DisplayID SDLCALL SDL_GetPrimaryDisplay(void); * - `SDL_PROP_DISPLAY_WAYLAND_WL_OUTPUT_POINTER`: the wl_output associated * with the display * + * On Windows: + * + * - `SDL_PROP_DISPLAY_WINDOWS_HMONITOR_POINTER`: the monitor handle (HMONITOR) + * associated with the display + * * \param displayID the instance ID of the display to query. * \returns a valid property ID on success or 0 on failure; call * SDL_GetError() for more information. @@ -678,6 +683,7 @@ extern SDL_DECLSPEC SDL_PropertiesID SDLCALL SDL_GetDisplayProperties(SDL_Displa #define SDL_PROP_DISPLAY_HDR_ENABLED_BOOLEAN "SDL.display.HDR_enabled" #define SDL_PROP_DISPLAY_KMSDRM_PANEL_ORIENTATION_NUMBER "SDL.display.KMSDRM.panel_orientation" #define SDL_PROP_DISPLAY_WAYLAND_WL_OUTPUT_POINTER "SDL.display.wayland.wl_output" +#define SDL_PROP_DISPLAY_WINDOWS_HMONITOR_POINTER "SDL.display.windows.hmonitor" /** * Get the name of a display in UTF-8 encoding. diff --git a/src/video/windows/SDL_windowsmodes.c b/src/video/windows/SDL_windowsmodes.c index 6123d8232c78f..7c08f8e565050 100644 --- a/src/video/windows/SDL_windowsmodes.c +++ b/src/video/windows/SDL_windowsmodes.c @@ -582,6 +582,7 @@ static void WIN_AddDisplay(SDL_VideoDevice *_this, HMONITOR hMonitor, const MONI if (SDL_wcscmp(internal->DeviceName, info->szDevice) == 0) { bool moved = (index != i); bool changed_bounds = false; + SDL_PropertiesID props = SDL_GetDisplayProperties(_this->displays[i]->id); if (internal->state != DisplayRemoved) { // We've already enumerated this display, don't move it @@ -603,6 +604,7 @@ static void WIN_AddDisplay(SDL_VideoDevice *_this, HMONITOR hMonitor, const MONI } internal->MonitorHandle = hMonitor; + SDL_SetPointerProperty(props, SDL_PROP_DISPLAY_WINDOWS_HMONITOR_POINTER, internal->MonitorHandle); internal->state = DisplayUnchanged; if (!_this->setting_display_mode) { @@ -663,6 +665,8 @@ static void WIN_AddDisplay(SDL_VideoDevice *_this, HMONITOR hMonitor, const MONI WIN_GetHDRProperties(_this, hMonitor, &display.HDR); #endif if (SDL_AddVideoDisplay(&display, false)) { + SDL_PropertiesID props = SDL_GetDisplayProperties(display.id); + SDL_SetPointerProperty(props, SDL_PROP_DISPLAY_WINDOWS_HMONITOR_POINTER, hMonitor); // The mode is owned by the video subsystem mode.internal = NULL; } else { From 7ffb8121ef80c196d07499e476ca33f3746d1716 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Fri, 21 Nov 2025 10:00:47 -0800 Subject: [PATCH 2/2] Fixed setting the monitor handle in the moved monitor case Also some miscellaneous organizational cleanup --- src/video/windows/SDL_windowsmodes.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/video/windows/SDL_windowsmodes.c b/src/video/windows/SDL_windowsmodes.c index 7c08f8e565050..e287f01d882e9 100644 --- a/src/video/windows/SDL_windowsmodes.c +++ b/src/video/windows/SDL_windowsmodes.c @@ -582,7 +582,6 @@ static void WIN_AddDisplay(SDL_VideoDevice *_this, HMONITOR hMonitor, const MONI if (SDL_wcscmp(internal->DeviceName, info->szDevice) == 0) { bool moved = (index != i); bool changed_bounds = false; - SDL_PropertiesID props = SDL_GetDisplayProperties(_this->displays[i]->id); if (internal->state != DisplayRemoved) { // We've already enumerated this display, don't move it @@ -604,9 +603,11 @@ static void WIN_AddDisplay(SDL_VideoDevice *_this, HMONITOR hMonitor, const MONI } internal->MonitorHandle = hMonitor; - SDL_SetPointerProperty(props, SDL_PROP_DISPLAY_WINDOWS_HMONITOR_POINTER, internal->MonitorHandle); internal->state = DisplayUnchanged; + SDL_PropertiesID props = SDL_GetDisplayProperties(_this->displays[i]->id); + SDL_SetPointerProperty(props, SDL_PROP_DISPLAY_WINDOWS_HMONITOR_POINTER, hMonitor); + if (!_this->setting_display_mode) { SDL_VideoDisplay *existing_display = _this->displays[i]; SDL_Rect bounds; @@ -665,10 +666,11 @@ static void WIN_AddDisplay(SDL_VideoDevice *_this, HMONITOR hMonitor, const MONI WIN_GetHDRProperties(_this, hMonitor, &display.HDR); #endif if (SDL_AddVideoDisplay(&display, false)) { - SDL_PropertiesID props = SDL_GetDisplayProperties(display.id); - SDL_SetPointerProperty(props, SDL_PROP_DISPLAY_WINDOWS_HMONITOR_POINTER, hMonitor); // The mode is owned by the video subsystem mode.internal = NULL; + + SDL_PropertiesID props = SDL_GetDisplayProperties(display.id); + SDL_SetPointerProperty(props, SDL_PROP_DISPLAY_WINDOWS_HMONITOR_POINTER, hMonitor); } else { SDL_free(displaydata); }