From 359bcc31d07640963eea97c448ab82acf80f0185 Mon Sep 17 00:00:00 2001 From: Mohit Sethi Date: Fri, 25 Nov 2022 21:32:36 +0530 Subject: [PATCH] Fix imgui window resizing and dragging issue while undocking. --- src/win32_window.c | 94 ++++++++++++++++++---------------------------- 1 file changed, 37 insertions(+), 57 deletions(-) diff --git a/src/win32_window.c b/src/win32_window.c index f0b7bcfd..3313a139 100644 --- a/src/win32_window.c +++ b/src/win32_window.c @@ -490,7 +490,9 @@ static void releaseMonitor(_GLFWwindow* window) static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { - static RECT border_thickness; + static RECT border_thickness = { 0, 0, 0, 0 }; + if (!_glfw.hints.window.titlebar) + SetRect(&border_thickness, 8, 8, 8, 8); _GLFWwindow* window = GetPropW(hWnd, L"GLFW"); if (!window) @@ -548,22 +550,8 @@ static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg, if (_glfw.hints.window.titlebar) break; - //find border thickness - SetRectEmpty(&border_thickness); - if (GetWindowLongPtr(hWnd, GWL_STYLE) & WS_THICKFRAME) - { - AdjustWindowRectEx(&border_thickness, GetWindowLongPtr(hWnd, GWL_STYLE) & ~WS_CAPTION, FALSE, NULL); - border_thickness.left *= -1; - border_thickness.top *= -1; - } - else// if (GetWindowLongPtr(hWnd, GWL_STYLE) & WS_BORDER) - { - SetRect(&border_thickness, 4, 4, 4, 4); - } - MARGINS margins = { 0 }; DwmExtendFrameIntoClientArea(hWnd, &margins); - SetWindowPos(hWnd, NULL, 0, 0, 0, 0, SWP_SHOWWINDOW | SWP_NOMOVE | SWP_NOSIZE | SWP_FRAMECHANGED); break; } @@ -573,14 +561,8 @@ static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg, if (_glfw.hints.window.titlebar) break; - // Extend the frame into the client area. MARGINS margins = { 0 }; - auto hr = DwmExtendFrameIntoClientArea(hWnd, &margins); - - if (!SUCCEEDED(hr)) - { - // Handle the error. - } + DwmExtendFrameIntoClientArea(hWnd, &margins); break; } @@ -1273,13 +1255,8 @@ static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg, // Extend the frame into the client area. MARGINS margins = { 0 }; - auto hr = DwmExtendFrameIntoClientArea(hWnd, &margins); - - if (!SUCCEEDED(hr)) - { - // Handle the error. - } - + DwmExtendFrameIntoClientArea(hWnd, &margins); + break; } case WM_NCHITTEST: @@ -1287,38 +1264,41 @@ static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg, if (_glfw.hints.window.titlebar) break; - POINT pt = { GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam) }; - ScreenToClient(hWnd, &pt); - RECT rc; - GetClientRect(hWnd, &rc); + if (GetWindowLongPtr(hWnd, GWL_STYLE) & WS_THICKFRAME) + { + POINT pt = { GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam) }; + ScreenToClient(hWnd, &pt); + RECT rc; + GetClientRect(hWnd, &rc); - int titlebarHittest = 0; - _glfwInputTitleBarHitTest(window, pt.x, pt.y, &titlebarHittest); + int titlebarHittest = 0; + _glfwInputTitleBarHitTest(window, pt.x, pt.y, &titlebarHittest); - if (titlebarHittest) - { - return HTCAPTION; - } - else - { - enum { left = 1, top = 2, right = 4, bottom = 8 }; - int hit = 0; - if (pt.x < border_thickness.left) hit |= left; - if (pt.x > rc.right - border_thickness.right) hit |= right; - if (pt.y < border_thickness.top) hit |= top; - if (pt.y > rc.bottom - border_thickness.bottom) hit |= bottom; + if (titlebarHittest) + { + return HTCAPTION; + } + else + { + enum { left = 1, top = 2, right = 4, bottom = 8 }; + int hit = 0; + if (pt.x < border_thickness.left) hit |= left; + if (pt.x > rc.right - border_thickness.right) hit |= right; + if (pt.y < border_thickness.top) hit |= top; + if (pt.y > rc.bottom - border_thickness.bottom) hit |= bottom; - if (hit & top && hit & left) return HTTOPLEFT; - if (hit & top && hit & right) return HTTOPRIGHT; - if (hit & bottom && hit & left) return HTBOTTOMLEFT; - if (hit & bottom && hit & right) return HTBOTTOMRIGHT; - if (hit & left) return HTLEFT; - if (hit & top) return HTTOP; - if (hit & right) return HTRIGHT; - if (hit & bottom) return HTBOTTOM; + if (hit & top && hit & left) return HTTOPLEFT; + if (hit & top && hit & right) return HTTOPRIGHT; + if (hit & bottom && hit & left) return HTBOTTOMLEFT; + if (hit & bottom && hit & right) return HTBOTTOMRIGHT; + if (hit & left) return HTLEFT; + if (hit & top) return HTTOP; + if (hit & right) return HTRIGHT; + if (hit & bottom) return HTBOTTOM; - return HTCLIENT; - } + return HTCLIENT; + } + } } }