Skip to content

Commit

Permalink
fallback: cancel touches, don't just release them when we suspend
Browse files Browse the repository at this point in the history
When we disable the touch device, any existing touches should be cancelled,
not just released.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
  • Loading branch information
whot committed Sep 27, 2018
1 parent cb02eca commit 500d03d
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 8 deletions.
37 changes: 31 additions & 6 deletions src/evdev-fallback.c
Original file line number Diff line number Diff line change
Expand Up @@ -490,6 +490,31 @@ fallback_flush_st_up(struct fallback_dispatch *dispatch,
return true;
}

static bool
fallback_flush_st_cancel(struct fallback_dispatch *dispatch,
struct evdev_device *device,
uint64_t time)
{
struct libinput_device *base = &device->base;
struct libinput_seat *seat = base->seat;
int seat_slot;

if (!(device->seat_caps & EVDEV_DEVICE_TOUCH))
return false;

seat_slot = dispatch->abs.seat_slot;
dispatch->abs.seat_slot = -1;

if (seat_slot == -1)
return false;

seat->slot_map &= ~(1 << seat_slot);

touch_notify_touch_cancel(base, time, -1, seat_slot);

return true;
}

static void
fallback_process_touch_button(struct fallback_dispatch *dispatch,
struct evdev_device *device,
Expand Down Expand Up @@ -1015,22 +1040,22 @@ fallback_interface_process(struct evdev_dispatch *evdev_dispatch,
}

static void
release_touches(struct fallback_dispatch *dispatch,
struct evdev_device *device,
uint64_t time)
cancel_touches(struct fallback_dispatch *dispatch,
struct evdev_device *device,
uint64_t time)
{
unsigned int idx;
bool need_frame = false;

need_frame = fallback_flush_st_up(dispatch, device, time);
need_frame = fallback_flush_st_cancel(dispatch, device, time);

for (idx = 0; idx < dispatch->mt.slots_len; idx++) {
struct mt_slot *slot = &dispatch->mt.slots[idx];

if (slot->seat_slot == -1)
continue;

if (fallback_flush_mt_up(dispatch, device, idx, time))
if (fallback_flush_mt_cancel(dispatch, device, idx, time))
need_frame = true;
}

Expand Down Expand Up @@ -1098,7 +1123,7 @@ fallback_return_to_neutral_state(struct fallback_dispatch *dispatch,
if ((time = libinput_now(libinput)) == 0)
return;

release_touches(dispatch, device, time);
cancel_touches(dispatch, device, time);
release_pressed_keys(dispatch, device, time);
memset(dispatch->hw_key_mask, 0, sizeof(dispatch->hw_key_mask));
memset(dispatch->hw_key_mask, 0, sizeof(dispatch->last_hw_key_mask));
Expand Down
2 changes: 1 addition & 1 deletion test/test-device.c
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ START_TEST(device_disable_touch_during_touch)
/* after disabling sendevents we require a touch up */
libinput_dispatch(li);
event = libinput_get_event(li);
litest_is_touch_event(event, LIBINPUT_EVENT_TOUCH_UP);
litest_is_touch_event(event, LIBINPUT_EVENT_TOUCH_CANCEL);
libinput_event_destroy(event);

event = libinput_get_event(li);
Expand Down
2 changes: 1 addition & 1 deletion test/test-touch.c
Original file line number Diff line number Diff line change
Expand Up @@ -955,7 +955,7 @@ START_TEST(touch_release_on_unplug)
libinput_dispatch(li);

ev = libinput_get_event(li);
litest_is_touch_event(ev, LIBINPUT_EVENT_TOUCH_UP);
litest_is_touch_event(ev, LIBINPUT_EVENT_TOUCH_CANCEL);
libinput_event_destroy(ev);

ev = libinput_get_event(li);
Expand Down

0 comments on commit 500d03d

Please sign in to comment.