diff --git a/frontend-ios/Sources/ShellUI/TouchPadGeometry.swift b/frontend-ios/Sources/ShellUI/TouchPadGeometry.swift index 06f5190f9..3b40e881a 100644 --- a/frontend-ios/Sources/ShellUI/TouchPadGeometry.swift +++ b/frontend-ios/Sources/ShellUI/TouchPadGeometry.swift @@ -325,6 +325,20 @@ struct PadGeo: Equatable { let want = TouchLayout.Control.allCases.filter { $0.drawn(full: full) && !(offsets[$0]?.isZero ?? true) } for round in 0..<2 { var todo = want.filter { $0.isFaceKey == (round == 1) } + if !todo.isEmpty { // all of them at once first, as the engine does (DmPadGeometry.h): a swap, or moves that only work together + var t = self + for c in todo { + let o = offsets[c] ?? .zero + t.move(c, CGFloat(o.dx) * step, CGFloat(o.dy) * step) + let d = t.clamp(c) + t.move(c, d.dx, d.dy) + } + if todo.allSatisfy({ t.controlFits($0) }) { + self = t; moved.formUnion(todo) + if todo.contains(where: \.isFaceKey) { faceSplit = true } + todo = [] + } + } var progress = true while !todo.isEmpty && progress { progress = false diff --git a/frontend-ios/Tests/ShellUITests/TouchLayoutTests.swift b/frontend-ios/Tests/ShellUITests/TouchLayoutTests.swift index 14f4b10db..4b8028b1c 100644 --- a/frontend-ios/Tests/ShellUITests/TouchLayoutTests.swift +++ b/frontend-ios/Tests/ShellUITests/TouchLayoutTests.swift @@ -195,6 +195,19 @@ import Testing #expect(source.contains("let value: String =")) #expect(source.contains("let traits: AccessibilityTraits =")) } + + /// The left stick and the A B X Y diamond trade places (DmPadGeometry.h's check_swap): placed together, not each waiting for the other's place. + @Test func theStickAndTheDiamondTradePlaces() { + for screen in [PadScreen(size: CGSize(width: 678, height: 457)), PadScreen(size: CGSize(width: 951, height: 669))] { + let built = PadGeo.make(screen, full: false) + let step = built.faceR / 2 + var l = TouchLayout() + l[.twoD, .face] = .init(dx: Int(((built.stick.x - built.face.x) / step).rounded()), dy: 0) + l[.twoD, .stick] = .init(dx: Int(((built.face.x - built.stick.x) / step).rounded()), dy: 0) + let g = PadGeo.make(screen, full: false, layout: l) + #expect(g.dropped.isEmpty && abs(g.stick.x - built.face.x) <= step && abs(g.face.x - built.stick.x) <= step) + } + } } import SwiftUI diff --git a/patches/0059-ios-touch-layout-keeps-moves-that-only-work-toge.patch b/patches/0059-ios-touch-layout-keeps-moves-that-only-work-toge.patch new file mode 100644 index 000000000..e5bff1143 --- /dev/null +++ b/patches/0059-ios-touch-layout-keeps-moves-that-only-work-toge.patch @@ -0,0 +1,75 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: David Nicolas <352909663+528z4b2kgc-ux@users.noreply.github.com> +Date: Fri, 13 Nov 2026 08:55:32 -0500 +Subject: [PATCH] ios: touch layout keeps moves that only work together + +Moved controls were placed one at a time against where the others still were, +so a swap (the left stick and the A B X Y diamond trading places) left both at +their built-in places. dm_pad_arrange now tries every moved control of a round +together first and keeps that when all of them fit; otherwise it places them +one at a time as before. check_swap covers it on iPhone Duo's screens. + +Upstream-Status: pending [builds on 0020-ios-touch-controls-layout] +Reason: A swap of two touch controls (stick and A B X Y) was rejected: keep moves that only work together +Issue: none (fix without an issue) + +--- + dm/ios/Sources/DmPadGeometry.h | 10 ++++++++++ + dm/ios/tests/pad_geometry/pad_geometry_check.m | 16 ++++++++++++++++ + 2 files changed, 26 insertions(+) + +diff --git a/dm/ios/Sources/DmPadGeometry.h b/dm/ios/Sources/DmPadGeometry.h +index 8515ca0..8bae326 100644 +--- a/dm/ios/Sources/DmPadGeometry.h ++++ b/dm/ios/Sources/DmPadGeometry.h +@@ -384,6 +384,16 @@ static inline void dm_pad_arrange(DmPadGeo *g, BOOL full, BOOL separated, const + for (int c = 0; c < DM_PAD_C_N; c++) if (dm_pad_control_drawn(c, full) && (layout->dx[set][c] || layout->dy[set][c])) want |= 1u << c; + for (int round = 0; round < 2; round++) { + unsigned todo = want & (round ? keys : ~keys); ++ if (todo) { // all of them at once first: a swap, or moves that only work together, would otherwise leave each control waiting for the other ++ DmPadGeo t = *g; BOOL all = YES; ++ for (int c = 0; c < DM_PAD_C_N; c++) if (todo & (1u << c)) { ++ dm_pad_move(&t, c, layout->dx[set][c] * step, layout->dy[set][c] * step); ++ CGPoint d = dm_pad_clamp(&t, full, c); ++ dm_pad_move(&t, c, d.x, d.y); ++ } ++ for (int c = 0; c < DM_PAD_C_N && all; c++) if ((todo & (1u << c)) && !dm_pad_control_fits(&t, full, c)) all = NO; ++ if (all) { *g = t; g->moved |= todo; if (todo & keys) g->faceSplit = YES; todo = 0; } ++ } + for (BOOL progress = YES; todo && progress; ) { + progress = NO; + for (int c = 0; c < DM_PAD_C_N; c++) if (todo & (1u << c)) { +diff --git a/dm/ios/tests/pad_geometry/pad_geometry_check.m b/dm/ios/tests/pad_geometry/pad_geometry_check.m +index 5c31ffc..a14ee97 100644 +--- a/dm/ios/tests/pad_geometry/pad_geometry_check.m ++++ b/dm/ios/tests/pad_geometry/pad_geometry_check.m +@@ -275,6 +275,21 @@ static void check_duo_outer_custom_bounds(void) { + FAIL("Duo outer: full bounds allowed a moved shoulder to overlap another"); + } + ++// Moves that only work together: the left stick and the A B X Y diamond trading places on iPhone Duo's screens, which the ++// one-control-at-a-time placement refused (each waited for the other's place, so both kept their built-in place). ++static void check_swap(void) { ++ struct { CGRect b; UIEdgeInsets in; const char *name; } s[] = {{CGRectMake(0, 0, 678, 457), {0, 47, 21, 47}, "Duo outer"}, {CGRectMake(0, 0, 951, 669), {0, 0, 20, 0}, "Duo inner"}}; ++ for (int i = 0; i < 2; i++) { ++ DmLayout L = dm_layout(s[i].b, s[i].in, NO, CGRectNull, DM_PICTURE_16_9); ++ DmPadGeo g0 = dm_pad_geo(s[i].b, s[i].in, L, NO, (DmPadOptions){.scale = 1}); ++ CGFloat step = g0.faceR / 2; DmPadLayout m; memset(&m, 0, sizeof m); ++ m.dx[0][DM_PAD_C_FACE] = (signed char)lround((g0.stick.x - g0.face.x) / step); ++ m.dx[0][DM_PAD_C_STICK] = (signed char)lround((g0.face.x - g0.stick.x) / step); ++ DmPadGeo g = dm_pad_geo(s[i].b, s[i].in, L, NO, (DmPadOptions){.scale = 1, .layout = &m}); ++ if (g.dropped || fabs(g.stick.x - g0.face.x) > step || fabs(g.face.x - g0.stick.x) > step) FAIL("swap: %s: stick and diamond did not trade places (dropped 0x%x)", s[i].name, g.dropped); ++ } ++} ++ + int main(void) { + const Screen screens[] = { + // iPhone landscape (the phone's only orientation): the Dynamic Island or notch on one side, the home indicator at the bottom. +@@ -382,6 +397,7 @@ int main(void) { + check_toggle_values(); + check_arrangement(screens, nscreens); + check_duo_outer_custom_bounds(); ++ check_swap(); + + if (!g_fail) printf("ok: %d screens, %d arrangements\n", nscreens, g_arranged); + return g_fail > 100 ? 100 : g_fail; diff --git a/patches/series b/patches/series index 97dd293bb..c8e23afb8 100644 --- a/patches/series +++ b/patches/series @@ -54,3 +54,4 @@ 0056-tools-shader-lib-a-failed-write-removes-its-part.patch 0057-motion-a-controller-is-a-source-once-its-rotatio.patch 0058-test-native-controller-motion-primes-the-adapter.patch +0059-ios-touch-layout-keeps-moves-that-only-work-toge.patch