A tiny friend in your Mac's notch and on your iPhone that keeps an eye on your AI coding agents: Claude Code, Codex, Cursor, Gemini CLI, Antigravity and more. Approve from the notch or your Lock Screen.
Swift ai-agentsanthropicantigravityclaudeclaude-codecodexcursordynamic-islandgemini-cliiosiphonlinuxmacosmacos-appmenubar-appnotchopen-sourceswiftswiftuiwindows
fix: keep Mochi's gaze right on any display arrangement
Steevenef7ca854fad8
diff --git a/.github/workflows/build.yml b/.github/workflows/build.ymlindex 04f54a91..a4b244e2 100644--- a/.github/workflows/build.yml+++ b/.github/workflows/build.yml@@ -21,6 +21,12 @@ jobs:- name: Test screen geometryrun: bash scripts/test-screen-geometry.sh+ - name: Test display choice+ run: bash scripts/test-display-choice.sh++ - name: Desktop Mochi and gaze tests+ run: bash scripts/test-desktop-mochi.sh+- name: Test link filterrun: bash scripts/test-safe-links.shdiff --git a/NotchBuddy/Sources/App/BotCanvasView.swift b/NotchBuddy/Sources/App/BotCanvasView.swiftindex 4e3b6490..c4827866 100644--- a/NotchBuddy/Sources/App/BotCanvasView.swift+++ b/NotchBuddy/Sources/App/BotCanvasView.swift@@ -6,7 +6,7 @@ struct BotCanvasView: View {@ObservedObject var state: AppStatevar particleOverhang: CGFloat = 0/// When set, overrides island-based eye-tracking (used by desktop Mochi).- /// CGPoint in the same coord space as state.mousePosition (y-down from screen top).+ /// CGPoint in the same coord space as state.mousePosition (DesktopSpace, y-down).var lookOriginOverride: CGPoint? = nil// One engine per view instance (main bot)@@ -153,18 +153,23 @@ struct BotCanvasView: View {if let origin = lookOriginOverride {return tanh((state.mousePosition.x - origin.x) / 260)}- // mousePosition is relative to the island's screen (see pollFrame), so its centre- // must be too: the island may sit on an external screen with a non-zero origin.- let screenMidX = IslandWindowController.islandScreen().frame.width / 2let (islandW, islandH) = islandSize(mode: state.mode, view: state.view,progress: state.uploadProgress,nw: state.notchWidth, nh: state.notchHeight)- let (botCx, _, _, _) = botPosition(mode: state.mode, view: state.view,- islandW: islandW, islandH: islandH,- uploadProgress: state.uploadProgress)- // Island is centered on screen; bot is at botCx within island coords- let botScreenX = screenMidX - islandW / 2 + botCx- return tanh((state.mousePosition.x - botScreenX) / 260)+ let (botCx, botCy, _, _) = botPosition(mode: state.mode, view: state.view,+ islandW: islandW, islandH: islandH,+ uploadProgress: state.uploadProgress)+ let bot = islandBotPoint(islandW: islandW, botCx: botCx, botCy: botCy)+ return tanh((state.mousePosition.x - bot.x) / 260)+ }++ /// Bot centre in DesktopSpace, like state.mousePosition. The island is centred at the+ /// top of its screen, which can be any display, anywhere in the arrangement.+ private func islandBotPoint(islandW: CGFloat, botCx: CGFloat, botCy: CGFloat) -> CGPoint {+ let screen = IslandWindowController.islandScreen().frame+ return DesktopSpace.topDown(CGPoint(x: screen.midX - islandW / 2 + botCx,+ y: screen.maxY - botCy),+ desktopTop: IslandWindowController.desktopTop)}private func lookY(state: AppState, size: CGSize) -> CGFloat {@@ -177,11 +182,11 @@ struct BotCanvasView: View {let actualH: CGFloat = (state.mode == .expanded && state.view == .prompt)? min(300, 240 + CGFloat(state.chatHistory.count) * 40): islandH- let (_, botCy, _, _) = botPosition(mode: state.mode, view: state.view,- islandW: islandW, islandH: actualH,- uploadProgress: state.uploadProgress)- // Island top = screen top → bot screen Y = botCy from island top- return -tanh((state.mousePosition.y - botCy) / 200)+ let (botCx, botCy, _, _) = botPosition(mode: state.mode, view: state.view,+ islandW: islandW, islandH: actualH,+ uploadProgress: state.uploadProgress)+ let bot = islandBotPoint(islandW: islandW, botCx: botCx, botCy: botCy)+ return -tanh((state.mousePosition.y - bot.y) / 200)}}diff --git a/NotchBuddy/Sources/App/DesktopMochi.swift b/NotchBuddy/Sources/App/DesktopMochi.swiftindex 81012f92..3e433b6f 100644--- a/NotchBuddy/Sources/App/DesktopMochi.swift+++ b/NotchBuddy/Sources/App/DesktopMochi.swift@@ -12,7 +12,7 @@ final class DesktopBotViewState: ObservableObject {@Published var isSleeping: Bool = false/// Pause entirely (screen sleep / lock).@Published var paused: Bool = false- /// Bot center in the same coord space as AppState.mousePosition (y-down from screen top).+ /// Bot center in the same coord space as AppState.mousePosition (DesktopSpace, y-down)./// Updated every poll frame; Canvas reads it inside TimelineView — @Published not needed.var lookOrigin: CGPoint = .zero}@@ -695,13 +695,11 @@ final class DesktopMochiController {// MARK: - Position helpersprivate func lookOriginFor(panel: NSPanel) -> CGPoint {- let screen = panel.screen ?? NSScreen.main!- return DesktopMochiLogic.lookOrigin(- panelMinX: panel.frame.minX,- panelMinY: panel.frame.minY,- screenMinX: screen.frame.minX,- screenHeight: screen.frame.height,- panelSize: DesktopMochiController.panelSize)+ DesktopMochiLogic.lookOrigin(+ panelMinX: panel.frame.minX,+ panelMinY: panel.frame.minY,+ desktopTop: IslandWindowController.desktopTop,+ panelSize: DesktopMochiController.panelSize)}private func clampToVisibleFrame(_ origin: NSPoint) -> NSPoint {diff --git a/NotchBuddy/Sources/App/DesktopMochiLogic.swift b/NotchBuddy/Sources/App/DesktopMochiLogic.swiftindex 3f7fad76..667d4194 100644--- a/NotchBuddy/Sources/App/DesktopMochiLogic.swift+++ b/NotchBuddy/Sources/App/DesktopMochiLogic.swift@@ -1,6 +1,17 @@import Foundationimport CoreGraphics+// MARK: - Desktop space++/// One y-down space for the whole desktop, like Quartz: x as in AppKit, y measured down+/// from the top of the menu-bar screen. The cursor and every Mochi (island or desktop)+/// use it, so the gaze stays right whichever screen each one sits on.+enum DesktopSpace {+ static func topDown(_ appKitPoint: CGPoint, desktopTop: CGFloat) -> CGPoint {+ CGPoint(x: appKitPoint.x, y: desktopTop - appKitPoint.y)+ }+}+// MARK: - Alert state machine phase/// Phase of the desktop Mochi lifecycle.@@ -45,16 +56,14 @@ enum DesktopMochiLogic {return dx * dx + dy * dy <= r * r}- /// Eye-tracking origin: panel center in screen-space with y-down from top of screen.- /// Matches the coordinate space of `AppState.mousePosition`.- static func lookOrigin(panelMinX: CGFloat,- panelMinY: CGFloat,- screenMinX: CGFloat,- screenHeight: CGFloat,- panelSize: CGFloat) -> CGPoint {- let cx = panelMinX + panelSize / 2- let cy = panelMinY + panelSize / 2- return CGPoint(x: cx - screenMinX, y: screenHeight - cy)+ /// Eye-tracking origin: panel center in `DesktopSpace`, the coordinate space of+ /// `AppState.mousePosition`.+ static func lookOrigin(panelMinX: CGFloat,+ panelMinY: CGFloat,+ desktopTop: CGFloat,+ panelSize: CGFloat) -> CGPoint {+ DesktopSpace.topDown(CGPoint(x: panelMinX + panelSize / 2, y: panelMinY + panelSize / 2),+ desktopTop: desktopTop)}/// Whether Mochi should immediately retract after landing (alert was active during the flight).diff --git a/NotchBuddy/Sources/App/IslandWindowController.swift b/NotchBuddy/Sources/App/IslandWindowController.swiftindex 5cbb054e..80d5203b 100644--- a/NotchBuddy/Sources/App/IslandWindowController.swift+++ b/NotchBuddy/Sources/App/IslandWindowController.swift@@ -303,9 +303,8 @@ final class IslandWindowController: NSWindowController {}}- // Mouse in screen coords (Y flipped, origin top-left) for Bot look-at- let screenH = panel.screen?.frame.height ?? NSScreen.main!.frame.height- let newPos = CGPoint(x: mouse.x - (panel.screen?.frame.minX ?? 0), y: screenH - mouse.y)+ // Mouse in desktop space (y-down from the menu-bar screen top) for Bot look-at+ let newPos = DesktopSpace.topDown(mouse, desktopTop: Self.desktopTop)let cur = AppState.shared.mousePositionif abs(newPos.x - cur.x) > 1 || abs(newPos.y - cur.y) > 1 {AppState.shared.mousePosition = newPos@@ -1104,6 +1103,9 @@ final class IslandWindowController: NSWindowController {NSScreen.screens.first { $0.safeAreaInsets.top > 0 }}+ /// Top of the menu-bar screen in AppKit coordinates: origin of `DesktopSpace`.+ static var desktopTop: CGFloat { NSScreen.screens.first?.frame.maxY ?? 0 }+/// Screen the island currently sits on (Settings window, desktop Mochi flights).private(set) static var currentScreen: NSScreen?diff --git a/tests/DesktopMochiTests.swift b/tests/DesktopMochiTests.swiftindex b2d5e029..be87116c 100644--- a/tests/DesktopMochiTests.swift+++ b/tests/DesktopMochiTests.swift@@ -70,25 +70,44 @@ enum DesktopMochiTests {// MARK: - lookOriginstatic func testLookOrigin() {- // Panel at (200, 300) on a 1440×900 screen starting at x=0+ // Panel at (200, 300) on a 1440×900 menu-bar screenlet o = DesktopMochiLogic.lookOrigin(panelMinX: 200, panelMinY: 300,- screenMinX: 0, screenHeight: 900,- panelSize: 120)- // cx = 200 + 60 = 260 → x = 260 - 0 = 260- precondition(o.x == 260, "lookOrigin x must be panel center relative to screen left")- // cy = 300 + 60 = 360 → y = 900 - 360 = 540+ desktopTop: 900, panelSize: 120)+ // cx = 200 + 60 = 260; cy = 300 + 60 = 360 → y = 900 - 360 = 540+ precondition(o.x == 260, "lookOrigin x must be the panel center")precondition(o.y == 540, "lookOrigin y must be flipped from bottom-left to top-left")- // Panel on a secondary screen starting at x=1440+ // Panel on a secondary screen to the right: x stays global, not screen-relativelet o2 = DesktopMochiLogic.lookOrigin(panelMinX: 1540, panelMinY: 100,- screenMinX: 1440, screenHeight: 1080,- panelSize: 120)- // cx = 1540 + 60 = 1600 → x = 1600 - 1440 = 160- precondition(o2.x == 160, "lookOrigin x must be relative to screen minX")- // cy = 100 + 60 = 160 → y = 1080 - 160 = 920- precondition(o2.y == 920, "lookOrigin y on secondary screen")+ desktopTop: 900, panelSize: 120)+ precondition(o2.x == 1600, "lookOrigin x must be global (DesktopSpace)")+ precondition(o2.y == 740, "lookOrigin y must be measured from the menu-bar screen top")++ // Gaze signs across a real arrangement. Menu-bar MacBook 1512×982 at (0,0);+ // external 2560×1440 above it at (-500, 982); portrait 1080×1920 on the left+ // at (-1080, -600). AppKit coordinates, y up.+ let top: CGFloat = 982+ func gaze(_ bot: CGPoint, _ mouse: CGPoint) -> (Int, Int) {+ let b = DesktopSpace.topDown(bot, desktopTop: top)+ let m = DesktopSpace.topDown(mouse, desktopTop: top)+ // Same formula as BotCanvasView / DesktopMochi: x right +, y up ++ return (sign(tanh((m.x - b.x) / 260)), sign(-tanh((m.y - b.y) / 200)))+ }+ // Mochi in the island at the top of the external screen above+ let islandOnTop = CGPoint(x: 780, y: 2422 - 16)+ precondition(gaze(islandOnTop, CGPoint(x: 1400, y: 100)) == (1, -1), "cursor on the MacBook below-right")+ precondition(gaze(islandOnTop, CGPoint(x: -1000, y: 0)) == (-1, -1), "cursor on the portrait screen")+ precondition(gaze(islandOnTop, CGPoint(x: 780, y: 2500)) == (0, 1), "cursor above Mochi")+ // Mochi on the desktop of the portrait screen, cursor on the external screen above+ let desktopOnLeft = DesktopMochiLogic.lookOrigin(panelMinX: -700, panelMinY: -200,+ desktopTop: top, panelSize: 120)+ let mouseAbove = DesktopSpace.topDown(CGPoint(x: 1000, y: 2000), desktopTop: top)+ precondition(mouseAbove.x > desktopOnLeft.x && mouseAbove.y < desktopOnLeft.y,+ "desktop Mochi looks right and up at a cursor on another screen")}+ private static func sign(_ v: CGFloat) -> Int { v == 0 ? 0 : (v < 0 ? -1 : 1) }+// MARK: - shouldRetractOnLandingstatic func testShouldRetractOnLanding() {