Files
punktfunk/crates/punktfunk-core/cbindgen.toml
T
enricobuehler 1d605fb781 feat(gamepad): controller discovery + client-negotiated pad type + rich DualSense end to end
The Apple client grows full gamepad support and punktfunk/1 learns to negotiate
the virtual pad type:

- Protocol: Hello carries a GamepadPref byte (offset 21, the same trailing-byte
  back-compat pattern as the compositor; echoed resolved in Welcome at 54).
  Host precedence: explicit client choice > PUNKTFUNK_GAMEPAD env > Xbox 360,
  DualSense (UHID) only where available. ABI: punktfunk_connect_ex2 +
  punktfunk_connection_gamepad (connect_ex delegates; ABI_VERSION stays 2 — the
  trailing byte IS the compat mechanism). punktfunk-client-rs gets --gamepad.

- Swift client: GamepadManager (app-lifetime discovery + selection — Settings
  lists every controller with capabilities/battery/"In use"; exactly ONE pad
  forwards as pad 0, auto = most recently connected, or pinned), GamepadCapture
  (snapshot-diff button/axis events, DualSense touchpad + ~250 Hz motion on the
  rich-input plane, held state released on switch/deactivate/stop),
  GamepadFeedback (rumble → CoreHaptics per-handle engines; lightbar →
  GCDeviceLight; player LEDs → playerIndex; adaptive-trigger blocks → the
  table-driven DualSenseTriggerEffect parser → GCDualSenseAdaptiveTrigger,
  exact for the 10-zone positional modes). The pad type auto-resolves from the
  physical controller at connect time, user-overridable in Settings.

- Host DualSense fixes surfaced by adversarial review against hid-playstation /
  SDL / Nielk1 ground truth: input-report sensor/touch offsets were off by one
  (the kernel read garbage motion + phantom touches), the L2/R2 trigger blocks
  were swapped (the report is right-trigger-first), feedback now gates on the
  report's valid-flags (a plain rumble write no longer blanks lightbar/
  triggers), and the touchpad rescale clamps to the advertised ABS_MT extents.

- Tests: Hello/Welcome trailing-byte back-compat, pick_gamepad precedence,
  byte-exact input-report layout, valid-flag gating, per-mode trigger-parser
  table (incl. packed 3-bit zones), wire conversions, and a scripted loopback
  feedback burst (PUNKTFUNK_TEST_FEEDBACK=1) asserted through the xcframework
  on the rumble + HID-output planes.

Validated: cargo test/clippy/fmt green on macOS + Linux (61 host tests), swift
build/test green, test-loopback.sh green, tvOS/iOS targets compile. DualSense
motion sign/scale is derived from the calibration blob, not yet live-verified
(constants isolated in GamepadWire).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-06-11 16:28:33 +02:00

58 lines
1.8 KiB
TOML

language = "C"
pragma_once = true
include_guard = "PUNKTFUNK_CORE_H"
autogen_warning = "/* Generated by cbindgen from punktfunk-core. Do not edit by hand. */"
header = "/* punktfunk-core C ABI — see crates/punktfunk-core/src/abi.rs */"
style = "type"
cpp_compat = true
tab_width = 4
documentation = true
documentation_style = "c99"
[parse]
parse_deps = false
[export.rename]
"InputEvent" = "PunktfunkInputEvent"
"InputKind" = "PunktfunkInputKind"
# Gamepad wire constants: bare BTN_* names collide with <linux/input-event-codes.h> (at
# DIFFERENT values — last definition silently wins); prefix everything we export.
"BTN_DPAD_UP" = "PUNKTFUNK_BTN_DPAD_UP"
"BTN_DPAD_DOWN" = "PUNKTFUNK_BTN_DPAD_DOWN"
"BTN_DPAD_LEFT" = "PUNKTFUNK_BTN_DPAD_LEFT"
"BTN_DPAD_RIGHT" = "PUNKTFUNK_BTN_DPAD_RIGHT"
"BTN_START" = "PUNKTFUNK_BTN_START"
"BTN_BACK" = "PUNKTFUNK_BTN_BACK"
"BTN_LS_CLICK" = "PUNKTFUNK_BTN_LS_CLICK"
"BTN_RS_CLICK" = "PUNKTFUNK_BTN_RS_CLICK"
"BTN_LB" = "PUNKTFUNK_BTN_LB"
"BTN_RB" = "PUNKTFUNK_BTN_RB"
"BTN_GUIDE" = "PUNKTFUNK_BTN_GUIDE"
"BTN_A" = "PUNKTFUNK_BTN_A"
"BTN_B" = "PUNKTFUNK_BTN_B"
"BTN_X" = "PUNKTFUNK_BTN_X"
"BTN_Y" = "PUNKTFUNK_BTN_Y"
"BTN_TOUCHPAD" = "PUNKTFUNK_BTN_TOUCHPAD"
"AXIS_LS_X" = "PUNKTFUNK_AXIS_LS_X"
"AXIS_LS_Y" = "PUNKTFUNK_AXIS_LS_Y"
"AXIS_RS_X" = "PUNKTFUNK_AXIS_RS_X"
"AXIS_RS_Y" = "PUNKTFUNK_AXIS_RS_Y"
"AXIS_LT" = "PUNKTFUNK_AXIS_LT"
"AXIS_RT" = "PUNKTFUNK_AXIS_RT"
"AUDIO_MAGIC" = "PUNKTFUNK_AUDIO_MAGIC"
"RUMBLE_MAGIC" = "PUNKTFUNK_RUMBLE_MAGIC"
# QualifiedScreamingSnakeCase already qualifies each variant with the enum name
# (PunktfunkStatus::Ok -> PUNKTFUNK_STATUS_OK); do NOT also set prefix_with_name or it doubles.
[enum]
rename_variants = "QualifiedScreamingSnakeCase"
[fn]
sort_by = "None"
[struct]
derive_eq = false
[defines]
"feature = quic" = "PUNKTFUNK_FEATURE_QUIC"