Memoji follows every mouse move (from upstream b5b04c2)
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 <noreply@anthropic.com>
This commit is contained in:
@@ -303,6 +303,7 @@ final class IslandWindowController: NSWindowController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Mouse in screen coords (Y flipped, origin top-left) for Bot look-at
|
// 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 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 newPos = CGPoint(x: mouse.x - (panel.screen?.frame.minX ?? 0), y: screenH - mouse.y)
|
||||||
let cur = AppState.shared.mousePosition
|
let cur = AppState.shared.mousePosition
|
||||||
@@ -363,6 +364,21 @@ final class IslandWindowController: NSWindowController {
|
|||||||
|
|
||||||
private var lastMouse: CGPoint = .zero
|
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())
|
// MARK: - Bot-head hover (love emote — mirrors prototype botHover())
|
||||||
|
|
||||||
private func botHoverIn(mousePos: CGPoint) {
|
private func botHoverIn(mousePos: CGPoint) {
|
||||||
@@ -719,6 +735,17 @@ final class IslandWindowController: NSWindowController {
|
|||||||
self?.handleDizzy()
|
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.
|
// Window attach drag.
|
||||||
// Uses MainActor.assumeIsolated (synchronous) to avoid race with pollFrame().
|
// Uses MainActor.assumeIsolated (synchronous) to avoid race with pollFrame().
|
||||||
// Global mouseUp is the reliable fallback when cursor is outside our panel frame.
|
// Global mouseUp is the reliable fallback when cursor is outside our panel frame.
|
||||||
|
|||||||
Reference in New Issue
Block a user