Play your own Switch games on iPhone/iPad — one-click macOS app, no terminal. | 把 Switch 游戏装进 iPhone:图形界面一键构建,不用命令行。Bring your own game.
Swift apple-siliconcustom-formathomebrewiosipaipadipadosiphonemetalnative-portnintendo-switchnxnativeromfsswitch-games
Mac: split a Joy-Con pair into two sideways controllers (#740)
LNPANDYfc56ca31138d
diff --git a/frontend/Sources/NX2Apple/ConsoleControllersView.swift b/frontend/Sources/NX2Apple/ConsoleControllersView.swiftindex 17944d42..67c0320c 100644--- a/frontend/Sources/NX2Apple/ConsoleControllersView.swift+++ b/frontend/Sources/NX2Apple/ConsoleControllersView.swift@@ -24,6 +24,7 @@ import NXLauncherfunc identify(controllerID: String) { base.identify(controllerID: controllerID) }func disconnect(controllerID: String) { base.disconnect(controllerID: controllerID) }func setPadMerge(_ enabled: Bool) { base.setPadMerge(enabled) }+ func setJoyconSplit(_ enabled: Bool) { base.setJoyconSplit(enabled) }func dismissToast() { base.dismissToast() }func back() { base.back() }func exitToDesktop() { base.exitToDesktop() }@@ -221,6 +222,7 @@ struct ConsoleToastView: View {ScrollView {VStack(alignment: .leading, spacing: 22) {mergeToggle+ joyconSplitToggleText(t("console.controllerNote")).font(.manrope(compact ? 17 : 22)).foregroundStyle(.secondary)HStack(spacing: 12) {ForEach(1...4, id: \.self) { player in@@ -268,6 +270,26 @@ struct ConsoleToastView: View {.accessibilityLabel(t("console.mergeAll")).accessibilityValue(t(state.padMerge ? "console.on" : "console.off"))}+ /// "Split Joy-Con pair into two controllers" (#740) as a switch with its state spelled out.+ private var joyconSplitToggle: some View {+ let flip = { driver.setJoyconSplit(!state.joyconSplit) }+ return Button(action: flip) {+ HStack(spacing: 14) {+ VStack(alignment: .leading, spacing: 6) {+ Label(t("console.joyconSplit"), systemImage: "rectangle.split.2x1").font(.manrope(compact ? 16 : 18, .semibold))+ Text(t(state.joyconSplit ? "console.on" : "console.off")).font(.manrope(compact ? 16 : 20)).foregroundStyle(state.joyconSplit ? LauncherPalette.cream : .secondary)+ }+ Spacer(minLength: 8)+ Toggle("", isOn: Binding(get: { state.joyconSplit }, set: { _ in flip() })).labelsHidden().toggleStyle(LauncherSwitchStyle()).allowsHitTesting(false)+ }+ .frame(maxWidth: .infinity, alignment: .leading).padding(14)+ .background(.white.opacity(0.045), in: RoundedRectangle(cornerRadius: 10)).contentShape(RoundedRectangle(cornerRadius: 10))+ }+ .buttonStyle(.plain)+ .padTarget("console.controller.joyconSplit", scope: scope, radius: 10, activate: flip, adjust: { _ in flip() })+ .accessibilityLabel(t("console.joyconSplit")).accessibilityValue(t(state.joyconSplit ? "console.on" : "console.off"))+ }+private func row(_ controller: ConsoleController) -> some View {VStack(alignment: .leading, spacing: 18) {HStack(spacing: 16) {diff --git a/frontend/Sources/NX2Apple/ConsoleLauncherDriver.swift b/frontend/Sources/NX2Apple/ConsoleLauncherDriver.swiftindex d02687d7..8ab5b3f6 100644--- a/frontend/Sources/NX2Apple/ConsoleLauncherDriver.swift+++ b/frontend/Sources/NX2Apple/ConsoleLauncherDriver.swift@@ -7,14 +7,17 @@ import Combine@MainActor final class LauncherControllerDriver: ConsoleDriver {@Published var state = ConsoleState()private let layout: ControlLayout- private var subscription: AnyCancellable?+ private var cancellables = Set<AnyCancellable>()init(layout: ControlLayout) {self.layout = layoutstate.padMerge = layout.padMerge- subscription = layout.$padMerge.sink { [weak self] merged in self?.state.padMerge = merged }+ state.joyconSplit = layout.joyconSplit+ layout.$padMerge.sink { [weak self] merged in self?.state.padMerge = merged }.store(in: &cancellables)+ layout.$joyconSplit.sink { [weak self] split in self?.state.joyconSplit = split }.store(in: &cancellables)}func setPadMerge(_ enabled: Bool) { layout.padMerge = enabled }+ func setJoyconSplit(_ enabled: Bool) { layout.joyconSplit = enabled }func openControllers() { state.openControllers() }func back() { state.back() }func dismissToast() { state.toast = nil }diff --git a/frontend/Sources/NX2Apple/ConsoleState.swift b/frontend/Sources/NX2Apple/ConsoleState.swiftindex 73043588..6c3803fe 100644--- a/frontend/Sources/NX2Apple/ConsoleState.swift+++ b/frontend/Sources/NX2Apple/ConsoleState.swift@@ -119,6 +119,7 @@ struct ConsoleState {var controllers: [ConsoleController] = []var isPreview = falsevar padMerge = false+ var joyconSplit = falsevar toast: ConsoleToast?var identifyingControllerID: String?var assigningControllerID: String?@@ -196,6 +197,7 @@ struct ConsoleState {func disconnect(controllerID: String)func requestAssignment(controllerID: String)func setPadMerge(_ enabled: Bool)+ func setJoyconSplit(_ enabled: Bool)func dismissToast()func requestPlayer(_ player: Int)func assignPlayer(controllerID: String, player: Int)@@ -209,6 +211,7 @@ struct ConsoleState {}extension ConsoleDriver {+ func setJoyconSplit(_ enabled: Bool) {}func consumePress(controllerID: String, isBack: Bool) -> Bool { false }func openHomeButtonSettings() { back() }}diff --git a/frontend/Sources/NX2Apple/Controls.swift b/frontend/Sources/NX2Apple/Controls.swiftindex 780b28ca..360524e4 100644--- a/frontend/Sources/NX2Apple/Controls.swift+++ b/frontend/Sources/NX2Apple/Controls.swift@@ -42,6 +42,9 @@ final class ControlLayout: ObservableObject {/// change, so it stays out of `isDefault`, `changeCount` and the Controls sheet's reset.@Published var padMerge: Bool { didSet { defaults.set(padMerge, forKey: Self.padMergeKey) } }static let padMergeKey = "padMerge"+ /// "Split Joy-Con pair into two controllers" (launcher setting, off by default): passed at Play as DM_JOYCON_SPLIT=1 (#740).+ @Published var joyconSplit: Bool { didSet { defaults.set(joyconSplit, forKey: Self.joyconSplitKey) } }+ static let joyconSplitKey = "joyconSplit"private let defaults: UserDefaults/// A key code, -1 for no key. `mode` is nil in settings saved before the layouts, which had only the custom buttons.private struct Saved: Codable { var keys: [String: Int]; var pad: [String: String]; var mode: String? }@@ -49,6 +52,7 @@ final class ControlLayout: ObservableObject {init(defaults: UserDefaults = .standard) {self.defaults = defaultspadMerge = defaults.bool(forKey: Self.padMergeKey)+ joyconSplit = defaults.bool(forKey: Self.joyconSplitKey)if let data = defaults.data(forKey: "controlLayout"), let saved = try? JSONDecoder().decode(Saved.self, from: data) {keys = saved.keys.filter { k, code in Self.functions.contains { $0.id == k } && code < 128 }.mapValues { $0 < 0 ? nil : $0 }pad = saved.pad.filter { b, to in Self.buttons.contains(b) && (to == "none" || Self.buttons.contains(to)) }@@ -102,6 +106,7 @@ final class ControlLayout: ObservableObject {var environment: [String: String] {var env: [String: String] = [:]if padMerge { env["DM_PAD_MERGE"] = "1" }+ if joyconSplit { env["DM_JOYCON_SPLIT"] = "1" }let k = Self.functions.compactMap { f in keys[f.id].map { "\(f.id)=\($0.map(String.init) ?? "none")" } }if !k.isEmpty { env["DM_KEYMAP"] = k.joined(separator: ",") }let active = activePaddiff --git a/frontend/Sources/NX2Apple/LauncherView.swift b/frontend/Sources/NX2Apple/LauncherView.swiftindex 5d055ee9..f7579ce6 100644--- a/frontend/Sources/NX2Apple/LauncherView.swift+++ b/frontend/Sources/NX2Apple/LauncherView.swift@@ -126,6 +126,7 @@ struct LauncherView: View {}}.onChange(of: consoleDriver.state.padMerge) { merged in if injectedDriver { controls.padMerge = merged } }+ .onChange(of: consoleDriver.state.joyconSplit) { split in if injectedDriver { controls.joyconSplit = split } }.onChange(of: consolePrompt) { open inpadFocus.scope = open ? "console.entry" : currentPadScopeif open { padFocus.focused = "console.entry.enter" }diff --git a/frontend/Sources/NX2Apple/LiveConsoleDriver.swift b/frontend/Sources/NX2Apple/LiveConsoleDriver.swiftindex d3b2cca8..6a728023 100644--- a/frontend/Sources/NX2Apple/LiveConsoleDriver.swift+++ b/frontend/Sources/NX2Apple/LiveConsoleDriver.swift@@ -27,6 +27,7 @@ struct ConsolePadSnapshot: Equatable {var battery: Double?var charging = falsevar canIdentify = true+ var kindOverride: ConsoleController.Kind? = nil/// The level to show, or nil when the controller has not really reported one. GameController gives 0 with an unknown state for a/// DualShock 4 over Bluetooth and before the first report, and some pads over USB report no battery or an unknown one: those are@@ -44,7 +45,8 @@ struct ConsolePadSnapshot: Equatable {let family = ConsoleGlyphs.Family(category: category)let c = (category ?? "").lowercased().replacingOccurrences(of: "-", with: "")let kind: ConsoleController.Kind- if c.contains("joycon") { kind = .paired }+ if let kindOverride { kind = kindOverride }+ else if c.contains("joycon") { kind = .paired }else if family == .nintendo { kind = .fullSize }else if family == .xbox { kind = .xbox }else { kind = .gamepad }@@ -91,8 +93,14 @@ struct ConsolePadSnapshot: Equatable {self.artwork = artwork ?? { game, repo in GameLibrary.artwork(for: game, repo: repo) }if pads == nil { self.devicePads = true }state.padMerge = controls.padMerge+ state.joyconSplit = controls.joyconSplitlibrary.objectWillChange.sink { [weak self] _ in self?.queueRefresh() }.store(in: &cancellables)controls.$padMerge.sink { [weak self] merged in self?.state.padMerge = merged }.store(in: &cancellables)+ controls.$joyconSplit.dropFirst().sink { [weak self] split in+ guard let self, self.state.joyconSplit != split else { return }+ self.state.joyconSplit = split+ self.refreshControllers(announce: false)+ }.store(in: &cancellables)refresh()refreshControllers(announce: false)announced = Set(state.controllers.map(\.id)) // controllers there at launch are not announced again by a repeated notification@@ -391,6 +399,28 @@ struct ConsolePadSnapshot: Equatable {showToast(String(format: t("console.assignedTo"), pad.name, player))}func setPadMerge(_ enabled: Bool) { controls.padMerge = enabled }+ func setJoyconSplit(_ enabled: Bool) {+ controls.joyconSplit = enabled+ state.joyconSplit = enabled+ refreshControllers(announce: false)+ }++ /// Expands each paired Joy-Con snapshot into separate `Joy-Con (L)` and `Joy-Con (R)` sideways controller snapshots when `enabled` is true (#740).+ static func splitJoyConSnapshots(_ pads: [ConsolePadSnapshot], enabled: Bool) -> [ConsolePadSnapshot] {+ guard enabled else { return pads }+ var out: [ConsolePadSnapshot] = []+ for pad in pads {+ if pad.controller.kind == .paired {+ out.append(ConsolePadSnapshot(id: pad.id + ".L", name: "Joy-Con (L)", category: "Nintendo Switch Joy-Con (L)",+ playerIndex: pad.playerIndex, battery: pad.battery, charging: pad.charging, canIdentify: pad.canIdentify, kindOverride: .gamepad))+ out.append(ConsolePadSnapshot(id: pad.id + ".R", name: "Joy-Con (R)", category: "Nintendo Switch Joy-Con (R)",+ playerIndex: nil, battery: pad.battery, charging: pad.charging, canIdentify: pad.canIdentify, kindOverride: .gamepad))+ } else {+ out.append(pad)+ }+ }+ return out+ }/// What this controller can do for Identify. The player lights have no capability flag in GameController, so any gamepad counts.static func identifyActions(_ c: GCController) -> [IdentifyPlan.Action] {@@ -601,6 +631,13 @@ struct ConsolePadSnapshot: Equatable {charging: reading?.charging ?? false, canIdentify: !Self.identifyActions(c).isEmpty)}}+ snapshots = Self.splitJoyConSnapshots(snapshots, enabled: controls.joyconSplit)+ if devicePads, controls.joyconSplit {+ for snap in snapshots where snap.id.hasSuffix(".L") || snap.id.hasSuffix(".R") {+ let base = String(snap.id.dropLast(2))+ if let dev = devices[base] { devices[snap.id] = dev }+ }+ }let live = Set(snapshots.map(\.id))batteryWatchers = batteryWatchers.filter { live.contains($0.key) || !devicePads }overrides = overrides.filter { live.contains($0.key) }diff --git a/frontend/Sources/NX2Apple/MockConsoleDriver.swift b/frontend/Sources/NX2Apple/MockConsoleDriver.swiftindex 88deb67d..618e408f 100644--- a/frontend/Sources/NX2Apple/MockConsoleDriver.swift+++ b/frontend/Sources/NX2Apple/MockConsoleDriver.swift@@ -106,6 +106,37 @@ import NXLauncherstate.assigningPlayer = state.assigningPlayer ?? controller.player ?? 1}func setPadMerge(_ enabled: Bool) { state.padMerge = enabled }+ func setJoyconSplit(_ enabled: Bool) {+ guard state.joyconSplit != enabled else { return }+ state.joyconSplit = enabled+ if enabled {+ var next: [ConsoleController] = []+ for c in state.controllers {+ if c.kind == .paired {+ next.append(ConsoleController(id: c.id + ".L", name: "Joy-Con (L)", player: c.player, kind: .gamepad, battery: c.battery, charging: c.charging, canIdentify: c.canIdentify))+ let free = (1...4).first { p in p != c.player && !state.controllers.contains(where: { $0.player == p }) && !next.contains(where: { $0.player == p }) }+ next.append(ConsoleController(id: c.id + ".R", name: "Joy-Con (R)", player: free, kind: .gamepad, battery: c.battery, charging: c.charging, canIdentify: c.canIdentify))+ } else {+ next.append(c)+ }+ }+ state.controllers = next+ } else {+ var next: [ConsoleController] = []+ var skippedR = Set<String>()+ for c in state.controllers {+ if skippedR.contains(c.id) { continue }+ if c.id.hasSuffix(".L") {+ let base = String(c.id.dropLast(2))+ skippedR.insert(base + ".R")+ next.append(ConsoleController(id: base, name: L10n.string("console.demoPaired", lang), player: c.player, kind: .paired, battery: c.battery, charging: c.charging, canIdentify: c.canIdentify))+ } else {+ next.append(c)+ }+ }+ state.controllers = next+ }+ }func dismissToast() { toastTask?.cancel(); state.toast = nil; state.identifyingControllerID = nil }/// A transport event simulated by tests or a preview coordinator, without hardware discovery.func connect(_ controller: ConsoleController) {diff --git a/frontend/Tests/NX2AppleTests/ConsoleLiveTests.swift b/frontend/Tests/NX2AppleTests/ConsoleLiveTests.swiftindex 42c2dd14..8027c24e 100644--- a/frontend/Tests/NX2AppleTests/ConsoleLiveTests.swift+++ b/frontend/Tests/NX2AppleTests/ConsoleLiveTests.swift@@ -213,6 +213,25 @@ import SwiftUIXCTAssertNotNil(driver.state.toast, "a Bluetooth controller cannot be dropped by an app: the toast says where")}+ func testJoyconSplitExpandsPairedJoyConIntoTwoSidewaysPlayers() throws {+ let pads = [ConsolePadSnapshot(id: "jc", name: "Joy-Con (L/R)", category: "Nintendo Switch Joy-Con (L/R)", playerIndex: 1, battery: 0.75, charging: true)]+ let (driver, _, layout) = try makeDriver(pads: pads)+ XCTAssertEqual(driver.state.controllers.map(\.name), ["Joy-Con (L/R)"])+ XCTAssertEqual(driver.state.controllers.map(\.kind), [.paired])+ driver.setJoyconSplit(true)+ XCTAssertTrue(layout.joyconSplit)+ XCTAssertTrue(driver.state.joyconSplit)+ XCTAssertEqual(driver.state.controllers.map(\.id), ["jc.L", "jc.R"])+ XCTAssertEqual(driver.state.controllers.map(\.name), ["Joy-Con (L)", "Joy-Con (R)"])+ XCTAssertEqual(driver.state.controllers.map(\.kind), [.gamepad, .gamepad])+ XCTAssertEqual(driver.state.controllers.map(\.player), [1, 2])+ XCTAssertEqual(driver.state.controllers.map(\.batteryPercent), [75, 75])+ driver.setJoyconSplit(false)+ XCTAssertFalse(layout.joyconSplit)+ XCTAssertEqual(driver.state.controllers.map(\.name), ["Joy-Con (L/R)"])+ XCTAssertEqual(driver.state.controllers.map(\.player), [1])+ }+func testEnteringAndLeavingConsoleModeRestoresTheWindowInOrder() async throws {var calls: [Bool] = []var finishEntering: (() -> Void)?diff --git a/frontend/Tests/NX2AppleTests/ConsolePadTests.swift b/frontend/Tests/NX2AppleTests/ConsolePadTests.swiftindex f007ad06..9eac3d36 100644--- a/frontend/Tests/NX2AppleTests/ConsolePadTests.swift+++ b/frontend/Tests/NX2AppleTests/ConsolePadTests.swift@@ -49,6 +49,14 @@ import NXModelXCTAssertEqual(layout.environment["DM_PAD_MERGE"], "1")layout.padMerge = falseXCTAssertFalse(driver.state.padMerge)+ XCTAssertFalse(driver.state.joyconSplit)+ driver.setJoyconSplit(true)+ XCTAssertTrue(layout.joyconSplit)+ XCTAssertTrue(driver.state.joyconSplit)+ XCTAssertEqual(layout.environment["DM_JOYCON_SPLIT"], "1")+ layout.joyconSplit = false+ XCTAssertFalse(driver.state.joyconSplit)+ XCTAssertNil(layout.environment["DM_JOYCON_SPLIT"])}func testGamepadActionsMapToConsoleInputs() {diff --git a/frontend/Tests/NX2AppleTests/ConsoleTests.swift b/frontend/Tests/NX2AppleTests/ConsoleTests.swiftindex 339917db..fb881c8f 100644--- a/frontend/Tests/NX2AppleTests/ConsoleTests.swift+++ b/frontend/Tests/NX2AppleTests/ConsoleTests.swift@@ -240,10 +240,13 @@ import NXModellet sizes: [(String, CGFloat, CGFloat)] = [("tv", 1920, 1080), ("mac", 1280, 800), ("compact", 390, 844)]for lang in CaptureLanguage.all([.en, .zh]) {for (name, width, height) in sizes {- for screen in ["full", "few", "empty", "controllers", "controllersMixed", "mixedHome", "controllerDesktop", "connectedToast", "starting", "options", "needsBuild", "needsData", "broken", "desktop", "prompt", "homeHint"] {- let driver = MockConsoleDriver(scenario: MockConsoleDriver.Scenario(rawValue: screen) ?? (screen == "mixedHome" || screen == "controllerDesktop" || screen == "connectedToast" ? .controllersMixed : .full), lang: lang, animated: false)+ for screen in ["full", "few", "empty", "controllers", "controllersMixed", "mixedHome", "controllerDesktop", "controllerDesktopSplit", "connectedToast", "starting", "options", "needsBuild", "needsData", "broken", "desktop", "prompt", "homeHint"] {+ let driver = MockConsoleDriver(scenario: MockConsoleDriver.Scenario(rawValue: screen) ?? (screen == "mixedHome" || screen == "controllerDesktop" || screen == "controllerDesktopSplit" || screen == "connectedToast" ? .controllersMixed : .full), lang: lang, animated: false)switch screen {case "mixedHome": driver.back()+ case "controllerDesktopSplit":+ driver.state.controllers = [.init(id: "pad.4", name: L10n.string("console.demoPaired", lang), player: 1, kind: .paired, battery: 0.75, charging: true)]+ driver.setJoyconSplit(true)case "connectedToast": driver.back(); driver.disconnect(controllerID: "pad.2"); driver.connect(.init(id: "pad.2", name: L10n.string("console.demoController", lang), player: 2))case "options": driver.openOptions("demo.0")case "needsBuild": driver.focus("demo.3"); driver.play("demo.3")@@ -254,7 +257,7 @@ import NXModeldefault: break}let view: AnyView- if screen == "controllerDesktop" {+ if screen == "controllerDesktop" || screen == "controllerDesktopSplit" {view = AnyView(ConsoleControllersSheet(driver: driver, lang: lang, close: {}).environmentObject(PadFocus()))} else if screen == "prompt" {view = AnyView(ConsoleConnectionPrompt(lang: lang, enterConsole: {}, dismissPrompt: {}).environmentObject(PadFocus()).preferredColorScheme(.dark))diff --git a/frontend/l10n/de.json b/frontend/l10n/de.jsonindex e4e5d6da..a56df225 100644--- a/frontend/l10n/de.json+++ b/frontend/l10n/de.json@@ -173,6 +173,7 @@"console.iphoneOnly": "Nur iPhone","console.iphoneOnlyNote": "Dieses Spiel ist nur für das iPhone gebaut. Baue es im Desktop-Modus auf der Seite „Builds“ für den Mac und spiele es dann hier.","console.japanese": "Japanisch",+ "console.joyconSplit": "Joy-Con in zwei Controller teilen","console.kind.fullSize": "Großes Pad","console.kind.gamepad": "Gamepad","console.kind.keyboard": "Tastatur",diff --git a/frontend/l10n/en.json b/frontend/l10n/en.jsonindex 882767f0..a2b1eb06 100644--- a/frontend/l10n/en.json+++ b/frontend/l10n/en.json@@ -171,6 +171,7 @@"console.iphoneOnly": "iPhone only","console.iphoneOnlyNote": "This game is built for iPhone only. Build it for Mac on the Builds page in desktop mode, then play it here.","console.japanese": "Japanese",+ "console.joyconSplit": "Split Joy-Con into two controllers","console.kind.fullSize": "Full-size pad","console.kind.gamepad": "Gamepad","console.kind.keyboard": "Keyboard",diff --git a/frontend/l10n/fr.json b/frontend/l10n/fr.jsonindex 4776aaed..bc97f6d6 100644--- a/frontend/l10n/fr.json+++ b/frontend/l10n/fr.json@@ -166,6 +166,7 @@"console.iphoneOnly": "iPhone uniquement","console.iphoneOnlyNote": "Ce jeu est compilé pour iPhone uniquement. Compilez-le pour Mac depuis la page Compilations en mode bureau, puis jouez-y ici.","console.japanese": "Japonais",+ "console.joyconSplit": "Séparer les Joy-Con en deux manettes","console.kind.fullSize": "Manette complète","console.kind.gamepad": "Manette","console.kind.keyboard": "Clavier",diff --git a/frontend/l10n/it.json b/frontend/l10n/it.jsonindex ea4f7eab..1a632fef 100644--- a/frontend/l10n/it.json+++ b/frontend/l10n/it.json@@ -172,6 +172,7 @@"console.iphoneOnly": "Solo iPhone","console.iphoneOnlyNote": "Questo gioco è compilato solo per iPhone. Compilalo per Mac dalla pagina Build in modalità desktop, poi giocalo qui.","console.japanese": "Giapponese",+ "console.joyconSplit": "Dividi i Joy-Con in due controller","console.kind.fullSize": "Controller completo","console.kind.gamepad": "Gamepad","console.kind.keyboard": "Tastiera",diff --git a/frontend/l10n/sv.json b/frontend/l10n/sv.jsonindex e5b30f42..d96db42c 100644--- a/frontend/l10n/sv.json+++ b/frontend/l10n/sv.json@@ -125,6 +125,7 @@"console.homeHint.later": "Inte nu","console.homeHint.open": "Öppna Inställningar","console.homeHint.title": "Avsluta med hemknappen",+ "console.joyconSplit": "Dela Joy-Con i två handkontroller","console.startInConsole": "Starta i konsolläge","console.startInConsoleNote": "Öppnar konsolläget varje gång launchern startar, med eller utan handkontroll. Lämna det från menyn Visa.","controls.applied": "Tillämpas nästa gång du väljer Spela här. Äldre byggen ignorerar det.",diff --git a/frontend/l10n/zh.json b/frontend/l10n/zh.jsonindex 1bb7540f..a7d9ad20 100644--- a/frontend/l10n/zh.json+++ b/frontend/l10n/zh.json@@ -172,6 +172,7 @@"console.iphoneOnly": "仅 iPhone 版","console.iphoneOnlyNote": "这款游戏只构建了 iPhone 版。请在桌面模式的“构建”页面构建 Mac 版,之后就能在这里游玩。","console.japanese": "日语",+ "console.joyconSplit": "将 Joy-Con 拆分为两个手柄","console.kind.fullSize": "全尺寸手柄","console.kind.gamepad": "游戏手柄","console.kind.keyboard": "键盘",diff --git a/patches/0074-mac-split-a-joy-con-pair-into-two-sideways-contr.patch b/patches/0074-mac-split-a-joy-con-pair-into-two-sideways-contr.patchnew file mode 100644index 00000000..3927ff72--- /dev/null+++ b/patches/0074-mac-split-a-joy-con-pair-into-two-sideways-contr.patch@@ -0,0 +1,752 @@+From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001+From: LNPANDY <[email protected]>+Date: Thu, 5 Nov 2026 18:43:24 +0800+Subject: [PATCH] Mac: split a Joy-Con pair into two sideways controllers+ (#740)++When DM_JOYCON_SPLIT=1 is set on macOS, front_mac.m skips GameController's combined Joy-Con input and reads Joy-Con (L) (0x057e:0x2006) and Joy-Con (R) (0x057e:0x2007) directly over IOHIDManager 0x30 reports so each half gets its own player slot with a 90-degree sideways stick and 6-axis IMU rotation, SL/SR mapped to L/R, and per-handle Core Haptics rumble (GCHapticsLocalityLeftHandle and GCHapticsLocalityRightHandle).++Upstream-Status: forwarded seedds/nxnative#1322+Reason: Mac: split a Joy-Con pair into two sideways controllers over HID 0x30 with motion and rumble+Issue: LNPANDY/NX2Apple#740+---+ dm/host/Makefile | 2 +-+ dm/host/front_mac.m | 85 +++++++++++--+ dm/host/haptics_apple.h | 1 ++ dm/host/haptics_apple.m | 33 +++--+ dm/host/pad_joycon.h | 139 ++++++++++++++++++++++ dm/host/pad_joycon_mac.h | 115 ++++++++++++++++++ dm/host/tests/Makefile | 2 +-+ dm/host/tests/t_haptics_apple.m | 14 ++++ dm/host/tests/t_pad_hid.c | 88 ++++++++++++++ dm/ios/tests/duo/Sources/DuoRuntimeStubs.m | 1 ++ docs/env_switches.tsv | 1 ++ 11 files changed, 464 insertions(+), 17 deletions(-)+ create mode 100644 dm/host/pad_joycon.h+ create mode 100644 dm/host/pad_joycon_mac.h++diff --git a/dm/host/Makefile b/dm/host/Makefile+index 8b66f0b..2100b89 100644+--- a/dm/host/Makefile++++ b/dm/host/Makefile+@@ -76,7 +76,7 @@ endif+ endif+ .PHONY: FORCE+ FORCE:+-dmhost: $(SRC) $(GFX) ../third_party/stb_vorbis/stb_vorbis.c dm.h hle.h romfs_image.h save_sync.h dm_input.h pad_slots.h hle_haptics.h haptics_apple.h motion_fusion.h motion_apple.h motion_pro.h motion_pro_mac.h pad_apple.h pad_hid.h pad_hid_mac.h home_quit.h home_quit_mac.h front.h $(GFX_H) $(GAME_H) $(GAME_STAMP) $(VPX_LIB) $(DAV1D_LIB) $(MSL_H)++dmhost: $(SRC) $(GFX) ../third_party/stb_vorbis/stb_vorbis.c dm.h hle.h romfs_image.h save_sync.h dm_input.h pad_slots.h hle_haptics.h haptics_apple.h motion_fusion.h motion_apple.h motion_pro.h motion_pro_mac.h pad_apple.h pad_hid.h pad_hid_mac.h pad_joycon.h pad_joycon_mac.h home_quit.h home_quit_mac.h front.h $(GFX_H) $(GAME_H) $(GAME_STAMP) $(VPX_LIB) $(DAV1D_LIB) $(MSL_H)+ clang $(CFLAGS) -I../gfx/nvn/include -I$(dir $(MSL_H)) -I../third_party/vulkan-headers/include -I$(dir $(GAME_H)) -I$(VPX) -I$(DAV1D)/include -I../third_party/stb_vorbis -fobjc-arc -o $@ $(SRC) $(GFX) $(VPX_LIB) $(DAV1D_LIB) -framework Cocoa -framework WebKit -framework UserNotifications -framework QuartzCore -framework Metal -framework MetalFX -framework GameController -framework CoreHaptics -framework IOKit -framework AudioToolbox -framework VideoToolbox -framework CoreMedia -framework CoreVideo -framework ImageIO -framework UniformTypeIdentifiers+ clean: # the host and everything make generates for it (gen/: the profile headers, the game stamp and the libvpx and dav1d builds; dmhost_* and *.dSYM beside them, as in .gitignore)+ rm -rf gen dmhost dmhost_* *.dSYM+diff --git a/dm/host/front_mac.m b/dm/host/front_mac.m+index 892df56..1d5f680 100644+--- a/dm/host/front_mac.m++++ b/dm/host/front_mac.m+@@ -25,6 +25,7 @@+ #include "motion_pro_mac.h"+ #include "pad_apple.h"+ #include "pad_hid_mac.h"++#include "pad_joycon_mac.h"+ #include "home_quit.h"+ #include "home_quit_mac.h"+ #include <signal.h>+@@ -200,28 +201,43 @@ static void pro_players_changed(GCController *gone) {+ dm_motion_pro_players(count, player);+ }+ static void pro_devices_changed(void) { pro_players_changed(nil); }+-// DM_PAD_MERGE: whether a controller still plays player 1 (gone: one just removed, not counted), a GameController one or a raw HID pad (pad_hid_mac.h)++static int gc_pad_used(GCController *c) {++ return c && c.extendedGamepad && !(g_joycon_split && joycon_is_gc_controller(c));++}++static void joycon_haptics_sync(GCController *gone) {++ if (!g_joycon_split) return;++ GCController *jc = nil;++ for (GCController *c in GCController.controllers) if (c != gone && joycon_is_gc_controller(c) && c.haptics) { jc = c; break; }++ if (g_merge) { if (g_joycons && jc) dm_haptics_apple_controller(0, jc); return; }++ for (joycon_pad *d = g_joycons; d; d = d->next) {++ int p = pad_slot_of(&g_slots, d); if (p < 0) continue;++ GCHapticsLocality loc = d->st.pid == JOYCON_PID_L ? GCHapticsLocalityLeftHandle : GCHapticsLocalityRightHandle;++ dm_haptics_apple_controller_locality(p, jc, loc);++ }++}++// DM_PAD_MERGE: whether a controller still plays player 1 (gone: one just removed, not counted), a GameController one or a raw HID pad (pad_hid_mac.h, pad_joycon_mac.h)+ static int merge_pads_left(GCController *gone) {+- if (g_hidpads) return 1;+- for (GCController *c in GCController.controllers) if (c.extendedGamepad && c != gone) return 1;++ if (g_hidpads || g_joycons) return 1;++ for (GCController *c in GCController.controllers) if (gc_pad_used(c) && c != gone) return 1;+ return 0;+ }+ // Called at start and on every connect / disconnect (gone: the controller that was just removed, nil on a connect)+ static void pads_changed(GCController *gone) {+ if (g_merge) {+ int any = 0;+- for (GCController *c in GCController.controllers) if (c.extendedGamepad && c != gone) {++ for (GCController *c in GCController.controllers) if (gc_pad_used(c) && c != gone) {+ any = 1; pad_keep_system_buttons(c); c.extendedGamepad.valueChangedHandler = ^(GCExtendedGamepad *g, GCControllerElement *el) { (void)el; pad_read(g); };+ dm_motion_attach(c, 0); // every controller is player 1: the last one moved drives its six-axis sensor+ pad_read(c.extendedGamepad);+ }+ if (gone) dm_motion_detach(gone, 0);+- if (!any) { if (!g_hidpads) dm_pad_set(0, 0, 0, 0, 0); dm_haptics_apple_controller(0, nil); } // a raw HID pad still plays player 1 (pad_hid_mac.h)++ if (!any) { if (!g_hidpads && !g_joycons) dm_pad_set(0, 0, 0, 0, 0); if (!g_joycons) dm_haptics_apple_controller(0, nil); } // a raw HID pad still plays player 1 (pad_hid_mac.h)++ joycon_haptics_sync(gone);+ pro_players_changed(gone);+ return;+ }+ NSArray<GCController *> *now = GCController.controllers; char nb[16];+- for (int p = 0; p < DM_PLAYERS; p++) if (g_held[p] && (g_held[p] == gone || ![now containsObject:g_held[p]])) {++ for (int p = 0; p < DM_PLAYERS; p++) if (g_held[p] && (g_held[p] == gone || ![now containsObject:g_held[p]] || !gc_pad_used(g_held[p]))) {+ npad_name(p, nb, sizeof nb); LOG("controller '%s' disconnected: player %d (npad %s) is free", pad_name(g_held[p]), p + 1, nb);+ g_held[p].extendedGamepad.valueChangedHandler = nil;+ dm_motion_detach(g_held[p], p);+@@ -229,7 +245,7 @@ static void pads_changed(GCController *gone) {+ pad_slot_free(&g_slots, (__bridge const void *)g_held[p]); g_held[p] = nil;+ dm_pad_set_player(p, 0, 0, 0, 0, 0); // nothing stays pressed+ }+- for (GCController *c in now) if (c.extendedGamepad && c != gone && pad_slot_of(&g_slots, (__bridge const void *)c) < 0) {++ for (GCController *c in now) if (gc_pad_used(c) && c != gone && pad_slot_of(&g_slots, (__bridge const void *)c) < 0) {+ int p = pad_slot_take(&g_slots, (__bridge const void *)c, pad_name(c));+ if (p < 0) { LOG("controller '%s' connected: all %d players are taken, not used", pad_name(c), DM_PLAYERS); continue; }+ g_held[p] = c; pad_keep_system_buttons(c);+@@ -239,6 +255,7 @@ static void pads_changed(GCController *gone) {+ pad_read(c.extendedGamepad);+ }+ dm_pad_players(pad_slot_mask(&g_slots));++ joycon_haptics_sync(gone);+ pro_players_changed(gone);+ }+ // Display sleep: macOS counts keyboard and mouse input as user activity, not a controller's, so in controller-only play the display dims and locks; the latency+@@ -259,12 +276,14 @@ static void pads_release(void) {+ if (g_merge) { if (merge_pads_left(nil)) dm_pad_set(0, 0, 0, 0, 0); return; }+ for (int p = 0; p < DM_PLAYERS; p++) if (g_held[p]) dm_pad_set_player(p, 0, 0, 0, 0, 0);+ for (hid_pad *d = g_hidpads; d; d = d->next) { int p = pad_slot_of(&g_slots, d); if (p >= 0) dm_pad_set_player(p, 0, 0, 0, 0, 0); }++ for (joycon_pad *d = g_joycons; d; d = d->next) { int p = pad_slot_of(&g_slots, d); if (p >= 0) dm_pad_set_player(p, 0, 0, 0, 0, 0); }+ }+ // Each controller read as it is now (focus back, the Home quit prompt closed)+ static void pads_reread(void) {+- if (g_merge) { for (GCController *c in GCController.controllers) if (c.extendedGamepad) pad_read(c.extendedGamepad); }++ if (g_merge) { for (GCController *c in GCController.controllers) if (gc_pad_used(c)) pad_read(c.extendedGamepad); }+ else for (int p = 0; p < DM_PLAYERS; p++) if (g_held[p].extendedGamepad) pad_read(g_held[p].extendedGamepad);+ for (hid_pad *d = g_hidpads; d; d = d->next) hidpad_read(d);++ for (joycon_pad *d = g_joycons; d; d = d->next) joycon_read(d);+ }+ static void hq_close(void);+ static void input_release(void) {+@@ -273,6 +292,11 @@ static void input_release(void) {+ display_awake(0);+ g_input_on = 0;+ dm_motion_pro_active(0);++ for (joycon_pad *d = g_joycons; d; d = d->next) {++ d->motion = (pro_motion){0};++ int p = g_merge ? 0 : pad_slot_of(&g_slots, d);++ if (p >= 0) dm_motion_clear_hid(p);++ }+ g_btn = 0; g_held_fn = 0; memset(g_shift_fn, 0, sizeof g_shift_fn); push();+ if (g_mouse_down) { g_mouse_down = 0; dm_touch_set(NULL, 0); }+ pads_release();+@@ -308,6 +332,43 @@ static void hidpad_detach(hid_pad *d) { // d is already off g_hidpads+ dm_pad_set_player(p, 0, 0, 0, 0, 0); // nothing stays pressed+ dm_pad_players(pad_slot_mask(&g_slots));+ }++// Split Joy-Con sideways controllers (pad_joycon_mac.h, DM_JOYCON_SPLIT=1): each half takes a player slot of its own++static void joycon_read(joycon_pad *d) {++ if (!g_input_on || hq_blocks_input(g_hq.phase)) return;++ int p = g_merge ? 0 : pad_slot_of(&g_slots, d); if (p < 0) return;++ pad_set(p, d->st.buttons, pad_axis(d->st.sx), pad_axis(d->st.sy), 0, 0);++}++static void joycon_read_motion(joycon_pad *d, const uint8_t *rep, size_t len) {++ if (!g_input_on || hq_blocks_input(g_hq.phase)) return;++ const char *e = getenv("DM_MOTION"); if (e && !atoi(e)) return;++ int p = g_merge ? 0 : pad_slot_of(&g_slots, d); if (p < 0) return;++ pro_motion_sample samples[3];++ int n = joycon_motion_decode(&d->motion, d->st.pid, rep, len, now_ns(), samples);++ for (int i = 0; i < n; i++) dm_motion_set_hid(p, samples[i].acc, samples[i].rot, samples[i].ns);++}++static void joycon_attach(joycon_pad *d) {++ int p = g_merge ? 0 : pad_slot_take(&g_slots, d, d->name); char nb[16];++ if (p < 0) { LOG("controller '%s' (split Joy-Con) connected: all %d players are taken, not used", d->name, DM_PLAYERS); return; }++ npad_name(p, nb, sizeof nb); LOG("controller '%s' (split Joy-Con) connected: player %d (npad %s), with motion (gyro) and rumble", d->name, p + 1, nb);++ if (!g_merge) dm_pad_players(pad_slot_mask(&g_slots));++ joycon_haptics_sync(nil);++ joycon_read(d);++}++static void joycon_detach(joycon_pad *d) {++ if (g_merge) {++ LOG("controller '%s' (split Joy-Con) disconnected", d->name);++ if (!g_joycons) { dm_motion_clear_hid(0); dm_haptics_apple_controller(0, nil); }++ if (!merge_pads_left(nil)) dm_pad_set(0, 0, 0, 0, 0);++ return;++ }++ int p = pad_slot_free(&g_slots, d); char nb[16]; if (p < 0) return;++ npad_name(p, nb, sizeof nb); LOG("controller '%s' (split Joy-Con) disconnected: player %d (npad %s) is free", d->name, p + 1, nb);++ dm_motion_clear_hid(p);++ dm_haptics_apple_controller(p, nil);++ dm_pad_set_player(p, 0, 0, 0, 0, 0);++ dm_pad_players(pad_slot_mask(&g_slots));++}++static void joycon_home_changed(void) { if (g_input_on) hq_poll(); }+ // Quit with the Home button (home_quit.h, LNPANDY/NX2Apple#336): held for 2 s it opens the prompt (home_quit_mac.h) over the game's view, A quits through the same path as ⌘Q+ // (NSApp terminate, so the save writer and the other exit handlers run as there), B or Home closes it. While the prompt is open the game is told it lost the focus, as the+ // Switch's HOME menu does, and gets no controller input or touch; the keyboard and ⌘Q work as always. DM_HOME_QUIT=0 turns it off+@@ -342,10 +403,16 @@ static void hq_log_setting(void) {+ static void hq_buttons(int *home, int *a, int *b, GCController **holder) {+ *home = *a = *b = 0;+ for (GCController *c in GCController.controllers) {++ if (!gc_pad_used(c)) continue;+ GCExtendedGamepad *g = c.extendedGamepad; if (!g) continue;+ if (g.buttonHome.isPressed) { *home = 1; if (!*holder) *holder = c; }+ *a |= g.buttonA.isPressed; *b |= g.buttonB.isPressed;+ }++ for (joycon_pad *d = g_joycons; d; d = d->next) {++ if (d->st.home) *home = 1;++ if (d->st.buttons & DM_BTN_A) *a = 1;++ if (d->st.buttons & DM_BTN_B) *b = 1;++ }+ }+ static void hq_fade(NSView *v, int in) {+ if (!v) return;+@@ -417,6 +484,7 @@ static void pads_start(void) {+ LOG("front end: %s", g_merge ? "every controller is player 1 (DM_PAD_MERGE)" : g_kbd_own ? "the keyboard is player 1, each controller a player of its own from player 2 on (DM_KBD_PLAYER=own)"+ : "each controller is a player of its own, the keyboard plays with player 1");+ hq_start();++ joycon_start();+ pads_changed(nil);+ hq_log_setting();+ dm_motion_pro_start(pro_devices_changed);+@@ -1432,6 +1500,7 @@ void front_run(void (*guest)(void)) {+ for (NSNotificationName nm in @[GCControllerDidConnectNotification, GCControllerDidDisconnectNotification])+ [NSNotificationCenter.defaultCenter addObserverForName:nm object:nil queue:NSOperationQueue.mainQueue usingBlock:^(NSNotification *n) {+ GCController *c = n.object; int conn = n.name == GCControllerDidConnectNotification;++ if (g_joycon_split && joycon_is_gc_controller(c)) return;+ if (!c.extendedGamepad || g_merge) LOG("controller %s: %s%s", conn ? "connected" : "disconnected", pad_name(c), c.extendedGamepad ? "" : " (no extended gamepad profile: not used)");+ pads_changed(conn ? nil : c);+ if (conn) hq_log_setting(); }];+diff --git a/dm/host/haptics_apple.h b/dm/host/haptics_apple.h+index 2fd1b0f..d8ce98f 100644+--- a/dm/host/haptics_apple.h++++ b/dm/host/haptics_apple.h+@@ -4,4 +4,5 @@+ #include "hle_haptics.h"+ void dm_haptics_apple_init(void);+ void dm_haptics_apple_controller(int player, GCController *controller);++void dm_haptics_apple_controller_locality(int player, GCController *controller, GCHapticsLocality locality);+ void dm_haptics_apple_shutdown(void);+diff --git a/dm/host/haptics_apple.m b/dm/host/haptics_apple.m+index ba849d0..ca0414f 100644+--- a/dm/host/haptics_apple.m++++ b/dm/host/haptics_apple.m+@@ -39,6 +39,7 @@ - (void)stop;+ static dispatch_queue_t queue;+ static NSMutableArray<DmRumbleChannel *> *channels[DM_PLAYERS];+ static GCController *controllers[DM_PLAYERS];++static GCHapticsLocality controllerLocalities[DM_PLAYERS];+ #if TARGET_OS_IPHONE+ static BOOL phoneSupported;+ #endif+@@ -330,17 +331,30 @@ static void default_controller(int p, GCDeviceHaptics *h, NSTimeInterval retryAf+ add_engine(p, -1, @"controller default", ^CHHapticEngine *(NSError **e) { (void)e; return [h createEngineWithLocality:GCHapticsLocalityDefault]; });+ channels[p].lastObject.retryAfter = retryAfter;+ }+-static void configure(int p, GCController *controller) {++static void configure(int p, GCController *controller, GCHapticsLocality locality) {+ for (DmRumbleChannel *c in channels[p]) [c stop];+ channels[p] = [NSMutableArray new];+ #if !TARGET_OS_IPHONE+ ds4_release(p);+- if (controller && ds4_route(p, controller)) { dm_haptics_route(p, 1); return; } // the report first, as SDL drives it++ if (controller && !locality && ds4_route(p, controller)) { dm_haptics_route(p, 1); return; } // the report first, as SDL drives it+ #endif+ if (controller) {+ GCDeviceHaptics *h = controller.haptics;+ NSSet *localities = h.supportedLocalities;+- if ([localities containsObject:GCHapticsLocalityLeftHandle] && [localities containsObject:GCHapticsLocalityRightHandle]) {++ if (locality && [localities containsObject:locality]) {++ NSString *label = [locality isEqualToString:GCHapticsLocalityLeftHandle] ? @"controller left handle" :++ ([locality isEqualToString:GCHapticsLocalityRightHandle] ? @"controller right handle" : @"controller handle");++ add_engine(p, -1, label, ^CHHapticEngine *(NSError **e) { (void)e; return [h createEngineWithLocality:locality]; });++ __weak NSArray *route = channels[p];++ for (DmRumbleChannel *c in channels[p]) c.fallback = ^(NSTimeInterval retryAfter) {++ if (!route || channels[p] != route) return;++ for (DmRumbleChannel *old in channels[p]) [old stop];++ channels[p] = [NSMutableArray new];++ default_controller(p, h, retryAfter);++ dm_haptics_route(p, 1);++ fprintf(stderr, "haptics: player %d retrying with the default controller locality\n", p + 1);++ };++ } else if ([localities containsObject:GCHapticsLocalityLeftHandle] && [localities containsObject:GCHapticsLocalityRightHandle]) {+ add_engine(p, 0, @"controller left handle", ^CHHapticEngine *(NSError **e) { (void)e; return [h createEngineWithLocality:GCHapticsLocalityLeftHandle]; });+ add_engine(p, 1, @"controller right handle", ^CHHapticEngine *(NSError **e) { (void)e; return [h createEngineWithLocality:GCHapticsLocalityRightHandle]; });+ // Advertised handle localities can still fail to start. Fall back to the standard+@@ -378,16 +392,21 @@ static void configure(int p, GCController *controller) {+ #endif+ dm_haptics_route(p, channels[p].count != 0);+ }+-void dm_haptics_apple_controller(int p, GCController *controller) {++void dm_haptics_apple_controller_locality(int p, GCController *controller, GCHapticsLocality locality) {+ if (!queue || p < 0 || p >= DM_PLAYERS) return;+ pthread_mutex_lock(&routeLock);+- if (controllers[p] != controller) {++ BOOL sameLoc = (controllerLocalities[p] == locality) || (locality && [controllerLocalities[p] isEqualToString:locality]);++ if (controllers[p] != controller || !sameLoc) {+ controllers[p] = controller;++ controllerLocalities[p] = locality;+ dm_haptics_route(p, 0); // invalidate queued work before changing hardware+- dispatch_sync(queue, ^{ configure(p, controller); });++ dispatch_sync(queue, ^{ configure(p, controller, locality); });+ }+ pthread_mutex_unlock(&routeLock);+ }++void dm_haptics_apple_controller(int p, GCController *controller) {++ dm_haptics_apple_controller_locality(p, controller, nil);++}+ static void suspend(unsigned reason, BOOL on) {+ dm_haptics_suspend(reason, on);+ void (^stop)(void) = ^{+@@ -412,7 +431,7 @@ void dm_haptics_apple_init(void) {+ #if TARGET_OS_IPHONE+ phoneSupported = CHHapticEngine.capabilitiesForHardware.supportsHaptics;+ #endif+- dispatch_sync(queue, ^{ configure(0, nil); });++ dispatch_sync(queue, ^{ configure(0, nil, nil); });+ NSNotificationCenter *nc = NSNotificationCenter.defaultCenter;+ #if TARGET_OS_IPHONE+ [nc addObserverForName:UIApplicationWillResignActiveNotification object:nil queue:nil usingBlock:^(NSNotification *n) { (void)n; suspend(DM_HAPTICS_INACTIVE, YES); }];+diff --git a/dm/host/pad_joycon.h b/dm/host/pad_joycon.h+new file mode 100644+index 0000000..18a2f0d+--- /dev/null++++ b/dm/host/pad_joycon.h+@@ -0,0 +1,139 @@++#pragma once++#include <math.h>++#include <stddef.h>++#include <stdint.h>++#include <string.h>++#include "dm_input.h"++#include "motion_pro.h"++++// Nintendo Switch Joy-Con sideways decoder (DM_JOYCON_SPLIT=1, LNPANDY/NX2Apple#740):++// macOS switches Bluetooth Joy-Con (L) (0x057e:0x2006) and Joy-Con (R) (0x057e:0x2007) to standard++// 0x30 49-byte input reports at 60 Hz, while GCController merges the pair into one controller and++// drops the rail SL and SR buttons. Each half here becomes one horizontal sideways controller with++// its stick rotated 90 degrees and its rail SL and SR mapped to L and R.++++#define JOYCON_VID 0x057e++#define JOYCON_PID_L 0x2006++#define JOYCON_PID_R 0x2007++#define JOYCON_REPORT_0x30 0x30++#define JOYCON_REPORT_MIN_LEN 12++#define JOYCON_STICK_CENTER 2048++#define JOYCON_STICK_RADIUS 1400.0f++#define JOYCON_STICK_DZ 0.12f++++typedef struct {++ uint16_t pid;++ int calibrated;++ int cx, cy;++ uint64_t buttons;++ float sx, sy;++ int home;++ int battery; // 0..4 from the upper nibble of byte 2 (4=full, 3=75%, 2=50%, 1=25%, 0=empty)++ int charging; // 1 when bit 4 of byte 2 is set++} joycon_state;++++static inline int joycon_is_pid(long vid, long pid) {++ return vid == JOYCON_VID && (pid == JOYCON_PID_L || pid == JOYCON_PID_R);++}++++static inline void joycon_init(joycon_state *s, uint16_t pid) {++ if (!s) return;++ memset(s, 0, sizeof *s);++ s->pid = pid;++ s->cx = JOYCON_STICK_CENTER;++ s->cy = JOYCON_STICK_CENTER;++}++++static inline void joycon_stick_scale(float x, float y, float *ox, float *oy) {++ float m = sqrtf(x * x + y * y);++ if (m <= JOYCON_STICK_DZ) { *ox = 0.0f; *oy = 0.0f; return; }++ float k = (m - JOYCON_STICK_DZ) / ((1.0f - JOYCON_STICK_DZ) * m);++ float sx = x * k, sy = y * k;++ *ox = sx < -1.0f ? -1.0f : (sx > 1.0f ? 1.0f : sx);++ *oy = sy < -1.0f ? -1.0f : (sy > 1.0f ? 1.0f : sy);++}++++static inline int joycon_decode_0x30(joycon_state *s, const uint8_t *r, size_t n) {++ if (!s || !r || n < JOYCON_REPORT_MIN_LEN || r[0] != JOYCON_REPORT_0x30) return 0;++ if (s->pid != JOYCON_PID_L && s->pid != JOYCON_PID_R) return 0;++++ s->charging = (r[2] >> 4) & 1;++ s->battery = (r[2] >> 5) & 7;++++ uint64_t b = 0;++ int rx = 0, ry = 0;++ if (s->pid == JOYCON_PID_L) {++ // Left Joy-Con held sideways (rotated 90 degrees counter-clockwise, rail on top):++ // Down->A (right), Left->B (bottom), Right->X (top), Up->Y (left), SL->L, SR->R++ uint8_t lb = r[5], sh = r[4];++ if (lb & 0x01) b |= DM_BTN_A;++ if (lb & 0x08) b |= DM_BTN_B;++ if (lb & 0x04) b |= DM_BTN_X;++ if (lb & 0x02) b |= DM_BTN_Y;++ if (lb & 0x20) b |= DM_BTN_L;++ if (lb & 0x10) b |= DM_BTN_R;++ if (lb & 0x40) b |= DM_BTN_ZL;++ if (lb & 0x80) b |= DM_BTN_ZR;++ if (sh & 0x01) b |= DM_BTN_PLUS;++ if (sh & 0x20) b |= DM_BTN_MINUS;++ if (sh & 0x08) b |= DM_BTN_LS;++ s->home = 0;++ rx = (int)r[6] | (((int)(r[7] & 0x0f)) << 8);++ ry = ((int)(r[7] >> 4)) | (((int)r[8]) << 4);++ } else {++ // Right Joy-Con held sideways (rotated 90 degrees clockwise, rail on top):++ // X->A (right), A->B (bottom), Y->X (top), B->Y (left), SL->L, SR->R++ uint8_t rb = r[3], sh = r[4];++ if (rb & 0x02) b |= DM_BTN_A;++ if (rb & 0x08) b |= DM_BTN_B;++ if (rb & 0x01) b |= DM_BTN_X;++ if (rb & 0x04) b |= DM_BTN_Y;++ if (rb & 0x20) b |= DM_BTN_L;++ if (rb & 0x10) b |= DM_BTN_R;++ if (rb & 0x40) b |= DM_BTN_ZL;++ if (rb & 0x80) b |= DM_BTN_ZR;++ if (sh & 0x02) b |= DM_BTN_PLUS;++ if (sh & 0x04) b |= DM_BTN_LS;++ s->home = (sh & 0x10) != 0;++ rx = (int)r[9] | (((int)(r[10] & 0x0f)) << 8);++ ry = ((int)(r[10] >> 4)) | (((int)r[11]) << 4);++ }++ s->buttons = b;++++ if (rx == 0 && ry == 0) {++ s->sx = 0.0f;++ s->sy = 0.0f;++ return 1;++ }++ if (!s->calibrated && rx >= 1650 && rx <= 2450 && ry >= 1650 && ry <= 2450) {++ s->cx = rx;++ s->cy = ry;++ s->calibrated = 1;++ }++ float dx = (float)(rx - s->cx) / JOYCON_STICK_RADIUS;++ float dy = (float)(ry - s->cy) / JOYCON_STICK_RADIUS;++ float rot_x = (s->pid == JOYCON_PID_L) ? -dy : dy;++ float rot_y = (s->pid == JOYCON_PID_L) ? dx : -dx;++ joycon_stick_scale(rot_x, rot_y, &s->sx, &s->sy);++ return 1;++}++++static inline int joycon_motion_decode(pro_motion *s, uint16_t pid, const uint8_t *r, size_t len, uint64_t now, pro_motion_sample out[3]) {++ if (pid != JOYCON_PID_L && pid != JOYCON_PID_R) return 0;++ int n = pro_motion_decode(s, r, len, now, out);++ for (int i = 0; i < n; i++) {++ float ax = out[i].acc[0], ay = out[i].acc[1], az = out[i].acc[2];++ float gx = out[i].rot[0], gy = out[i].rot[1], gz = out[i].rot[2];++ if (pid == JOYCON_PID_L) {++ // Left Joy-Con rotated 90 degrees counter-clockwise (rail on top)++ out[i].acc[0] = -ay; out[i].acc[1] = ax; out[i].acc[2] = az;++ out[i].rot[0] = -gy; out[i].rot[1] = gx; out[i].rot[2] = gz;++ } else {++ // Right Joy-Con IMU sensor is mounted flipped 180 degrees around X (raw Y and Z inverted++ // relative to Left/Pro, see Linux hid-nintendo.c), then rotated 90 degrees clockwise++ out[i].acc[0] = ay; out[i].acc[1] = ax; out[i].acc[2] = -az;++ out[i].rot[0] = gy; out[i].rot[1] = gx; out[i].rot[2] = -gz;++ }++ }++ return n;++}+diff --git a/dm/host/pad_joycon_mac.h b/dm/host/pad_joycon_mac.h+new file mode 100644+index 0000000..a995be7+--- /dev/null++++ b/dm/host/pad_joycon_mac.h+@@ -0,0 +1,115 @@++// Mac: split a Bluetooth Joy-Con pair into two sideways controllers (pad_joycon.h, LNPANDY/NX2Apple#740).++// When DM_JOYCON_SPLIT=1 is set, front_mac.m skips GameController's combined Joy-Con entry and reads Joy-Con (L) (0x057e:0x2006)++// and Joy-Con (R) (0x057e:0x2007) directly with IOHIDManager so each half gets its own player slot.++#pragma once++#import <IOKit/hid/IOHIDManager.h>++#import <GameController/GameController.h>++#import <GameController/GCSyntheticDeviceKeys.h>++#include "pad_joycon.h"++#include <stdio.h>++#include <stdlib.h>++++typedef struct joycon_pad {++ IOHIDDeviceRef hid;++ joycon_state st;++ pro_motion motion;++ char name[64];++ uint8_t rep[128];++ struct joycon_pad *next;++} joycon_pad;++++static IOHIDManagerRef g_joycon_manager;++static joycon_pad *g_joycons;++static int g_joycon_split;++static void joycon_attach(joycon_pad *d);++static void joycon_detach(joycon_pad *d);++static void joycon_read(joycon_pad *d);++static void joycon_read_motion(joycon_pad *d, const uint8_t *rep, size_t len);++static void joycon_home_changed(void);++++static int joycon_is_gc_controller(GCController *c) {++ if (!c) return 0;++ NSString *cat = c.productCategory ?: @"";++ NSString *ven = c.vendorName ?: @"";++ return [cat rangeOfString:@"Joy-Con" options:NSCaseInsensitiveSearch].location != NSNotFound++ || [cat rangeOfString:@"JoyCon" options:NSCaseInsensitiveSearch].location != NSNotFound++ || [ven rangeOfString:@"Joy-Con" options:NSCaseInsensitiveSearch].location != NSNotFound++ || [ven rangeOfString:@"JoyCon" options:NSCaseInsensitiveSearch].location != NSNotFound;++}++++static void joycon_report(void *ctx, IOReturn result, void *sender, IOHIDReportType type, uint32_t id, uint8_t *rep, CFIndex len) {++ (void)sender; (void)type; (void)id;++ joycon_pad *d = ctx;++ if (result != kIOReturnSuccess || !d || len <= 0) return;++ int was_home = d->st.home;++ if (!joycon_decode_0x30(&d->st, rep, (size_t)len)) return;++ joycon_read(d);++ joycon_read_motion(d, rep, (size_t)len);++ if (d->st.home != was_home) joycon_home_changed();++}++++static void joycon_found(void *ctx, IOReturn result, void *sender, IOHIDDeviceRef hid) {++ (void)ctx; (void)sender;++ if (!g_joycon_split || result != kIOReturnSuccess || IOHIDDeviceGetProperty(hid, CFSTR(kIOHIDGCSyntheticDeviceKey)) == kCFBooleanTrue) return;++ for (joycon_pad *d = g_joycons; d; d = d->next) if (d->hid == hid) return;++ NSNumber *vendor = (__bridge NSNumber *)IOHIDDeviceGetProperty(hid, CFSTR(kIOHIDVendorIDKey));++ NSNumber *product = (__bridge NSNumber *)IOHIDDeviceGetProperty(hid, CFSTR(kIOHIDProductIDKey));++ long vid = vendor.longValue, pid = product.longValue;++ if (!joycon_is_pid(vid, pid)) return;++ joycon_pad *d = calloc(1, sizeof *d);++ if (!d) { LOG("[RED] Split Joy-Con: cannot allocate device state"); return; }++ joycon_init(&d->st, (uint16_t)pid);++ snprintf(d->name, sizeof d->name, "%s", pid == JOYCON_PID_L ? "Joy-Con (L)" : "Joy-Con (R)");++ d->hid = (IOHIDDeviceRef)CFRetain(hid);++ joycon_pad **link = &g_joycons;++ while (*link) link = &(*link)->next;++ *link = d;++ IOHIDDeviceRegisterInputReportCallback(hid, d->rep, sizeof d->rep, joycon_report, d);++ joycon_attach(d);++}++++static void joycon_removed(void *ctx, IOReturn result, void *sender, IOHIDDeviceRef hid) {++ (void)ctx; (void)result; (void)sender;++ joycon_pad **link = &g_joycons;++ while (*link && (*link)->hid != hid) link = &(*link)->next;++ if (!*link) return;++ joycon_pad *d = *link;++ *link = d->next;++ IOHIDDeviceRegisterInputReportCallback(hid, d->rep, 0, NULL, NULL);++ joycon_detach(d);++ CFRelease(d->hid);++ free(d);++}++++static void joycon_start(void) {++ const char *e = getenv("DM_JOYCON_SPLIT");++ g_joycon_split = e && atoi(e);++ if (!g_joycon_split || g_joycon_manager) return;++ g_joycon_manager = IOHIDManagerCreate(kCFAllocatorDefault, kIOHIDOptionsTypeNone);++ if (!g_joycon_manager) return;++ IOHIDManagerSetDeviceMatchingMultiple(g_joycon_manager, (__bridge CFArrayRef)@[++ @{@kIOHIDVendorIDKey: @(JOYCON_VID), @kIOHIDProductIDKey: @(JOYCON_PID_L)},++ @{@kIOHIDVendorIDKey: @(JOYCON_VID), @kIOHIDProductIDKey: @(JOYCON_PID_R)}]);++ IOHIDManagerRegisterDeviceMatchingCallback(g_joycon_manager, joycon_found, NULL);++ IOHIDManagerRegisterDeviceRemovalCallback(g_joycon_manager, joycon_removed, NULL);++ IOHIDManagerScheduleWithRunLoop(g_joycon_manager, CFRunLoopGetMain(), kCFRunLoopCommonModes);++ IOReturn r = IOHIDManagerOpen(g_joycon_manager, kIOHIDOptionsTypeNone);++ if (r != kIOReturnSuccess) {++ LOG("[RED] Split Joy-Con: cannot open HID (0x%x), keeping GameController's combined pair", r);++ IOHIDManagerUnscheduleFromRunLoop(g_joycon_manager, CFRunLoopGetMain(), kCFRunLoopCommonModes);++ CFRelease(g_joycon_manager);++ g_joycon_manager = NULL;++ g_joycon_split = 0;++ return;++ }++ // Attach Joy-Con (L) before Joy-Con (R) when both are already connected at launch so (L) gets Player 1 and (R) gets Player 2.++ NSSet *devs = CFBridgingRelease(IOHIDManagerCopyDevices(g_joycon_manager));++ const int order[2] = {JOYCON_PID_L, JOYCON_PID_R};++ for (int i = 0; i < 2; i++) {++ for (id obj in devs) {++ IOHIDDeviceRef hid = (__bridge IOHIDDeviceRef)obj;++ NSNumber *pid = (__bridge NSNumber *)IOHIDDeviceGetProperty(hid, CFSTR(kIOHIDProductIDKey));++ if (pid.intValue == order[i]) joycon_found(NULL, kIOReturnSuccess, NULL, hid);++ }++ }++}+diff --git a/dm/host/tests/Makefile b/dm/host/tests/Makefile+index aee5576..0941fff 100644+--- a/dm/host/tests/Makefile++++ b/dm/host/tests/Makefile+@@ -350,7 +350,7 @@ tsan-threads-run: $(addprefix $(B)/,$(TSAN_T))+ $(B)/t_altstack+ DM_QOS_MAP=1 $(B)/t_notify_sched+ DM_QOS_MAP=1 $(B)/t_notify_sched --all-peers+-$(B)/t_pad_hid: t_pad_hid.c ../pad_hid.h ../dm_input.h | $(B)++$(B)/t_pad_hid: t_pad_hid.c ../pad_hid.h ../pad_joycon.h ../motion_pro.h ../dm_input.h | $(B)+ $(CLANG) -O1 -g -Wall -Werror -Wno-unused-function -fsanitize=address,undefined -I.. -o $@ t_pad_hid.c++ # Line coverage (../../sanitizers/coverage.mk): make coverage builds every test of run into $(B)/cov with COV_FLAGS, runs them and writes $(B)/cov/coverage.lcov.+diff --git a/dm/host/tests/t_haptics_apple.m b/dm/host/tests/t_haptics_apple.m+index 27adba0..f7a5dfb 100644+--- a/dm/host/tests/t_haptics_apple.m++++ b/dm/host/tests/t_haptics_apple.m+@@ -440,6 +440,20 @@ int main(void) { @autoreleasepool {+ send_pair(0, 0); drain();+ dm_haptics_apple_controller(0, nil); dm_haptics_apple_controller(1, nil); drain();+ assert(back.closes == 1 && second.closes == 1 && objects == 0); // every iterator and service released++ // Split Joy-Con single-locality routing: Player 1 takes LeftHandle, Player 2 takes RightHandle on the same GCController++ TestController *jc = [TestController new]; jc.haptics = [TestHaptics new];++ jc.haptics.supportedLocalities = [NSSet setWithObjects:GCHapticsLocalityDefault, GCHapticsLocalityLeftHandle, GCHapticsLocalityRightHandle, nil];++ dm_haptics_apple_controller_locality(0, (id)jc, GCHapticsLocalityLeftHandle);++ dm_haptics_apple_controller_locality(1, (id)jc, GCHapticsLocalityRightHandle);++ drain();++ assert(channels[0].count == 1 && channels[1].count == 1);++ dm_vibration_update ujc[] = {{0, 0, {0.6f, 160, 0.6f, 320}}, {0, 1, {0.6f, 160, 0.6f, 320}},++ {1, 0, {0.4f, 160, 0.4f, 320}}, {1, 1, {0.4f, 160, 0.4f, 320}}};++ dm_haptics_send(ujc, 4); drain();++ assert(jc.haptics.attempts == 2);++ assert([jc.haptics.requestedLocalities[0] isEqual:GCHapticsLocalityLeftHandle]);++ assert([jc.haptics.requestedLocalities[1] isEqual:GCHapticsLocalityRightHandle]);++ dm_haptics_apple_controller(0, nil); dm_haptics_apple_controller(1, nil); drain();+ assert(ds4_crc((const uint8_t *)"123456789", 9) == 0xCBF43926u); // the report's CRC32 (IEEE, reflected)+ dm_haptics_apple_shutdown();+ puts("Apple haptics: channels, pulses, idle release, startup handlers, engine replacement, backoff, stale callbacks, plain players, level cutoff and the DualShock 4 route passed");+diff --git a/dm/host/tests/t_pad_hid.c b/dm/host/tests/t_pad_hid.c+index 48341c7..898ad8f 100644+--- a/dm/host/tests/t_pad_hid.c++++ b/dm/host/tests/t_pad_hid.c+@@ -1,10 +1,97 @@+ // Raw HID gamepads (pad_hid.h, GitHub issue #637): the default map and DM_HID_MAP, hat directions, axis scaling, the stick dead zone and analog triggers+ #include <stdio.h>+ #include "../pad_hid.h"++#include "../pad_joycon.h"++ static int checks, fails;+ #define CHECK(c) do { checks++; if (!(c)) { fails++; printf("FAIL %s:%d %s\n", __FILE__, __LINE__, #c); } } while (0)+++static void pack_stick(uint8_t *p, int x, int y) {++ p[0] = (uint8_t)(x & 0xff);++ p[1] = (uint8_t)(((x >> 8) & 0x0f) | ((y & 0x0f) << 4));++ p[2] = (uint8_t)((y >> 4) & 0xff);++}++++static void test_joycon_split(void) {++ CHECK(joycon_is_pid(0x057e, 0x2006) && joycon_is_pid(0x057e, 0x2007));++ CHECK(!joycon_is_pid(0x057e, 0x2009) && !joycon_is_pid(0x045e, 0x2006));++++ joycon_state jl, jr;++ joycon_init(&jl, JOYCON_PID_L);++ joycon_init(&jr, JOYCON_PID_R);++ uint8_t rep[49];++ memset(rep, 0, sizeof rep);++ CHECK(!joycon_decode_0x30(&jl, rep, sizeof rep)); // report id 0x00 rejected++ rep[0] = 0x30;++ CHECK(!joycon_decode_0x30(&jl, rep, 11)); // truncated report rejected++++ // Real Joy-Con (L) 0x30 sample captured on macOS (center 1958, 2117, battery 0x4e = not charging, level 2; 0x5e = charging, level 2)++ rep[2] = 0x4e;++ pack_stick(rep + 6, 1958, 2117);++ CHECK(joycon_decode_0x30(&jl, rep, sizeof rep));++ CHECK(jl.calibrated && jl.cx == 1958 && jl.cy == 2117);++ CHECK(jl.charging == 0 && jl.battery == 2);++ rep[2] = 0x5e;++ CHECK(joycon_decode_0x30(&jl, rep, sizeof rep) && jl.charging == 1 && jl.battery == 2);++ CHECK(jl.buttons == 0 && jl.sx == 0.0f && jl.sy == 0.0f);++++ // Sideways Left Joy-Con buttons: Down->A, Left->B, Right->X, Up->Y, SL->L, SR->R, L->ZL, ZL->ZR, Minus->PLUS, Capture->MINUS, LS->LS++ rep[5] = 0x01; CHECK(joycon_decode_0x30(&jl, rep, sizeof rep) && jl.buttons == DM_BTN_A);++ rep[5] = 0x08; CHECK(joycon_decode_0x30(&jl, rep, sizeof rep) && jl.buttons == DM_BTN_B);++ rep[5] = 0x04; CHECK(joycon_decode_0x30(&jl, rep, sizeof rep) && jl.buttons == DM_BTN_X);++ rep[5] = 0x02; CHECK(joycon_decode_0x30(&jl, rep, sizeof rep) && jl.buttons == DM_BTN_Y);++ rep[5] = 0x20 | 0x10; CHECK(joycon_decode_0x30(&jl, rep, sizeof rep) && jl.buttons == (DM_BTN_L | DM_BTN_R));++ rep[5] = 0x40 | 0x80; CHECK(joycon_decode_0x30(&jl, rep, sizeof rep) && jl.buttons == (DM_BTN_ZL | DM_BTN_ZR));++ rep[5] = 0; rep[4] = 0x01 | 0x20 | 0x08;++ CHECK(joycon_decode_0x30(&jl, rep, sizeof rep) && jl.buttons == (DM_BTN_PLUS | DM_BTN_MINUS | DM_BTN_LS));++ rep[4] = 0;++++ // Sideways Left Joy-Con stick rotation (90 deg CCW): physical right (+X) is sideways up (+Y), physical down (-Y) is sideways right (+X)++ pack_stick(rep + 6, 1958 + 1400, 2117);++ CHECK(joycon_decode_0x30(&jl, rep, sizeof rep) && jl.sx == 0.0f && jl.sy > 0.99f);++ pack_stick(rep + 6, 1958, 2117 - 1400);++ CHECK(joycon_decode_0x30(&jl, rep, sizeof rep) && jl.sx > 0.99f && jl.sy == 0.0f);++++ // Real Joy-Con (R) 0x30 sample captured on macOS (center 2067, 2415, battery 0x80 = full, not charging)++ memset(rep, 0, sizeof rep);++ rep[0] = 0x30; rep[2] = 0x80;++ pack_stick(rep + 9, 2067, 2415);++ CHECK(joycon_decode_0x30(&jr, rep, sizeof rep));++ CHECK(jr.calibrated && jr.cx == 2067 && jr.cy == 2415);++ CHECK(jr.charging == 0 && jr.battery == 4);++++ // Sideways Right Joy-Con buttons: X->A, A->B, Y->X, B->Y, SL->L, SR->R, R->ZL, ZR->ZR, Plus->PLUS, RS->LS, Home->home++ rep[3] = 0x02; CHECK(joycon_decode_0x30(&jr, rep, sizeof rep) && jr.buttons == DM_BTN_A);++ rep[3] = 0x08; CHECK(joycon_decode_0x30(&jr, rep, sizeof rep) && jr.buttons == DM_BTN_B);++ rep[3] = 0x01; CHECK(joycon_decode_0x30(&jr, rep, sizeof rep) && jr.buttons == DM_BTN_X);++ rep[3] = 0x04; CHECK(joycon_decode_0x30(&jr, rep, sizeof rep) && jr.buttons == DM_BTN_Y);++ rep[3] = 0x20 | 0x10; CHECK(joycon_decode_0x30(&jr, rep, sizeof rep) && jr.buttons == (DM_BTN_L | DM_BTN_R));++ rep[3] = 0; rep[4] = 0x02 | 0x04 | 0x10;++ CHECK(joycon_decode_0x30(&jr, rep, sizeof rep) && jr.buttons == (DM_BTN_PLUS | DM_BTN_LS) && jr.home == 1);++ rep[4] = 0;++++ // Sideways Right Joy-Con stick rotation (90 deg CW): physical left (-X) is sideways up (+Y), physical up (+Y) is sideways right (+X)++ pack_stick(rep + 9, 2067 - 1400, 2415);++ CHECK(joycon_decode_0x30(&jr, rep, sizeof rep) && jr.sx == 0.0f && jr.sy > 0.99f);++ pack_stick(rep + 9, 2067, 2415 + 1400);++ CHECK(joycon_decode_0x30(&jr, rep, sizeof rep) && jr.sx > 0.99f && jr.sy == 0.0f);++++ // Sideways 6-axis IMU motion rotation for Left (90 deg CCW) and Right (raw Y/Z inverted + 90 deg CW)++ memset(rep + 13, 0, 36);++ rep[1] = 7;++ // Sample 0: raw_ax = 4096 (1g toward upright top), raw_az = 4096 (1g face-up support on Left, inverted on Right)++ int16_t raw_ax = 4096, raw_az_l = 4096, raw_az_r = -4096;++ memcpy(rep + 13, &raw_ax, 2); memcpy(rep + 17, &raw_az_l, 2);++ pro_motion ml = {0}, mr = {0}; pro_motion_sample msl[3], msr[3];++ CHECK(joycon_motion_decode(&ml, JOYCON_PID_L, rep, sizeof rep, 50000000ULL, msl) == 3);++ // Upright (+raw_ax) gives sy = -1; rotated 90 deg CCW gives sideways acc_x = -sy = +1, acc_z = -1++ CHECK(fabsf(msl[0].acc[0] - 1.0f) < 1e-4f && fabsf(msl[0].acc[1]) < 1e-4f && fabsf(msl[0].acc[2] + 1.0f) < 1e-4f);++ memcpy(rep + 17, &raw_az_r, 2);++ CHECK(joycon_motion_decode(&mr, JOYCON_PID_R, rep, sizeof rep, 50000000ULL, msr) == 3);++ // Right Joy-Con rotated 90 deg CW with inverted raw Z: sideways acc_x = +sy = -1, acc_z = -1++ CHECK(fabsf(msr[0].acc[0] + 1.0f) < 1e-4f && fabsf(msr[0].acc[1]) < 1e-4f && fabsf(msr[0].acc[2] + 1.0f) < 1e-4f);++}+++ int main(void) {+ pad_hid h; int32_t s[4];+ pad_hid_init(&h, NULL);+@@ -34,6 +121,7 @@ int main(void) {+ h.has[PH_Z] = 0; h.has[PH_RX] = 1; h.axis[PH_RX] = -1; pad_hid_sticks(&h, s); CHECK(s[2] == -DM_STICK_MAX && s[3] == 0); // Rx / Ry without Z+ h.has[PH_ACCEL] = 1; h.axis[PH_ACCEL] = -1; CHECK(!(pad_hid_buttons(&h) & DM_BTN_ZR));+ h.axis[PH_ACCEL] = pad_hid_norm(200, 0, 255); CHECK(pad_hid_buttons(&h) & DM_BTN_ZR);++ test_joycon_split();+ printf("t_pad_hid: %d checks, %d failed\n", checks, fails);+ return fails != 0;+ }+diff --git a/dm/ios/tests/duo/Sources/DuoRuntimeStubs.m b/dm/ios/tests/duo/Sources/DuoRuntimeStubs.m+index 2b64998..500e86f 100644+--- a/dm/ios/tests/duo/Sources/DuoRuntimeStubs.m++++ b/dm/ios/tests/duo/Sources/DuoRuntimeStubs.m+@@ -103,6 +103,7 @@ void dm_motion_clear(int player) {+ int duo_harness_rumble(void) { return g_rumble; }+ void dm_haptics_apple_init(void) {}+ void dm_haptics_apple_controller(int player, GCController *controller) { (void)player; (void)controller; }++void dm_haptics_apple_controller_locality(int player, GCController *controller, GCHapticsLocality locality) { (void)player; (void)controller; (void)locality; }++ int front_ios_boot_ok(void) { return 1; }+ void front_ios_boot(void) {}+diff --git a/docs/env_switches.tsv b/docs/env_switches.tsv+index 772479e..8404674 100644+--- a/docs/env_switches.tsv++++ b/docs/env_switches.tsv+@@ -85,6 +85,7 @@ DM_JIT_CAPTURE path Folder the Mac host writes what a game's `nn::jit` plugin ma+ DM_JIT_LOG diagnostic `1` logs every `nn::jit` `GenerateCode` request+ DM_JIT_MISS_DUMP diagnostic Folder for the input of each `nn::jit` request a served image lacks+ DM_JIT_SERVE path Folder of a `nn::jit` image (`jit.img`, `jit.tsv`, `jit.out`): the Mac serves requests from it as the iOS app does, and the plugin does not run++DM_JOYCON_SPLIT switch `1` splits a Bluetooth Nintendo Switch Joy-Con pair on macOS (`0x057e:0x2006` and `0x057e:0x2007`) into two sideways controllers over `IOHIDManager` (`pad_joycon_mac.h`, requires Input Monitoring permission) with per-half 6-axis motion and `LeftHandle` / `RightHandle` Core Haptics rumble+ DM_KBD switch `=<text>`: the system keyboard returns that text as OK without showing an input box; unset with no window, it returns cancel+ DM_KBD_PLAYER switch `own` makes the Mac keyboard player 1 on its own, with controllers from player 2 on (by default the first controller shares player 1 with the keyboard)+ DM_KEYMAP player Mac keyboard: `<name>=<key code>,…` puts a button (`A` … `Down`), a stick direction (`LUp` … `RRight`) or `Shake` on another key (macOS virtual key code, or `none`); one key holds one function (`input_map.h`)diff --git a/patches/series b/patches/seriesindex cc46df43..982c7032 100644--- a/patches/series+++ b/patches/series@@ -41,3 +41,4 @@0071-ios-shell-restore-native-duo-orientation.patch0072-nsp-script-the-first-dotnet-with-an-sdk-10-goes.patch0073-nsp-script-hand-the-extraction-and-the-shader-sp.patch+0074-mac-split-a-joy-con-pair-into-two-sideways-contr.patchdiff --git a/release-notes/v1.1.1.md b/release-notes/v1.1.1.mdindex f737d4ec..9f73e27f 100644--- a/release-notes/v1.1.1.md+++ b/release-notes/v1.1.1.md@@ -24,6 +24,7 @@- **Preparing game**: after Play, the shell shows "Preparing game…" while it unpacks the shaders and hands over to the engine, and ignores the controller until then. By @Silverhza (#652)- **Windows launcher without git**: the Qt launcher in the Actions zip carries the engine tree, so a player needs no git and no checkout of the repository (#615, #616)- **Experimental builder (off by default)**: Settings, Build tools, Use experimental builder runs the extraction and the shader split with nxbuild, a build tool written in Rust. For the games tested, the files are byte for byte the same as before, and the two stages take seconds, not minutes. Any other case, and any failure, uses the standard builder. Checked with Super Mario Bros. Wonder (#749, #752)+- **Split a Joy-Con pair into two controllers (Mac)**: the Controllers sheet now has "Split Joy-Con into two controllers" (off by default). When on, a Bluetooth Joy-Con pair becomes two sideways controllers (Joy-Con (L) as Player 1 and Joy-Con (R) as Player 2) with rotated sticks and 6-axis motion, SL and SR mapped to L and R, and separate left and right handle rumble (#740, #745)- **Italian texts**: 24 texts of the launcher are reworded to read less literally, and the Switch 2 texts say engine like the rest. By @zatteogit and @Dino0005 (#687, #704)**Known issues**@@ -63,6 +64,7 @@- **正在准备游戏**:点 Play 后,壳 App 在解包着色器并交给引擎期间显示「Preparing game…」,并在此期间忽略手柄。作者 @Silverhza(#652)- **没有 git 的 Windows 启动器**:Actions zip 里的 Qt 启动器自带引擎目录,玩家不需要 git,也不需要仓库检出(#615、#616)- **实验性构建器(默认关闭)**:「设置」>「构建工具」>「使用实验性构建器」会用 nxbuild(一个用 Rust 编写的构建工具)完成解包和着色器拆分。对已测试的游戏,输出文件与以前逐字节相同,这两步只需几秒到几十秒,而不是几分钟。其他情况以及出现故障时,仍使用标准构建器。已用 Super Mario Bros. Wonder 检查(#749、#752)+- **将 Joy-Con 拆分为两个手柄(Mac)**:「控制器」面板新增「将 Joy-Con 拆分为两个手柄」开关(默认关闭)。开启后,蓝牙连接的一对 Joy-Con 会拆分为两个独立横握手柄(左 Joy-Con 为玩家 1、右 Joy-Con 为玩家 2),具备横握摇杆与六轴体感旋转、SL 与 SR 映射为 L 与 R,以及左右独立震动反馈(#740、#745)- **意大利语文字**:启动器的 24 条文字改得不再那么直译,Switch 2 的文字也和其余部分一样用 engine。作者 @zatteogit 和 @Dino0005(#687、#704)**已知问题**