Skip to content

Commit fab42a1

Browse files
committed
wayland: Check focus when dispatching relative motion
In rare cases, a leave event can be grouped with relative motion in a frame. Ensure a valid focus window when dispatching relative motion.
1 parent 8a2fbef commit fab42a1

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

src/video/wayland/SDL_waylandevents.c

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1191,19 +1191,21 @@ static void pointer_handle_axis_relative_direction(void *data, struct wl_pointer
11911191
static void pointer_dispatch_relative_motion(SDL_WaylandSeat *seat)
11921192
{
11931193
SDL_WindowData *window = seat->pointer.focus;
1194-
SDL_Mouse *mouse = SDL_GetMouse();
11951194

1196-
double dx;
1197-
double dy;
1198-
if (mouse->InputTransform || !mouse->enable_relative_system_scale) {
1199-
dx = wl_fixed_to_double(seat->pointer.pending_frame.relative.dx_unaccel);
1200-
dy = wl_fixed_to_double(seat->pointer.pending_frame.relative.dy_unaccel);
1201-
} else {
1202-
dx = wl_fixed_to_double(seat->pointer.pending_frame.relative.dx) * window->pointer_scale.x;
1203-
dy = wl_fixed_to_double(seat->pointer.pending_frame.relative.dy) * window->pointer_scale.y;
1204-
}
1195+
if (window) {
1196+
SDL_Mouse *mouse = SDL_GetMouse();
1197+
double dx;
1198+
double dy;
1199+
if (mouse->InputTransform || !mouse->enable_relative_system_scale) {
1200+
dx = wl_fixed_to_double(seat->pointer.pending_frame.relative.dx_unaccel);
1201+
dy = wl_fixed_to_double(seat->pointer.pending_frame.relative.dy_unaccel);
1202+
} else {
1203+
dx = wl_fixed_to_double(seat->pointer.pending_frame.relative.dx) * window->pointer_scale.x;
1204+
dy = wl_fixed_to_double(seat->pointer.pending_frame.relative.dy) * window->pointer_scale.y;
1205+
}
12051206

1206-
SDL_SendMouseMotion(seat->pointer.pending_frame.timestamp_ns, window->sdlwindow, seat->pointer.sdl_id, true, (float)dx, (float)dy);
1207+
SDL_SendMouseMotion(seat->pointer.pending_frame.timestamp_ns, window->sdlwindow, seat->pointer.sdl_id, true, (float)dx, (float)dy);
1208+
}
12071209
}
12081210

12091211
static void pointer_dispatch_axis(SDL_WaylandSeat *seat)

0 commit comments

Comments
 (0)