From 08949d136cb5a75c3068188bf7826de8ee7860a8 Mon Sep 17 00:00:00 2001 From: maksarsanjeev Date: Wed, 14 Oct 2026 00:13:48 +0300 Subject: [PATCH] Memoji follows every mouse move (from upstream b5b04c2) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The look target came from the island poll (10–30 Hz), so the head turned in steps; mouse-moved monitors now update it on every move. The upstream step-debt frame clock fix (956413f) doesn't apply: BroV never had that clock, its engine steps by real elapsed time. Co-Authored-By: Claude Opus 5.5 --- .../Sources/App/IslandWindowController.swift | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) 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.