Skip to content

Play your own Switch games on iPhone/iPad — one-click macOS app, no terminal. | 把 Switch 游戏装进 iPhone:图形界面一键构建,不用命令行。Bring your own game.

7.1 KB
Raw Blame
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: v0lumehi <[email protected]>
Date: Fri, 30 Oct 2026 22:25:32 +0100
Subject: [PATCH] front_mac: hide the pointer after a few idle seconds over the
 game

The Mac host never hid the pointer, so it stayed on the picture of a game in a window and in fullscreen. It now hides after DM_CURSOR_HIDE seconds (3 by default) without movement over the game view and shows again on the next movement, click or scroll.

Upstream-Status: fork-only (declined seedds/nxnative#755, closed for #584)
Reason: The Mac host never hid the pointer over a game
Issue: LNPANDY/NX2Apple#272
---
 dm/host/front_mac.m          | 16 ++++++++++++++++
 docs/env_switches.tsv        |  1 +
 docs/reference/frame-rate.md |  8 ++++++++
 3 files changed, 25 insertions(+)

diff --git a/dm/host/front_mac.m b/dm/host/front_mac.m
index ecbf20c..44eaf20 100644
--- a/dm/host/front_mac.m
+++ b/dm/host/front_mac.m
@@ -1408,6 +1408,22 @@ void front_run(void (*guest)(void)) {
                 (void)n; want = 0; entering = 0; g_fs_failed = nil; }];   // startup succeeded: later manual refusals have no startup request to retry
             dispatch_async(dispatch_get_main_queue(), enter);
         }
+        // The pointer hides after DM_CURSOR_HIDE seconds (3 by default, 0 keeps it) without movement over the game, and comes back with the next movement, click or scroll. macOS
+        // hides it only for a game that asks (a game window does not, and a pointer left over a fullscreen game stays on the picture); it is also shown whenever the window is
+        // not key or the pointer is outside the game view, so the title bar and other windows keep theirs
+        const char *ch = getenv("DM_CURSOR_HIDE"); double idle = ch && *ch ? atof(ch) : 3.0;
+        if (idle > 0) {
+            win.acceptsMouseMovedEvents = YES;
+            __block double last = CACurrentMediaTime(); __block int hidden = 0;
+            void (^show)(void) = ^{ if (hidden) { hidden = 0; [NSCursor unhide]; } };
+            [NSEvent addLocalMonitorForEventsMatchingMask:NSEventMaskMouseMoved | NSEventMaskLeftMouseDragged | NSEventMaskRightMouseDragged | NSEventMaskOtherMouseDragged |
+                NSEventMaskLeftMouseDown | NSEventMaskRightMouseDown | NSEventMaskOtherMouseDown | NSEventMaskScrollWheel handler:^NSEvent *(NSEvent *e) { last = CACurrentMediaTime(); show(); return e; }];
+            [NSTimer scheduledTimerWithTimeInterval:0.25 repeats:YES block:^(NSTimer *t) {
+                (void)t; NSView *cv = win.contentView;
+                int over = win.isKeyWindow && NSApp.isActive && NSPointInRect([cv convertPoint:win.mouseLocationOutsideOfEventStream fromView:nil], cv.bounds);
+                if (hidden && !over) show();
+                else if (!hidden && over && CACurrentMediaTime() - last >= idle) { hidden = 1; [NSCursor hide]; } }];
+        }
         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;
diff --git a/docs/env_switches.tsv b/docs/env_switches.tsv
index 483ef76..c51d5c4 100644
--- a/docs/env_switches.tsv
+++ b/docs/env_switches.tsv
@@ -22,6 +22,7 @@ DM_CHEATS_WINDOW	switch	`1` opens the Mac Cheats panel beside the game from the
 DM_COPY_GAME_RESOURCES	switch	`NO` skips the Xcode build phase that copies the game's resources into the app (`stage_resources.sh`, on by default); `build_ipa.sh` sets it for its unsigned build, which packs them itself
 DM_COPY_ROMFS	switch	`NO` keeps the game files out of the app, in the Xcode build phase (`stage_resources.sh`) and in the unsigned IPA of `build_ipa.sh` (on by default): `main.m` takes the validated `Documents/romfs.img` copied by `scripts/push_romfs.sh`, then a `Documents/romfs` folder; the build writes the image's identity as `romfs.id` into the app, and `main.m` uses only a matching image (`--romfs separate` of the NSP script sets this)
 DM_CTL	diagnostic	`=<file>` (Mac): the host polls the file every 100 ms and runs each appended line: button presses, `shot`, `passdump`, `texdump`, `env KEY=VALUE`, `peek`, `memdump`, `drag` and more
+DM_CURSOR_HIDE	player	`=<seconds>` hides the Mac pointer after that many seconds without movement over the game window (3 by default) and shows it again on the next movement, click or scroll; `0` keeps it
 DM_DBG	diagnostic	When set, prints the guest's `svcOutputDebugString` text to stderr as `[guest]` lines
 DM_DBG_AU_FRAMES	diagnostic	`=<frames>` asks the Mac's Core Audio output for that many frames per callback instead of about 5 ms (1024 reproduces the iOS default that caused crackling)
 DM_DETCLOCK	switch	`=<step ns>`: from the first present on, the guest clock advances a fixed step per present instead of following the wall clock, and the random source becomes a fixed-seed stream (replay and test runs)
diff --git a/docs/reference/frame-rate.md b/docs/reference/frame-rate.md
index d644ee7..4cb6675 100644
--- a/docs/reference/frame-rate.md
+++ b/docs/reference/frame-rate.md
@@ -310,6 +310,14 @@ Frame pacing: the host's frame step, engine frame limiters, present intervals an
 - **Check:** the reporter confirmed that the deferred request entered fullscreen on its first attempt and stayed there, without a refusal. A harness of the startup callbacks checks both readiness orders, bounded refusal recovery, and cancellation before startup or a queued retry, plus later manual failures after successful startup.
 - **Not checked:** the revised lifecycle handling in a real game through the launcher's console mode; native refusal recovery (the reporter's deferred request succeeded without it).
 
+### The pointer stays on a Mac game
+
+- **Symptom:** the mouse pointer stayed on the picture of a Mac game, in a window and in fullscreen, until it was moved to a screen corner.
+- **Cause:** `front_run` never hid it. macOS hides the pointer only for an app that asks, and a game window is not one.
+- **Fix:** `front_mac.m` `front_run` hides it after `DM_CURSOR_HIDE` seconds (3 by default, `0` keeps it) without movement over the game view, and shows it on the next movement, click or scroll (a local event monitor and a 0.25 s timer). It is shown whenever the window is not key or the pointer is outside the game view, so the title bar and other windows keep theirs.
+- **Found on:** the NX2Apple launcher's issue #272, no game in particular.
+- **Not checked:** not yet run on a game here.
+
 ### Frame latency 2 for the display link in fullscreen
 
 - **Symptom:** on a ProMotion built-in screen, only in fullscreen, the frame step went 1 → 2 → 3 vsyncs on frames costing 0.1–0.6 vsyncs (`3 late frames; cost 0.32 vsyncs`) and the game presented 15 frames a second; a window, or the screen set to a fixed 60 Hz, did not do it. The `DM_NVN_TSV` rows show presents shown one 120 Hz refresh late (`@pres_at_ms` − `@link_target_ms` = 8.3 ms) with a skipped tick after each (`@link_gap_ms` 33 ms), and `@link_lead_ms` about 16 ms against about 50 ms in a window.