diff --git a/external/ImGui/source/imgui_impl_glfw.cpp b/external/ImGui/source/imgui_impl_glfw.cpp index 29632dcc7..2d1a45520 100644 --- a/external/ImGui/source/imgui_impl_glfw.cpp +++ b/external/ImGui/source/imgui_impl_glfw.cpp @@ -472,10 +472,12 @@ static void ImGui_ImplGlfw_UpdateMouseCursor() } else { - // Show OS mouse cursor - // 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]); - glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_NORMAL); + #if !defined(OS_WINDOWS) + // Show OS mouse cursor + // 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]); + glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_NORMAL); + #endif } } } diff --git a/include/window.hpp b/include/window.hpp index fded346e1..9c81e04a7 100644 --- a/include/window.hpp +++ b/include/window.hpp @@ -25,7 +25,8 @@ namespace hex { private: void setupNativeWindow(); - void updateNativeWindow(); + void beginNativeWindowFrame(); + void endNativeWindowFrame(); void drawTitleBar(); void frameBegin(); diff --git a/source/window/linux_window.cpp b/source/window/linux_window.cpp index e52be8a25..6a03987e4 100644 --- a/source/window/linux_window.cpp +++ b/source/window/linux_window.cpp @@ -37,7 +37,11 @@ EventManager::post(); } - void Window::updateNativeWindow() { + void Window::beginNativeWindowFrame() { + + } + + void Window::endNativeWindowFrame() { } diff --git a/source/window/macos_window.cpp b/source/window/macos_window.cpp index be396b1be..fe5aa11fc 100644 --- a/source/window/macos_window.cpp +++ b/source/window/macos_window.cpp @@ -23,7 +23,11 @@ EventManager::post(); } - void Window::updateNativeWindow() { + void Window::beginNativeWindowFrame() { + + } + + void Window::endNativeWindowFrame() { } diff --git a/source/window/win_window.cpp b/source/window/win_window.cpp index 0c62f4104..ba26adf59 100644 --- a/source/window/win_window.cpp +++ b/source/window/win_window.cpp @@ -30,11 +30,13 @@ static LRESULT windowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { switch (uMsg) { + case WM_NCPAINT: + return DefWindowProcW(hwnd, uMsg, wParam, lParam); case WM_NCCALCSIZE: { RECT &rect = *reinterpret_cast(lParam); RECT client = rect; - DefWindowProcW(hwnd, WM_NCCALCSIZE, wParam, lParam); + CallWindowProc((WNDPROC)oldWndProc, hwnd, uMsg, wParam, lParam); if (IsMaximized(hwnd)) { WINDOWINFO windowInfo = { .cbSize = sizeof(WINDOWINFO) }; @@ -58,23 +60,26 @@ case HTRIGHT: case HTLEFT: mouseCursorIcon = ImGuiMouseCursor_ResizeEW; - return TRUE; + break; case HTTOP: case HTBOTTOM: mouseCursorIcon = ImGuiMouseCursor_ResizeNS; - return TRUE; + break; case HTTOPLEFT: case HTBOTTOMRIGHT: mouseCursorIcon = ImGuiMouseCursor_ResizeNWSE; - return TRUE; + break; case HTTOPRIGHT: case HTBOTTOMLEFT: mouseCursorIcon = ImGuiMouseCursor_ResizeNESW; - return TRUE; - default: + break; + case HTCAPTION: + case HTCLIENT: mouseCursorIcon = ImGuiMouseCursor_None; - return TRUE; + break; } + + return TRUE; } case WM_NCHITTEST: { POINT cursor = { GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam) }; @@ -131,6 +136,8 @@ } case WM_SETTINGCHANGE: { + if (lParam == 0) break; + if (LPCTSTR(lParam) == std::string_view("ImmersiveColorSet")) { EventManager::post(); } @@ -149,7 +156,7 @@ if (AttachConsole(ATTACH_PARENT_PROCESS)) { // Redirect cin, cout and cerr to that console - freopen("CONIN$", "w", stdin); + freopen("CONIN$", "r", stdin); freopen("CONOUT$", "w", stdout); freopen("CONERR$", "w", stderr); setvbuf(stdin, nullptr, _IONBF, 0); @@ -184,7 +191,7 @@ DWORD attribute = DWMNCRP_ENABLED; ::DwmSetWindowAttribute(hwnd, DWMWA_NCRENDERING_POLICY, &attribute, sizeof(attribute)); - ::SetWindowPos(hwnd, nullptr, 0, 0, 0, 0, SWP_NOZORDER | SWP_NOOWNERZORDER | SWP_NOACTIVATE | SWP_FRAMECHANGED | SWP_ASYNCWINDOWPOS | SWP_NOSIZE | SWP_NOMOVE); + ::SetWindowPos(hwnd, nullptr, 0, 0, 0, 0, SWP_NOZORDER | SWP_NOOWNERZORDER | SWP_FRAMECHANGED | SWP_NOSIZE | SWP_NOMOVE); ::SetWindowLong(hwnd, GWL_STYLE, GetWindowLong(hwnd, GWL_STYLE) | WS_OVERLAPPEDWINDOW); bool themeFollowSystem = ContentRegistry::Settings::getSetting("hex.builtin.setting.interface", "hex.builtin.setting.interface.color") == 0; @@ -207,11 +214,48 @@ EventManager::post(); } - void Window::updateNativeWindow() { + void Window::beginNativeWindowFrame() { titleBarHeight = ImGui::GetCurrentWindow()->MenuBarHeight(); + } - if (mouseCursorIcon != ImGuiMouseCursor_None) + void Window::endNativeWindowFrame() { + if (mouseCursorIcon != ImGuiMouseCursor_None) { ImGui::SetMouseCursor(mouseCursorIcon); + } + + 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() { diff --git a/source/window/window.cpp b/source/window/window.cpp index 6479332dc..bb2c209d3 100644 --- a/source/window/window.cpp +++ b/source/window/window.cpp @@ -400,8 +400,7 @@ namespace hex { this->resetLayout(); } - this->updateNativeWindow(); - + this->beginNativeWindowFrame(); } ImGui::End(); ImGui::PopStyleVar(2); @@ -511,6 +510,7 @@ namespace hex { } void Window::frameEnd() { + this->endNativeWindowFrame(); ImGui::Render(); int displayWidth, displayHeight;