From e8fd7f74bd6ddc91843194481b60688b4a2bfb50 Mon Sep 17 00:00:00 2001 From: Frank Praznik Date: Wed, 22 Feb 2023 12:02:25 -0500 Subject: [PATCH] windows: Track the window display ID locally Track the current window display ID locally so as not to depend on specific behavior of the video layer, which may change the value at times when it isn't expected. --- src/video/windows/SDL_windowsevents.c | 7 +++++-- src/video/windows/SDL_windowswindow.c | 1 + src/video/windows/SDL_windowswindow.h | 1 + 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/video/windows/SDL_windowsevents.c b/src/video/windows/SDL_windowsevents.c index 06d9e1c031..487ce3c30e 100644 --- a/src/video/windows/SDL_windowsevents.c +++ b/src/video/windows/SDL_windowsevents.c @@ -1241,7 +1241,7 @@ WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) RECT rect; int x, y; int w, h; - SDL_DisplayID displayID = SDL_GetDisplayForWindow(data->window); + const SDL_DisplayID original_displayID = data->last_displayID; if (data->initializing || data->in_border_change) { break; @@ -1294,7 +1294,10 @@ WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) /* Forces a WM_PAINT event */ InvalidateRect(hwnd, NULL, FALSE); - if (data->window->last_displayID != displayID) { + /* Update the window display position */ + data->last_displayID = SDL_GetDisplayForWindow(data->window); + + if (data->last_displayID != original_displayID) { /* Display changed, check ICC profile */ WIN_UpdateWindowICCProfile(data->window, SDL_TRUE); } diff --git a/src/video/windows/SDL_windowswindow.c b/src/video/windows/SDL_windowswindow.c index 9806e89125..fbc901d759 100644 --- a/src/video/windows/SDL_windowswindow.c +++ b/src/video/windows/SDL_windowswindow.c @@ -309,6 +309,7 @@ static int SetupWindowData(_THIS, SDL_Window *window, HWND hwnd, HWND parent, SD data->last_pointer_update = (LPARAM)-1; data->videodata = videodata; data->initializing = SDL_TRUE; + data->last_displayID = window->last_displayID; data->scaling_dpi = WIN_GetScalingDPIForHWND(videodata, hwnd); #ifdef HIGHDPI_DEBUG diff --git a/src/video/windows/SDL_windowswindow.h b/src/video/windows/SDL_windowswindow.h index 2aa59c93e7..c27ba0341b 100644 --- a/src/video/windows/SDL_windowswindow.h +++ b/src/video/windows/SDL_windowswindow.h @@ -62,6 +62,7 @@ struct SDL_WindowData RECT cursor_clipped_rect; SDL_Point last_raw_mouse_position; SDL_bool mouse_tracked; + SDL_DisplayID last_displayID; WCHAR *ICMFileName; struct SDL_VideoData *videodata; #if SDL_VIDEO_OPENGL_EGL