Ocideck/macos/Runner/MainFlutterWindow.swift
Brenno de Winter 280934d331 Deliver hover events to non-key windows on macOS
Flutter's macOS engine only sends mouse-moved events to the key window
by default. The borderless audience (beamer) window deliberately never
becomes key, so chart tooltips never appeared on the second screen, and
hover styling stuck around whenever a window lost key status before the
exit event arrived. Track the mouse whenever the app is active instead,
for both the main window and every secondary window.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-06-10 11:29:42 +02:00

27 lines
1 KiB
Swift

import Cocoa
import FlutterMacOS
import desktop_multi_window
class MainFlutterWindow: NSWindow {
override func awakeFromNib() {
let flutterViewController = FlutterViewController()
// Keep hover events flowing while this window is not key (e.g. when a
// dialog or the beamer window is in front): otherwise an element that was
// hovered when the window lost key status keeps its hover styling because
// the matching exit event is never delivered.
flutterViewController.mouseTrackingMode = .inActiveApp
let windowFrame = self.frame
self.contentViewController = flutterViewController
self.setFrame(windowFrame, display: true)
RegisterGeneratedPlugins(registry: flutterViewController)
// Register the app's plugins in every sub-window (e.g. the audience/beamer
// window) too, so video_player, image loading, etc. work there as well.
FlutterMultiWindowPlugin.setOnWindowCreatedCallback { controller in
RegisterGeneratedPlugins(registry: controller)
}
super.awakeFromNib()
}
}