denise-evdev
Linux evdev input for Denise, a direct-rendering UI toolkit in Rust for embedded Linux and systems without a desktop environment.
Reads mice, touchscreens and keyboards straight from /dev/input/event*, with no
display server in the way, and turns them into denise::InputEvents.
#
#
Blocking, and how not to spin
poll drains whatever is ready and returns. A frame loop that wants to sleep
should wait on InputBackend::raw_fds together with the DRM device's descriptor,
so the process idles in the kernel until either input arrives or the display
retires a flip — rather than waking up to ask.
That list changes under you. A wireless mouse that was asleep at startup has no
device node until somebody moves it, and poll opens it when it appears — so ask
devices_changed() each pass and take raw_fds again when it says yes. Holding
the first list forever is how a panel ends up with a mouse it can see in
/dev/input and cannot read.
Keyboards
Key positions are translated to KeyCode, then composed into text: dead keys,
AltGr, and the modifier state that decides both. Two layouts ship, US and
Norwegian — the Norwegian AltGr assignments are a careful reconstruction and
want checking against real hardware.
There is also a console guard: on a bare VT the kernel is still echoing every
keystroke behind the panel, so console puts the tty into a raw, graphics mode for
the life of the process and restores it afterwards — including on panic, which is
the case that leaves a machine unusable if it is forgotten.
Testing
translate and keymap are platform-independent and unit tested everywhere. That
is not tidiness: multitouch slot tracking, frame batching and modifier state are
the parts that break, and each is far easier to pin down as a table of raw event
codes than by dragging a finger across a panel and guessing. Only device discovery
and reading are gated to Linux.
Three examples help on a new board: input prints translated events, keys shows
what a keyboard produces layout by layout, and pointer tracks a cursor.
Permissions
Reading /dev/input/event* needs membership in the input group, or root. Being
able to read every keystroke on the machine is exactly as sensitive as it sounds,
which is why the group exists.
Platform
Linux only; elsewhere the crate compiles to almost nothing. unsafe is permitted
here and every block carries a // SAFETY: comment.
Where this sits
Implements denise::InputSource. Pair it with
denise-drm or
denise-fbdev for output.
Status
M2 complete, with touch routing exercised in unit tests and on a VM; no physical touchscreen has confirmed it yet. Part of Denise — see the repository README for the whole picture.
MIT licensed.