Fix imgui window resizing and dragging issue while undocking.

This commit is contained in:
Mohit Sethi 2022-11-25 21:32:36 +05:30
parent d516e66801
commit 359bcc31d0

View File

@ -490,7 +490,9 @@ static void releaseMonitor(_GLFWwindow* window)
static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg, static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg,
WPARAM wParam, LPARAM lParam) 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"); _GLFWwindow* window = GetPropW(hWnd, L"GLFW");
if (!window) if (!window)
@ -548,22 +550,8 @@ static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg,
if (_glfw.hints.window.titlebar) if (_glfw.hints.window.titlebar)
break; 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 }; MARGINS margins = { 0 };
DwmExtendFrameIntoClientArea(hWnd, &margins); DwmExtendFrameIntoClientArea(hWnd, &margins);
SetWindowPos(hWnd, NULL, 0, 0, 0, 0, SWP_SHOWWINDOW | SWP_NOMOVE | SWP_NOSIZE | SWP_FRAMECHANGED);
break; break;
} }
@ -573,14 +561,8 @@ static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg,
if (_glfw.hints.window.titlebar) if (_glfw.hints.window.titlebar)
break; break;
// Extend the frame into the client area.
MARGINS margins = { 0 }; MARGINS margins = { 0 };
auto hr = DwmExtendFrameIntoClientArea(hWnd, &margins); DwmExtendFrameIntoClientArea(hWnd, &margins);
if (!SUCCEEDED(hr))
{
// Handle the error.
}
break; break;
} }
@ -1273,12 +1255,7 @@ static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg,
// Extend the frame into the client area. // Extend the frame into the client area.
MARGINS margins = { 0 }; MARGINS margins = { 0 };
auto hr = DwmExtendFrameIntoClientArea(hWnd, &margins); DwmExtendFrameIntoClientArea(hWnd, &margins);
if (!SUCCEEDED(hr))
{
// Handle the error.
}
break; break;
} }
@ -1287,38 +1264,41 @@ static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg,
if (_glfw.hints.window.titlebar) if (_glfw.hints.window.titlebar)
break; break;
POINT pt = { GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam) }; if (GetWindowLongPtr(hWnd, GWL_STYLE) & WS_THICKFRAME)
ScreenToClient(hWnd, &pt); {
RECT rc; POINT pt = { GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam) };
GetClientRect(hWnd, &rc); ScreenToClient(hWnd, &pt);
RECT rc;
GetClientRect(hWnd, &rc);
int titlebarHittest = 0; int titlebarHittest = 0;
_glfwInputTitleBarHitTest(window, pt.x, pt.y, &titlebarHittest); _glfwInputTitleBarHitTest(window, pt.x, pt.y, &titlebarHittest);
if (titlebarHittest) if (titlebarHittest)
{ {
return HTCAPTION; return HTCAPTION;
} }
else else
{ {
enum { left = 1, top = 2, right = 4, bottom = 8 }; enum { left = 1, top = 2, right = 4, bottom = 8 };
int hit = 0; int hit = 0;
if (pt.x < border_thickness.left) hit |= left; if (pt.x < border_thickness.left) hit |= left;
if (pt.x > rc.right - border_thickness.right) hit |= right; if (pt.x > rc.right - border_thickness.right) hit |= right;
if (pt.y < border_thickness.top) hit |= top; if (pt.y < border_thickness.top) hit |= top;
if (pt.y > rc.bottom - border_thickness.bottom) hit |= bottom; if (pt.y > rc.bottom - border_thickness.bottom) hit |= bottom;
if (hit & top && hit & left) return HTTOPLEFT; if (hit & top && hit & left) return HTTOPLEFT;
if (hit & top && hit & right) return HTTOPRIGHT; if (hit & top && hit & right) return HTTOPRIGHT;
if (hit & bottom && hit & left) return HTBOTTOMLEFT; if (hit & bottom && hit & left) return HTBOTTOMLEFT;
if (hit & bottom && hit & right) return HTBOTTOMRIGHT; if (hit & bottom && hit & right) return HTBOTTOMRIGHT;
if (hit & left) return HTLEFT; if (hit & left) return HTLEFT;
if (hit & top) return HTTOP; if (hit & top) return HTTOP;
if (hit & right) return HTRIGHT; if (hit & right) return HTRIGHT;
if (hit & bottom) return HTBOTTOM; if (hit & bottom) return HTBOTTOM;
return HTCLIENT; return HTCLIENT;
} }
}
} }
} }