impr: Allow closing menus by clicking on title bar on Windows

This commit is contained in:
WerWolv 2024-02-03 20:19:39 +01:00
parent ab02cb0a19
commit 3555fc01c5
1 changed files with 10 additions and 1 deletions

View File

@ -33,6 +33,7 @@ namespace hex {
static LONG_PTR s_oldWndProc; static LONG_PTR s_oldWndProc;
static float s_titleBarHeight; static float s_titleBarHeight;
static Microsoft::WRL::ComPtr<ITaskbarList4> s_taskbarList; static Microsoft::WRL::ComPtr<ITaskbarList4> s_taskbarList;
static bool s_mouseButtonDown = false;
void nativeErrorMessage(const std::string &message) { void nativeErrorMessage(const std::string &message) {
log::fatal(message); log::fatal(message);
@ -131,6 +132,12 @@ namespace hex {
switch (uMsg) { switch (uMsg) {
case WM_MOUSELAST: case WM_MOUSELAST:
break; break;
case WM_NCLBUTTONDOWN:
s_mouseButtonDown = true;
break;
case WM_NCLBUTTONUP:
s_mouseButtonDown = false;
break;
case WM_NCACTIVATE: case WM_NCACTIVATE:
case WM_NCPAINT: case WM_NCPAINT:
// Handle Windows Aero Snap // Handle Windows Aero Snap
@ -222,12 +229,14 @@ namespace hex {
return HTBOTTOMRIGHT; return HTBOTTOMRIGHT;
case RegionClient: case RegionClient:
default: default:
if (cursor.y < (window.top + s_titleBarHeight * 2)) { if (cursor.y < (window.top + s_titleBarHeight * 2) && !s_mouseButtonDown) {
if (hoveredWindowName == "##MainMenuBar" || hoveredWindowName == "ImHexDockSpace") { if (hoveredWindowName == "##MainMenuBar" || hoveredWindowName == "ImHexDockSpace") {
if (!ImGui::IsAnyItemHovered()) { if (!ImGui::IsAnyItemHovered()) {
return HTCAPTION; return HTCAPTION;
} }
} }
} else {
return HTCLIENT;
} }
break; break;