Skip to content

feat(sokol): Linux evdev/udev + wasm Gamepad API detection sources (Phase 1) #249

@apotema

Description

@apotema

Phase 1 of controller-support epic: labelle-toolkit/labelle-engine#609

Goal

sokol gamepad sources for desktop Linux (evdev + libudev) and wasm (HTML5 Gamepad API), so a sokol build has controller detection — and on Linux, better reconnection than raylib.

Context

sokol has no gamepad layer on any platform. Unlike Android, on desktop Linux an app can open /dev/input/event* directly (subject to permissions), and on the web the Gamepad API is pollable. These plug into the Phase 0 comptime fallback (only compiled in when the backend declares no pollGamepadEvents).

Scope

Linux (evdev + libudev):

  1. libudev monitor for add/remove → GamepadEvents into the ring buffer; enumerate existing /dev/input/event* at startup.
  2. Derive a stable guid from the device input_id (vendor/product/version + phys) — gives correct reconnection (raylib can't).
  3. Permissions: on EACCES, surface via describeGamepads unavailable_reason + a one-time log hint (input group / udev rule). Ship a sample 99-labelle-gamepads.rules (uaccess) and document Flatpak --device=input.
  4. Filter duplicate js*/event* nodes and non-gamepad devices (accelerometers etc.).

wasm (HTML5 Gamepad API):
5. gamepadconnected/gamepaddisconnected events → ring buffer; gamepad.idname, index → slot.

Acceptance criteria

  • sokol+Linux: plug/unplug emits events; replug restores same input_id guid; permission failure produces a clear diagnostic, not silence.
  • Sample udev rule shipped + documented.
  • sokol+wasm: connect/disconnect events propagate.

Non-goals

  • Semantic button/axis mapping (the SDL_GameControllerDB problem) is Phase 3. This issue is detection + identity.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions