From a6ca61d732768568b8d9ee6657047c2400d2149c Mon Sep 17 00:00:00 2001 From: Tudor Brindus Date: Thu, 21 May 2020 00:06:09 -0400 Subject: [PATCH] wayland: update pointer position on initial enter event --- src/video/wayland/SDL_waylandevents.c | 34 +++++++++++++++------------ 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/src/video/wayland/SDL_waylandevents.c b/src/video/wayland/SDL_waylandevents.c index 90486595e..fe3adf795 100644 --- a/src/video/wayland/SDL_waylandevents.c +++ b/src/video/wayland/SDL_waylandevents.c @@ -219,6 +219,21 @@ Wayland_PumpEvents(_THIS) } } +static void +pointer_handle_motion(void *data, struct wl_pointer *pointer, + uint32_t time, wl_fixed_t sx_w, wl_fixed_t sy_w) +{ + struct SDL_WaylandInput *input = data; + SDL_WindowData *window = input->pointer_focus; + input->sx_w = sx_w; + input->sy_w = sy_w; + if (input->pointer_focus) { + const int sx = wl_fixed_to_int(sx_w); + const int sy = wl_fixed_to_int(sy_w); + SDL_SendMouseMotion(window->sdlwindow, 0, 0, sx, sy); + } +} + static void pointer_handle_enter(void *data, struct wl_pointer *pointer, uint32_t serial, struct wl_surface *surface, @@ -243,6 +258,10 @@ pointer_handle_enter(void *data, struct wl_pointer *pointer, if (window) { input->pointer_focus = window; SDL_SetMouseFocus(window->sdlwindow); + /* In the case of e.g. a pointer confine warp, we may receive an enter + * 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); } } @@ -258,21 +277,6 @@ pointer_handle_leave(void *data, struct wl_pointer *pointer, } } -static void -pointer_handle_motion(void *data, struct wl_pointer *pointer, - uint32_t time, wl_fixed_t sx_w, wl_fixed_t sy_w) -{ - struct SDL_WaylandInput *input = data; - SDL_WindowData *window = input->pointer_focus; - input->sx_w = sx_w; - input->sy_w = sy_w; - if (input->pointer_focus) { - const int sx = wl_fixed_to_int(sx_w); - const int sy = wl_fixed_to_int(sy_w); - SDL_SendMouseMotion(window->sdlwindow, 0, 0, sx, sy); - } -} - static SDL_bool ProcessHitTest(struct SDL_WaylandInput *input, uint32_t serial) {