Skip to content

Commit

Permalink
Fix Windows cursor with trails disappearing in fullscreen
Browse files Browse the repository at this point in the history
Fixed by turning off mouse trails when going into fullscreen, then restoring trails when exiting fullscreen or game
  • Loading branch information
Gromph authored and lekoder committed Dec 18, 2021
1 parent eb5ef02 commit fb9cd3d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
20 changes: 20 additions & 0 deletions platform/windows/os_windows.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ void OS_Windows::initialize_core() {
crash_handler.initialize();

last_button_state = 0;
restore_mouse_trails = 0;

//RedirectIOToConsole();
maximized = false;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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;

Expand All @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions platform/windows/os_windows.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit fb9cd3d

Please sign in to comment.