From 01a02d40333b7d558e9e757bda9ea97018d14c73 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Wed, 29 Mar 2023 10:56:41 +1000 Subject: fallback: don't double-map if any left-handed buttons are down The key_count array for buttons records the logical button sent to the client - for left-handed configurations that means a BTN_LEFT is recorded as BTN_RIGHT. When the device is suspended and we are releasing all keys we must thus release the button code as-is without trying to map it again. Fixes #881 Signed-off-by: Peter Hutterer --- src/evdev-fallback.c | 7 ++++++- test/test-pointer.c | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/src/evdev-fallback.c b/src/evdev-fallback.c index ae33d45a..129b214e 100644 --- a/src/evdev-fallback.c +++ b/src/evdev-fallback.c @@ -1057,10 +1057,15 @@ release_pressed_keys(struct fallback_dispatch *dispatch, LIBINPUT_KEY_STATE_RELEASED); break; case KEY_TYPE_BUTTON: + /* Note: the left-handed configuration is nonzero for + * the mapped button (not the physical button), in + * get_key_down_count(). We must not map this to left-handed + * again, see #881. + */ evdev_pointer_notify_button( device, time, - evdev_to_left_handed(device, code), + code, LIBINPUT_BUTTON_STATE_RELEASED); break; } diff --git a/test/test-pointer.c b/test/test-pointer.c index 78fb2760..ed93b763 100644 --- a/test/test-pointer.c +++ b/test/test-pointer.c @@ -1304,6 +1304,38 @@ START_TEST(pointer_left_handed_during_click_multiple_buttons) } END_TEST +START_TEST(pointer_left_handed_disable_with_button_down) +{ + struct libinput *li = litest_create_context(); + struct litest_device *dev = litest_add_device(li, LITEST_MOUSE); + + enum libinput_config_status status; + status = libinput_device_config_left_handed_set(dev->libinput_device, 1); + ck_assert_int_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS); + + litest_drain_events(li); + litest_button_click_debounced(dev, li, BTN_LEFT, 1); + libinput_dispatch(li); + litest_assert_button_event(li, + BTN_RIGHT, + LIBINPUT_BUTTON_STATE_PRESSED); + + litest_delete_device(dev); + libinput_dispatch(li); + + litest_assert_button_event(li, + BTN_RIGHT, + LIBINPUT_BUTTON_STATE_RELEASED); + + struct libinput_event *event = libinput_get_event(li); + litest_assert_event_type(event, LIBINPUT_EVENT_DEVICE_REMOVED); + litest_assert_empty_queue(li); + libinput_event_destroy(event); + + litest_destroy_context(li); +} +END_TEST + START_TEST(pointer_scroll_button) { struct litest_device *dev = litest_current_device(); @@ -3730,6 +3762,7 @@ TEST_COLLECTION(pointer) litest_add(pointer_left_handed, LITEST_RELATIVE|LITEST_BUTTON, LITEST_ANY); litest_add(pointer_left_handed_during_click, LITEST_RELATIVE|LITEST_BUTTON, LITEST_ANY); litest_add(pointer_left_handed_during_click_multiple_buttons, LITEST_RELATIVE|LITEST_BUTTON, LITEST_ANY); + litest_add_no_device(pointer_left_handed_disable_with_button_down); litest_add(pointer_accel_defaults, LITEST_RELATIVE, LITEST_ANY); litest_add(pointer_accel_invalid, LITEST_RELATIVE, LITEST_ANY); -- cgit v1.2.1