diff options
author | Peter Hutterer <peter.hutterer@who-t.net> | 2023-04-18 16:53:05 +1000 |
---|---|---|
committer | Peter Hutterer <peter.hutterer@who-t.net> | 2023-04-27 13:15:14 +1000 |
commit | d3481c88072d0a9713939d0eb0fb83478a032186 (patch) | |
tree | 374ec884f7565b5167edd492ec432b8a3bdebdfd /src/evdev-wheel.c | |
parent | 64af4beb6b969ce346b0c30648e833c3db7b5e86 (diff) | |
download | libinput-d3481c88072d0a9713939d0eb0fb83478a032186.tar.gz |
evdev: if a device's rotation is around 180 degrees, flip the wheel
For a device used upside-down, make sure the wheels correspond to the
new physical directions. There's a grace range of 20 degrees either way
since that seems like it makes sense.
For 90 degree rotation (or 270 degree) the wheel is left as-is, the
heuristics to guess what angle we want in this case is not clear enough.
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Diffstat (limited to 'src/evdev-wheel.c')
-rw-r--r-- | src/evdev-wheel.c | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/src/evdev-wheel.c b/src/evdev-wheel.c index 2381cb77..13efece6 100644 --- a/src/evdev-wheel.c +++ b/src/evdev-wheel.c @@ -323,6 +323,21 @@ wheel_handle_direction_change(struct fallback_dispatch *dispatch, } } +static void +fallback_rotate_wheel(struct fallback_dispatch *dispatch, + struct evdev_device *device, + struct input_event *e) +{ + /* Special case: if we're upside down (-ish), + * swap the direction of the wheels so that user-down + * means scroll down. This isn't done for any other angle + * since it's not clear what the heuristics should be.*/ + if (dispatch->rotation.angle >= 160.0 && + dispatch->rotation.angle <= 220.0) { + e->value *= -1; + } +} + void fallback_wheel_process_relative(struct fallback_dispatch *dispatch, struct evdev_device *device, @@ -330,6 +345,7 @@ fallback_wheel_process_relative(struct fallback_dispatch *dispatch, { switch (e->code) { case REL_WHEEL: + fallback_rotate_wheel(dispatch, device, e); dispatch->wheel.lo_res.y += e->value; if (dispatch->wheel.emulate_hi_res_wheel) dispatch->wheel.hi_res.y += e->value * 120; @@ -337,6 +353,7 @@ fallback_wheel_process_relative(struct fallback_dispatch *dispatch, wheel_handle_event(dispatch, WHEEL_EVENT_SCROLL, time); break; case REL_HWHEEL: + fallback_rotate_wheel(dispatch, device, e); dispatch->wheel.lo_res.x += e->value; if (dispatch->wheel.emulate_hi_res_wheel) dispatch->wheel.hi_res.x += e->value * 120; @@ -344,6 +361,7 @@ fallback_wheel_process_relative(struct fallback_dispatch *dispatch, wheel_handle_event(dispatch, WHEEL_EVENT_SCROLL, time); break; case REL_WHEEL_HI_RES: + fallback_rotate_wheel(dispatch, device, e); dispatch->wheel.hi_res.y += e->value; dispatch->wheel.hi_res_event_received = true; dispatch->pending_event |= EVDEV_WHEEL; @@ -351,6 +369,7 @@ fallback_wheel_process_relative(struct fallback_dispatch *dispatch, wheel_handle_event(dispatch, WHEEL_EVENT_SCROLL, time); break; case REL_HWHEEL_HI_RES: + fallback_rotate_wheel(dispatch, device, e); dispatch->wheel.hi_res.x += e->value; dispatch->wheel.hi_res_event_received = true; dispatch->pending_event |= EVDEV_WHEEL; |