mirror of
https://github.com/libsdl-org/SDL.git
synced 2025-10-16 06:45:59 +00:00
Refactor AdjustWindowRectEx() into WIN_AdjustWindowRectForHWND()
Also include the window EXSTYLE to calls to AdjustWindowRectEx()
This commit is contained in:
@@ -154,7 +154,7 @@ static DWORD GetWindowStyleEx(SDL_Window *window)
|
||||
* Returns arguments to pass to SetWindowPos - the window rect, including frame, in Windows coordinates.
|
||||
* Can be called before we have a HWND.
|
||||
*/
|
||||
static int WIN_AdjustWindowRectWithStyle(SDL_Window *window, DWORD style, BOOL menu, int *x, int *y, int *width, int *height, SDL_WindowRect rect_type)
|
||||
static int WIN_AdjustWindowRectWithStyle(SDL_Window *window, DWORD style, DWORD styleEx, BOOL menu, int *x, int *y, int *width, int *height, SDL_WindowRect rect_type)
|
||||
{
|
||||
SDL_VideoData *videodata = SDL_GetVideoDevice() ? SDL_GetVideoDevice()->driverdata : NULL;
|
||||
RECT rect;
|
||||
@@ -162,17 +162,17 @@ static int WIN_AdjustWindowRectWithStyle(SDL_Window *window, DWORD style, BOOL m
|
||||
/* Client rect, in points */
|
||||
switch (rect_type) {
|
||||
case SDL_WINDOWRECT_CURRENT:
|
||||
SDL_RelativeToGlobalForWindow(window,window->x, window->y, x, y);
|
||||
SDL_RelativeToGlobalForWindow(window, window->x, window->y, x, y);
|
||||
*width = window->w;
|
||||
*height = window->h;
|
||||
break;
|
||||
case SDL_WINDOWRECT_WINDOWED:
|
||||
SDL_RelativeToGlobalForWindow(window,window->windowed.x, window->windowed.y, x, y);
|
||||
SDL_RelativeToGlobalForWindow(window, window->windowed.x, window->windowed.y, x, y);
|
||||
*width = window->windowed.w;
|
||||
*height = window->windowed.h;
|
||||
break;
|
||||
case SDL_WINDOWRECT_FLOATING:
|
||||
SDL_RelativeToGlobalForWindow(window,window->floating.x, window->floating.y, x, y);
|
||||
SDL_RelativeToGlobalForWindow(window, window->floating.x, window->floating.y, x, y);
|
||||
*width = window->floating.w;
|
||||
*height = window->floating.h;
|
||||
break;
|
||||
@@ -202,12 +202,12 @@ static int WIN_AdjustWindowRectWithStyle(SDL_Window *window, DWORD style, BOOL m
|
||||
UINT frame_dpi;
|
||||
SDL_WindowData *data = window->driverdata;
|
||||
frame_dpi = (data && videodata->GetDpiForWindow) ? videodata->GetDpiForWindow(data->hwnd) : USER_DEFAULT_SCREEN_DPI;
|
||||
if (videodata->AdjustWindowRectExForDpi(&rect, style, menu, 0, frame_dpi) == 0) {
|
||||
if (videodata->AdjustWindowRectExForDpi(&rect, style, menu, styleEx, frame_dpi) == 0) {
|
||||
return WIN_SetError("AdjustWindowRectExForDpi()");
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (AdjustWindowRectEx(&rect, style, menu, 0) == 0) {
|
||||
if (AdjustWindowRectEx(&rect, style, menu, styleEx) == 0) {
|
||||
return WIN_SetError("AdjustWindowRectEx()");
|
||||
}
|
||||
}
|
||||
@@ -231,20 +231,54 @@ static int WIN_AdjustWindowRectWithStyle(SDL_Window *window, DWORD style, BOOL m
|
||||
return 0;
|
||||
}
|
||||
|
||||
void WIN_AdjustWindowRect(SDL_Window *window, int *x, int *y, int *width, int *height, SDL_WindowRect rect_type)
|
||||
int WIN_AdjustWindowRect(SDL_Window *window, int *x, int *y, int *width, int *height, SDL_WindowRect rect_type)
|
||||
{
|
||||
SDL_WindowData *data = window->driverdata;
|
||||
HWND hwnd = data->hwnd;
|
||||
DWORD style;
|
||||
DWORD style, styleEx;
|
||||
BOOL menu;
|
||||
|
||||
style = GetWindowLong(hwnd, GWL_STYLE);
|
||||
styleEx = GetWindowLong(hwnd, GWL_EXSTYLE);
|
||||
#if defined(__XBOXONE__) || defined(__XBOXSERIES__)
|
||||
menu = FALSE;
|
||||
#else
|
||||
menu = (style & WS_CHILDWINDOW) ? FALSE : (GetMenu(hwnd) != NULL);
|
||||
#endif
|
||||
WIN_AdjustWindowRectWithStyle(window, style, 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)
|
||||
{
|
||||
SDL_VideoDevice *videodevice = SDL_GetVideoDevice();
|
||||
SDL_VideoData *videodata = videodevice ? videodevice->driverdata : NULL;
|
||||
DWORD style, styleEx;
|
||||
BOOL menu;
|
||||
|
||||
style = GetWindowLong(hwnd, GWL_STYLE);
|
||||
styleEx = GetWindowLong(hwnd, GWL_EXSTYLE);
|
||||
#if defined(__XBOXONE__) || defined(__XBOXSERIES__)
|
||||
menu = FALSE;
|
||||
#else
|
||||
menu = (style & WS_CHILDWINDOW) ? FALSE : (GetMenu(hwnd) != NULL);
|
||||
#endif
|
||||
|
||||
#if defined(__XBOXONE__) || defined(__XBOXSERIES__)
|
||||
AdjustWindowRectEx(&rect, style, menu, styleEx);
|
||||
#else
|
||||
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. */
|
||||
UINT frame_dpi = videodata->GetDpiForWindow ? videodata->GetDpiForWindow(hwnd) : USER_DEFAULT_SCREEN_DPI;
|
||||
if (!videodata->AdjustWindowRectExForDpi(lpRect, style, menu, styleEx, frame_dpi)) {
|
||||
return WIN_SetError("AdjustWindowRectExForDpi()");
|
||||
}
|
||||
} else {
|
||||
if (!AdjustWindowRectEx(lpRect, style, menu, styleEx)) {
|
||||
return WIN_SetError("AdjustWindowRectEx()");
|
||||
}
|
||||
}
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
int WIN_SetWindowPositionInternal(SDL_Window *window, UINT flags, SDL_WindowRect rect_type)
|
||||
@@ -603,7 +637,7 @@ int WIN_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_PropertiesI
|
||||
|
||||
/* Figure out what the window area will be */
|
||||
WIN_ConstrainPopup(window);
|
||||
WIN_AdjustWindowRectWithStyle(window, style, FALSE, &x, &y, &w, &h, SDL_WINDOWRECT_FLOATING);
|
||||
WIN_AdjustWindowRectWithStyle(window, style, styleEx, FALSE, &x, &y, &w, &h, SDL_WINDOWRECT_FLOATING);
|
||||
|
||||
hwnd = CreateWindowEx(styleEx, SDL_Appname, TEXT(""), style,
|
||||
x, y, w, h, parent, NULL, SDL_Instance, NULL);
|
||||
@@ -1073,7 +1107,7 @@ int WIN_SetWindowFullscreen(SDL_VideoDevice *_this, SDL_Window *window, SDL_Vide
|
||||
SDL_WindowData *data = window->driverdata;
|
||||
HWND hwnd = data->hwnd;
|
||||
MONITORINFO minfo;
|
||||
DWORD style;
|
||||
DWORD style, styleEx;
|
||||
HWND top;
|
||||
int x, y;
|
||||
int w, h;
|
||||
@@ -1108,6 +1142,7 @@ int WIN_SetWindowFullscreen(SDL_VideoDevice *_this, SDL_Window *window, SDL_Vide
|
||||
style = GetWindowLong(hwnd, GWL_STYLE);
|
||||
style &= ~STYLE_MASK;
|
||||
style |= GetWindowStyle(window);
|
||||
styleEx = GetWindowLong(hwnd, GWL_EXSTYLE);
|
||||
|
||||
if (fullscreen) {
|
||||
x = minfo.rcMonitor.left;
|
||||
@@ -1136,7 +1171,7 @@ int WIN_SetWindowFullscreen(SDL_VideoDevice *_this, SDL_Window *window, SDL_Vide
|
||||
}
|
||||
|
||||
menu = (style & WS_CHILDWINDOW) ? FALSE : (GetMenu(hwnd) != NULL);
|
||||
WIN_AdjustWindowRectWithStyle(window, style, menu,
|
||||
WIN_AdjustWindowRectWithStyle(window, style, styleEx, menu,
|
||||
&x, &y,
|
||||
&w, &h,
|
||||
data->windowed_mode_was_maximized ? SDL_WINDOWRECT_WINDOWED : SDL_WINDOWRECT_FLOATING);
|
||||
|
Reference in New Issue
Block a user