Skip to content

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.

Choose which screen Mochi lives on

Steeven4c4831d73246
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
index 879ac24e..c50bd05f 100644
--- a/CONTRIBUTING.md
+++ b/CONTRIBUTING.md
@@ -15,6 +15,7 @@ Check resting island dimensions on screens with and without a notch:
```bash
bash scripts/test-screen-geometry.sh
+bash scripts/test-display-choice.sh
```
## Good first contributions
diff --git a/NotchBuddy/NotchBuddy.xcodeproj/project.pbxproj b/NotchBuddy/NotchBuddy.xcodeproj/project.pbxproj
index 2d2950ec..87865664 100644
--- a/NotchBuddy/NotchBuddy.xcodeproj/project.pbxproj
+++ b/NotchBuddy/NotchBuddy.xcodeproj/project.pbxproj
@@ -19,6 +19,7 @@
118FC4AE0AC74D84B4A134D8 /* VercelPoller.swift in Sources */ = {isa = PBXBuildFile; fileRef = 71718D1B87A39A4879DD2A9D /* VercelPoller.swift */; };
1558BB00C530B721172F6E65 /* StripePoller.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2EF78999D68D56ADE4CEFBE2 /* StripePoller.swift */; };
160EDB9D06275E2607DA5151 /* N8nPoller.swift in Sources */ = {isa = PBXBuildFile; fileRef = B89DA1A0C21AE3535A1760BB /* N8nPoller.swift */; };
+ 1D23613B270FE8B11C5E27A7 /* IslandDisplayChoice.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4A09E73F1E58019EF6EA2A62 /* IslandDisplayChoice.swift */; };
186AB8904029767DAA5277CF /* IslandScreenGeometry.swift in Sources */ = {isa = PBXBuildFile; fileRef = 78BC1357785CA1B099A33969 /* IslandScreenGeometry.swift */; };
18D47AE663EB96BE5638D5F7 /* ClaudePlanCardView.swift in Sources */ = {isa = PBXBuildFile; fileRef = F4263B550838CC5614569D13 /* ClaudePlanCardView.swift */; };
1969590AFEE6CB21404346F1 /* CalcomPoller.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3104222B3F17BA5E8DEA5277 /* CalcomPoller.swift */; };
@@ -72,6 +73,7 @@
9DD56C95ECABDDCE23652D50 /* HookServer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 79D8DD79C3DD9BBC584B3CB2 /* HookServer.swift */; };
B2D86BE268D6F4C86BD0C446 /* ChatMarkdown.swift in Sources */ = {isa = PBXBuildFile; fileRef = D797CC384B5BC70D34F121BC /* ChatMarkdown.swift */; };
B3EC9CF3C8BD629C3530E8F1 /* sounds in Resources */ = {isa = PBXBuildFile; fileRef = C066E2B991AA4F56B2724263 /* sounds */; };
+ 9E34044A001B01C3A514D20A /* IslandDisplayChoice.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4A09E73F1E58019EF6EA2A62 /* IslandDisplayChoice.swift */; };
B605F976F4141435F27CF266 /* IslandRootView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 15A1A8206F73376F4CAF2057 /* IslandRootView.swift */; };
B733A76DD197F6D6D949284C /* HotKeyCenter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1218B86E249691AF44F819AC /* HotKeyCenter.swift */; };
BA65FC4A40F7227837C26214 /* DesktopMochiLogic.swift in Sources */ = {isa = PBXBuildFile; fileRef = C086E1932F86B9C2B559BE03 /* DesktopMochiLogic.swift */; };
@@ -111,6 +113,7 @@
/* Begin PBXFileReference section */
1218B86E249691AF44F819AC /* HotKeyCenter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HotKeyCenter.swift; sourceTree = "<group>"; };
+ 4A09E73F1E58019EF6EA2A62 /* IslandDisplayChoice.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IslandDisplayChoice.swift; sourceTree = "<group>"; };
15A1A8206F73376F4CAF2057 /* IslandRootView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IslandRootView.swift; sourceTree = "<group>"; };
168A9A73B519018FAB0AA465 /* GitHubActivity.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GitHubActivity.swift; sourceTree = "<group>"; };
192844E7299DEED5C2372067 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
@@ -190,6 +193,7 @@
C581F7B1A9F14B281B60063E /* GreetingCanvasView.swift */,
79D8DD79C3DD9BBC584B3CB2 /* HookServer.swift */,
1218B86E249691AF44F819AC /* HotKeyCenter.swift */,
+ 4A09E73F1E58019EF6EA2A62 /* IslandDisplayChoice.swift */,
15A1A8206F73376F4CAF2057 /* IslandRootView.swift */,
78BC1357785CA1B099A33969 /* IslandScreenGeometry.swift */,
D8212018F09EA1E96FBD63CD /* IslandStateMachine.swift */,
@@ -380,6 +384,7 @@
8C32A0C3EAF536D3836F61D5 /* GreetingCanvasView.swift in Sources */,
2C798C3837A63B9BB561A1A0 /* HookServer.swift in Sources */,
B733A76DD197F6D6D949284C /* HotKeyCenter.swift in Sources */,
+ 9E34044A001B01C3A514D20A /* IslandDisplayChoice.swift in Sources */,
CA3321C14A11FED94E48B3E3 /* IslandRootView.swift in Sources */,
186AB8904029767DAA5277CF /* IslandScreenGeometry.swift in Sources */,
5B9A00AFB0837731FA678E4E /* IslandStateMachine.swift in Sources */,
@@ -435,6 +440,7 @@
C0E18D0F6F5F6D131E6066B8 /* GreetingCanvasView.swift in Sources */,
9DD56C95ECABDDCE23652D50 /* HookServer.swift in Sources */,
530443F46F896F037A56F663 /* HotKeyCenter.swift in Sources */,
+ 1D23613B270FE8B11C5E27A7 /* IslandDisplayChoice.swift in Sources */,
B605F976F4141435F27CF266 /* IslandRootView.swift in Sources */,
0D68A4C4E3422487DB7B2262 /* IslandScreenGeometry.swift in Sources */,
3756B7E1A55D9CEC8C4D34A4 /* IslandStateMachine.swift in Sources */,
diff --git a/NotchBuddy/Sources/App/AppDelegate.swift b/NotchBuddy/Sources/App/AppDelegate.swift
index bca82b95..9e5a8270 100644
--- a/NotchBuddy/Sources/App/AppDelegate.swift
+++ b/NotchBuddy/Sources/App/AppDelegate.swift
@@ -82,10 +82,9 @@ final class AppDelegate: NSObject, NSApplicationDelegate {
}
/// Centres the window horizontally and keeps its title bar clear of the island panel
- /// (320 pt tall at the top of the notch screen), shrinking it to fit if needed.
+ /// (320 pt tall at the top of the island screen), shrinking it to fit if needed.
private func placeBelowIsland(_ win: NSWindow) {
- let screen = IslandWindowController.notchScreen() ?? NSScreen.main ?? win.screen
- guard let screen else { win.center(); return }
+ let screen = IslandWindowController.islandScreen()
let visible = screen.visibleFrame
let islandBottom = screen.frame.maxY - 320 - 12 // island panel height + margin
let top = min(visible.maxY, islandBottom)
diff --git a/NotchBuddy/Sources/App/AppState.swift b/NotchBuddy/Sources/App/AppState.swift
index 4a1047e9..62f6129b 100644
--- a/NotchBuddy/Sources/App/AppState.swift
+++ b/NotchBuddy/Sources/App/AppState.swift
@@ -253,6 +253,11 @@ final class AppState: ObservableObject {
didSet { UserDefaults.standard.set(Int(hotkeyCode), forKey: "hotkeyCode") }
}
+ // Screen hosting the island (notch screen by default) — persisted
+ @Published var islandDisplay: IslandDisplayChoice = .notch {
+ didSet { UserDefaults.standard.set(islandDisplay.storageValue, forKey: "islandDisplay") }
+ }
+
// Vercel project filter — empty = watch all projects
@Published var vercelProjectFilter: Set<String> = [] {
didSet {
@@ -424,6 +429,7 @@ final class AppState: ObservableObject {
if let v = ud.object(forKey: "hotkeyEnabled") as? Bool { hotkeyEnabled = v }
if let v = ud.object(forKey: "hotkeyFlags") as? Int { hotkeyFlags = UInt(v) }
if let v = ud.object(forKey: "hotkeyCode") as? Int { hotkeyCode = UInt16(v) }
+ if let v = ud.string(forKey: "islandDisplay") { islandDisplay = IslandDisplayChoice(storageValue: v) }
if let d = ud.data(forKey: "vercelProjectFilter"),
let a = try? JSONDecoder().decode([String].self, from: d) { vercelProjectFilter = Set(a) }
if let d = ud.data(forKey: "n8nWorkflowFilter"),
diff --git a/NotchBuddy/Sources/App/BotCanvasView.swift b/NotchBuddy/Sources/App/BotCanvasView.swift
index 38f5598e..4e3b6490 100644
--- a/NotchBuddy/Sources/App/BotCanvasView.swift
+++ b/NotchBuddy/Sources/App/BotCanvasView.swift
@@ -153,7 +153,9 @@ struct BotCanvasView: View {
if let origin = lookOriginOverride {
return tanh((state.mousePosition.x - origin.x) / 260)
}
- let screen = NSScreen.main ?? NSScreen.screens[0]
+ // 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 / 2
let (islandW, islandH) = islandSize(mode: state.mode, view: state.view,
progress: state.uploadProgress,
nw: state.notchWidth, nh: state.notchHeight)
@@ -161,7 +163,7 @@ struct BotCanvasView: View {
islandW: islandW, islandH: islandH,
uploadProgress: state.uploadProgress)
// Island is centered on screen; bot is at botCx within island coords
- let botScreenX = screen.frame.midX - islandW / 2 + botCx
+ let botScreenX = screenMidX - islandW / 2 + botCx
return tanh((state.mousePosition.x - botScreenX) / 260)
}
diff --git a/NotchBuddy/Sources/App/DesktopMochi.swift b/NotchBuddy/Sources/App/DesktopMochi.swift
index b810365c..81012f92 100644
--- a/NotchBuddy/Sources/App/DesktopMochi.swift
+++ b/NotchBuddy/Sources/App/DesktopMochi.swift
@@ -257,7 +257,7 @@ final class DesktopMochiController {
phase = .flyingOut
let s = DesktopMochiController.panelSize
- let screen = IslandWindowController.notchScreen() ?? NSScreen.main!
+ let screen = IslandWindowController.islandScreen()
let startOrigin = NSPoint(x: screen.frame.midX - s/2, y: screen.frame.maxY - s)
let target = loadSavedPosition()
@@ -329,7 +329,7 @@ final class DesktopMochiController {
cancellables.removeAll()
isSleeping = false
let s = DesktopMochiController.panelSize
- let screen = IslandWindowController.notchScreen() ?? NSScreen.main!
+ let screen = IslandWindowController.islandScreen()
let targetOrigin = NSPoint(x: screen.frame.midX - s/2, y: screen.frame.maxY - s)
NSAnimationContext.runAnimationGroup({ ctx in
ctx.duration = 0.45
@@ -357,7 +357,7 @@ final class DesktopMochiController {
isSleeping = false
let s = DesktopMochiController.panelSize
- let screen = IslandWindowController.notchScreen() ?? NSScreen.main!
+ let screen = IslandWindowController.islandScreen()
let targetOrigin = NSPoint(x: screen.frame.midX - s/2, y: screen.frame.maxY - s)
NSAnimationContext.runAnimationGroup({ ctx in
ctx.duration = 0.45
diff --git a/NotchBuddy/Sources/App/IslandDisplayChoice.swift b/NotchBuddy/Sources/App/IslandDisplayChoice.swift
new file mode 100644
index 00000000..c1d7eca0
--- /dev/null
+++ b/NotchBuddy/Sources/App/IslandDisplayChoice.swift
@@ -0,0 +1,65 @@
+import Foundation
+
+/// Which screen hosts the island. Persisted in UserDefaults as `storageValue`.
+enum IslandDisplayChoice: Equatable, Hashable {
+ /// Default: the built-in screen with a notch, else the main screen.
+ case notch
+ /// The screen that carries the menu bar (first in `NSScreen.screens`).
+ case menuBar
+ /// The island moves to the screen under the cursor while it is not open.
+ case followMouse
+ /// A specific screen, identified by its display UUID (stable across reboots).
+ case display(uuid: String)
+
+ private static let displayPrefix = "display:"
+
+ init(storageValue: String) {
+ switch storageValue {
+ case "menuBar": self = .menuBar
+ case "followMouse": self = .followMouse
+ default:
+ if storageValue.hasPrefix(Self.displayPrefix) {
+ let uuid = String(storageValue.dropFirst(Self.displayPrefix.count))
+ self = uuid.isEmpty ? .notch : .display(uuid: uuid)
+ } else {
+ self = .notch
+ }
+ }
+ }
+
+ var storageValue: String {
+ switch self {
+ case .notch: return "notch"
+ case .menuBar: return "menuBar"
+ case .followMouse: return "followMouse"
+ case .display(let uuid): return Self.displayPrefix + uuid
+ }
+ }
+}
+
+/// What the resolver needs to know about a connected screen, in `NSScreen.screens` order.
+struct IslandDisplayCandidate {
+ let uuid: String?
+ let hasNotch: Bool
+ let containsMouse: Bool
+}
+
+enum IslandDisplayResolver {
+ /// Index of the screen that should host the island, or nil to use the default
+ /// (notch screen, else main screen). A disconnected chosen screen falls back too.
+ static func index(for choice: IslandDisplayChoice,
+ in candidates: [IslandDisplayCandidate]) -> Int? {
+ guard !candidates.isEmpty else { return nil }
+ let notchIndex = candidates.firstIndex { $0.hasNotch }
+ switch choice {
+ case .notch:
+ return notchIndex
+ case .menuBar:
+ return 0
+ case .followMouse:
+ return candidates.firstIndex { $0.containsMouse } ?? notchIndex
+ case .display(let uuid):
+ return candidates.firstIndex { $0.uuid == uuid } ?? notchIndex
+ }
+ }
+}
diff --git a/NotchBuddy/Sources/App/IslandRootView.swift b/NotchBuddy/Sources/App/IslandRootView.swift
index eb91f230..ef3bfd5a 100644
--- a/NotchBuddy/Sources/App/IslandRootView.swift
+++ b/NotchBuddy/Sources/App/IslandRootView.swift
@@ -163,6 +163,14 @@ struct IslandContainer: View {
.onReceive(NotificationCenter.default.publisher(for: .botGreet)) { _ in
greetNotif.toggle()
}
+ .onReceive(NotificationCenter.default.publisher(for: .islandScreenChanged)) { _ in
+ // New screen, new resting size (notch ↔ bar): snap without animation.
+ let (w, h) = islandSize(mode: state.mode, view: state.view,
+ progress: state.uploadProgress,
+ nw: state.notchWidth, nh: state.notchHeight)
+ islandWidth = w
+ islandHeight = (state.mode == .expanded && state.view == .prompt) ? chatPromptHeight : h
+ }
}
private func modeOrder(_ m: IslandMode) -> Int {
diff --git a/NotchBuddy/Sources/App/IslandWindowController.swift b/NotchBuddy/Sources/App/IslandWindowController.swift
index c49e37ff..5cbb054e 100644
--- a/NotchBuddy/Sources/App/IslandWindowController.swift
+++ b/NotchBuddy/Sources/App/IslandWindowController.swift
@@ -15,6 +15,7 @@ final class IslandWindowController: NSWindowController {
private var frameTimer: Timer?
private var keyMonitor: Any?
private var viewSubscription: AnyCancellable?
+ private var displaySubscription: AnyCancellable?
// Confused recovery timer (set by handleDizzy)
private var confusedRecoveryTimer: DispatchWorkItem?
@@ -51,7 +52,8 @@ final class IslandWindowController: NSWindowController {
private var localKeyMonitor: Any?
convenience init() {
- let screen = Self.notchScreen() ?? NSScreen.main!
+ let screen = Self.targetScreen(for: AppState.shared.islandDisplay)
+ Self.currentScreen = screen
let geometry = Self.screenGeometry(for: screen)
let nW = geometry.width
let nH = geometry.height
@@ -156,6 +158,63 @@ final class IslandWindowController: NSWindowController {
self.islandPanel.makeKey()
}
}
+
+ // Screen choice changed in Settings: move right away (explicit user action).
+ displaySubscription = state.$islandDisplay
+ .dropFirst()
+ .receive(on: DispatchQueue.main)
+ .sink { [weak self] choice in
+ self?.moveToTargetScreen(choice: choice)
+ }
+
+ // Screen plugged/unplugged, lid closed, arrangement or resolution changed.
+ NotificationCenter.default.addObserver(
+ forName: NSApplication.didChangeScreenParametersNotification, object: nil, queue: .main
+ ) { [weak self] _ in
+ Task { @MainActor in self?.moveToTargetScreen(choice: AppState.shared.islandDisplay) }
+ }
+ }
+
+ // MARK: - Screen choice
+
+ private func moveToTargetScreen(choice: IslandDisplayChoice) {
+ guard !inAttachDrag, attachDragStart == nil else { return }
+ relocate(to: Self.targetScreen(for: choice))
+ }
+
+ /// Recomputes the resting geometry for `screen` and moves the panel to its top centre.
+ /// Always re-applied, even on the same screen: its menu bar or resolution may have changed.
+ private func relocate(to screen: NSScreen) {
+ guard let panel = window as? IslandPanel else { return }
+ let geometry = Self.screenGeometry(for: screen)
+ notchW = geometry.width
+ notchH = geometry.height
+ hasNotch = geometry.hasNotch
+ panel.notchWidth = notchW
+ panel.notchHeight = notchH
+ AppState.shared.notchWidth = notchW
+ AppState.shared.notchHeight = notchH
+ AppState.shared.hasNotch = hasNotch
+ Self.currentScreen = screen
+
+ let sf = screen.frame
+ let size = panel.frame.size
+ panel.setFrame(NSRect(x: sf.midX - size.width/2, y: sf.maxY - size.height,
+ width: size.width, height: size.height), display: true)
+ // notchWidth/hasNotch are not @Published: tell the views to resize the island.
+ NotificationCenter.default.post(name: .islandScreenChanged, object: nil)
+ state.objectWillChange.send()
+ }
+
+ /// Follow-the-mouse mode: hop to the cursor's screen while the island is not open,
+ /// so an approval or a chat never jumps away mid-click.
+ private func followMouseIfNeeded(_ mouse: NSPoint) {
+ guard state.islandDisplay == .followMouse,
+ state.mode != .expanded, !inAttachDrag, attachDragStart == nil else { return }
+ if let current = Self.currentScreen, current.frame.contains(mouse) { return }
+ guard let target = NSScreen.screens.first(where: { $0.frame.contains(mouse) }),
+ target != Self.currentScreen else { return }
+ relocate(to: target)
}
// MARK: - FSM wiring
@@ -221,6 +280,7 @@ final class IslandWindowController: NSWindowController {
guard let panel = window as? IslandPanel else { return }
let mouse = NSEvent.mouseLocation
+ followMouseIfNeeded(mouse)
// Convert mouse to panel-local coords (macOS: origin bottom-left)
let pf = panel.frame
@@ -1044,6 +1104,35 @@ final class IslandWindowController: NSWindowController {
NSScreen.screens.first { $0.safeAreaInsets.top > 0 }
}
+ /// Screen the island currently sits on (Settings window, desktop Mochi flights).
+ private(set) static var currentScreen: NSScreen?
+
+ static func islandScreen() -> NSScreen {
+ if let s = currentScreen, NSScreen.screens.contains(s) { return s }
+ return notchScreen() ?? NSScreen.main!
+ }
+
+ /// Screen matching the user's choice; falls back to the notch screen, then the main one.
+ static func targetScreen(for choice: IslandDisplayChoice) -> NSScreen {
+ let screens = NSScreen.screens
+ let mouse = NSEvent.mouseLocation
+ let candidates = screens.map {
+ IslandDisplayCandidate(uuid: displayUUID($0), hasNotch: $0.safeAreaInsets.top > 0,
+ containsMouse: $0.frame.contains(mouse))
+ }
+ if let i = IslandDisplayResolver.index(for: choice, in: candidates) { return screens[i] }
+ return notchScreen() ?? NSScreen.main ?? screens[0]
+ }
+
+ /// Stable display UUID (the NSScreenNumber can change after a reboot or a replug).
+ static func displayUUID(_ screen: NSScreen) -> String? {
+ let key = NSDeviceDescriptionKey("NSScreenNumber")
+ guard let number = screen.deviceDescription[key] as? NSNumber,
+ let uuid = CGDisplayCreateUUIDFromDisplayID(number.uint32Value)?.takeRetainedValue()
+ else { return nil }
+ return CFUUIDCreateString(nil, uuid) as String
+ }
+
static func screenGeometry(for screen: NSScreen) -> IslandScreenGeometry {
let visibleMenuBarHeight = screen.frame.maxY - screen.visibleFrame.maxY
// visibleFrame includes the menu bar only while it is visible. Keep a
@@ -1136,6 +1225,8 @@ extension Notification.Name {
static let greetingHover = Notification.Name("notchBuddy.greetingHover")
static let greetingInterrupt = Notification.Name("notchBuddy.greetingInterrupt")
static let openWardrobeFromDesktop = Notification.Name("notchBuddy.openWardrobeFromDesktop")
+ // Island moved to another screen (resting size may differ: notch vs bar)
+ static let islandScreenChanged = Notification.Name("notchBuddy.islandScreenChanged")
}
// MARK: - islandSize (takes real notch dimensions)
diff --git a/NotchBuddy/Sources/App/SettingsView.swift b/NotchBuddy/Sources/App/SettingsView.swift
index 9a3d0408..36387a53 100644
--- a/NotchBuddy/Sources/App/SettingsView.swift
+++ b/NotchBuddy/Sources/App/SettingsView.swift
@@ -93,6 +93,9 @@ struct SettingsView: View {
)
}
+ // Connected screens for the Display picker, refreshed when screens change
+ @State private var connectedScreens: [(uuid: String, name: String)] = []
+
// Sidebar selection persisted across sessions
@AppStorage("settingsSection") private var selectedSection: String = "general"
#if PHONE_LINK
@@ -262,6 +265,35 @@ struct SettingsView: View {
.padding(6)
}
+ GroupBox("Display") {
+ VStack(alignment: .leading, spacing: 10) {
+ Picker("Show Mochi on", selection: $state.islandDisplay) {
+ Text("Screen with the notch").tag(IslandDisplayChoice.notch)
+ Text("Main screen (menu bar)").tag(IslandDisplayChoice.menuBar)
+ Text("Follow the mouse").tag(IslandDisplayChoice.followMouse)
+ Divider()
+ ForEach(connectedScreens, id: \.uuid) { screen in
+ Text(screen.name).tag(IslandDisplayChoice.display(uuid: screen.uuid))
+ }
+ if case .display(let uuid) = state.islandDisplay,
+ !connectedScreens.contains(where: { $0.uuid == uuid }) {
+ Text("Saved screen (not connected)").tag(state.islandDisplay)
+ }
+ }
+ .frame(maxWidth: 360)
+ Text("On a screen without a notch, Mochi sits in a small bar at the top. Follow the mouse moves it to your cursor's screen while it is closed.")
+ .font(.system(size: 11))
+ .foregroundColor(.secondary)
+ .fixedSize(horizontal: false, vertical: true)
+ }
+ .padding(6)
+ .onAppear { refreshConnectedScreens() }
+ .onReceive(NotificationCenter.default.publisher(
+ for: NSApplication.didChangeScreenParametersNotification)) { _ in
+ refreshConnectedScreens()
+ }
+ }
+
GroupBox("Hotkey") {
VStack(alignment: .leading, spacing: 10) {
Toggle("Show island with shortcut", isOn: $state.hotkeyEnabled)
@@ -327,6 +359,13 @@ struct SettingsView: View {
#endif
}
+ private func refreshConnectedScreens() {
+ connectedScreens = NSScreen.screens.compactMap { screen in
+ guard let uuid = IslandWindowController.displayUUID(screen) else { return nil }
+ return (uuid, screen.localizedName)
+ }
+ }
+
// MARK: - Active pills section
@ViewBuilder private var activePillsSection: some View {
diff --git a/README.md b/README.md
index abf6f8cd..68312267 100644
--- a/README.md
+++ b/README.md
@@ -49,7 +49,7 @@ Meet **Mochi**: a soft little squircle with big eyes that pops out of your notch
- ⌨️ **Keyboard shortcuts** — open the chat, jump to an alert or a terminal, switch pills, mute, send Mochi to the desktop or open the wardrobe from anywhere; all customizable in Settings → Shortcuts.
- 🎭 **A real character** — idle breathing, blinks, eyes on a sphere that follow your mouse, emotes, 28 handcrafted sounds, a greeting on launch.
- 🫥 **Invisible when idle** — hides away when nothing is running, peeks out when you hover the notch (the top edge of the screen on Windows and Linux).
-- 🖥️ **Any Mac, notch or not** — on an iMac, a Mac mini, or a MacBook with its lid closed on an external display, Mochi sits in a small bar at the top of the screen.
+- 🖥️ **Any Mac, notch or not** — on an iMac, a Mac mini, or a MacBook with its lid closed on an external display, Mochi sits in a small bar at the top of the screen. With several displays, pick his screen in Settings → General, or let him follow your mouse *(macOS)*.
- 🔒 **Private by design** — no telemetry, no account. Keys live in your macOS Keychain, Windows Credential Manager or Linux Secret Service (GNOME Keyring, KWallet). The app only talks to the services you plug in.
<table>
diff --git a/docs/SPEC.md b/docs/SPEC.md
index e2a511a1..59c65ed3 100644
--- a/docs/SPEC.md
+++ b/docs/SPEC.md
@@ -8,10 +8,17 @@ Toutes les mesures sont en points macOS. Les valeurs viennent de `reference/notc
- Une `NSPanel` sans bordure : `styleMask [.borderless, .nonactivatingPanel]`, fond transparent, sans ombre, niveau au-dessus de la barre de menus (`.mainMenu + 3` ou équivalent qui passe au-dessus de la barre et des apps plein écran), `collectionBehavior [.canJoinAllSpaces, .stationary, .fullScreenAuxiliary, .ignoresCycle]`.
- Taille fixe 720 × 320, ancrée en haut au centre de l'écran qui a un notch. L'island est dessinée dedans, collée au bord haut.
+- **Choix de l'écran** (`AppState.islandDisplay`, UserDefaults `islandDisplay`, réglage **Display** dans General) :
+ - `notch` (défaut) : écran avec notch, sinon écran principal. Comportement historique.
+ - `menuBar` : l'écran qui porte la barre de menus (`NSScreen.screens[0]`).
+ - `display:<UUID>` : un écran précis, identifié par `CGDisplayCreateUUIDFromDisplayID` (stable après redémarrage, contrairement à `NSScreenNumber`). Écran débranché → repli sur l'écran avec notch, puis l'écran principal ; il revient dès qu'il est rebranché.
+ - `followMouse` : l'island passe sur l'écran du curseur, uniquement en `hidden` ou `compact` et hors glisser-déposer de Mochi. Ouverte (approbation, chat, salut…), elle ne bouge pas. Vérifié dans la boucle 60 Hz existante, sans timer supplémentaire.
+ - Résolution pure dans `IslandDisplayResolver` (`IslandDisplayChoice.swift`, testé par `scripts/test-display-choice.sh`). `IslandWindowController.relocate(to:)` recalcule la géométrie (notch ou barre), déplace la panel et poste `.islandScreenChanged` pour que `IslandContainer` reprenne ses dimensions au repos.
+ - Recalcul à chaque `NSApplication.didChangeScreenParametersNotification` (écran branché ou débranché, capot fermé, résolution, disposition). La fenêtre Réglages et les envols de Mochi sur le bureau visent l'écran courant de l'island (`IslandWindowController.islandScreen()`).
- **Clics traversants** : la zone transparente ne doit jamais bloquer les clics. Toggle `ignoresMouseEvents` à 60 Hz selon que `NSEvent.mouseLocation` est dans la forme de l'island (plus 6 pt de marge) ou pas.
- La panel peut devenir key uniquement quand un champ texte de l'island a le focus (prompt, mail). Sinon elle ne vole jamais le focus.
- Détection du notch : `NSScreen.safeAreaInsets.top` > 0 et `auxiliaryTopLeftArea` / `auxiliaryTopRightArea`. Largeur du notch `wN` = largeur écran − les deux zones auxiliaires ; hauteur `hN` = `safeAreaInsets.top`. Le prototype utilise `wN = 184`, `hN = 32` : dans l'app, prendre les vraies valeurs.
-- Pas d'écran avec notch (Mac de bureau, écran externe ou capot fermé) : afficher sur l'écran principal une barre noire de 80 pt au repos (`hidden`), avec Mochi visible au centre et son animation en pause ; 240 pt en `compact`, en haut au centre. Hauteur plafonnée à 24 pt et à celle de la barre de menus ; personnage et pastilles adaptés à cette hauteur. Le salut se replie vers les dimensions réelles de la barre compacte. La zone de survol au repos ne déborde pas sous la barre. Les vues ouvertes gardent leur largeur de 640 pt.
+- Pas d'écran avec notch (Mac de bureau, écran externe ou capot fermé), ou écran sans notch choisi dans **Display** : afficher sur cet écran une barre noire de 80 pt au repos (`hidden`), avec Mochi visible au centre et son animation en pause ; 240 pt en `compact`, en haut au centre. Hauteur plafonnée à 24 pt et à celle de la barre de menus ; personnage et pastilles adaptés à cette hauteur. Le salut se replie vers les dimensions réelles de la barre compacte. La zone de survol au repos ne déborde pas sous la barre. Les vues ouvertes gardent leur largeur de 640 pt.
- Suivi de la souris : polling de `NSEvent.mouseLocation` à chaque frame. Aucune permission nécessaire.
### Forme de l'island
@@ -234,6 +241,7 @@ Fenêtre Réglages (SwiftUI, simple), sections dans l'ordre d'affichage :
- **Integrations** : clé ou token (Trousseau) pour chaque service (n8n, Stripe, GitHub, Vercel, Resend, Notion, Cal.com).
- **Sound** : son on/off, volume.
- **Behavior** : fermeture après N s d'inactivité ; masquage après N min sans mouvement.
+- **Display** : écran de l'island — Screen with the notch (défaut), Main screen (menu bar), Follow the mouse, ou un écran précis par son nom (`NSScreen.localizedName`). Un écran mémorisé mais débranché s'affiche « Saved screen (not connected) ». Voir §1.
- **Active pills** : pastilles actives (VS Code toujours actif + jusqu'à 4 autres) ; sélecteur de pastille principale (affiché uniquement si une pastille workspace est active) ; liste par catégorie (voir catalogue §5).
- **Hotkey** : raccourci global pour ouvrir le notch.
- **Startup** : lancer au démarrage (`SMAppService.mainApp`).
diff --git a/scripts/test-display-choice.sh b/scripts/test-display-choice.sh
new file mode 100755
index 00000000..6ec5ab5d
--- /dev/null
+++ b/scripts/test-display-choice.sh
@@ -0,0 +1,8 @@
+#!/usr/bin/env bash
+set -euo pipefail
+cd "$(dirname "$0")/.."
+TEST_DIR="$(mktemp -d "${TMPDIR:-/tmp}/coucou-display.XXXXXX")"
+trap 'rm -rf "$TEST_DIR"' EXIT
+swiftc NotchBuddy/Sources/App/IslandDisplayChoice.swift \
+ tests/IslandDisplayChoiceTests.swift -o "$TEST_DIR/display-tests"
+"$TEST_DIR/display-tests"
diff --git a/tests/IslandDisplayChoiceTests.swift b/tests/IslandDisplayChoiceTests.swift
new file mode 100644
index 00000000..b28db7e9
--- /dev/null
+++ b/tests/IslandDisplayChoiceTests.swift
@@ -0,0 +1,42 @@
+import Foundation
+
+@main
+enum IslandDisplayChoiceTests {
+ static func main() {
+ // Storage round-trip, unknown values fall back to the notch default.
+ for choice: IslandDisplayChoice in [.notch, .menuBar, .followMouse, .display(uuid: "ABC-123")] {
+ precondition(IslandDisplayChoice(storageValue: choice.storageValue) == choice)
+ }
+ precondition(IslandDisplayChoice(storageValue: "") == .notch)
+ precondition(IslandDisplayChoice(storageValue: "garbage") == .notch)
+ precondition(IslandDisplayChoice(storageValue: "display:") == .notch)
+
+ // External screen holds the menu bar, MacBook (with notch) is second, mouse on the third.
+ let screens = [
+ IslandDisplayCandidate(uuid: "EXT-1", hasNotch: false, containsMouse: false),
+ IslandDisplayCandidate(uuid: "MBP", hasNotch: true, containsMouse: false),
+ IslandDisplayCandidate(uuid: "EXT-2", hasNotch: false, containsMouse: true),
+ ]
+ precondition(IslandDisplayResolver.index(for: .notch, in: screens) == 1)
+ precondition(IslandDisplayResolver.index(for: .menuBar, in: screens) == 0)
+ precondition(IslandDisplayResolver.index(for: .followMouse, in: screens) == 2)
+ precondition(IslandDisplayResolver.index(for: .display(uuid: "EXT-2"), in: screens) == 2)
+
+ // A disconnected chosen screen falls back to the notch screen.
+ precondition(IslandDisplayResolver.index(for: .display(uuid: "GONE"), in: screens) == 1)
+
+ // No notch anywhere (lid closed): nil means "use the main screen".
+ let desk = [
+ IslandDisplayCandidate(uuid: "EXT-1", hasNotch: false, containsMouse: false),
+ IslandDisplayCandidate(uuid: "EXT-2", hasNotch: false, containsMouse: false),
+ ]
+ precondition(IslandDisplayResolver.index(for: .notch, in: desk) == nil)
+ precondition(IslandDisplayResolver.index(for: .display(uuid: "GONE"), in: desk) == nil)
+ // Mouse between screens (rounding at an edge): keep the default.
+ precondition(IslandDisplayResolver.index(for: .followMouse, in: desk) == nil)
+
+ precondition(IslandDisplayResolver.index(for: .menuBar, in: []) == nil)
+
+ print("IslandDisplayChoice tests passed")
+ }
+}