How def3r/haka works
Project Type and Purpose
• Haka is a native, CLI‐based user‐level daemon for Wayland that listens to global keyboard events, captures selected text, and appends it to organized note files without polluting the clipboard.
• It’s not a full-stack web app but a system utility: a monolithic C program with clearly separated layers (input Listener → core Logic → Event Handlers → Action Executors → external tools & file storage).
Main Components
a. Input Layer
• Linux evdev devices (/dev/input/*)
• libevdev library
b. Core Haka Daemon
• Main loop (src/haka.c)
• Configuration parser (haka.cfg via hakaUtils)
• Capability / privileges manager (setcap approach)
c. Event Dispatch & Binding
• Event handler module (include/hakaEventHandler.h + src/hakaEventHandler.c)
• Binding definitions (src/bindings.c)
d. Action Executors
• Notes file manager (openNotesFile, write/unordered-list macros)
• UI launcher for file selection (tofi)
• Clipboard integration (wl-clipboard)
• External editor launcher (neovim via configured terminal)
e. Storage
• Notes directory (file system storage)
• Configuration files (haka.cfg, tofi.cfg)
f. Service Integration
• systemd user service (generated by daemon.sh)
• Shell scripts (build.sh, daemon.sh)
Interactions & Data Flow
• Write to notes file (file I/O)
• If “open menu”: launch tofi (subprocess) → user picks file → return path
• If “paste selection”: invoke wl-copy / wl-paste → append text
• If “open editor”: spawn terminal → neovim on selected file
Architectural Patterns & Principles
• Layered design: Input → Core → Handlers → Actions → External
• Separation of concerns: config parsing, event dispatch, action implementation in separate modules
• Minimal-privilege approach: use of Linux capabilities to drop root while retaining input-group access
• Plugin-like extensibility: new handlers bound via a macro (Bind) and header/function registration