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
Qt front end: repo download/update, install-all, high-DPI and a 70 MB package; touch geometry + Mac preview
LNPANDY9112ddaddae3
diff --git a/.github/workflows/build-qt.yml b/.github/workflows/build-qt.ymlindex 4d1add00..f7bd980c 100644--- a/.github/workflows/build-qt.yml+++ b/.github/workflows/build-qt.yml@@ -52,9 +52,51 @@ jobs:# --collect-all PySide6 keeps the Qt plugins (platforms/, styles/) that a# windowed build otherwise drops, which is the usual "could not find the# Qt platform plugin windows" failure.+ # --collect-all PySide6 keeps the Qt platform plugins a windowed build+ # otherwise drops, but it also drags in every Qt module (~180 MB of which+ # QtWebEngine alone is 100+). The exclusions below cut the package from+ # ~250 MB to ~70 MB: this app draws widgets and nothing else.pyinstaller --noconfirm --clean --windowed \--name "NS Port Builder" \--collect-all PySide6 \+ --exclude-module PySide6.QtWebEngineCore \+ --exclude-module PySide6.QtWebEngineWidgets \+ --exclude-module PySide6.QtWebEngineQuick \+ --exclude-module PySide6.QtWebChannel \+ --exclude-module PySide6.QtWebSockets \+ --exclude-module PySide6.QtQml \+ --exclude-module PySide6.QtQuick \+ --exclude-module PySide6.QtQuickWidgets \+ --exclude-module PySide6.QtQuick3D \+ --exclude-module PySide6.QtMultimedia \+ --exclude-module PySide6.QtMultimediaWidgets \+ --exclude-module PySide6.QtCharts \+ --exclude-module PySide6.QtDataVisualization \+ --exclude-module PySide6.Qt3DCore \+ --exclude-module PySide6.Qt3DRender \+ --exclude-module PySide6.Qt3DInput \+ --exclude-module PySide6.Qt3DLogic \+ --exclude-module PySide6.Qt3DAnimation \+ --exclude-module PySide6.Qt3DExtras \+ --exclude-module PySide6.QtBluetooth \+ --exclude-module PySide6.QtNfc \+ --exclude-module PySide6.QtPositioning \+ --exclude-module PySide6.QtSerialPort \+ --exclude-module PySide6.QtSql \+ --exclude-module PySide6.QtTest \+ --exclude-module PySide6.QtDesigner \+ --exclude-module PySide6.QtHelp \+ --exclude-module PySide6.QtPdf \+ --exclude-module PySide6.QtPdfWidgets \+ --exclude-module PySide6.QtSpatialAudio \+ --exclude-module PySide6.QtTextToSpeech \+ --exclude-module PySide6.QtUiTools \+ --exclude-module PySide6.QtScxml \+ --exclude-module PySide6.QtRemoteObjects \+ --exclude-module PySide6.QtStateMachine \+ --exclude-module PySide6.QtHttpServer \+ --exclude-module PySide6.QtGraphs \+ --exclude-module PySide6.QtGraphsWidgets \--paths . \run_gui.pydiff --git a/dm/host/front_mac.m b/dm/host/front_mac.mindex 2899c036..f83f2dff 100644--- a/dm/host/front_mac.m+++ b/dm/host/front_mac.m@@ -12,6 +12,7 @@#include "dm.h"#include "dm_input.h"#include "front.h"+#include "touchpad_geometry.h" // the virtual pad iOS draws, so the preview matches it#include "hle.h"#include "pad_slots.h"#include "haptics_apple.h"@@ -187,6 +188,87 @@ static void pads_start(void) {// Mouse as a single-point touchscreen (front.h dm_touch_set): left button down / drag = finger 0, release = lifted. The content view takes the clicks,// not a window-wide event monitor, so clicks on the title bar, the window buttons and the resize edges still reach AppKit.+// Touch preview (DM_TOUCH_PREVIEW=1): the virtual pad iOS draws, over the picture, with the+// control under the mouse highlighted. Geometry comes from touchpad_geometry.h — the same header+// the iPhone controls use — so tuning the layout here is tuning it there. The safe-area insets are+// zero because a Mac window has no notch; an iPhone reports its own.+@interface DmTouchPreview : NSView+@property (nonatomic) NSPoint hover;+@property (nonatomic) BOOL tracking;+@end+@implementation DmTouchPreview+- (BOOL)isFlipped { return YES; } // top-left origin, as the geometry header expects+- (void)updateTrackingAreas {+ [super updateTrackingAreas];+ for (NSTrackingArea *a in self.trackingAreas) [self removeTrackingArea:a];+ [self addTrackingArea:[[NSTrackingArea alloc] initWithRect:self.bounds+ options:NSTrackingMouseMoved | NSTrackingMouseEnteredAndExited | NSTrackingActiveInKeyWindow | NSTrackingInVisibleRect+ owner:self userInfo:nil]];+}+- (void)mouseMoved:(NSEvent *)e { self.hover = [self convertPoint:e.locationInWindow fromView:nil]; self.tracking = NO; [self setNeedsDisplay:YES]; }+- (void)mouseEntered:(NSEvent *)e { [self mouseMoved:e]; }+- (void)mouseExited:(NSEvent *)e { (void)e; self.tracking = NO; [self setNeedsDisplay:YES]; }+- (void)mouseDown:(NSEvent *)e { self.hover = [self convertPoint:e.locationInWindow fromView:nil]; self.tracking = YES; [self setNeedsDisplay:YES]; }+- (void)mouseUp:(NSEvent *)e { (void)e; self.tracking = NO; [self setNeedsDisplay:YES]; }+- (void)drawRect:(NSRect)dirty {+ (void)dirty;+ float w = self.bounds.size.width, h = self.bounds.size.height;+ if (w < 1 || h < 1) return;+ float u = dm_touchpad_u(h);+ float hx = self.hover.x, hy = self.hover.y;+ [[NSColor colorWithWhite:1 alpha:0.22] setStroke];+ NSBezierPath *ring = [NSBezierPath bezierPath];+ // left stick, right stick, d-pad: circles with the highlight when the hover is inside+ struct { dm_touchpad_point c; float r; } circles[3] = {+ { dm_touchpad_stick_home(w, h, 0, 0, 0, 0), DM_TP_STICK_R * u },+ { { w - DM_TP_STICK_X * u, h - DM_TP_PAD_Y * u }, DM_TP_RSTICK_R * u },+ { dm_touchpad_dpad_center(w, h, 0, 0, 0, 0), DM_TP_DPAD_R * u },+ };+ for (int i = 0; i < 3; i++) {+ [ring removeAllPoints];+ [ring appendBezierPathWithOvalInRect:NSMakeRect(circles[i].c.x - circles[i].r, circles[i].c.y - circles[i].r, circles[i].r * 2, circles[i].r * 2)];+ float dx = hx - circles[i].c.x, dy = hy - circles[i].c.y;+ BOOL in = dx * dx + dy * dy <= circles[i].r * circles[i].r;+ BOOL hot = in && self.tracking;+ NSColor *stroke = hot ? [NSColor colorWithRed:0.2 green:0.8 blue:0.35 alpha:0.85] : [NSColor colorWithWhite:1 alpha:0.22];+ [stroke setStroke];+ [ring setLineWidth:hot ? 3.0 : 1.5];+ [ring stroke];+ }+ // the four face buttons, highlighted as a set (that is how the iOS pad reports them)+ uint64_t held = self.tracking ? dm_touchpad_face_buttons(hx, hy, w - DM_TP_FACE_X * u, h - DM_TP_PAD_Y * u, DM_TP_FACE_GAP * u, DM_TP_FACE_R * u) : 0;+ static const char *names[4] = { "A", "B", "X", "Y" };+ for (int b = 0; b < 4; b++) {+ dm_touchpad_point c = dm_touchpad_face_button(w, h, 0, 0, 0, 0, b);+ BOOL on = (held >> b) & 1;+ NSColor *fill = on ? [NSColor colorWithRed:0.2 green:0.8 blue:0.35 alpha:0.9] : [NSColor colorWithWhite:1 alpha:0.30];+ [fill setFill];+ NSBezierPath *p = [NSBezierPath bezierPathWithOvalInRect:NSMakeRect(c.x - DM_TP_FACE_R * u, c.y - DM_TP_FACE_R * u, DM_TP_FACE_R * 2 * u, DM_TP_FACE_R * 2 * u)];+ [p fill];+ NSDictionary *attrs = @{ NSFontAttributeName: [NSFont boldSystemFontOfSize:(11 * u > 9 ? 11 * u : 9)],+ NSForegroundColorAttributeName: [NSColor colorWithWhite:0 alpha:0.75] };+ NSSize s = [@(names[b]) sizeWithAttributes:attrs];+ [@(names[b]) drawAtPoint:NSMakePoint(c.x - s.width / 2, c.y - s.height / 2) withAttributes:attrs];+ }+ // shoulders+ dm_touchpad_point zl = { DM_TP_ZL_X * u, DM_TP_ZL_Y * u };+ dm_touchpad_point l = { DM_TP_L_X * u, DM_TP_L_Y * u };+ dm_touchpad_point r = dm_touchpad_right_shoulder(w, h, 0, 0, 0, 0, 0);+ dm_touchpad_point zr = dm_touchpad_right_shoulder(w, h, 0, 0, 0, 0, 1);+ dm_touchpad_point sh[4] = { zl, l, r, zr };+ for (int i = 0; i < 4; i++) {+ float rad = DM_TP_ZL_R * u;+ float dx = hx - sh[i].x, dy = hy - sh[i].y;+ BOOL in = self.tracking && dx * dx + dy * dy <= rad * rad;+ NSColor *stroke = in ? [NSColor colorWithRed:0.2 green:0.8 blue:0.35 alpha:0.85] : [NSColor colorWithWhite:1 alpha:0.22];+ [stroke setStroke];+ NSBezierPath *p = [NSBezierPath bezierPathWithOvalInRect:NSMakeRect(sh[i].x - rad, sh[i].y - rad, rad * 2, rad * 2)];+ [p setLineWidth:in ? 3.0 : 1.5];+ [p stroke];+ }+}+@end+@interface DmGameView : NSView @end@implementation DmGameView- (void)mouseDown:(NSEvent *)e { [self mouseDragged:e]; }@@ -245,6 +327,16 @@ void front_run(void (*guest)(void)) {g_layer.contentsScale = win.backingScaleFactor;if (getenv("DM_METAL_HUD") && atoi(getenv("DM_METAL_HUD"))) { g_layer.developerHUDProperties = @{@"mode": @"default"}; LOG("front end: Metal performance HUD on (DM_METAL_HUD)"); } // Apple's HUD over the game: frame rate, frame and GPU time, memoryv.layer = g_layer; [(DmGameView *)v fitDrawable];+ if (getenv("DM_TOUCH_PREVIEW") && atoi(getenv("DM_TOUCH_PREVIEW"))) {+ // Over the picture, click-through to the game: the preview only draws, it never takes+ // the mouse away from the single-point touchscreen below it.+ DmTouchPreview *tp = [[DmTouchPreview alloc] initWithFrame:v.bounds];+ tp.autoresizingMask = NSViewWidthSizable | NSViewHeightSizable;+ tp.wantsLayer = YES;+ tp.layer.backgroundColor = NSColor.clearColor.CGColor;+ [v addSubview:tp];+ LOG("front end: touch preview on (DM_TOUCH_PREVIEW=1) — the virtual pad iOS draws, with the control under the mouse highlighted");+ }[win center];[win makeKeyAndOrderFront:nil];g_screen_fps = (int)(win.screen ?: NSScreen.mainScreen).maximumFramesPerSecond;diff --git a/dm/host/tests/Makefile b/dm/host/tests/Makefileindex 3ef378cd..b3735d52 100644--- a/dm/host/tests/Makefile+++ b/dm/host/tests/Makefile@@ -5,7 +5,7 @@ PYTHON ?= python3# tests that use the game profile need GAME=<base game title ID> (there is no default game); GINC only expands when used, so tests without the profile build as beforeGINC = $(if $(strip $(GAME)),-I../gen/$(GAME) -I../../games/$(GAME),$(error GAME is not set: make GAME=<base game title ID>: $(shell python3 ../../games/game.py list | awk -F'\t' '{printf "%s (%s) ", $$1, $$3}')))GAME_H = ../gen/$(GAME)/game_profile.h-run: $(B)/t_heap_size $(B)/t_touch $(B)/t_gesture $(B)/t_oe $(B)/t_fs $(B)/t_fs_commit_list $(B)/t_thread_leak $(B)/t_fs_case $(B)/t_audio $(B)/t_audio_spsc $(B)/t_swkbd $(B)/t_altstack $(B)/t_condvar $(B)/t_condvar_old $(B)/t_pctl $(B)/t_time $(B)/t_shared_font $(B)/t_vorbis $(B)/t_vorbis_divides $(B)/t_hid $(B)/t_haptics $(B)/t_haptics_apple+run: $(B)/t_heap_size $(B)/t_touch $(B)/t_gesture $(B)/t_oe $(B)/t_fs $(B)/t_fs_commit_list $(B)/t_thread_leak $(B)/t_fs_case $(B)/t_audio $(B)/t_audio_spsc $(B)/t_swkbd $(B)/t_altstack $(B)/t_condvar $(B)/t_condvar_old $(B)/t_pctl $(B)/t_time $(B)/t_shared_font $(B)/t_vorbis $(B)/t_vorbis_divides $(B)/t_hid $(B)/t_haptics $(B)/t_haptics_apple $(B)/t_touchpad_geometry$(B)/t_heap_size$(B)/t_touch$(B)/t_gesture@@ -32,6 +32,7 @@ run: $(B)/t_heap_size $(B)/t_touch $(B)/t_gesture $(B)/t_oe $(B)/t_fs $(B)/t_fs_$(B)/t_hid$(B)/t_haptics$(B)/t_haptics_apple+ $(B)/t_touchpad_geometry$(B)/t_nrorun: $(B)/t_nrorun: $(B)/t_system_event@@ -90,6 +91,8 @@ $(B)/t_hid_tsan: t_hid.c ../hle_hid.c ../hle_haptics.c ../hle_haptics.h ../pad_sclang -O1 -g -fsanitize=thread -Wall -Werror -Wno-unused-function -I.. $(GINC) -o $@ t_hid.c ../hle_haptics.c$(B)/t_haptics: t_haptics.c ../hle_haptics.c ../hle_haptics.h ../dm_input.h | $(B)clang -O1 -g -Wall -Werror -I.. -o $@ t_haptics.c ../hle_haptics.c+$(B)/t_touchpad_geometry: t_touchpad_geometry.c ../touchpad_geometry.h ../dm_input.h | $(B)+ clang -O1 -Wall -I.. $(GINC) -o $@ t_touchpad_geometry.c$(B)/t_haptics_apple: t_haptics_apple.m ../haptics_apple.m ../haptics_apple.h ../hle_haptics.c ../hle_haptics.h | $(B)clang -O1 -g -fobjc-arc -Wall -Werror -I.. -o $@ t_haptics_apple.m ../hle_haptics.c -framework Cocoa -framework GameController -framework CoreHaptics$(B)/t_time: t_time.c ../hle_time.c ../hle.h ../dm.h $(GAME_H) | $(B)diff --git a/dm/host/tests/t_touchpad_geometry.c b/dm/host/tests/t_touchpad_geometry.cnew file mode 100644index 00000000..bad6c625--- /dev/null+++ b/dm/host/tests/t_touchpad_geometry.c@@ -0,0 +1,131 @@+#include "../touchpad_geometry.h"+#include <assert.h>+#include <math.h>+#include <stdio.h>++static void nearf(float actual, float expected, float tolerance) {+ assert(fabsf(actual - expected) <= tolerance);+}++static void test_layout(float width, float height, float expected_u) {+ float u = dm_touchpad_u(height);+ nearf(u, expected_u, 0.0001f);++ dm_touchpad_point face = dm_touchpad_face_center(width, height, 0, 0, 0, 0);+ dm_touchpad_point stick = dm_touchpad_stick_home(width, height, 0, 0, 0, 0);+ dm_touchpad_point dpad = dm_touchpad_dpad_center(width, height, 0, 0, 0, 0);+ nearf(face.x, width - DM_TP_FACE_X * u, 0.001f);+ nearf(face.y, height - DM_TP_PAD_Y * u, 0.001f);+ nearf(stick.x, DM_TP_STICK_X * u, 0.001f);+ nearf(stick.y, height - DM_TP_PAD_Y * u, 0.001f);+ nearf(dpad.x, DM_TP_LOW_X * u, 0.001f);+ nearf(dpad.y, height - DM_TP_LOW_Y * u, 0.001f);++ dm_touchpad_point a = dm_touchpad_face_button(width, height, 0, 0, 0, 0, 0);+ dm_touchpad_point b = dm_touchpad_face_button(width, height, 0, 0, 0, 0, 1);+ dm_touchpad_point x = dm_touchpad_face_button(width, height, 0, 0, 0, 0, 2);+ dm_touchpad_point y = dm_touchpad_face_button(width, height, 0, 0, 0, 0, 3);+ float gap = DM_TP_FACE_GAP * u;+ nearf(a.x - face.x, gap, 0.001f); nearf(a.y, face.y, 0.001f);+ nearf(b.y - face.y, gap, 0.001f); nearf(b.x, face.x, 0.001f);+ nearf(x.y - face.y, -gap, 0.001f); nearf(x.x, face.x, 0.001f);+ nearf(y.x - face.x, -gap, 0.001f); nearf(y.y, face.y, 0.001f);+}++static void test_directional_ownership(void) {+ const float cx = 400, cy = 300, gap = 50, radius = 33.75f;+ assert(dm_touchpad_face_buttons(cx + gap, cy, cx, cy, gap, radius) & DM_BTN_A);+ assert(dm_touchpad_face_buttons(cx, cy + gap, cx, cy, gap, radius) & DM_BTN_B);+ assert(dm_touchpad_face_buttons(cx, cy - gap, cx, cy, gap, radius) & DM_BTN_X);+ assert(dm_touchpad_face_buttons(cx - gap, cy, cx, cy, gap, radius) & DM_BTN_Y);++ const float r = 48;+ assert(dm_touchpad_dpad_buttons(cx + r, cy, cx, cy, r) == DM_BTN_RIGHT);+ assert(dm_touchpad_dpad_buttons(cx, cy - r, cx, cy, r) == DM_BTN_UP);+ assert(dm_touchpad_dpad_buttons(cx - r, cy, cx, cy, r) == DM_BTN_LEFT);+ assert(dm_touchpad_dpad_buttons(cx, cy + r, cx, cy, r) == DM_BTN_DOWN);+ assert(dm_touchpad_dpad_buttons(cx + r, cy - r, cx, cy, r) == (DM_BTN_RIGHT | DM_BTN_UP));+ assert(dm_touchpad_dpad_buttons(cx, cy, cx, cy, r) == 0); // native centre dead region+}++static void test_stick_shaping(void) {+ const float r = 77;+ int32_t x, y;+ dm_touchpad_stick_axis(r * 0.05f, 0, r, 0, &x, &y);+ assert(x == 0 && y == 0); // dead zone++ dm_touchpad_stick_axis(r * 0.45f, 0, r, 0, &x, &y);+ assert(x >= 16383 && x <= 16384 && y == 0); // half of full travel after dead-zone remap++ dm_touchpad_stick_axis(0, -r, r, 0, &x, &y);+ assert(x == 0 && y == DM_STICK_MAX);+ dm_touchpad_stick_axis(-r, 0, r, 0, &x, &y);+ assert(x == -DM_STICK_MAX && y == 0);++ dm_touchpad_stick_axis(r * 0.1f, 0, r, 1, &x, &y);+ assert(x == DM_STICK_MAX && y == 0); // legacy full-tilt right-stick mode+}++static void test_safe_insets_and_resize(void) {+ dm_touchpad_rect safe = dm_touchpad_safe_rect(844, 390, 42, 0, 42, 21);+ nearf(safe.x, 42, 0.001f); nearf(safe.y, 0, 0.001f);+ nearf(safe.width, 760, 0.001f); nearf(safe.height, 369, 0.001f);++ dm_touchpad_rect corner = dm_touchpad_corner_rect(844, 390, 42, 0, 42, 21);+ nearf(corner.x, 21, 0.001f); nearf(corner.width, 802, 0.001f);+ nearf(corner.height, 369, 0.001f);+ dm_touchpad_point face = dm_touchpad_face_center(844, 390, 42, 0, 42, 21);+ dm_touchpad_point stick = dm_touchpad_stick_home(844, 390, 42, 0, 42, 21);+ float u = 390.0f / 430.0f;+ nearf(face.x, 21 + 802 - DM_TP_FACE_X * u, 0.001f);+ nearf(stick.x, 21 + DM_TP_STICK_X * u, 0.001f);++ // 16:9 and 21:10 both cap control size at 1.3; a short resized window scales down.+ test_layout(1920, 1080, 1.3f);+ test_layout(1680, 800, 1.3f);+ test_layout(1280, 430, 1.0f);+}++static void test_botw_right_cluster_and_camera_tap(void) {+ for (int i = 0; i < 2; i++) {+ float w = i ? 1920.0f : 844.0f, h = i ? 1080.0f : 390.0f;+ float u = dm_touchpad_u(h);+ dm_touchpad_point face = dm_touchpad_face_center(w,h,0,0,0,0);+ dm_touchpad_point r = dm_touchpad_right_shoulder(w,h,0,0,0,0,0);+ dm_touchpad_point zr = dm_touchpad_right_shoulder(w,h,0,0,0,0,1);+ dm_touchpad_point x = dm_touchpad_face_button(w,h,0,0,0,0,2);+ nearf(r.y,zr.y,0.001f);+ nearf(zr.x-r.x,(DM_TP_ZL_R*2+DM_TP_SHOULDER_GAP)*u,0.001f);+ assert(r.y + DM_TP_ZL_R*u < x.y - DM_TP_FACE_R*u);+ assert(zr.x + DM_TP_ZL_R*u < w);+ float xgr = DM_TP_FACE_R * u * 1.25f;+ float shoulder_hit = DM_TP_ZL_R * u * DM_TP_SHOULDER_HIT_SCALE;+ assert(hypotf(r.x-x.x,r.y-x.y) > shoulder_hit+xgr);+ assert(hypotf(zr.x-x.x,zr.y-x.y) > shoulder_hit+xgr);+ assert(face.y > 0);++ float slop = DM_TP_LOOK_TAP_SLOP*u;+ assert(!dm_touchpad_look_dragged(400,200,400+slop*.5f,200,slop));+ assert(dm_touchpad_look_dragged(400,200,400+slop*1.1f,200,slop));+ // A drag that returns to its start is still classified as a drag by the caller's sticky flag.+ int dragged = dm_touchpad_look_dragged(400,200,400+slop*1.1f,200,slop);+ assert(dragged);+ assert(dm_touchpad_look_tap(.2f,0));+ assert(!dm_touchpad_look_tap(.36f,0));+ assert(!dm_touchpad_look_tap(.1f,1));+ assert(dm_touchpad_look_double_tap(10000000.08,10000000.28,100,100,101,102,u));+ assert(!dm_touchpad_look_double_tap(10000000.08,10000000.48,100,100,101,102,u));+ assert(!dm_touchpad_look_double_tap(10000000.08,10000000.28,100,100,100+49*u,102,u));+ dragged |= dm_touchpad_look_dragged(400,200,400,200,slop);+ assert(dragged);+ }+}++int main(void) {+ test_directional_ownership();+ test_stick_shaping();+ test_safe_insets_and_resize();+ test_botw_right_cluster_and_camera_tap();+ puts("touchpad geometry: direction ownership, layout, and stick shaping passed");+ return 0;+}diff --git a/dm/host/touchpad_geometry.h b/dm/host/touchpad_geometry.hnew file mode 100644index 00000000..affbb2d1--- /dev/null+++ b/dm/host/touchpad_geometry.h@@ -0,0 +1,179 @@+// Shared virtual-pad geometry for the UIKit controls and the opt-in Mac preview.+#pragma once+#include <math.h>++typedef struct { float x, y; } dm_touchpad_point;+typedef struct { float x, y, width, height; } dm_touchpad_rect;++#include "dm_input.h"++#define DM_TP_ZL_X 44.0f+#define DM_TP_ZL_Y 40.0f+#define DM_TP_ZL_R 26.0f+#define DM_TP_L_X 44.0f+#define DM_TP_L_Y 108.0f+#define DM_TP_L_R 24.0f+#define DM_TP_DROP_TIP 1.45f+#define DM_TP_CORNER_IN 0.5f+#define DM_TP_FACE_X 81.0f+#define DM_TP_PAD_Y 82.0f+#define DM_TP_FACE_GAP 50.0f+#define DM_TP_FACE_R 27.0f+#define DM_TP_PILL_DX 52.0f+#define DM_TP_PILL_Y 22.0f+#define DM_TP_PILL_W 50.0f+#define DM_TP_PILL_H 28.0f+#define DM_TP_SWAP_R 15.0f+#define DM_TP_STICK_X 81.0f+#define DM_TP_STICK_R 77.0f+#define DM_TP_KNOB_R 30.0f+#define DM_TP_STICK_GRAB 1.4f+#define DM_TP_LSWIPE (1.0f / 3.0f)+#define DM_TP_FULL 0.8f+#define DM_TP_DEAD 0.1f+#define DM_TP_LOW_X 231.0f+#define DM_TP_LOW_Y 64.0f+#define DM_TP_DPAD_R 48.0f+#define DM_TP_ARM_W 17.0f+#define DM_TP_ARM_IN 11.0f+#define DM_TP_DPAD_GRAB 1.3f+#define DM_TP_RSTICK_R 60.0f+#define DM_TP_RSWIPE (1.0f / 2.0f)+#define DM_TP_CLICK_X 102.0f+#define DM_TP_CLICK_R 17.0f+#define DM_TP_LOOK_TAP_SLOP 12.0f+#define DM_TP_LOOK_TAP_MAX_SECONDS 0.35f+#define DM_TP_LOOK_DOUBLE_TAP_INTERVAL 0.35f+#define DM_TP_LOOK_DOUBLE_TAP_DISTANCE 48.0f+#define DM_TP_SHOULDER_GAP 8.0f+#define DM_TP_SHOULDER_HIT_SCALE 1.0f++static inline float dm_touchpad_u(float height) {+ float u = height / 430.0f;+ return u < 1.3f ? u : 1.3f;+}++// safe insets and result use top-left coordinates, as UIKit does. AppKit+// callers convert their bottom-left mouse coordinates at the view boundary.+static inline dm_touchpad_rect dm_touchpad_corner_rect(float width, float height,+ float left, float top,+ float right, float bottom) {+ return (dm_touchpad_rect){left * .5f, top, width - (left + right) * .5f,+ height - top - bottom};+}++static inline dm_touchpad_rect dm_touchpad_safe_rect(float width, float height,+ float left, float top,+ float right, float bottom) {+ return (dm_touchpad_rect){left, top, width - left - right, height - top - bottom};+}++static inline dm_touchpad_point dm_touchpad_face_center(float width, float height,+ float left, float top,+ float right, float bottom) {+ dm_touchpad_rect c = dm_touchpad_corner_rect(width, height, left, top, right, bottom);+ float u = dm_touchpad_u(height);+ return (dm_touchpad_point){c.x + c.width - DM_TP_FACE_X * u,+ c.y + c.height - DM_TP_PAD_Y * u};+}++// R and ZR sit together just above the face cluster on BOTW's virtual pad.+static inline dm_touchpad_point dm_touchpad_right_shoulder(float width, float height,+ float left, float top,+ float right, float bottom,+ int zr) {+ dm_touchpad_point face = dm_touchpad_face_center(width, height, left, top, right, bottom);+ float u = dm_touchpad_u(height);+ float half = (DM_TP_ZL_R + DM_TP_SHOULDER_GAP * .5f) * u;+ float y = face.y - (DM_TP_FACE_GAP + DM_TP_FACE_R + DM_TP_ZL_R + 18.0f) * u;+ return (dm_touchpad_point){face.x + (zr ? half : -half), y};+}++static inline int dm_touchpad_look_dragged(float down_x, float down_y,+ float x, float y, float slop) {+ float dx = x - down_x, dy = y - down_y;+ return dx * dx + dy * dy > slop * slop;+}+static inline int dm_touchpad_look_tap(float duration, int dragged) {+ return !dragged && duration >= 0.0f && duration <= DM_TP_LOOK_TAP_MAX_SECONDS;+}+static inline int dm_touchpad_look_double_tap(double first_time, double second_time,+ float first_x, float first_y,+ float second_x, float second_y,+ float u) {+ float dx = second_x - first_x, dy = second_y - first_y;+ double dt = second_time - first_time;+ float limit = DM_TP_LOOK_DOUBLE_TAP_DISTANCE * u;+ return dt >= 0.0f && dt <= DM_TP_LOOK_DOUBLE_TAP_INTERVAL && dx*dx + dy*dy <= limit*limit;+}++static inline dm_touchpad_point dm_touchpad_stick_home(float width, float height,+ float left, float top,+ float right, float bottom) {+ dm_touchpad_rect c = dm_touchpad_corner_rect(width, height, left, top, right, bottom);+ float u = dm_touchpad_u(height);+ return (dm_touchpad_point){c.x + DM_TP_STICK_X * u,+ c.y + c.height - DM_TP_PAD_Y * u};+}++static inline dm_touchpad_point dm_touchpad_dpad_center(float width, float height,+ float left, float top,+ float right, float bottom) {+ dm_touchpad_rect c = dm_touchpad_corner_rect(width, height, left, top, right, bottom);+ float u = dm_touchpad_u(height);+ return (dm_touchpad_point){c.x + DM_TP_LOW_X * u,+ c.y + c.height - DM_TP_LOW_Y * u};+}++static inline dm_touchpad_point dm_touchpad_face_button(float width, float height,+ float left, float top,+ float right, float bottom,+ int button) {+ dm_touchpad_point c = dm_touchpad_face_center(width, height, left, top, right, bottom);+ float g = DM_TP_FACE_GAP * dm_touchpad_u(height);+ switch (button) {+ case 0: c.x += g; break; // A+ case 1: c.y += g; break; // B+ case 2: c.y -= g; break; // X+ default: c.x -= g; break; // Y+ }+ return c;+}++static inline uint64_t dm_touchpad_face_buttons(float x, float y, float center_x,+ float center_y, float gap, float radius) {+ uint64_t bits = 0;+ for (int b = 0; b < 4; b++) {+ dm_touchpad_point c = {center_x, center_y};+ if (b == 0) c.x += gap;+ else if (b == 1) c.y += gap;+ else if (b == 2) c.y -= gap;+ else c.x -= gap;+ float dx = x - c.x, dy = y - c.y;+ if (dx * dx + dy * dy <= radius * radius) bits |= 1ull << b;+ }+ return bits;+}++static inline uint64_t dm_touchpad_dpad_buttons(float x, float y, float center_x,+ float center_y, float radius) {+ float dx = x - center_x, dy = y - center_y;+ if (hypotf(dx, dy) < radius * .25f) return 0;+ float a = atan2f(-dy, dx) * (180.0f / 3.14159265358979323846f);+ uint64_t bits = 0;+ if (a > -67.5f && a < 67.5f) bits |= DM_BTN_RIGHT;+ if (a > 22.5f && a < 157.5f) bits |= DM_BTN_UP;+ if (a > 112.5f || a < -112.5f) bits |= DM_BTN_LEFT;+ if (a < -22.5f && a > -157.5f) bits |= DM_BTN_DOWN;+ return bits;+}++static inline void dm_touchpad_stick_axis(float dx, float dy, float radius,+ int full_tilt, int32_t *x, int32_t *y) {+ float d = hypotf(dx, dy), dead = radius * DM_TP_DEAD;+ if (d <= (full_tilt ? 0.0f : dead) || radius <= 0.0f) { *x = *y = 0; return; }+ float magnitude = (full_tilt ? 1.0f : fminf((d - dead) / (radius * DM_TP_FULL - dead), 1.0f)) / d;+ *x = (int32_t)lrintf(dx * magnitude * DM_STICK_MAX);+ *y = (int32_t)lrintf(-dy * magnitude * DM_STICK_MAX);+}+diff --git a/frontend-qt/nspb_qt/__main__.py b/frontend-qt/nspb_qt/__main__.pyindex 2e0894e8..8cecf008 100644--- a/frontend-qt/nspb_qt/__main__.py+++ b/frontend-qt/nspb_qt/__main__.py@@ -3,6 +3,8 @@ from __future__ import annotationsimport sys+from PySide6.QtCore import Qt+from PySide6.QtGui import QGuiApplicationfrom PySide6.QtWidgets import QApplicationfrom .model import Model@@ -11,6 +13,11 @@ from .ui import MainWindowdef main() -> int:+ # High-DPI: let Qt scale with the screen. On a handheld (a small 720p/800p panel at+ # 125-150%) the default policy rounds the scale factor up and the window no longer fits;+ # PassThrough honours the system factor as-is and the font sizes below stay in points.+ QGuiApplication.setHighDpiScaleFactorRoundingPolicy(+ Qt.HighDpiScaleFactorRoundingPolicy.PassThrough)app = QApplication(sys.argv)app.setApplicationName('NS Port Builder')app.setApplicationDisplayName('NS Port Builder')diff --git a/frontend-qt/nspb_qt/localization.py b/frontend-qt/nspb_qt/localization.pyindex b87fcf09..08194922 100644--- a/frontend-qt/nspb_qt/localization.py+++ b/frontend-qt/nspb_qt/localization.py@@ -76,6 +76,7 @@ TABLE: dict[str, tuple[str, str]] = {'dep.checking': ('检测中…', 'Checking…'),'dep.allReady': ('全部就绪', 'All ready'),'dep.missing': ('缺 %d 项', '%d missing'),+ 'dep.installAll': ('一键安装全部缺失项', 'Install all missing'),'dep.recheck': ('重新检测', 'Check again'),'dep.install': ('安装', 'Install'),'dep.installing': ('安装中…', 'Installing…'),diff --git a/frontend-qt/nspb_qt/model.py b/frontend-qt/nspb_qt/model.pyindex 5b4c5372..369bf14b 100644--- a/frontend-qt/nspb_qt/model.py+++ b/frontend-qt/nspb_qt/model.py@@ -88,6 +88,9 @@ class Model(QObject):self.out_dir = ''self.ipa_path = ''self.archive_path = ''+ self.repo_busy = False+ self.repo_behind: int | None = None+ self.repo_status = ''self._proc: subprocess.Popen | None = Noneself._thread: threading.Thread | None = Noneself._line_buf = ''@@ -210,6 +213,127 @@ class Model(QObject):def all_deps_ok(self) -> bool:return self.deps_checked and all(d.ok for d in self.deps)++ # ---- repository download and updates (the SwiftUI app has these; parity matters) ----++ REPO_URL = 'https://github.com/LNPANDY/NX2Apple.git'++ def git_binary(self) -> str | None:+ return pu._which('git', [r'C:\Program Files\Git\cmd\git.exe',+ r'C:\Program Files\Git\bin\git.exe'] if pu.IS_WIN else [])++ def clone_repo(self, dest: str | None = None) -> None:+ """Shallow-clone the project into ~/NX2Apple (or `dest`) and select it.++ Shallow on purpose: a quarter of the bytes and a third of the time of a full clone, and+ fetch/pull keep working on it. Runs on a thread with its progress in the log.+ """+ git = self.git_binary()+ if not git:+ self.repoChanged.emit()+ self.logAppended.emit(self.t('repo.gitMissing') + '\n')+ return+ target = dest or str(Path.home() / 'NX2Apple')+ if Path(target).exists():+ if self.is_repo(target):+ self.repo_path = target+ self.repoChanged.emit()+ else:+ self.logAppended.emit(self.t('repo.destBusy', target) + '\n')+ return+ self.repo_busy = True+ self.repoChanged.emit()+ self.logAppended.emit(f'$ git clone --depth 1 {self.REPO_URL} {target}\n')++ def work() -> None:+ ok = False+ try:+ p = subprocess.Popen([git, 'clone', '--depth', '1', '--single-branch', '--progress',+ self.REPO_URL, target],+ stdout=subprocess.PIPE, stderr=subprocess.STDOUT, text=True,+ errors='replace', env=pu.child_env(), **pu.no_window_kwargs())+ assert p.stdout is not None+ for line in p.stdout:+ self.logAppended.emit(line.replace('\r', '\n'))+ p.wait()+ ok = p.returncode == 0+ except OSError as e:+ self.logAppended.emit(f'{e}\n')+ self.repo_busy = False+ if ok and self.is_repo(target):+ self.repo_path = target+ elif not ok:+ shutil.rmtree(target, ignore_errors=True) # a failed clone leaves a stub+ self.repoChanged.emit()++ threading.Thread(target=work, daemon=True).start()++ def pull_repo(self) -> None:+ """Fast-forward the checkout to origin/main. The build's own files live outside the+ repository, so this never disturbs a previous build."""+ git = self.git_binary()+ if not git or not self.repo_ok or not self.repo_is_git:+ return+ self.repo_busy = True+ self.repoChanged.emit()++ def work() -> None:+ out = ''+ try:+ r = subprocess.run([git, '-C', self.repo_path, 'pull', '--ff-only', 'origin', 'main'],+ capture_output=True, text=True, env=pu.child_env(),+ **pu.no_window_kwargs())+ out = (r.stdout or '') + (r.stderr or '')+ self.repo_status = self.t('repo.pulled') if r.returncode == 0 else self.t('repo.pullFail')+ except OSError as e:+ out, self.repo_status = str(e), self.t('repo.pullFail')+ self.repo_busy = False+ if out:+ self.logAppended.emit(out + '\n')+ self.repoChanged.emit()++ threading.Thread(target=work, daemon=True).start()++ def check_repo_updates(self) -> None:+ """How far behind origin/main the checkout is (0 = current)."""+ git = self.git_binary()+ if not git or not self.repo_ok or not self.repo_is_git:+ return+ self.repo_busy = True+ self.repoChanged.emit()++ def work() -> None:+ try:+ subprocess.run([git, '-C', self.repo_path, 'fetch', 'origin', 'main'],+ capture_output=True, text=True, env=pu.child_env(),+ **pu.no_window_kwargs())+ r = subprocess.run([git, '-C', self.repo_path, 'rev-list', '--count',+ 'HEAD..origin/main'],+ capture_output=True, text=True, env=pu.child_env(),+ **pu.no_window_kwargs())+ if r.returncode == 0:+ self.repo_behind = int(r.stdout.strip() or 0)+ self.repo_status = (self.t('repo.upToDate') if self.repo_behind == 0+ else self.t('repo.behind', self.repo_behind))+ except (OSError, ValueError):+ pass+ self.repo_busy = False+ self.repoChanged.emit()++ threading.Thread(target=work, daemon=True).start()++ # ---- installing what is missing ----++ def install_all_missing(self) -> None:+ """Walk the dependency rows and run each one's install command in turn.++ Sequential on purpose: the installers compete for the same package manager and the+ output is far easier to follow one tool at a time.+ """+ for d in list(self.deps):+ if not d.ok and d.install:+ self.install_dep(d)+def install_dep(self, dep: Dep) -> None:"""Run a dependency's fix on a thread, streaming its output to the log."""if not dep.install:diff --git a/frontend-qt/nspb_qt/ui.py b/frontend-qt/nspb_qt/ui.pyindex 086b0f9a..e9ec5fe8 100644--- a/frontend-qt/nspb_qt/ui.py+++ b/frontend-qt/nspb_qt/ui.py@@ -24,7 +24,15 @@ class MainWindow(QMainWindow):super().__init__()self.m = modelself.setWindowTitle('NS Port Builder')- self.resize(1000, 980)+ # Size to the screen, not to a fixed 1000x980: on a handheld's 1280x800 panel a fixed+ # height puts the footer below the screen edge and the window cannot be shrunk enough to+ # reach it. Fit within 90% of the available area and let the scroll area do the rest.+ avail = self.screen().availableGeometry() if self.screen() else None+ if avail is not None:+ self.resize(min(1000, int(avail.width() * 0.92)), min(980, int(avail.height() * 0.90)))+ else:+ self.resize(1000, 980)+ self.setMinimumSize(560, 400)self._mono = QFontDatabase.systemFont(QFontDatabase.FixedFont)root = QWidget()@@ -128,6 +136,19 @@ class MainWindow(QMainWindow):self.choose_btn.clicked.connect(self._choose_repo)row.addWidget(self.choose_btn)lay.addLayout(row)+ # A machine without a clone gets Download; a clone gets Check/Pull. Same as the macOS app.+ actions = QHBoxLayout()+ actions.setSpacing(8)+ self.download_btn = QPushButton(self.m.t('repo.download'))+ self.download_btn.clicked.connect(lambda: self.m.clone_repo())+ self.check_btn = QPushButton(self.m.t('repo.check'))+ self.check_btn.clicked.connect(self.m.check_repo_updates)+ self.pull_btn = QPushButton(self.m.t('repo.pull'))+ self.pull_btn.clicked.connect(self.m.pull_repo)+ for b in (self.download_btn, self.check_btn, self.pull_btn):+ actions.addWidget(b)+ actions.addStretch(1)+ lay.addLayout(actions)self.repo_status = QLabel('')self.repo_status.setObjectName('note')lay.addWidget(self.repo_status)@@ -176,6 +197,9 @@ class MainWindow(QMainWindow):self.deps_summary = QLabel('')head.addWidget(self.deps_summary)head.addStretch(1)+ self.install_all_btn = QPushButton(self.m.t('dep.installAll'))+ self.install_all_btn.clicked.connect(self.m.install_all_missing)+ head.addWidget(self.install_all_btn)recheck = QPushButton(self.m.t('dep.recheck'))recheck.clicked.connect(self.m.check_deps)head.addWidget(recheck)@@ -239,10 +263,18 @@ class MainWindow(QMainWindow):else (self.m.repo_path or self.m.t('repo.notFound')))if self.m.repo_ok:self.repo_dot.setStyleSheet(f'color: {GREEN};')- self.repo_status.setText(self.m.t('repo.ok') if self.m.repo_is_git else self.m.t('repo.noGit'))+ self.repo_status.setText(self.m.repo_status or+ (self.m.t('repo.ok') if self.m.repo_is_git else self.m.t('repo.noGit')))else:self.repo_dot.setStyleSheet(f'color: {RED};')- self.repo_status.setText(self.m.t('repo.firstHint'))+ self.repo_status.setText(self.m.repo_status or self.m.t('repo.firstHint'))+ # Download when there is no usable checkout; Check/Pull when there is a git one.+ self.download_btn.setVisible(not self.m.repo_ok)+ self.check_btn.setVisible(self.m.repo_ok and self.m.repo_is_git)+ self.pull_btn.setVisible(self.m.repo_ok and self.m.repo_is_git)+ busy = self.m.repo_busy or self.m.running+ for b in (self.download_btn, self.check_btn, self.pull_btn, self.choose_btn):+ b.setEnabled(not busy)self._refresh_inputs()self._refresh_deps()@@ -322,6 +354,10 @@ class MainWindow(QMainWindow):else:self.deps_summary.setText(self.m.t('dep.checking'))self.deps_summary.setStyleSheet(f'color: {MUTED};')+ missing_installable = [d for d in self.m.deps if not d.ok and d.install]+ self.install_all_btn.setVisible(bool(missing_installable))+ self.install_all_btn.setEnabled(bool(missing_installable) and+ not any(d.installing for d in self.m.deps))self._refresh_running()def _refresh_stages(self) -> None:diff --git a/frontend/Sources/NSPortBuilder/Localization.swift b/frontend/Sources/NSPortBuilder/Localization.swiftindex f3fb78b5..66d9e90d 100644--- a/frontend/Sources/NSPortBuilder/Localization.swift+++ b/frontend/Sources/NSPortBuilder/Localization.swift@@ -127,6 +127,7 @@ enum L10n {"dep.checking": ("检测中…", "Checking…"),"dep.allReady": ("全部就绪", "All ready"),"dep.missing": ("缺 %d 项", "%d missing"),+ "dep.installAll": ("一键安装全部缺失项", "Install all missing"),"dep.recheck": ("重新检测", "Check again"),"dep.install": ("安装", "Install"),"dep.installing": ("安装中…", "Installing…"),