The problem
I wanted a desktop pet on Hyprland, the kind that used to live on Windows desktops years ago. Wayland has no equivalent of an always-on-top, click-through, input-transparent window that a compositor just hands you. Getting that overlay right meant talking to the compositor’s own protocols, not a toolkit abstraction built for normal application windows.
The harder problem showed up once the overlay worked: a surface that correctly asks for no keyboard interactivity also never gets told when a key is pressed. There was no protocol-legal way to know the user was typing.
How it works
Sit on top, take nothing
A wlr-layer-shell surface on the top layer, with keyboard interactivity explicitly set to none. It draws over every window but never steals a keystroke or blocks a click on what is behind it.
One sprite sheet, six states
Idle, typing, drag, stretch, bounce and lean all read from a single 32×32-per-frame sheet, one row per animation. Idle and typing have four frames each; the others stop at the first fully transparent cell. Nearest-neighbor upscaling keeps the pixel art sharp at any size. The repo’s one Python file, tools/gen_anim.py, is an offline helper that makes animation rows for the sheet; it never runs with the pet.
Detect typing without a keyboard
nekopet opens every /dev/input/eventN device directly and parses the raw 24-byte input_event struct itself, watching for key-press codes on its own thread per device. The cost is access: on most distros those nodes are readable only by root or the input group, and they carry every keystroke, so nekopet keeps one flag, that a key went down, and never which key.
Eyes that follow the cursor
Wayland gives a client no way to query the pointer position outside its own surface, so tracking only works while the cursor is over the cat. Pupil offsets are computed from pointer-motion events against hardcoded source-pixel coordinates on the sprite.
Result
- 868Lines of Rust for input, rendering and the Wayland client
- 6States driven from one event loop, no animation library
- 0External processes at runtime: one native binary, no Electron, no Python
What I would change next
The keyboard watcher opens every /dev/input/eventN node it can and spawns a thread per device instead of filtering to actual keyboards first. It works because a typical machine only has a handful of event nodes, but it is the kind of shortcut that stops being fine on a machine with more input devices attached.
Next case study
CipherOS & DerpFest
Official maintainer · 2 ROMs
Maintainer for the Redmi S2/Y2 on two Android ROMs: kernel compiled from source, device trees kept current.
17,500+Downloads across 23 official builds