From 5a8fe368911802adcce6ccf69bff4ccaed84e714 Mon Sep 17 00:00:00 2001 From: Dan <361560+Gromph@users.noreply.github.com> Date: Thu, 16 Sep 2021 12:34:46 -0700 Subject: [PATCH] Fix Windows cursor with trails disappearing in fullscreen Fixed by turning off mouse trails when going into fullscreen, then restoring trails when exiting fullscreen or game --- platform/windows/os_windows.cpp | 20 ++++++++++++++++++++ platform/windows/os_windows.h | 1 + 2 files changed, 21 insertions(+) diff --git a/platform/windows/os_windows.cpp b/platform/windows/os_windows.cpp index b2f0ad9467..f84ca3edad 100644 --- a/platform/windows/os_windows.cpp +++ b/platform/windows/os_windows.cpp @@ -212,6 +212,7 @@ void OS_Windows::initialize_core() { crash_handler.initialize(); last_button_state = 0; + restore_mouse_trails = 0; //RedirectIOToConsole(); maximized = false; @@ -1426,6 +1427,13 @@ Error OS_Windows::initialize(const VideoMode &p_desired, int p_video_driver, int video_mode.fullscreen=false; }*/ pre_fs_valid = false; + + // If the user has mouse trails enabled in windows, then sometimes the cursor disappears in fullscreen mode. + // Save number of trails so we can restore when exiting, then turn off mouse trails + SystemParametersInfoA(SPI_GETMOUSETRAILS, 0, &restore_mouse_trails, 0); + if (restore_mouse_trails > 1) { + SystemParametersInfoA(SPI_SETMOUSETRAILS, 0, 0, 0); + } } DWORD dwExStyle; @@ -1770,6 +1778,10 @@ void OS_Windows::finalize() { if (user_proc) { SetWindowLongPtr(hWnd, GWLP_WNDPROC, (LONG_PTR)user_proc); }; + + if (restore_mouse_trails > 1) { + SystemParametersInfoA(SPI_SETMOUSETRAILS, restore_mouse_trails, 0, 0); + } } void OS_Windows::finalize_core() { @@ -2124,6 +2136,10 @@ void OS_Windows::set_window_fullscreen(bool p_enabled) { MoveWindow(hWnd, pos.x, pos.y, size.width, size.height, TRUE); + SystemParametersInfoA(SPI_GETMOUSETRAILS, 0, &restore_mouse_trails, 0); + if (restore_mouse_trails > 1) { + SystemParametersInfoA(SPI_SETMOUSETRAILS, 0, 0, 0); + } } else { RECT rect; @@ -2143,6 +2159,10 @@ void OS_Windows::set_window_fullscreen(bool p_enabled) { MoveWindow(hWnd, rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top, TRUE); pre_fs_valid = true; + + if (restore_mouse_trails > 1) { + SystemParametersInfoA(SPI_SETMOUSETRAILS, restore_mouse_trails, 0, 0); + } } } bool OS_Windows::is_window_fullscreen() const { diff --git a/platform/windows/os_windows.h b/platform/windows/os_windows.h index 1cf7d4744a..41b152123a 100644 --- a/platform/windows/os_windows.h +++ b/platform/windows/os_windows.h @@ -334,6 +334,7 @@ class OS_Windows : public OS { Vector2 im_position; MouseMode mouse_mode; + int restore_mouse_trails; bool alt_mem; bool gr_mem; bool shift_mem;