KarsMulder / evsieve

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

will this work with Multi-pointers? #35

Open leleleSDX opened 11 months ago

leleleSDX commented 11 months ago

Xorg servers starting from version 1.7 have a feature called "multi-pointer". Basically it allows to have multiple mouse cursors (each with its own keyboard focus) on the screen and control them with separate physical input devices.

Multi-Pointer X on ArchWiki

KarsMulder commented 11 months ago

As for the first question, I suppose it can work by mapping the key-down and key-repeat events to EV_REL events that move your mouse. Of particular interest here is the --output name=... clause that allows you to give your output devices a name that xinput recognises. The following script could turn a keyboard into a mouse:

        --map key:up:1~    rel:y:-20 \
        --map key:down:1~  rel:y:20  \
        --map key:left:1~  rel:x:-20 \
        --map key:right:1~ rel:x:20  \
        --output rel name=fancy-mouse

... at least, that is what was supposed to work, but it turns out that some part of the xinput stack refuses to recognize something as a mouse unless it supports rel:x, rel:y and rel:hwheel. My keyboard apparently has a scrolling wheel which mad the above work for me, but it may not work for others unless you map another key to the scrolling wheel.

evsieve --input /dev/input/by-id/keyboard \
        --map key:up:1~    rel:y:-20 \
        --map key:down:1~  rel:y:20  \
        --map key:left:1~  rel:x:-20 \
        --map key:right:1~ rel:x:20  \
        --map key:pageup:1~    rel:hwheel:1 \
        --map key:pagedown:1~  rel:hwheel:-1 \
        --output  name=fancy-mouse

Assuming that you can create something xinput recognises as a mouse, you can then assign it its own pointer using the following xinput commands:

xinput create-master "Fancy"
xinput reattach pointer:fancy-mouse "Fancy pointer"

I was further investigating the possibility of mapping a gamepad to a mouse, but then I ran into the above issue of needing to get a scrolling wheel from somewhere, and another issue that my the rate at which my gamepad emits events reporting the state of the sticks is inconsistent (lots of events if you move the stick a lot, zero events if you keep the stick at a stationary position).

Which means that a script that smoothly maps sticks to mice is probably not going to happen until I add some way to smooth out the rate of event reporting.

(Below is the script I was working on for the stick-to-mice map. It suffers from both of the aforementioned issues.)

evsieve --input /dev/input/by-id/usb-Sony_Interactive_Entertainment_Wireless_Controller-if03-event-joystick \
        --map abs:x rel:x@mouse1 \
        --map abs:y rel:y@mouse1 \
        --map abs:rx rel:x@mouse2 \
        --map abs:ry rel:y@mouse2 \
        `# Multiply the value of all EV_REL events by 0.25 and subtract 32.` \
        `# These values were designed for a controller that outputs values in the range 0~255 with value 127 being the rest stand.` \
        --map rel ::0.25x-32 \
        `# Remove small movements to avoid jitter.` \
        --block rel::-2~2 \
        --output @mouse1 name=first-mouse \
        --output @mouse2 name=second-mouse 
leleleSDX commented 11 months ago

thanks for the sample scripts. i will try it further on my end to see what works.