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
Touch controls: choose where the left stick sits (patch 0065)
v0lumehi3f5266a612b9
diff --git a/frontend-ios/README.md b/frontend-ios/README.mdindex fecaf276..76e6e171 100644--- a/frontend-ios/README.md+++ b/frontend-ios/README.md@@ -63,7 +63,7 @@ The caller returns changed values through `games`. The views keep no second copy| `FolderPicker` | `DocumentFolderPicker` is a `UIDocumentPickerViewController` for a folder, opened in place. Tests use a fake. | `DocumentPicker` in `dm/ios/Sources/Launcher.swift` || Log | Show log reads the tail (256 KB) of `log.txt` in the game's data folder, else the app's folder, into a read-only sheet. | || Update | `ShellHostConfig.updateURL` is opened by Update app. | |-| Touch controls | The shell settings' Touch controls group, for every game: a preview of the controls on a phone held sideways (`TouchControlsPreview`, which mirrors the engine's `DmPadGeometry.h` for that screen) and the Size row (small, medium, large). `ShellSettingsStore.touchSize` stores it, and `gameDefaults` passes it to the engine as `DM_TOUCH_SIZE` (medium is the engine's own size and is not passed). The engine keeps a size off a screen too small for it. `TouchControlsCaptureTests` renders the group on the Mac. | `dm/ios/Sources/DmPadGeometry.h` (patch 0064) |+| Touch controls | The shell settings' Touch controls group, for every game: a preview of the controls on a phone held sideways (`TouchControlsPreview`, which mirrors the engine's `DmPadGeometry.h` for that screen) the Size row (small, medium, large) and the Left stick row (corner, higher, inward, the preview marks the default place with a dashed ring). `ShellSettingsStore.touchSize` and `touchStick` store them, and `gameDefaults` passes them to the engine as `DM_TOUCH_SIZE` and `DM_TOUCH_STICK` (medium and the corner are the engine's own and are not passed). The engine keeps a choice off a screen too small for it. `TouchControlsCaptureTests` renders the group on the Mac. | `dm/ios/Sources/DmPadGeometry.h` (patches 0064, 0065) || Controllers | `ShellHostModel.startControllers()` runs `GamepadAdapter` and fills `controllers` (`ControllerInfo`) and `input` (`ShellInput`). Global mappings are stored in `ShellSettingsStore.padMap`, individual overrides in the game's suite under `GameDefaults.padMapKey`. At launch, each button resolves game > global > default and is passed to the engine as `DM_PAD_MAP`. A profile's own `DM_PAD_MAP` row takes precedence. Touch controls and shell navigation keep their original mapping. | |```swiftdiff --git a/frontend-ios/Sources/ShellUI/Resources/Localizable.xcstrings b/frontend-ios/Sources/ShellUI/Resources/Localizable.xcstringsindex 4147c767..46a1ec74 100644--- a/frontend-ios/Sources/ShellUI/Resources/Localizable.xcstrings+++ b/frontend-ios/Sources/ShellUI/Resources/Localizable.xcstrings@@ -1147,6 +1147,46 @@}}},+ "Corner": {+ "localizations": {+ "de": {+ "stringUnit": {+ "state": "translated",+ "value": "Ecke"+ }+ },+ "en": {+ "stringUnit": {+ "state": "translated",+ "value": "Corner"+ }+ },+ "fr": {+ "stringUnit": {+ "state": "translated",+ "value": "Coin"+ }+ },+ "it": {+ "stringUnit": {+ "state": "translated",+ "value": "Angolo"+ }+ },+ "sv": {+ "stringUnit": {+ "state": "translated",+ "value": "Hörn"+ }+ },+ "zh-Hans": {+ "stringUnit": {+ "state": "translated",+ "value": "角落"+ }+ }+ }+ },"Custom": {"localizations": {"de": {@@ -2107,42 +2147,42 @@}}},- "For every game. On a screen too small for a size, the controls stay smaller.": {+ "For every game. On a screen too small for a choice, the controls stay closer to where they were.": {"localizations": {"de": {"stringUnit": {"state": "translated",- "value": "Für alle Spiele. Ist der Bildschirm für eine Größe zu klein, bleiben die Tasten kleiner."+ "value": "Für alle Spiele. Ist der Bildschirm für eine Wahl zu klein, bleiben die Tasten näher an ihrem alten Platz."}},"en": {"stringUnit": {"state": "translated",- "value": "For every game. On a screen too small for a size, the controls stay smaller."+ "value": "For every game. On a screen too small for a choice, the controls stay closer to where they were."}},"fr": {"stringUnit": {"state": "translated",- "value": "Pour tous les jeux. Sur un écran trop petit pour une taille, les commandes restent plus petites."+ "value": "Pour tous les jeux. Sur un écran trop petit pour un choix, les commandes restent plus près de leur place."}},"it": {"stringUnit": {"state": "translated",- "value": "Per tutti i giochi. Su uno schermo troppo piccolo per una dimensione, i comandi restano più piccoli."+ "value": "Per tutti i giochi. Su uno schermo troppo piccolo per una scelta, i comandi restano più vicini al loro posto."}},"sv": {"stringUnit": {"state": "translated",- "value": "För alla spel. På en skärm som är för liten för en storlek förblir kontrollerna mindre."+ "value": "För alla spel. På en skärm som är för liten för ett val stannar kontrollerna närmare sin plats."}},"zh-Hans": {"stringUnit": {"state": "translated",- "value": "适用于所有游戏。屏幕放不下所选大小时,按键会保持较小。"+ "value": "适用于所有游戏。屏幕放不下所选设置时,按键会尽量留在原来的位置附近。"}}}@@ -2667,6 +2707,46 @@}}},+ "Higher": {+ "localizations": {+ "de": {+ "stringUnit": {+ "state": "translated",+ "value": "Höher"+ }+ },+ "en": {+ "stringUnit": {+ "state": "translated",+ "value": "Higher"+ }+ },+ "fr": {+ "stringUnit": {+ "state": "translated",+ "value": "Plus haut"+ }+ },+ "it": {+ "stringUnit": {+ "state": "translated",+ "value": "In alto"+ }+ },+ "sv": {+ "stringUnit": {+ "state": "translated",+ "value": "Högre"+ }+ },+ "zh-Hans": {+ "stringUnit": {+ "state": "translated",+ "value": "靠上"+ }+ }+ }+ },"Hold B to close": {"localizations": {"de": {@@ -2827,6 +2907,46 @@}}},+ "Inward": {+ "localizations": {+ "de": {+ "stringUnit": {+ "state": "translated",+ "value": "Innen"+ }+ },+ "en": {+ "stringUnit": {+ "state": "translated",+ "value": "Inward"+ }+ },+ "fr": {+ "stringUnit": {+ "state": "translated",+ "value": "Au centre"+ }+ },+ "it": {+ "stringUnit": {+ "state": "translated",+ "value": "Al centro"+ }+ },+ "sv": {+ "stringUnit": {+ "state": "translated",+ "value": "Längre in"+ }+ },+ "zh-Hans": {+ "stringUnit": {+ "state": "translated",+ "value": "靠内"+ }+ }+ }+ },"Italian": {"localizations": {"de": {@@ -3227,6 +3347,46 @@}}},+ "Left stick": {+ "localizations": {+ "de": {+ "stringUnit": {+ "state": "translated",+ "value": "Linker Stick"+ }+ },+ "en": {+ "stringUnit": {+ "state": "translated",+ "value": "Left stick"+ }+ },+ "fr": {+ "stringUnit": {+ "state": "translated",+ "value": "Stick gauche"+ }+ },+ "it": {+ "stringUnit": {+ "state": "translated",+ "value": "Levetta sinistra"+ }+ },+ "sv": {+ "stringUnit": {+ "state": "translated",+ "value": "Vänster spak"+ }+ },+ "zh-Hans": {+ "stringUnit": {+ "state": "translated",+ "value": "左摇杆"+ }+ }+ }+ },"Left stick press": {"localizations": {"de": {diff --git a/frontend-ios/Sources/ShellUI/ShellSettingsStore.swift b/frontend-ios/Sources/ShellUI/ShellSettingsStore.swiftindex 5cbffcc5..6a9cb6c0 100644--- a/frontend-ios/Sources/ShellUI/ShellSettingsStore.swift+++ b/frontend-ios/Sources/ShellUI/ShellSettingsStore.swift@@ -14,6 +14,9 @@ public final class ShellSettingsStore: @unchecked Sendable {public static let touchSizeKey = "touchSize" // small, medium or large: DM_TOUCH_SIZE for every game/// The touch controls' sizes, as the engine reads DM_TOUCH_SIZE. Medium is the built-in size and is never stored.public static let touchSizes = ["small", "medium", "large"]+ public static let touchStickKey = "touchStick" // corner, higher or inward: DM_TOUCH_STICK for every game+ /// Where the left stick sits, as the engine reads DM_TOUCH_STICK. The corner is the built-in place and is never stored.+ public static let touchStickPlaces = ["corner", "higher", "inward"]/// The store the app reads and writes. Tests and previews swap it.nonisolated(unsafe) public static var current = ShellSettingsStore()@@ -50,6 +53,16 @@ public final class ShellSettingsStore: @unchecked Sendable {if size == "medium" { defaults.removeObject(forKey: Self.touchSizeKey) } else { defaults.set(size, forKey: Self.touchSizeKey) }}+ /// Where the left stick sits in every game: in the corner (the built-in place), higher, or further in.+ public var touchStick: String {+ let value = defaults.string(forKey: Self.touchStickKey) ?? "corner"+ return Self.touchStickPlaces.contains(value) ? value : "corner"+ }+ public func storeTouchStick(_ place: String) {+ guard Self.touchStickPlaces.contains(place) else { return }+ if place == "corner" { defaults.removeObject(forKey: Self.touchStickKey) } else { defaults.set(place, forKey: Self.touchStickKey) }+ }+public var padMap: PadMap { PadMap(defaults.dictionary(forKey: Self.padMapKey) as? [String: String] ?? [:]) }public func setPadButton(_ button: String, to output: String) {var map = padMap@@ -68,6 +81,7 @@ public final class ShellSettingsStore: @unchecked Sendable {public var gameDefaults: [String: String] {var values = performanceHUD.map { ["DM_METAL_HUD": $0 ? "1" : "0"] } ?? [:]if touchSize != "medium" { values["DM_TOUCH_SIZE"] = touchSize }+ if touchStick != "corner" { values["DM_TOUCH_STICK"] = touchStick }return values}}diff --git a/frontend-ios/Sources/ShellUI/ShellSettingsView.swift b/frontend-ios/Sources/ShellUI/ShellSettingsView.swiftindex f03481e4..2dff6ea6 100644--- a/frontend-ios/Sources/ShellUI/ShellSettingsView.swift+++ b/frontend-ios/Sources/ShellUI/ShellSettingsView.swift@@ -6,6 +6,7 @@ enum ShellSettingsRows {static let gameID = "shell"static let hud = "shell.hud"static let touchSize = "shell.touchSize"+ static let touchStick = "shell.touchStick"static let targetPrefix = "shs.row."static func hudRow(_ store: ShellSettingsStore) -> SettingRow {@@ -21,15 +22,24 @@ enum ShellSettingsRows {value: store.touchSize)}- /// Under the preview: the rows are for every game, and the engine keeps a size off a screen too small for it. A note of its- /// own, not the row's, so the segments keep the card's width.- static var touchNote: String { ShellStrings.text("For every game. On a screen too small for a size, the controls stay smaller.") }+ /// Where the left stick sits in every game. The buttons on the right keep their place.+ static func touchStickRow(_ store: ShellSettingsStore) -> SettingRow {+ SettingRow(id: touchStick, label: ShellStrings.text("Left stick"),+ kind: .choice([SettingOption("corner", ShellStrings.text("Corner")), SettingOption("higher", ShellStrings.text("Higher")),+ SettingOption("inward", ShellStrings.text("Inward"))]),+ value: store.touchStick)+ }++ /// Under the preview: the rows are for every game, and the engine keeps the controls apart on a screen too small for a+ /// choice. A note of its own, not the rows', so the segments keep the card's width.+ static var touchNote: String { ShellStrings.text("For every game. On a screen too small for a choice, the controls stay closer to where they were.") }/// A change of one of the rows, from the row itself or from the list of choices.static func apply(_ id: String, value: String, to store: ShellSettingsStore) {switch id {case hud: store.storePerformanceHUD(value == "1")case touchSize: store.storeTouchSize(value)+ case touchStick: store.storeTouchStick(value)default: break}}@@ -91,12 +101,13 @@ struct ShellSettingsView: View {}}SettingsGroup(title: ShellStrings.text("Touch controls")) {- TouchControlsPreview(size: store.touchSize)+ TouchControlsPreview(size: store.touchSize, stick: store.touchStick)TouchControlsNote()- let size = ShellSettingsRows.touchSizeRow(store)- SettingControl(gameID: ShellSettingsRows.gameID, row: size, targetPrefix: ShellSettingsRows.targetPrefix) {- ShellSettingsRows.apply(size.id, value: $0, to: store)- }.equatable()+ ForEach([ShellSettingsRows.touchSizeRow(store), ShellSettingsRows.touchStickRow(store)]) { row in+ SettingControl(gameID: ShellSettingsRows.gameID, row: row, targetPrefix: ShellSettingsRows.targetPrefix) {+ ShellSettingsRows.apply(row.id, value: $0, to: store)+ }.equatable()+ }}SettingsGroup(title: ShellStrings.text("Interface")) {let hud = ShellSettingsRows.hudRow(store)diff --git a/frontend-ios/Sources/ShellUI/TouchControlsPreview.swift b/frontend-ios/Sources/ShellUI/TouchControlsPreview.swiftindex 7feb0c28..1c6d79f0 100644--- a/frontend-ios/Sources/ShellUI/TouchControlsPreview.swift+++ b/frontend-ios/Sources/ShellUI/TouchControlsPreview.swift@@ -2,8 +2,8 @@ import SwiftUI/// Where the touch controls sit on an iPhone Pro Max held sideways (932 x 430 points, the side insets of the Dynamic Island and the home/// indicator), for the preview in the settings. It mirrors the engine's `DmPadGeometry.h` (patch 0064) for that one screen, in the 3D-/// layout so every control shows: the same constants in u, the bottom corners halfway into the side insets. The engine stays the-/// truth on the device, where a size that does not fit a screen moves toward medium.+/// layout so every control shows: the same constants in u, the bottom corners halfway into the side insets, the left stick's place (patch+/// 0065). The engine stays the truth on the device, where a choice that does not fit a screen moves toward the built-in layout.struct TouchPadPreviewGeometry: Equatable {static let screen = CGSize(width: 932, height: 430)static let insets = (left: 59.0, right: 59.0, bottom: 21.0)@@ -20,7 +20,9 @@ struct TouchPadPreviewGeometry: Equatable {static func scale(_ size: String) -> CGFloat { size == "small" ? 0.8 : size == "large" ? 1.2 : 1 }let u: CGFloat- init(size: String) { u = Self.scale(size) }+ /// DM_TOUCH_STICK: corner, higher or inward.+ let place: String+ init(size: String, stick: String = "corner") { u = Self.scale(size); place = stick }private var safe: CGRect { CGRect(x: Self.insets.left, y: 0, width: Self.screen.width - Self.insets.left - Self.insets.right, height: Self.screen.height) }private var corner: CGRect {@@ -28,9 +30,24 @@ struct TouchPadPreviewGeometry: Equatable {}private func side(_ r: CGRect, right: Bool, _ dx: CGFloat, _ y: CGFloat) -> CGPoint { CGPoint(x: right ? r.maxX - dx : r.minX + dx, y: y) }- var stick: CGPoint { side(corner, right: false, 81 * u, corner.maxY - 82 * u) }+ private var cornerStick: CGPoint { side(corner, right: false, 81 * u, corner.maxY - 82 * u) }+ /// How far the stick moves for its place: higher up to 70 u, until its ring would reach L's circle, inward 60 u (the engine+ /// shrinks either in 2 u steps until nothing overlaps; on this screen only higher meets something, L, at the large size).+ private var shift: CGVector {+ switch place {+ case "higher":+ let l = side(safe, right: false, 44 * u, 108 * u), r = 24 * u+ var d = 70 * u+ while d > 0 && hypot(cornerStick.x - l.x, cornerStick.y - d - l.y) < 77 * u + r { d -= 2 * u }+ return CGVector(dx: 0, dy: -max(d, 0))+ case "inward": return CGVector(dx: 60 * u, dy: 0)+ default: return .zero+ }+ }+ var stick: CGPoint { CGPoint(x: cornerStick.x + shift.dx, y: cornerStick.y + shift.dy) }var face: CGPoint { side(corner, right: true, 81 * u, corner.maxY - 82 * u) }- var dpad: CGPoint { side(corner, right: false, 231 * u, corner.maxY - 64 * u) }+ /// The D-pad sits inward of the stick and moves with it when the stick moves inward.+ var dpad: CGPoint { side(corner, right: false, 231 * u + (place == "inward" ? shift.dx : 0), corner.maxY - 64 * u) }var shapes: [Shape] {var out: [Shape] = []@@ -74,12 +91,20 @@ struct TouchControlsNote: View {/// It is a picture, VoiceOver reads it as one element with its size, and the rows below it change it.struct TouchControlsPreview: View {var size: String+ var stick = "corner"var body: some View {- let geometry = TouchPadPreviewGeometry(size: size)+ let geometry = TouchPadPreviewGeometry(size: size, stick: stick)+ let home = TouchPadPreviewGeometry(size: size).stickCanvas { context, canvas inlet k = canvas.width / TouchPadPreviewGeometry.screen.widthcontext.scaleBy(x: k, y: k)+ // A moved stick leaves a dashed cream outline where it sits by default, so the move reads at a glance.+ if geometry.stick != home {+ let r = 77 * geometry.u+ context.stroke(Path(ellipseIn: CGRect(x: home.x - r, y: home.y - r, width: 2 * r, height: 2 * r)),+ with: .color(ShellPalette.cream.opacity(0.45)), style: StrokeStyle(lineWidth: 2, dash: [7, 6]))+ }for shape in geometry.shapes { draw(shape, in: &context) }}.aspectRatio(TouchPadPreviewGeometry.screen.width / TouchPadPreviewGeometry.screen.height, contentMode: .fit)@@ -88,7 +113,7 @@ struct TouchControlsPreview: View {).clipShape(RoundedRectangle(cornerRadius: 22, style: .continuous)).overlay(RoundedRectangle(cornerRadius: 22, style: .continuous).strokeBorder(.white.opacity(0.14), lineWidth: 3))- .animation(.smooth(duration: 0.2), value: size)+ .animation(.smooth(duration: 0.2), value: size + stick).accessibilityElement().accessibilityLabel(ShellStrings.text("Preview of the touch controls")).accessibilityIdentifier("touch.preview")diff --git a/frontend-ios/Tests/ShellHostTests/ShellHostModelTests.swift b/frontend-ios/Tests/ShellHostTests/ShellHostModelTests.swiftindex ed90d600..97509b0c 100644--- a/frontend-ios/Tests/ShellHostTests/ShellHostModelTests.swift+++ b/frontend-ios/Tests/ShellHostTests/ShellHostModelTests.swift@@ -45,6 +45,9 @@ final class Clock: @unchecked Sendable { var date: Date; init(_ d: Date) { dateshell.storeTouchSize("medium")await model.playNow(Fixtures.orbit)#expect(launcher.launched.last?.environment["DM_TOUCH_SIZE"] == nil)+ shell.storeTouchStick("higher")+ await model.playNow(Fixtures.orbit)+ #expect(launcher.launched.last?.environment["DM_TOUCH_STICK"] == "higher")}@Test func padOverridesPersistMergeAndReset() async throws {diff --git a/frontend-ios/Tests/ShellHostTests/ShellSettingsStoreTests.swift b/frontend-ios/Tests/ShellHostTests/ShellSettingsStoreTests.swiftindex 7064f63d..d682c3a6 100644--- a/frontend-ios/Tests/ShellHostTests/ShellSettingsStoreTests.swift+++ b/frontend-ios/Tests/ShellHostTests/ShellSettingsStoreTests.swift@@ -50,6 +50,18 @@ import ShellUI#expect(store.touchSize == "medium" && store.gameDefaults.isEmpty, "a stored value nobody knows reads as medium")}+ @Test func theStickPlaceGoesToEveryGameAndTheCornerIsNotStored() {+ let store = shell()+ #expect(store.touchStick == "corner" && store.gameDefaults["DM_TOUCH_STICK"] == nil)+ store.storeTouchStick("inward")+ store.storeTouchSize("small")+ #expect(store.gameDefaults == ["DM_TOUCH_STICK": "inward", "DM_TOUCH_SIZE": "small"])+ store.storeTouchStick("left")+ #expect(store.touchStick == "inward", "a place the engine does not know is not stored")+ store.storeTouchStick("corner")+ #expect(store.defaults.object(forKey: ShellSettingsStore.touchStickKey) == nil && store.gameDefaults == ["DM_TOUCH_SIZE": "small"])+ }+@Test func theFolderNamesAreKept() {let store = shell()store.storeDataFolderName("Switch")diff --git a/frontend-ios/Tests/ShellUITests/TouchControlsCaptureTests.swift b/frontend-ios/Tests/ShellUITests/TouchControlsCaptureTests.swiftindex 41fa1bbb..bd0322ba 100644--- a/frontend-ios/Tests/ShellUITests/TouchControlsCaptureTests.swift+++ b/frontend-ios/Tests/ShellUITests/TouchControlsCaptureTests.swift@@ -51,15 +51,26 @@ final class TouchControlsCaptureTests: XCTestCase {/// The group alone at each size, at a phone's width and an iPad panel's.func testCaptureEachSize() throws {- for size in ShellSettingsStore.touchSizes {- let s = store([ShellSettingsStore.touchSizeKey: size])- let group = SettingsGroup(title: ShellStrings.text("Touch controls")) {- TouchControlsPreview(size: s.touchSize)- TouchControlsNote()- SettingControl(gameID: ShellSettingsRows.gameID, row: ShellSettingsRows.touchSizeRow(s), change: { _ in })- }.padding(24)- try capture("touch-size-\(size)", width: 402, height: 520, group)+ for size in ShellSettingsStore.touchSizes { try captureGroup("touch-size-\(size)", [ShellSettingsStore.touchSizeKey: size]) }+ }++ /// Each place of the left stick, at medium and with the large size.+ func testCaptureEachStickPlace() throws {+ for place in ShellSettingsStore.touchStickPlaces {+ try captureGroup("touch-stick-\(place)", [ShellSettingsStore.touchStickKey: place])+ try captureGroup("touch-stick-\(place)-large", [ShellSettingsStore.touchStickKey: place, ShellSettingsStore.touchSizeKey: "large"])}}++ private func captureGroup(_ name: String, _ values: [String: String]) throws {+ let s = store(values)+ let group = SettingsGroup(title: ShellStrings.text("Touch controls")) {+ TouchControlsPreview(size: s.touchSize, stick: s.touchStick)+ TouchControlsNote()+ SettingControl(gameID: ShellSettingsRows.gameID, row: ShellSettingsRows.touchSizeRow(s), change: { _ in })+ SettingControl(gameID: ShellSettingsRows.gameID, row: ShellSettingsRows.touchStickRow(s), change: { _ in })+ }.padding(24)+ try capture(name, width: 402, height: 640, group)+ }}#endifdiff --git a/frontend-ios/Tests/ShellUITests/TouchControlsTests.swift b/frontend-ios/Tests/ShellUITests/TouchControlsTests.swiftindex 99563c09..494ec43b 100644--- a/frontend-ios/Tests/ShellUITests/TouchControlsTests.swift+++ b/frontend-ios/Tests/ShellUITests/TouchControlsTests.swift@@ -44,6 +44,31 @@ import Testing}}+ @Test func theStickRowOffersTheEnginePlacesAndStoresThem() {+ let store = store()+ let row = ShellSettingsRows.touchStickRow(store)+ guard case .choice(let options) = row.kind else { Issue.record("not a choice"); return }+ #expect(options.map(\.id) == ShellSettingsStore.touchStickPlaces && row.value == "corner")+ #expect(ChoicePresentation.resolve(labels: options.map(\.label), width: 320, textScale: 1) == .segmented)+ ShellSettingsRows.apply(row.id, value: "higher", to: store)+ #expect(store.touchStick == "higher" && store.gameDefaults["DM_TOUCH_STICK"] == "higher")+ }++ /// The preview moves only the left stick (and for inward the D-pad with it), as the engine does (DmPadGeometry.h, patch 0065).+ @Test(arguments: ShellSettingsStore.touchSizes)+ func thePreviewMovesTheStickAndNothingOnTheRight(size: String) {+ let corner = TouchPadPreviewGeometry(size: size), higher = TouchPadPreviewGeometry(size: size, stick: "higher"),+ inward = TouchPadPreviewGeometry(size: size, stick: "inward")+ #expect(higher.stick.x == corner.stick.x && corner.stick.y - higher.stick.y >= 30 * corner.u)+ #expect(inward.stick.y == corner.stick.y && inward.stick.x - corner.stick.x >= 30 * corner.u)+ #expect(abs((inward.dpad.x - corner.dpad.x) - (inward.stick.x - corner.stick.x)) < 0.001 && higher.dpad == corner.dpad)+ #expect(higher.face == corner.face && inward.face == corner.face)+ for g in [higher, inward] {+ let screen = CGRect(origin: .zero, size: TouchPadPreviewGeometry.screen)+ for box in g.shapes.map(TouchPadPreviewGeometry.bounds) { #expect(screen.contains(box)) }+ }+ }+@Test func theSizesKeepTheirOrder() {#expect(TouchPadPreviewGeometry(size: "small").u < TouchPadPreviewGeometry(size: "medium").u)#expect(TouchPadPreviewGeometry(size: "large").u > TouchPadPreviewGeometry(size: "medium").u)diff --git a/frontend/l10n/de.json b/frontend/l10n/de.jsonindex 64202886..d2d3e97c 100644--- a/frontend/l10n/de.json+++ b/frontend/l10n/de.json@@ -666,8 +666,12 @@"ios.ui.touchMedium": "Mittel","ios.ui.touchPreview": "Vorschau der Touch-Steuerung","ios.ui.touchSize": "Größe",- "ios.ui.touchSizeNote": "Für alle Spiele. Ist der Bildschirm für eine Größe zu klein, bleiben die Tasten kleiner.",+ "ios.ui.touchSizeNote": "Für alle Spiele. Ist der Bildschirm für eine Wahl zu klein, bleiben die Tasten näher an ihrem alten Platz.","ios.ui.touchSmall": "Klein",+ "ios.ui.touchStick": "Linker Stick",+ "ios.ui.touchStickCorner": "Ecke",+ "ios.ui.touchStickHigher": "Höher",+ "ios.ui.touchStickInward": "Innen","key.clear": "Löschen","key.code": "Taste %ld","key.delete": "Rückschritt",diff --git a/frontend/l10n/en.json b/frontend/l10n/en.jsonindex b4290670..2b4077e3 100644--- a/frontend/l10n/en.json+++ b/frontend/l10n/en.json@@ -784,8 +784,12 @@"ios.ui.touchMedium": "Medium","ios.ui.touchPreview": "Preview of the touch controls","ios.ui.touchSize": "Size",- "ios.ui.touchSizeNote": "For every game. On a screen too small for a size, the controls stay smaller.",+ "ios.ui.touchSizeNote": "For every game. On a screen too small for a choice, the controls stay closer to where they were.","ios.ui.touchSmall": "Small",+ "ios.ui.touchStick": "Left stick",+ "ios.ui.touchStickCorner": "Corner",+ "ios.ui.touchStickHigher": "Higher",+ "ios.ui.touchStickInward": "Inward","ios.ui.turnOff": "Turn off","ios.ui.turnOffCloudSaves": "Turn off cloud saves","ios.ui.unavailable": "Unavailable",diff --git a/frontend/l10n/fr.json b/frontend/l10n/fr.jsonindex ae68ea82..f7643cfa 100644--- a/frontend/l10n/fr.json+++ b/frontend/l10n/fr.json@@ -668,8 +668,12 @@"ios.ui.touchMedium": "Moyenne","ios.ui.touchPreview": "Aperçu des commandes tactiles","ios.ui.touchSize": "Taille",- "ios.ui.touchSizeNote": "Pour tous les jeux. Sur un écran trop petit pour une taille, les commandes restent plus petites.",+ "ios.ui.touchSizeNote": "Pour tous les jeux. Sur un écran trop petit pour un choix, les commandes restent plus près de leur place.","ios.ui.touchSmall": "Petite",+ "ios.ui.touchStick": "Stick gauche",+ "ios.ui.touchStickCorner": "Coin",+ "ios.ui.touchStickHigher": "Plus haut",+ "ios.ui.touchStickInward": "Au centre","key.clear": "Effacer","key.code": "Touche %ld","key.delete": "Supprimer",diff --git a/frontend/l10n/it.json b/frontend/l10n/it.jsonindex f10abce3..5ee0175b 100644--- a/frontend/l10n/it.json+++ b/frontend/l10n/it.json@@ -669,8 +669,12 @@"ios.ui.touchMedium": "Media","ios.ui.touchPreview": "Anteprima dei comandi touch","ios.ui.touchSize": "Dimensione",- "ios.ui.touchSizeNote": "Per tutti i giochi. Su uno schermo troppo piccolo per una dimensione, i comandi restano più piccoli.",+ "ios.ui.touchSizeNote": "Per tutti i giochi. Su uno schermo troppo piccolo per una scelta, i comandi restano più vicini al loro posto.","ios.ui.touchSmall": "Piccola",+ "ios.ui.touchStick": "Levetta sinistra",+ "ios.ui.touchStickCorner": "Angolo",+ "ios.ui.touchStickHigher": "In alto",+ "ios.ui.touchStickInward": "Al centro","key.clear": "Cancella","key.code": "Tasto %ld","key.delete": "Elimina",diff --git a/frontend/l10n/sv.json b/frontend/l10n/sv.jsonindex db1ddf5f..62bafcce 100644--- a/frontend/l10n/sv.json+++ b/frontend/l10n/sv.json@@ -511,8 +511,12 @@"ios.ui.touchMedium": "Mellan","ios.ui.touchPreview": "Förhandsvisning av pekkontrollerna","ios.ui.touchSize": "Storlek",- "ios.ui.touchSizeNote": "För alla spel. På en skärm som är för liten för en storlek förblir kontrollerna mindre.",+ "ios.ui.touchSizeNote": "För alla spel. På en skärm som är för liten för ett val stannar kontrollerna närmare sin plats.","ios.ui.touchSmall": "Liten",+ "ios.ui.touchStick": "Vänster spak",+ "ios.ui.touchStickCorner": "Hörn",+ "ios.ui.touchStickHigher": "Högre",+ "ios.ui.touchStickInward": "Längre in","key.clear": "Rensa","key.code": "Tangent %ld","key.delete": "Radera",diff --git a/frontend/l10n/zh.json b/frontend/l10n/zh.jsonindex 0681a77d..c6d39cd2 100644--- a/frontend/l10n/zh.json+++ b/frontend/l10n/zh.json@@ -785,8 +785,12 @@"ios.ui.touchMedium": "中","ios.ui.touchPreview": "触控按键预览","ios.ui.touchSize": "大小",- "ios.ui.touchSizeNote": "适用于所有游戏。屏幕放不下所选大小时,按键会保持较小。",+ "ios.ui.touchSizeNote": "适用于所有游戏。屏幕放不下所选设置时,按键会尽量留在原来的位置附近。","ios.ui.touchSmall": "小",+ "ios.ui.touchStick": "左摇杆",+ "ios.ui.touchStickCorner": "角落",+ "ios.ui.touchStickHigher": "靠上",+ "ios.ui.touchStickInward": "靠内","ios.ui.turnOff": "关闭","ios.ui.turnOffCloudSaves": "关闭云存档","ios.ui.unavailable": "不可用",diff --git a/patches/0065-ios-touch-stick-place.patch b/patches/0065-ios-touch-stick-place.patchnew file mode 100644index 00000000..a85db98d--- /dev/null+++ b/patches/0065-ios-touch-stick-place.patch@@ -0,0 +1,156 @@+From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001+From: v0lumehi <[email protected]>+Date: Tue, 3 Nov 2026 15:20:07 +0100+Subject: [PATCH] ios: place the left touch stick higher or further in+ (DM_TOUCH_STICK)++Players on large phones find the left stick too low in the corner+(LNPANDY/NX2Apple#558). DM_TOUCH_STICK=corner|higher|inward moves it: higher+lifts it up to 70 u toward the shoulders, inward moves it up to 60 u toward+the middle and takes the D-pad of the 3D layout along, which sits inward+of it. The diamond, the shoulders and the top row keep their place.++The move shrinks in steps until no drawn control overlaps another and+everything stays inside the safe area. On a screen with no room the stick+stays in the corner. Drawing, the hit-test and the grab read the same+place. test_pad_geometry.py checks every place on every screen, size and+layout, that the stick really moves on the phones and that the right side+does not.++Upstream-Status: pending (on seedds/nxnative#683)+Reason: Players on large phones want the left touch stick higher or further in (#558)+Issue: LNPANDY/NX2Apple#558++---+ dm/ios/Sources/DmGamepad.m | 7 ++++--+ dm/ios/Sources/DmPadGeometry.h | 23 ++++++++++++++++++ .../tests/pad_geometry/pad_geometry_check.m | 25 +++++++++++++++++--+ 3 files changed, 51 insertions(+), 4 deletions(-)++diff --git a/dm/ios/Sources/DmGamepad.m b/dm/ios/Sources/DmGamepad.m+index ec35bb3..ba6707d 100644+--- a/dm/ios/Sources/DmGamepad.m++++ b/dm/ios/Sources/DmGamepad.m+@@ -9,7 +9,7 @@+ // Touch-down ownership: locked keys first (shoulders, − / +, the layout button, L3 / R3), then whichever of the diamond, the D-pad and the left stick has the smallest distance / grab radius (the left stick's grab circle borders the D-pad),+ // then in 3D the right stick for a touch in the right third.+ // Everything hugs the edges and corners to leave the picture room; controls sit over the picture, one CAShapeLayer each: a press only swaps the fill, a stick only moves its knob, nothing redraws the whole screen.+-// Where each control sits is DmPadGeometry.h (pure, tested on the Mac); the player picks the size there through DM_TOUCH_SIZE (small, medium, large; a size that does not fit the screen moves toward medium).++// Where each control sits is DmPadGeometry.h (pure, tested on the Mac); the player picks the size there through DM_TOUCH_SIZE (small, medium, large; a size that does not fit the screen moves toward medium) and the left stick's place through DM_TOUCH_STICK (corner, higher, inward).+ // Touches no control takes (in 3D, those outside the right third) go to the game's touch screen when DmLayout assigns a local game viewport (pushGame; Super Mario Galaxy's pointer in handheld mode).+ // The virtual gamepad (layout button included) hides while a physical controller is connected and comes back when it is removed; unclaimed touches go to the game only when a local game viewport exists. Physical controllers keep every button (D-pad and right stick included) and map by position: bottom = B, right = A, left = Y, top = X (same positions as on a Switch controller); a Nintendo pad maps by its labels (pad_apple.h).+ // Each physical controller is a player of its own (local co-op), as on the Mac: the first one connected is player 1, together with the touch gamepad, the next player 2, and so on up to 8; see "Physical controllers" below.+@@ -147,7 +147,7 @@ @implementation DmGamepad {+ CALayer *_controls; // holds every control layer: hidden while a physical controller is connected (the view itself stays, for game touches)+ BOOL _padOff; // a physical controller is connected: every touch goes to the game+ DmLayout _layout;+- DmPadOptions _opts; // the player's options from the environment (DM_TOUCH_SIZE)++ DmPadOptions _opts; // the player's options from the environment (DM_TOUCH_SIZE, DM_TOUCH_STICK)+ DmPadGeo _geo; CGRect _geoBounds; UIEdgeInsets _geoInsets; BOOL _geoFull, _geoValid; // where the controls are, and what it was computed for+ UITouch *_game[16]; // touches on the game's touch screen by finger slot+ }+@@ -172,6 +172,9 @@ - (instancetype)initWithFrame:(CGRect)f {+ const char *size = getenv("DM_TOUCH_SIZE");+ _opts.scale = dm_pad_size_scale(size);+ if (size && *size) LOG("front end: touch controls size %s (DM_TOUCH_SIZE)", _opts.scale < 1 ? "small" : _opts.scale > 1 ? "large" : "medium");++ const char *stick = getenv("DM_TOUCH_STICK");++ _opts.stick = dm_pad_stick_place(stick);++ if (stick && *stick) LOG("front end: left stick %s (DM_TOUCH_STICK)", _opts.stick == DM_PAD_STICK_HIGHER ? "higher" : _opts.stick == DM_PAD_STICK_INWARD ? "inward" : "in the corner");+ [self registerForTraitChanges:@[UITraitDisplayScale.class] withHandler:^(id<UITraitEnvironment> environment, UITraitCollection *previous) {+ [(UIView *)environment setNeedsLayout];+ }];+diff --git a/dm/ios/Sources/DmPadGeometry.h b/dm/ios/Sources/DmPadGeometry.h+index a03f3ec..18dc25e 100644+--- a/dm/ios/Sources/DmPadGeometry.h++++ b/dm/ios/Sources/DmPadGeometry.h+@@ -2,6 +2,7 @@+ // and the player's options, so the placement is tested without a device (dm/ios/tests/test_pad_geometry.py).+ // Every length is in u (1 = 430 points tall, iPhone Pro Max landscape), x measured from the outer edge, the right half mirrors.+ // The options come from the environment (the shell's settings, Documents/env.txt): DM_TOUCH_SIZE = small | medium | large scales u.++// DM_TOUCH_STICK = corner | higher | inward places the left stick (inward takes the D-pad along); the right-hand controls never move.+ // An option never moves a control off the screen or onto another one: a size that does not fit falls back step by step to the size that does+ // (dm_pad_geo_fits: every drawn shape inside its rectangle, no two drawn shapes overlap).+ #pragma once+@@ -14,8 +15,10 @@ NS_ASSUME_NONNULL_BEGIN+ enum { DM_PAD_ZL = 0, DM_PAD_L, DM_PAD_ZR, DM_PAD_R }; // the order of DmPadGeo.drop+ enum { DM_PAD_MINUS = 0, DM_PAD_PLUS }; // the order of DmPadGeo.pill+++enum { DM_PAD_STICK_CORNER = 0, DM_PAD_STICK_HIGHER, DM_PAD_STICK_INWARD }; // DM_TOUCH_STICK+ typedef struct {+ CGFloat scale; // DM_TOUCH_SIZE: 0.8 small, 1 medium (the built-in size), 1.2 large++ int stick; // DM_TOUCH_STICK: where the left stick sits (the D-pad moves with it when it moves inward); the right-hand controls keep their place+ } DmPadOptions;++ typedef struct {+@@ -53,6 +56,14 @@ static inline CGFloat dm_pad_size_scale(const char *_Nullable v) {+ return 1;+ }+++// DM_TOUCH_STICK: corner (also unset, empty or unknown), higher or inward.++static inline int dm_pad_stick_place(const char *_Nullable v) {++ if (v && !strcmp(v, "higher")) return DM_PAD_STICK_HIGHER;++ if (v && !strcmp(v, "inward")) return DM_PAD_STICK_INWARD;++ return DM_PAD_STICK_CORNER;++}++static const CGFloat DM_PAD_STICK_UP = 70, DM_PAD_STICK_IN = 60; // how far higher / inward moves the left stick (in u), at most+++ static inline CGPoint dm_pad_side(CGRect s, int right, CGFloat dx, CGFloat y) { return CGPointMake(right ? CGRectGetMaxX(s) - dx : CGRectGetMinX(s) + dx, y); }++ // The geometry at one unit, with no fitting.+@@ -170,6 +181,18 @@ static inline DmPadGeo dm_pad_geo(CGRect bounds, UIEdgeInsets insets, DmLayout l+ scale = scale > 1 ? fmax(1, scale - 0.05) : fmin(1, scale + 0.05);+ g = dm_pad_geo_at(bounds, insets, layout, full, u0 * scale);+ }++ // The left stick's place: higher lifts it toward the shoulders, inward moves it (and the D-pad, which sits inward of it) toward the++ // middle. The move shrinks in steps until nothing overlaps; on a screen with no room the stick stays in the corner.++ if (o.stick != DM_PAD_STICK_CORNER) {++ BOOL up = o.stick == DM_PAD_STICK_HIGHER;++ CGPoint stick = g.stick, dpad = g.dpad;++ for (CGFloat d = (up ? DM_PAD_STICK_UP : DM_PAD_STICK_IN) * g.u; d > 0; d -= 2 * g.u) {++ if (up) g.stick = CGPointMake(stick.x, stick.y - d);++ else { g.stick = CGPointMake(stick.x + d, stick.y); g.dpad = CGPointMake(dpad.x + d, dpad.y); }++ if (dm_pad_geo_fits(&g, full)) return g;++ }++ g.stick = stick; g.dpad = dpad;++ }+ return g;+ }++diff --git a/dm/ios/tests/pad_geometry/pad_geometry_check.m b/dm/ios/tests/pad_geometry/pad_geometry_check.m+index f5b7112..54b83b1 100644+--- a/dm/ios/tests/pad_geometry/pad_geometry_check.m++++ b/dm/ios/tests/pad_geometry/pad_geometry_check.m+@@ -76,10 +76,31 @@ int main(void) {+ if (!p.portrait || !NEAR(p.face.x, CGRectGetMinX(s) + 0.72 * s.size.width) || !NEAR(p.stick.x, CGRectGetMinX(s) + 0.28 * s.size.width)) FAIL("portrait: thumbs moved");+ }++- // Every size on every screen, 2D and 3D: inside, and no overlap.++ // Every size and stick place on every screen, 2D and 3D: inside, and no overlap.++ static const char *places[] = {"corner", "higher", "inward"};++ if (dm_pad_stick_place(NULL) != DM_PAD_STICK_CORNER || dm_pad_stick_place("left") != DM_PAD_STICK_CORNER || dm_pad_stick_place("higher") != DM_PAD_STICK_HIGHER++ || dm_pad_stick_place("inward") != DM_PAD_STICK_INWARD) FAIL("DM_TOUCH_STICK: corner is the default");+ for (int i = 0; i < nscreens; i++)+ for (int full = 0; full < 2; full++)+- for (int z = 0; z < 3; z++) check_fits(&screens[i], full, k_sizes[z], (DmPadOptions){dm_pad_size_scale(k_sizes[z])});++ for (int z = 0; z < 3; z++)++ for (int p = 0; p < 3; p++) {++ char what[64]; snprintf(what, sizeof what, "%s %s", k_sizes[z], places[p]);++ check_fits(&screens[i], full, what, (DmPadOptions){dm_pad_size_scale(k_sizes[z]), dm_pad_stick_place(places[p])});++ }++++ // The stick moves where asked on the phones, and nothing on the right moves with it.++ for (int i = 0; i <= 4; i++)++ for (int full = 0; full < 2; full++)++ for (int z = 0; z < 3; z++) {++ DmPadOptions o = {dm_pad_size_scale(k_sizes[z]), DM_PAD_STICK_CORNER};++ DmPadGeo c = geo(&screens[i], full, o);++ o.stick = DM_PAD_STICK_HIGHER; DmPadGeo h = geo(&screens[i], full, o);++ o.stick = DM_PAD_STICK_INWARD; DmPadGeo n = geo(&screens[i], full, o);++ if (!(c.stick.y - h.stick.y >= 30 * c.u) || h.stick.x != c.stick.x) FAIL("%s %s %s: higher lifts the stick only %.1f", screens[i].name, full ? "3D" : "2D", k_sizes[z], c.stick.y - h.stick.y);++ if (!(n.stick.x - c.stick.x >= 30 * c.u) || n.stick.y != c.stick.y) FAIL("%s %s %s: inward moves the stick only %.1f", screens[i].name, full ? "3D" : "2D", k_sizes[z], n.stick.x - c.stick.x);++ if (full && !NEAR(n.dpad.x - c.dpad.x, n.stick.x - c.stick.x)) FAIL("%s 3D %s: the D-pad does not move with the stick", screens[i].name, k_sizes[z]);++ if (!CGPointEqualToPoint(h.face, c.face) || !CGPointEqualToPoint(n.face, c.face) || !CGPointEqualToPoint(n.drop[DM_PAD_R], c.drop[DM_PAD_R])) FAIL("%s: the right side moved", screens[i].name);++ }++ // The sizes keep their order everywhere, and on a phone in landscape large really is larger and small smaller.+ for (int i = 0; i < nscreens; i++)diff --git a/patches/series b/patches/seriesindex bc262895..e15e12a5 100644--- a/patches/series+++ b/patches/series@@ -39,3 +39,4 @@0061-ios-adapt-gameplay-to-duo-portrait-and-tabletop.patch0062-ios-apply-controller-button-mappings-to-physical.patch0064-ios-touch-controls-size.patch+0065-ios-touch-stick-place.patch