Skip to main content

Module capture

Module capture 

Source
Expand description

Linux keystroke capture.

Reads key events from every keyboard under /dev/input via evdev and translates them — honoring the keyboard layout and modifiers via xkbcommon — into Key values for the keystroke buffer.

The trigger chord itself (Super+Ctrl+Shift+Alt+letter) is not delivered here — Hyprland intercepts it (via the inline keybind set up by hotkey) and signals the daemon over SIGUSR1. Capture only suppresses the would-be Key::Reset that the chord’s letter press would otherwise emit, so the buffer survives the chord and the trigger has a word to fix.

One OS thread per keyboard device runs for the life of the process; start returns the channel they feed.

Layout note: the keymap is the system / XKB_DEFAULT_* default. A layout configured only in the compositor (e.g. hyprland.conf) is not yet read — that is M5 polish.

Structs§

ResetKeyConfig
User-configurable view of which “control” keys reset the per-window buffer. The daemon passes the current settings via set_reset_keys at startup and on every config reload; classify reads it under a RwLock::read (essentially free) to decide whether a given key is a Key::Reset or just ignored. Defaults match the safest behavior — every context-changing key resets except for Tab and Escape, which rarely change typed text and would otherwise drop the buffer for no gain.

Enums§

CaptureError
An error starting keystroke capture.

Functions§

caret_suspect_flag
Shared flag set by the mouse-listener threads whenever the user clicks a mouse button, and cleared by the daemon after the next fix-word emit or buffer reset. When true, the daemon’s word-fix path widens its nearby-word scan to the entire buffer — the buffer’s caret tracking can’t follow a mouse click, but the buffer’s text is still accurate, so scanning all of it for a typo is the best we can do without OS-level cursor snooping. Returned as an Arc so the daemon can both read and reset it.
set_reset_keys
Replace the daemon-wide reset-key config. Cheap (one RwLock write); call at startup and on every config reload.
start
Start capturing keystrokes from every keyboard under /dev/input.
wait_mods_clear
Block up to timeout for every chord modifier (Ctrl/Shift/Alt/ Super) to be released across every keyboard device the daemon is watching. Returns true if everything cleared in time, false on timeout.