wayland: update pointer position on initial enter event

Tudor Brindus 2020-05-21 00:06:09 -04:00
parent 68e1731e02
commit a6ca61d732
1 changed files with 19 additions and 15 deletions

View File

@ -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 static void
pointer_handle_enter(void *data, struct wl_pointer *pointer, pointer_handle_enter(void *data, struct wl_pointer *pointer,
uint32_t serial, struct wl_surface *surface, uint32_t serial, struct wl_surface *surface,
@ -243,6 +258,10 @@ pointer_handle_enter(void *data, struct wl_pointer *pointer,
if (window) { if (window) {
input->pointer_focus = window; input->pointer_focus = window;
SDL_SetMouseFocus(window->sdlwindow); 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 static SDL_bool
ProcessHitTest(struct SDL_WaylandInput *input, uint32_t serial) ProcessHitTest(struct SDL_WaylandInput *input, uint32_t serial)
{ {