Pass the frame DPI to WIN_AdjustWindowRectForHWND()

This commit is contained in:
Sam Lantinga
2024-01-12 09:31:58 -08:00
parent e4ee1cade7
commit 7efeb36131
3 changed files with 9 additions and 11 deletions

View File

@@ -1045,7 +1045,7 @@ WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
size.left = 0; size.left = 0;
size.bottom = h; size.bottom = h;
size.right = w; size.right = w;
WIN_AdjustWindowRectForHWND(hwnd, &size); WIN_AdjustWindowRectForHWND(hwnd, &size, 0);
w = size.right - size.left; w = size.right - size.left;
h = size.bottom - size.top; h = size.bottom - size.top;
#ifdef HIGHDPI_DEBUG #ifdef HIGHDPI_DEBUG
@@ -1493,10 +1493,6 @@ WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
int frame_w, frame_h; int frame_w, frame_h;
int query_client_w_win, query_client_h_win; int query_client_w_win, query_client_h_win;
const DWORD style = GetWindowLong(hwnd, GWL_STYLE);
const DWORD styleEx = GetWindowLong(hwnd, GWL_EXSTYLE);
const BOOL menu = (style & WS_CHILDWINDOW) ? FALSE : (GetMenu(hwnd) != NULL);
#ifdef HIGHDPI_DEBUG #ifdef HIGHDPI_DEBUG
SDL_Log("WM_GETDPISCALEDSIZE: current DPI: %d potential DPI: %d input size: (%dx%d)", SDL_Log("WM_GETDPISCALEDSIZE: current DPI: %d potential DPI: %d input size: (%dx%d)",
prevDPI, nextDPI, sizeInOut->cx, sizeInOut->cy); prevDPI, nextDPI, sizeInOut->cx, sizeInOut->cy);
@@ -1507,7 +1503,7 @@ WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
RECT rect = { 0 }; RECT rect = { 0 };
if (!(data->window->flags & SDL_WINDOW_BORDERLESS)) { if (!(data->window->flags & SDL_WINDOW_BORDERLESS)) {
data->videodata->AdjustWindowRectExForDpi(&rect, style, menu, styleEx, prevDPI); WIN_AdjustWindowRectForHWND(hwnd, &rect, prevDPI);
} }
frame_w = -rect.left + rect.right; frame_w = -rect.left + rect.right;
@@ -1524,7 +1520,7 @@ WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
rect.bottom = query_client_h_win; rect.bottom = query_client_h_win;
if (!(data->window->flags & SDL_WINDOW_BORDERLESS)) { if (!(data->window->flags & SDL_WINDOW_BORDERLESS)) {
data->videodata->AdjustWindowRectExForDpi(&rect, style, menu, styleEx, nextDPI); WIN_AdjustWindowRectForHWND(hwnd, &rect, nextDPI);
} }
/* This is supposed to control the suggested rect param of WM_DPICHANGED */ /* This is supposed to control the suggested rect param of WM_DPICHANGED */
@@ -1570,7 +1566,7 @@ WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
rect.bottom = data->window->h; rect.bottom = data->window->h;
if (!(data->window->flags & SDL_WINDOW_BORDERLESS)) { if (!(data->window->flags & SDL_WINDOW_BORDERLESS)) {
WIN_AdjustWindowRectForHWND(hwnd, &rect); WIN_AdjustWindowRectForHWND(hwnd, &rect, newDPI);
} }
w = rect.right - rect.left; w = rect.right - rect.left;

View File

@@ -248,7 +248,7 @@ int WIN_AdjustWindowRect(SDL_Window *window, int *x, int *y, int *width, int *he
return WIN_AdjustWindowRectWithStyle(window, style, styleEx, menu, x, y, width, height, rect_type); return WIN_AdjustWindowRectWithStyle(window, style, styleEx, menu, x, y, width, height, rect_type);
} }
int WIN_AdjustWindowRectForHWND(HWND hwnd, LPRECT lpRect) int WIN_AdjustWindowRectForHWND(HWND hwnd, LPRECT lpRect, UINT frame_dpi)
{ {
SDL_VideoDevice *videodevice = SDL_GetVideoDevice(); SDL_VideoDevice *videodevice = SDL_GetVideoDevice();
SDL_VideoData *videodata = videodevice ? videodevice->driverdata : NULL; SDL_VideoData *videodata = videodevice ? videodevice->driverdata : NULL;
@@ -268,7 +268,9 @@ int WIN_AdjustWindowRectForHWND(HWND hwnd, LPRECT lpRect)
#else #else
if (WIN_IsPerMonitorV2DPIAware(videodevice)) { if (WIN_IsPerMonitorV2DPIAware(videodevice)) {
/* With per-monitor v2, the window border/titlebar size depend on the DPI, so we need to call AdjustWindowRectExForDpi instead of AdjustWindowRectEx. */ /* With per-monitor v2, the window border/titlebar size depend on the DPI, so we need to call AdjustWindowRectExForDpi instead of AdjustWindowRectEx. */
UINT frame_dpi = videodata->GetDpiForWindow ? videodata->GetDpiForWindow(hwnd) : USER_DEFAULT_SCREEN_DPI; if (!frame_dpi) {
frame_dpi = videodata->GetDpiForWindow ? videodata->GetDpiForWindow(hwnd) : USER_DEFAULT_SCREEN_DPI;
}
if (!videodata->AdjustWindowRectExForDpi(lpRect, style, menu, styleEx, frame_dpi)) { if (!videodata->AdjustWindowRectExForDpi(lpRect, style, menu, styleEx, frame_dpi)) {
return WIN_SetError("AdjustWindowRectExForDpi()"); return WIN_SetError("AdjustWindowRectExForDpi()");
} }

View File

@@ -120,7 +120,7 @@ extern int WIN_SetWindowPositionInternal(SDL_Window *window, UINT flags, SDL_Win
extern void WIN_ShowWindowSystemMenu(SDL_Window *window, int x, int y); extern void WIN_ShowWindowSystemMenu(SDL_Window *window, int x, int y);
extern int WIN_SetWindowFocusable(SDL_VideoDevice *_this, SDL_Window *window, SDL_bool focusable); extern int WIN_SetWindowFocusable(SDL_VideoDevice *_this, SDL_Window *window, SDL_bool focusable);
extern int WIN_AdjustWindowRect(SDL_Window *window, int *x, int *y, int *width, int *height, SDL_WindowRect rect_type); extern int WIN_AdjustWindowRect(SDL_Window *window, int *x, int *y, int *width, int *height, SDL_WindowRect rect_type);
extern int WIN_AdjustWindowRectForHWND(HWND hwnd, LPRECT lpRect); extern int WIN_AdjustWindowRectForHWND(HWND hwnd, LPRECT lpRect, UINT frame_dpi);
/* Ends C function definitions when using C++ */ /* Ends C function definitions when using C++ */
#ifdef __cplusplus #ifdef __cplusplus