Skip to content

Commit 1edaad1

Browse files
phcoderKontrabant
authored andcommitted
Handle wayland touch cancel message
Suppose host has some three-finger gesture. Then we get the following sequence of events: DOWN-DOWN-DOWN-MOTION-CANCEL Note that there is no UP in this sequence. So if we don't handle CANCEL then we end up thinking that fingers are still touching the screen. Ideally we should inform the application that cancel has happened as not to trigger spurious taps but still this is way better than being stuck with phantom finger touch.
1 parent c9f3cbe commit 1edaad1

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

src/video/wayland/SDL_waylandevents.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -932,6 +932,28 @@ static void touch_handler_frame(void *data, struct wl_touch *touch)
932932

933933
static void touch_handler_cancel(void *data, struct wl_touch *touch)
934934
{
935+
struct SDL_WaylandTouchPoint *tp;
936+
while ((tp = touch_points.head)) {
937+
wl_fixed_t fx = 0, fy = 0;
938+
struct wl_surface *surface = NULL;
939+
int id = tp->id;
940+
941+
touch_del(id, &fx, &fy, &surface);
942+
943+
if (surface) {
944+
SDL_WindowData *window_data = (SDL_WindowData *)wl_surface_get_user_data(surface);
945+
946+
if (window_data) {
947+
const double dblx = wl_fixed_to_double(fx) * window_data->pointer_scale_x;
948+
const double dbly = wl_fixed_to_double(fy) * window_data->pointer_scale_y;
949+
const float x = dblx / window_data->sdlwindow->w;
950+
const float y = dbly / window_data->sdlwindow->h;
951+
952+
SDL_SendTouch((SDL_TouchID)(intptr_t)touch, (SDL_FingerID)id,
953+
window_data->sdlwindow, SDL_FALSE, x, y, 1.0f);
954+
}
955+
}
956+
}
935957
}
936958

937959
static const struct wl_touch_listener touch_listener = {

0 commit comments

Comments
 (0)