Skip to content

Commit

Permalink
wayland: update pointer position on initial enter event
Browse files Browse the repository at this point in the history
  • Loading branch information
Xyene committed May 21, 2020
1 parent 68e1731 commit a6ca61d
Showing 1 changed file with 19 additions and 15 deletions.
34 changes: 19 additions & 15 deletions src/video/wayland/SDL_waylandevents.c
Expand Up @@ -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,
Expand All @@ -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);
}
}

Expand All @@ -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)
{
Expand Down

0 comments on commit a6ca61d

Please sign in to comment.