1
0
mirror of synced 2024-11-13 18:50:53 +01:00

fix: Cursor types on Windows sometimes getting stuck

This commit is contained in:
WerWolv 2023-05-20 21:10:12 +02:00
parent c91e3875d4
commit 7336c8dddc
2 changed files with 41 additions and 73 deletions

View File

@ -753,7 +753,43 @@ static void ImGui_ImplGlfw_UpdateMouseCursor()
if (!bd->BorderlessWindow) { if (!bd->BorderlessWindow) {
// Show OS mouse cursor // Show OS mouse cursor
// FIXME-PLATFORM: Unfocused windows seems to fail changing the mouse cursor with GLFW 3.2, but 3.3 works here. // FIXME-PLATFORM: Unfocused windows seems to fail changing the mouse cursor with GLFW 3.2, but 3.3 works here.
glfwSetCursor(window, bd->MouseCursors[imgui_cursor] ? bd->MouseCursors[imgui_cursor] : bd->MouseCursors[ImGuiMouseCursor_Arrow]); #if defined(_WIN32)
switch (imgui_cursor) {
case ImGuiMouseCursor_Arrow:
SetCursor(LoadCursor(nullptr, IDC_ARROW));
break;
case ImGuiMouseCursor_Hand:
SetCursor(LoadCursor(nullptr, IDC_HAND));
break;
case ImGuiMouseCursor_ResizeEW:
SetCursor(LoadCursor(nullptr, IDC_SIZEWE));
break;
case ImGuiMouseCursor_ResizeNS:
SetCursor(LoadCursor(nullptr, IDC_SIZENS));
break;
case ImGuiMouseCursor_ResizeNWSE:
SetCursor(LoadCursor(nullptr, IDC_SIZENWSE));
break;
case ImGuiMouseCursor_ResizeNESW:
SetCursor(LoadCursor(nullptr, IDC_SIZENESW));
break;
case ImGuiMouseCursor_ResizeAll:
SetCursor(LoadCursor(nullptr, IDC_SIZEALL));
break;
case ImGuiMouseCursor_NotAllowed:
SetCursor(LoadCursor(nullptr, IDC_NO));
break;
case ImGuiMouseCursor_TextInput:
SetCursor(LoadCursor(nullptr, IDC_IBEAM));
break;
default:
case ImGuiMouseCursor_None:
SetCursor(LoadCursor(nullptr, IDC_ARROW));
break;
}
#else
glfwSetCursor(window, bd->MouseCursors[imgui_cursor] ? bd->MouseCursors[imgui_cursor] : bd->MouseCursors[ImGuiMouseCursor_Arrow]);
#endif
glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_NORMAL); glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_NORMAL);
} }
// IMHEX PATCH END // IMHEX PATCH END

View File

@ -32,7 +32,6 @@ namespace hex {
static LONG_PTR g_oldWndProc; static LONG_PTR g_oldWndProc;
static float g_titleBarHeight; static float g_titleBarHeight;
static ImGuiMouseCursor g_mouseCursorIcon;
static Microsoft::WRL::ComPtr<ITaskbarList4> g_taskbarList; static Microsoft::WRL::ComPtr<ITaskbarList4> g_taskbarList;
// Custom Window procedure for receiving OS events // Custom Window procedure for receiving OS events
@ -72,6 +71,8 @@ namespace hex {
// Custom window procedure for borderless window // Custom window procedure for borderless window
static LRESULT borderlessWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { static LRESULT borderlessWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
switch (uMsg) { switch (uMsg) {
case WM_MOUSELAST:
break;
case WM_NCACTIVATE: case WM_NCACTIVATE:
case WM_NCPAINT: case WM_NCPAINT:
// Handle Windows Aero Snap // Handle Windows Aero Snap
@ -101,37 +102,6 @@ namespace hex {
return 0; return 0;
} }
case WM_SETCURSOR: {
// Handle mouse cursor icon
auto cursorPos = LOWORD(lParam);
switch (cursorPos) {
case HTRIGHT:
case HTLEFT:
g_mouseCursorIcon = ImGuiMouseCursor_ResizeEW;
break;
case HTTOP:
case HTBOTTOM:
g_mouseCursorIcon = ImGuiMouseCursor_ResizeNS;
break;
case HTTOPLEFT:
case HTBOTTOMRIGHT:
g_mouseCursorIcon = ImGuiMouseCursor_ResizeNWSE;
break;
case HTTOPRIGHT:
case HTBOTTOMLEFT:
g_mouseCursorIcon = ImGuiMouseCursor_ResizeNESW;
break;
case HTCAPTION:
case HTCLIENT:
g_mouseCursorIcon = ImGuiMouseCursor_None;
break;
default:
break;
}
return TRUE;
}
case WM_NCHITTEST: { case WM_NCHITTEST: {
// Handle window resizing and moving // Handle window resizing and moving
@ -159,8 +129,9 @@ namespace hex {
RegionTop * (cursor.y < (window.top + border.y)) | RegionTop * (cursor.y < (window.top + border.y)) |
RegionBottom * (cursor.y >= (window.bottom - border.y)); RegionBottom * (cursor.y >= (window.bottom - border.y));
if (result != 0 && (ImGui::IsAnyItemHovered() || ImGui::IsPopupOpen(nullptr, ImGuiPopupFlags_AnyPopupId))) if (result != 0 && (ImGui::IsAnyItemHovered() || ImGui::IsPopupOpen(nullptr, ImGuiPopupFlags_AnyPopupId))) {
break; break;
}
switch (result) { switch (result) {
case RegionLeft: case RegionLeft:
@ -371,45 +342,6 @@ namespace hex {
void Window::endNativeWindowFrame() { void Window::endNativeWindowFrame() {
if (!ImHexApi::System::isBorderlessWindowModeEnabled()) if (!ImHexApi::System::isBorderlessWindowModeEnabled())
return; return;
if (g_mouseCursorIcon != ImGuiMouseCursor_None) {
ImGui::SetMouseCursor(g_mouseCursorIcon);
}
// Translate ImGui mouse cursors to Win32 mouse cursors
switch (ImGui::GetMouseCursor()) {
case ImGuiMouseCursor_Arrow:
SetCursor(LoadCursor(nullptr, IDC_ARROW));
break;
case ImGuiMouseCursor_Hand:
SetCursor(LoadCursor(nullptr, IDC_HAND));
break;
case ImGuiMouseCursor_ResizeEW:
SetCursor(LoadCursor(nullptr, IDC_SIZEWE));
break;
case ImGuiMouseCursor_ResizeNS:
SetCursor(LoadCursor(nullptr, IDC_SIZENS));
break;
case ImGuiMouseCursor_ResizeNWSE:
SetCursor(LoadCursor(nullptr, IDC_SIZENWSE));
break;
case ImGuiMouseCursor_ResizeNESW:
SetCursor(LoadCursor(nullptr, IDC_SIZENESW));
break;
case ImGuiMouseCursor_ResizeAll:
SetCursor(LoadCursor(nullptr, IDC_SIZEALL));
break;
case ImGuiMouseCursor_NotAllowed:
SetCursor(LoadCursor(nullptr, IDC_NO));
break;
case ImGuiMouseCursor_TextInput:
SetCursor(LoadCursor(nullptr, IDC_IBEAM));
break;
default:
case ImGuiMouseCursor_None:
SetCursor(LoadCursor(nullptr, IDC_ARROW));
break;
}
} }
void Window::drawTitleBar() { void Window::drawTitleBar() {