From 62b835a2cdc1216753229ddb3ebd0fcdcc988eb9 Mon Sep 17 00:00:00 2001 From: Guilherme Felipe Date: Sun, 8 Apr 2018 21:59:51 -0300 Subject: [PATCH] Fix custom cursor when it's hidden [Linux] Ensures that the custom cursor will be used when changing to MOUSE_MODE_VISIBLE. Fix #3086 [Windows] Fix cursor flickering when MOUSE_MODE_HIDDEN. [Mac] Fix possible cursor flicker when MOUSE_MODE_HIDDEN. --- platform/osx/os_osx.mm | 5 +++++ platform/windows/os_windows.cpp | 10 +++++++++- platform/x11/os_x11.cpp | 2 +- 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/platform/osx/os_osx.mm b/platform/osx/os_osx.mm index 0c5524dd08c..fbefd41bb7c 100644 --- a/platform/osx/os_osx.mm +++ b/platform/osx/os_osx.mm @@ -1474,6 +1474,11 @@ void OS_OSX::set_cursor_shape(CursorShape p_shape) { if (cursor_shape == p_shape) return; + if (mouse_mode != MOUSE_MODE_VISIBLE) { + cursor_shape = p_shape; + return; + } + if (cursors[p_shape] != NULL) { [cursors[p_shape] set]; } else { diff --git a/platform/windows/os_windows.cpp b/platform/windows/os_windows.cpp index f51d969c168..9c37b65d771 100644 --- a/platform/windows/os_windows.cpp +++ b/platform/windows/os_windows.cpp @@ -1299,7 +1299,9 @@ void OS_Windows::set_mouse_mode(MouseMode p_mode) { if (p_mode == MOUSE_MODE_CAPTURED || p_mode == MOUSE_MODE_HIDDEN) { hCursor = SetCursor(NULL); } else { - SetCursor(hCursor); + CursorShape c = cursor_shape; + cursor_shape = CURSOR_MAX; + set_cursor_shape(c); } } @@ -1863,6 +1865,11 @@ void OS_Windows::set_cursor_shape(CursorShape p_shape) { if (cursor_shape == p_shape) return; + if (mouse_mode != MOUSE_MODE_VISIBLE) { + cursor_shape = p_shape; + return; + } + static const LPCTSTR win_cursors[CURSOR_MAX] = { IDC_ARROW, IDC_IBEAM, @@ -1888,6 +1895,7 @@ void OS_Windows::set_cursor_shape(CursorShape p_shape) { } else { SetCursor(LoadCursor(hInstance, win_cursors[p_shape])); } + cursor_shape = p_shape; } diff --git a/platform/x11/os_x11.cpp b/platform/x11/os_x11.cpp index 338d13410fe..1928800d8c5 100644 --- a/platform/x11/os_x11.cpp +++ b/platform/x11/os_x11.cpp @@ -634,7 +634,7 @@ void OS_X11::set_mouse_mode(MouseMode p_mode) { bool showCursor = (p_mode == MOUSE_MODE_VISIBLE || p_mode == MOUSE_MODE_CONFINED); if (showCursor) { - XUndefineCursor(x11_display, x11_window); // show cursor + XDefineCursor(x11_display, x11_window, cursors[current_cursor]); // show cursor } else { XDefineCursor(x11_display, x11_window, null_cursor); // hide cursor }