Geometry follows layout. Labels follow keymap.
PhysicalLayout describes key positions and sizes
LogicalKeymap maps key codes to display labels
HIDDeviceMonitor discovers connected keyboards
x, y, width, height, and totalWidth/totalHeight for aspect ratio. Ships with US (ANSI), International (ISO/JIS/ABNT2/Korean), and Ergonomic (Kinesis, Corne, Sofle, Ferris Sweep) registries. Supports custom user layouts.struct PhysicalLayout: Identifiable { let id: String // "macbook-us", "kinesis-360" let name: String // "MacBook US" let keys: [PhysicalKey] let totalWidth: Double let totalHeight: Double }
UInt16 key codes to display strings. Splits labels into coreLabels (30-key letter block, always shown) and extraLabels (number row and punctuation, toggled). Includes QWERTY, Colemak, Colemak-DH, Dvorak, Workman, Graphite, AZERTY, and QWERTZ. A special "system" keymap queries UCKeyTranslate for dynamic OS-driven labels.struct LogicalKeymap: Identifiable { let id: String let coreLabels: [UInt16: String] // letter block let extraLabels: [UInt16: String] // numbers + punctuation func displayLabel(for key: PhysicalKey, includeExtraKeys: Bool) -> String }
connectedKeyboards as an @Published array. Filters out VirtualHID devices and anonymous BLE devices (VID:PID 0:0). Each device is identified by vendorID, productID, and productName.@MainActor final class HIDDeviceMonitor: ObservableObject { @Published private(set) var connectedKeyboards: [HIDKeyboardEvent] @Published private(set) var lastConnectedKeyboard: HIDKeyboardEvent? }
kanata --list output into structured ConnectedDevice records. Pure parsing logic kept separate from Process execution for testability. Identifies VirtualHID devices, extracts vendor/product IDs, and deduplicates by device hash.enum DeviceEnumerationService { static func parseAllDevices( fromKanataList output: String ) -> [ConnectedDevice] }
PhysicalLayout for key positions and sizes, and a LogicalKeymap for display labels. Combines them at render time — never stores merged data.HIDDeviceMonitor starts IOKit run loop, scans for connected USB/BT keyboardsPhysicalLayout — key geometry flows to overlay viewLogicalKeymap labels applied to layout — displayLabel(for:includeExtraKeys:)HIDDeviceMonitor publishes event → DeviceEnumerationService identifies device(switch ((device N)) ...) only for keys with different mappingskeys array directly.coreLabels for the letter block, extraLabels for number row and punctuation.(switch ((device N)) ... break) wrapper. All other keys are emitted normally.