From bf59b9da67a45e49d7b67aec23cb9545c46d6f28 Mon Sep 17 00:00:00 2001 From: Samuel Gomes Date: Sat, 29 Jul 2023 10:38:23 +0530 Subject: [PATCH] Fix incorrect client rect offset when compiled with LLVM-MingW --- internal/c/parts/core/src/freeglut_window.c | 37 +++++++++------------ 1 file changed, 15 insertions(+), 22 deletions(-) diff --git a/internal/c/parts/core/src/freeglut_window.c b/internal/c/parts/core/src/freeglut_window.c index e707aa06d..b689668f7 100644 --- a/internal/c/parts/core/src/freeglut_window.c +++ b/internal/c/parts/core/src/freeglut_window.c @@ -989,31 +989,24 @@ void fgSetWindow ( SFG_Window *window ) */ void fghComputeWindowRectFromClientArea_UseStyle( const DWORD windowStyle, RECT *clientRect, BOOL posIsOutside ) { - int xBorderWidth = 0, yBorderWidth = 0; + RECT windowRect = {0, 0, 0, 0}; + DWORD windowExStyle = 0; + + CopyRect(&windowRect, clientRect); - /* If window has title bar, correct rect for it */ - if (windowStyle & WS_SYSMENU) /* Need to query for WS_SYSMENU to see if we have a title bar, the WS_CAPTION query is also true for a WS_DLGFRAME only... */ - if (posIsOutside) - clientRect->bottom += GetSystemMetrics( SM_CYCAPTION ); - else - clientRect->top -= GetSystemMetrics( SM_CYCAPTION ); + /* Get rect including non-client area */ + AdjustWindowRectEx(&windowRect, windowStyle, FALSE, windowExStyle); - /* get width of window's borders (frame), correct rect for it. - * Note, borders can be of zero width if style does not specify borders - */ - fghGetBorderWidth(windowStyle, &xBorderWidth, &yBorderWidth); - if (posIsOutside) - { - clientRect->right += xBorderWidth * 2; - clientRect->bottom += yBorderWidth * 2; - } - else - { - clientRect->left -= xBorderWidth; - clientRect->right += xBorderWidth; - clientRect->top -= yBorderWidth; - clientRect->bottom += yBorderWidth; + /* Move window right and down by non-client area extent on left and top, if wanted */ + if (posIsOutside) { + windowRect.right += clientRect->left - windowRect.left; + windowRect.bottom += clientRect->top - windowRect.top; + windowRect.left = clientRect->left; + windowRect.top = clientRect->top; } + + /* done, copy windowRect to output */ + CopyRect(clientRect, &windowRect); } /* Computes position of corners of window Rect (outer position including