133e25849d
Sources reorganized (client: Home/Session/Settings/Stores/Support/Trust; kit: Audio/Connection/Gamepad/Input/Support/Video/Views) with the big files split along the same seams. The gamepad mode is couch-complete, and now on macOS too (the living-room Mac case), not just iOS/iPadOS: - GamepadSettingsView: a console-style, fully controller-navigable settings screen (X from the launcher) — up/down moves focus, left/right steps values (clamped, boundary thud), A cycles/toggles, B closes; the focused row shows a one-line description. Backed by GamepadMenuList, the vertical sibling of GamepadCarousel, and SettingsOptions — the option lists hoisted out of SettingsView statics and shared by the touch, tvOS and gamepad settings. - GamepadAddHostView + GamepadKeyboard: register a host end to end with a pad — field rows open an on-screen controller keyboard (dpad grid, A types, X backspaces, B done); the launcher carousel ends in an Add Host tile, so the dead-end "add one with touch first" empty state is gone. - Launcher polish: contextual hint bar with the pad's real button glyphs, controller name + battery chip, one shared console chrome. - GamepadScreenBackground: an animated aurora (TimelineView-driven drifting blobs in the brand's violet family, breathing radii, slow hue shift, legibility scrim; freezes under Reduce Motion). Pure SwiftUI on purpose — a .metal library only bundles reliably in one of the two build systems (SPM vs the xcodeproj's synced folders) these sources compile under. - macOS port: settings/add-host/library present as sized sheets (a macOS sheet takes its content's IDEAL size, and the GeometryReader-driven screens collapsed to nothing), NSScreen-based mode lists, scroll indicators .never (the "always show scroll bars" setting overrides .hidden), tray scrims so scrolled rows dim under the pinned title/hints, extra title clearance, and a PUNKTFUNK_FORCE_GAMEPAD_UI=1 dev hook — launcher/settings/add-host/keyboard/ library render-verified live on a real Mac + LAN hosts. - GamepadMenuInput: X button support, and (re)start now snapshots held buttons so a controller handoff press never fires twice (the B that closed the keyboard no longer also cancels the screen underneath). - Cleanups: one "Connection failed" alert in ContentView instead of one per home screen; HostDiscovery.advertises/unsaved shared by both home screens. - host: can_encode_444 stub for the non-Linux/Windows host build (the macOS synthetic-source loopback used by the Swift tests). Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
63 lines
2.6 KiB
Swift
63 lines
2.6 KiB
Swift
// The gamepad wire contract shared by capture (GamepadCapture), feedback (GamepadFeedback),
|
|
// and the tests — button bits, axis ids, and the touchpad/motion unit conversions.
|
|
|
|
import Foundation
|
|
|
|
/// The gamepad wire contract (mirrors `punktfunk_core::input::gamepad`).
|
|
public enum GamepadWire {
|
|
public static let dpadUp: UInt32 = 0x0001
|
|
public static let dpadDown: UInt32 = 0x0002
|
|
public static let dpadLeft: UInt32 = 0x0004
|
|
public static let dpadRight: UInt32 = 0x0008
|
|
public static let start: UInt32 = 0x0010
|
|
public static let back: UInt32 = 0x0020
|
|
public static let leftStickClick: UInt32 = 0x0040
|
|
public static let rightStickClick: UInt32 = 0x0080
|
|
public static let leftShoulder: UInt32 = 0x0100
|
|
public static let rightShoulder: UInt32 = 0x0200
|
|
public static let guide: UInt32 = 0x0400
|
|
public static let a: UInt32 = 0x1000
|
|
public static let b: UInt32 = 0x2000
|
|
public static let x: UInt32 = 0x4000
|
|
public static let y: UInt32 = 0x8000
|
|
/// DualSense touchpad click (Moonlight's extended-button bit position).
|
|
public static let touchpadClick: UInt32 = 0x10_0000
|
|
|
|
public static let allButtons: [UInt32] = [
|
|
dpadUp, dpadDown, dpadLeft, dpadRight, start, back,
|
|
leftStickClick, rightStickClick, leftShoulder, rightShoulder, guide,
|
|
a, b, x, y, touchpadClick,
|
|
]
|
|
|
|
public static let axisLSX: UInt32 = 0
|
|
public static let axisLSY: UInt32 = 1
|
|
public static let axisRSX: UInt32 = 2
|
|
public static let axisRSY: UInt32 = 3
|
|
public static let axisLT: UInt32 = 4
|
|
public static let axisRT: UInt32 = 5
|
|
|
|
/// Raw DualSense gyro units per rad/s: hid-playstation's calibration over the host's
|
|
/// fixed blob resolves to 20 LSB per deg/s.
|
|
public static let gyroLSBPerRadS: Float = 20 * 180 / .pi
|
|
/// Raw DualSense accelerometer units per g (same derivation).
|
|
public static let accelLSBPerG: Float = 10_000
|
|
|
|
/// GC touchpad coordinates (±1, +y up) → wire (0...65535, origin top-left, +y down).
|
|
public static func touchpad(x: Float, y: Float) -> (x: UInt16, y: UInt16) {
|
|
let wx = ((x.clamped(to: -1...1) + 1) / 2 * 65535).rounded()
|
|
let wy = ((1 - y.clamped(to: -1...1)) / 2 * 65535).rounded()
|
|
return (UInt16(wx), UInt16(wy))
|
|
}
|
|
|
|
/// Scale + clamp one motion component into the raw signed-16 sensor domain.
|
|
public static func motionRaw(_ value: Float, scale: Float) -> Int16 {
|
|
Int16((value * scale).rounded().clamped(to: Float(Int16.min)...Float(Int16.max)))
|
|
}
|
|
}
|
|
|
|
extension Float {
|
|
fileprivate func clamped(to range: ClosedRange<Float>) -> Float {
|
|
Swift.min(Swift.max(self, range.lowerBound), range.upperBound)
|
|
}
|
|
}
|