rvaiya / keyd

A key remapping daemon for linux.
MIT License
2.54k stars 155 forks source link

small (but nonzero) resource usage from pointer events? #430

Open ces42 opened 1 year ago

ces42 commented 1 year ago

I noticed that keyd will have a small amount of cpu usage while I'm using my touchpad (~0.3% on my i7-1065G7). Indeed, running KEYD_DEBUG=2 keyd show several hundred lines of output like this per second:

DEBUG: src/device.c:407: Unrecognized EV_ABS code: 35
DEBUG: src/device.c:407: Unrecognized EV_ABS code: 36
DEBUG: src/device.c:454: unrecognized evdev event type: 4 5 253000
DEBUG: src/device.c:407: Unrecognized EV_ABS code: 35
DEBUG: src/device.c:407: Unrecognized EV_ABS code: 36
DEBUG: src/device.c:454: unrecognized evdev event type: 4 5 260100

This is even though I have restricted ids in /etc/key/default.conf to what should be only my keyboard.

It seems like the issue is that https://github.com/rvaiya/keyd/blob/4a86057943ed594ca384d88047411979bac643d0/src/device.c#L323 doesn't prevent keyd from reading from the device because if I add dev->fd = -1; at the top of the definition of device_ungrab() https://github.com/rvaiya/keyd/blob/4a86057943ed594ca384d88047411979bac643d0/src/device.c#L318-L325 the issue goes away.

I assume that a better way of fixing this would be to remove unwanted devices from device_table.

rvaiya commented 1 year ago

This is by design. keyd passively monitors all input events, including those of ungrabbed devices in order to accommodate things like clearing oneshot modifiers on click. Trackpads in particular will produce a lot of extraneous ABS events which are mostly ignored (at the moment). This should only be observable when moving the mouse and should still constitute a tiny fraction of CPU usage. Is this causing a real world issue? What caused you to notice this?

ces42 commented 1 year ago

I wanted to make sure that keyd wouldn't add any unnecessary battery drain so I checked htop and saw that keyd was using more cpu than I was used from interception-tools / caps2esc. 0.3% of one core is probably not a "real world issue" although I always that these things could add up, especially on older hardware.