fallback: disable mouse scroll wheel while middle button is pressed

Signed-off-by: José Expósito <jose.exposito89@gmail.com>
This commit is contained in:
JoseExposito 2021-03-13 20:06:06 +01:00 committed by Peter Hutterer
parent 0f79fe6677
commit cd4f2f32b5
4 changed files with 52 additions and 1 deletions

View file

@ -176,7 +176,7 @@ debounce_notify_button(struct fallback_dispatch *fallback,
code = evdev_to_left_handed(device, code); code = evdev_to_left_handed(device, code);
evdev_pointer_notify_physical_button(device, time, code, state); fallback_notify_physical_button(fallback, device, time, code, state);
} }
static void static void

View file

@ -61,6 +61,19 @@ fallback_lid_notify_toggle(struct fallback_dispatch *dispatch,
} }
} }
void
fallback_notify_physical_button(struct fallback_dispatch *dispatch,
struct evdev_device *device,
uint64_t time,
int button,
enum libinput_button_state state)
{
if (button == BTN_MIDDLE)
dispatch->wheel.is_inhibited = (state == LIBINPUT_BUTTON_STATE_PRESSED);
evdev_pointer_notify_physical_button(device, time, button, state);
}
static enum libinput_switch_state static enum libinput_switch_state
fallback_interface_get_switch_state(struct evdev_dispatch *evdev_dispatch, fallback_interface_get_switch_state(struct evdev_dispatch *evdev_dispatch,
enum libinput_switch sw) enum libinput_switch sw)
@ -212,6 +225,12 @@ fallback_flush_wheels(struct fallback_dispatch *dispatch,
if (!(device->seat_caps & EVDEV_DEVICE_POINTER)) if (!(device->seat_caps & EVDEV_DEVICE_POINTER))
return; return;
if (dispatch->wheel.is_inhibited) {
dispatch->wheel.delta.x = 0;
dispatch->wheel.delta.y = 0;
return;
}
if (device->model_flags & EVDEV_MODEL_LENOVO_SCROLLPOINT) { if (device->model_flags & EVDEV_MODEL_LENOVO_SCROLLPOINT) {
struct normalized_coords unaccel = { 0.0, 0.0 }; struct normalized_coords unaccel = { 0.0, 0.0 };

View file

@ -99,6 +99,7 @@ struct fallback_dispatch {
struct { struct {
struct device_coords delta; struct device_coords delta;
bool is_inhibited;
} wheel; } wheel;
struct { struct {
@ -244,5 +245,11 @@ get_key_down_count(struct evdev_device *device, int code)
void fallback_init_debounce(struct fallback_dispatch *dispatch); void fallback_init_debounce(struct fallback_dispatch *dispatch);
void fallback_debounce_handle_state(struct fallback_dispatch *dispatch, void fallback_debounce_handle_state(struct fallback_dispatch *dispatch,
uint64_t time); uint64_t time);
void
fallback_notify_physical_button(struct fallback_dispatch *dispatch,
struct evdev_device *device,
uint64_t time,
int button,
enum libinput_button_state state);
#endif #endif

View file

@ -675,6 +675,30 @@ START_TEST(pointer_scroll_wheel)
} }
END_TEST END_TEST
START_TEST(pointer_scroll_wheel_pressed_noscroll)
{
struct litest_device *dev = litest_current_device();
struct libinput *li = dev->libinput;
litest_drain_events(li);
litest_button_click_debounced(dev, li, BTN_MIDDLE, true);
litest_drain_events(li);
for (int i = 0; i < 10; i++) {
litest_event(dev, EV_REL, REL_WHEEL, 1);
litest_event(dev, EV_REL, REL_HWHEEL, 1);
litest_event(dev, EV_SYN, SYN_REPORT, 0);
}
libinput_dispatch(li);
litest_assert_empty_queue(li);
litest_button_click_debounced(dev, li, BTN_MIDDLE, false);
}
END_TEST
START_TEST(pointer_scroll_natural_defaults) START_TEST(pointer_scroll_natural_defaults)
{ {
struct litest_device *dev = litest_current_device(); struct litest_device *dev = litest_current_device();
@ -3141,6 +3165,7 @@ TEST_COLLECTION(pointer)
litest_add_for_device(pointer_button_has_no_button, LITEST_KEYBOARD); litest_add_for_device(pointer_button_has_no_button, LITEST_KEYBOARD);
litest_add(pointer_recover_from_lost_button_count, LITEST_BUTTON, LITEST_CLICKPAD); litest_add(pointer_recover_from_lost_button_count, LITEST_BUTTON, LITEST_CLICKPAD);
litest_add(pointer_scroll_wheel, LITEST_WHEEL, LITEST_TABLET); litest_add(pointer_scroll_wheel, LITEST_WHEEL, LITEST_TABLET);
litest_add_for_device(pointer_scroll_wheel_pressed_noscroll, LITEST_MOUSE);
litest_add(pointer_scroll_button, LITEST_RELATIVE|LITEST_BUTTON, LITEST_ANY); litest_add(pointer_scroll_button, LITEST_RELATIVE|LITEST_BUTTON, LITEST_ANY);
litest_add(pointer_scroll_button_noscroll, LITEST_ABSOLUTE|LITEST_BUTTON, LITEST_RELATIVE); litest_add(pointer_scroll_button_noscroll, LITEST_ABSOLUTE|LITEST_BUTTON, LITEST_RELATIVE);
litest_add(pointer_scroll_button_noscroll, LITEST_ANY, LITEST_RELATIVE|LITEST_BUTTON); litest_add(pointer_scroll_button_noscroll, LITEST_ANY, LITEST_RELATIVE|LITEST_BUTTON);