Architecture

padctl is a userspace daemon that maps vendor-specific USB/HID gamepad reports to standard Linux input events via uinput or UHID. Device support is driven by declarative TOML configs in devices/; user preferences live in separate mapping TOMLs.

+----------------------------+
| Physical Device (USB / BT) |
+----------------------------+
              |
      +-------+-------+
      |               |
      v               v
+----------------+  +-------------------+
| HID / hidraw   |  | Vendor / libusb   |
| io/hidraw.zig  |  | io/usbraw.zig     |
+----------------+  +-------------------+
       \              /
        \            /
         v          v
      +--------------------+
      | DeviceIO (unified) |
      +--------------------+
                |
                v
      +--------------------+
      | main loop (ppoll)  |
      +--------------------+
                |
      +---------+---------+
      |                   |
      v                   v
+------------------+  +------------------+
| config/device.zig|  | io/netlink.zig   |
| devices/*.toml   |  | kernel uevents   |
+------------------+  +------------------+
          |
          v
+-----------------------------------------+
| [input rules] -> interpreter -> state   |
| [output]     -> OutputConfig            |
+-----------------------------------------+
                      |
                      v
           +----------------------+
           | mapper (layer/remap) |
           +----------------------+
                |            |
                v            v
      +----------------+  +------------------+
      | gamepad output |  | auxiliary output |
      | uinput or UHID |  | mouse/touch/keys |
      +----------------+  +------------------+
  • I/O — io/hidraw.zig reads HID devices; io/usbraw.zig uses libusb for vendor-class interfaces. Both sit behind one DeviceIO interface.
  • Main loop — event_loop.zig runs a ppoll loop; supervisor.zig uses netlink uevents (io/netlink.zig) to attach and detach devices on hotplug.
  • Device config — config/device.zig parses devices/*.toml. Input rules feed an interpreter that produces gamepad state; [output] becomes an OutputConfig.
  • Mapper — applies the user's mapping (layers, remaps, gyro and stick modes), then emits to the virtual gamepad and the optional auxiliary mouse/touchpad/keyboard device.