KarsMulder / evsieve

A utility for mapping events from Linux event devices.
GNU General Public License v2.0
199 stars 11 forks source link

Slow vertical mouse movements aren't registered when using "--map rel ::0.5x" to reduce mouse sensitivity #42

Closed oneirophon closed 4 months ago

oneirophon commented 4 months ago

I'm running evsieve version 1.4.0 under Artix linux with an X-Keys L-Trac trackball mouse, and when trying to reduce the mouse sensitivity, horizontal movements work as expected, but vertical movements are only registered if I move the trackball quickly. If I roll it slowly, I can keep going forever without moving the mouse cursor. When troubleshooting this, I additionally discovered that the X and Y axes are reversed so that X is vertical; I'm not sure why that is or whether it's relevant here.

Here's my script:

#!/bin/bash
evsieve --input /dev/input/by-id/usb-Clearly_Superior_Technologies._CST_Laser_Trackball-event-mouse grab \
        --map rel ::0.5x                                                                                 \
        --output create-link=/dev/input/by-id/virtual-mouse
KarsMulder commented 4 months ago

You could use --print to check, but I think that the issue is that small movements end up getting represented by events with either value 1 or -1. When an event with value 1 or -1 gets mapped to ::0.5x, then an event with value 0.5 or –0.5 should be generated in theory, but that value gets rounded towards zero because the value of events must be an integer.

With the power of hindsight, it might've been a better decision to round away from zero. Both ways of rounding create noticable artifacts (small movements either becoming smaller or larger than they should be), but a movement that is too large seems like a lesser evil than a movement too small.

But that would still not mean that the problems are fixed, because the small movements of size 1 would not be scaled down at all, and you'd have to move the mouse three times as fast to double the movement speed.

The behaviour of the ideal solution would be to map half of the rel::1 events to rel::1 and the other half to rel::0, to create a speed of 0.5 on average. However, adjusting the meaning of ::0.5x to do that has two drawbacks:

... basically, fixing this would break some properties that you might assume --map to have. In hindsight, over again, it was maybe a bad idea to implement scaling in the --map argument.

I've added a --scale argument to main branch (commit 1464f50eb3058bf74813226fa26b04c12eae4881). This argument scales rel-type events the way you'd want them to, and is currently not implemented for abs-type events, though I should probably make it do something for abs-type elements to. We could after all still use an argument that puts the abs-type arguments in a certain range without having to manually figure out which scale factor and offset you need.

Usage example:

evsieve --input /dev/input/by-id/usb-Clearly_Superior_Technologies._CST_Laser_Trackball-event-mouse grab \
        --scale rel factor=0.5 \
        --output create-link=/dev/input/by-id/virtual-mouse
oneirophon commented 4 months ago

Thank you so much! I just tested this out and everything works exactly as expected, except that seems to affect the speed of scrolling as well as mouse movements. This is fine for my use case, though, as I wasn't running into any trouble adjusting the scroll speed in Sway, whereas my trackball was ignoring my Sway config's settings for mouse speed.

KarsMulder commented 4 months ago

You can restrict the --scale argument to only apply to some of the rel-type events instead of all of them. I am going to assume that rel:x and rel:y are the event codes that determine the vertical and horizontal movement of your cursor:

evsieve --input /dev/input/by-id/usb-Clearly_Superior_Technologies._CST_Laser_Trackball-event-mouse grab \
        --scale rel:x rel:y factor=0.5 \
        --output create-link=/dev/input/by-id/virtual-mouse
oneirophon commented 4 months ago

Just tested that out and everything seems to be working just fine; thanks again!