Skip to main content

Module translate

Module translate 

Source
Expand description

Turning raw evdev events into InputEvents.

This is a state machine, and it is the part of input handling that is actually difficult. It is kept platform-independent so every case below is a unit test rather than something you discover by dragging a finger across a panel in a workshop.

Three things it gets right that a naive loop does not:

  • Frames. evdev delivers a position as separate REL_X and REL_Y events terminated by SYN_REPORT. Emitting on each axis produces two moves per physical motion, doubling every drag and breaking every gesture threshold. Nothing is emitted until the frame closes.
  • Ordering. A click arrives in the same frame as the motion that positioned it. Motion is resolved first, so a button event carries where the pointer actually was, not where it had been.
  • Contact identity. Multitouch slots are stateful: a slot keeps reporting for the same finger until its tracking id goes to -1, and only the axes that changed are resent.

A touchpad reports the same slots as a touchscreen, and is not one: where the finger is on the pad says nothing about where on the screen it points. A translator told it is reading a touchpad (Translator::set_touchpad) moves the pointer by how far a finger travels, scrolls with two, and turns a short tap into a click. The rest of the protocol is read the same way.

Structs§

AbsAxis
The calibration of one absolute axis.
RawEvent
One event as read from /dev/input/eventN.
Translator
Accumulates raw events and emits InputEvents a frame at a time.

Constants§

MAX_SLOTS
Contacts tracked at once. Ten fingers is more than any panel this targets.