From bd2e318c02656637bda38c89737420aae6499131 Mon Sep 17 00:00:00 2001
From: Frank Praznik <[EMAIL REDACTED]>
Date: Fri, 30 Oct 2026 12:49:47 -0400
Subject: [PATCH] win32: Save and restore the previous DPI context when working
around the ClipCursor issue
This path should never be hit if the context isn't set to unaware, but save and restore the previous context value just to be safe, as it adds no overhead.
---
src/video/windows/SDL_windowswindow.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/src/video/windows/SDL_windowswindow.c b/src/video/windows/SDL_windowswindow.c
index 2e904c32a7f9e..637689353abf0 100644
--- a/src/video/windows/SDL_windowswindow.c
+++ b/src/video/windows/SDL_windowswindow.c
@@ -1636,7 +1636,8 @@ void WIN_UpdateClipCursor(SDL_Window *window)
*/
// Temporarily set the thread to per-monitor awareness v2 to get the display DPI.
- if (videodata->SetThreadDpiAwarenessContext(DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2)) {
+ DPI_AWARENESS_CONTEXT prev_ctx = videodata->SetThreadDpiAwarenessContext(DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2);
+ if (prev_ctx) {
HMONITOR hmon = MonitorFromWindow(data->hwnd, MONITOR_DEFAULTTONEAREST);
if (hmon) {
UINT hdpi_uint, vdpi_uint;
@@ -1658,7 +1659,7 @@ void WIN_UpdateClipCursor(SDL_Window *window)
}
}
}
- videodata->SetThreadDpiAwarenessContext(DPI_AWARENESS_CONTEXT_UNAWARE);
+ videodata->SetThreadDpiAwarenessContext(prev_ctx);
}
}