Commit cf84ec441f8192ee50ae2aa8c6f8bf70c3bb91ca

Cameron Gutman 2021-01-20T23:19:24

Improve reliability of cursor hiding on GNOME Wayland Hiding the cursor doesn't appear to work reliably on GNOME when another window steals mouse focus right as we call SDL_ShowCursor(SDL_DISABLE). This can happen when the keyboard shortcut inhibition permission prompt appears in response to a call to SDL_SetRelativeMouseMode() with SDL_HINT_GRAB_KEYBOARD=1. The result is that the default cursor is stuck locked in position and visible on screen indefinitely. By redrawing the cursor on pointer focus enter, the cursor now disappears upon the first mouse motion event. It's not perfect but it's way better than the current behavior.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
diff --git a/src/video/wayland/SDL_waylandevents.c b/src/video/wayland/SDL_waylandevents.c
index 0030166..0c127c8 100644
--- a/src/video/wayland/SDL_waylandevents.c
+++ b/src/video/wayland/SDL_waylandevents.c
@@ -326,6 +326,10 @@ pointer_handle_enter(void *data, struct wl_pointer *pointer,
          * event with no following motion event, but with the new coordinates
          * as part of the enter event. */
         pointer_handle_motion(data, pointer, serial, sx_w, sy_w);
+        /* If the cursor was changed while our window didn't have pointer
+         * focus, we might need to trigger another call to
+         * wl_pointer_set_cursor() for the new cursor to be displayed. */
+        SDL_SetCursor(NULL);
     }
 }