diff --git a/NotchBuddy/Sources/App/IslandWindowController.swift b/NotchBuddy/Sources/App/IslandWindowController.swift index 8c99fd7..22ff634 100644 --- a/NotchBuddy/Sources/App/IslandWindowController.swift +++ b/NotchBuddy/Sources/App/IslandWindowController.swift @@ -303,6 +303,7 @@ final class IslandWindowController: NSWindowController { } // Mouse in screen coords (Y flipped, origin top-left) for Bot look-at + Self.islandScreenFrame = panel.screen?.frame 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) let cur = AppState.shared.mousePosition @@ -363,6 +364,21 @@ final class IslandWindowController: NSWindowController { private var lastMouse: CGPoint = .zero + /// Mochi's look target from the current mouse position, in the same coordinates the poll + /// uses (the island's screen, y from its top). + /// Frame of the screen the island is on, kept by the poll. + static var islandScreenFrame: CGRect? + + static func trackMouseLook() { + let app = AppState.shared + guard app.mode != .hidden || app.mochiOnDesktop else { return } + guard let frame = islandScreenFrame ?? NSScreen.main?.frame else { return } + let mouse = NSEvent.mouseLocation + let pos = CGPoint(x: mouse.x - frame.minX, y: frame.height - mouse.y) + let cur = app.mousePosition + if abs(pos.x - cur.x) > 1 || abs(pos.y - cur.y) > 1 { app.mousePosition = pos } + } + // MARK: - Bot-head hover (love emote — mirrors prototype botHover()) private func botHoverIn(mousePos: CGPoint) { @@ -719,6 +735,17 @@ final class IslandWindowController: NSWindowController { self?.handleDizzy() } + // Eye tracking at the mouse's own rate (from upstream b5b04c2): the look target + // followed the island poll (10–30 Hz), so the head turned in steps. Nothing runs while + // the mouse is still; a hidden island skips the work. + NSEvent.addGlobalMonitorForEvents(matching: [.mouseMoved, .leftMouseDragged]) { _ in + MainActor.assumeIsolated { IslandWindowController.trackMouseLook() } + } + NSEvent.addLocalMonitorForEvents(matching: [.mouseMoved, .leftMouseDragged]) { event in + MainActor.assumeIsolated { IslandWindowController.trackMouseLook() } + return event + } + // Window attach drag. // Uses MainActor.assumeIsolated (synchronous) to avoid race with pollFrame(). // Global mouseUp is the reliable fallback when cursor is outside our panel frame.