Skip to content

Commit

Permalink
Fix imgui window resizing and dragging issue while undocking.
Browse files Browse the repository at this point in the history
  • Loading branch information
GloriousPtr committed Nov 25, 2022
1 parent d516e66 commit 359bcc3
Showing 1 changed file with 41 additions and 61 deletions.
102 changes: 41 additions & 61 deletions src/win32_window.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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;
}
Expand All @@ -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;
}
Expand Down Expand Up @@ -1273,52 +1255,50 @@ 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:
{
if (_glfw.hints.window.titlebar)
break;

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);

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;

return HTCLIENT;
}
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);

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;

return HTCLIENT;
}
}
}
}

Expand Down

0 comments on commit 359bcc3

Please sign in to comment.