|
|
|
@ -28,6 +28,11 @@ public final class HUDOverlayController { |
|
|
|
NotificationCenter.default.addObserver(forName: NSApplication.didChangeScreenParametersNotification, object: nil, queue: .main) { [weak self] _ in |
|
|
|
self?.reposition() |
|
|
|
} |
|
|
|
NSWorkspace.shared.notificationCenter.addObserver(forName: NSWorkspace.activeSpaceDidChangeNotification, object: nil, queue: .main) { [weak self] _ in |
|
|
|
guard let self = self, self.isVisible, let window = self.window else { return } |
|
|
|
self.reposition() |
|
|
|
self.bringToTopOfAllSpaces(window) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@ -40,8 +45,16 @@ public final class HUDOverlayController { |
|
|
|
) |
|
|
|
panel.isOpaque = false |
|
|
|
panel.backgroundColor = .clear |
|
|
|
panel.level = .statusBar |
|
|
|
panel.collectionBehavior = [.canJoinAllSpaces, .fullScreenAuxiliary, .stationary] |
|
|
|
// Critical for Full-Screen Spaces & modal dialogs: |
|
|
|
// 1) NSPanel defaults hidesOnDeactivate=true (hides whenever another app is active/full-screen!) |
|
|
|
panel.hidesOnDeactivate = false |
|
|
|
panel.canHide = false |
|
|
|
panel.isFloatingPanel = true |
|
|
|
panel.becomesKeyOnlyIfNeeded = true |
|
|
|
panel.worksWhenModal = true |
|
|
|
// 2) ScreenSaver level (1000) renders reliably above ALL Full-Screen apps, video players, Dock, and popups |
|
|
|
panel.level = NSWindow.Level(rawValue: Int(CGWindowLevelForKey(.screenSaverWindow))) |
|
|
|
panel.collectionBehavior = [.canJoinAllSpaces, .fullScreenAuxiliary, .stationary, .ignoresCycle] |
|
|
|
panel.hasShadow = false |
|
|
|
panel.ignoresMouseEvents = true |
|
|
|
panel.alphaValue = 0.0 |
|
|
|
@ -58,10 +71,25 @@ public final class HUDOverlayController { |
|
|
|
reposition() |
|
|
|
} |
|
|
|
|
|
|
|
private func activeTargetScreen() -> NSScreen? { |
|
|
|
let mouseLoc = NSEvent.mouseLocation |
|
|
|
if let underMouse = NSScreen.screens.first(where: { NSMouseInRect(mouseLoc, $0.frame, false) }) { |
|
|
|
return underMouse |
|
|
|
} |
|
|
|
return NSScreen.main ?? NSScreen.screens.first |
|
|
|
} |
|
|
|
|
|
|
|
private func bringToTopOfAllSpaces(_ window: NSPanel) { |
|
|
|
window.hidesOnDeactivate = false |
|
|
|
window.level = NSWindow.Level(rawValue: Int(CGWindowLevelForKey(.screenSaverWindow))) |
|
|
|
window.collectionBehavior = [.canJoinAllSpaces, .fullScreenAuxiliary, .stationary, .ignoresCycle] |
|
|
|
window.orderFrontRegardless() |
|
|
|
} |
|
|
|
|
|
|
|
private func reposition() { |
|
|
|
guard let window = self.window, let screen = NSScreen.main ?? NSScreen.screens.first else { return } |
|
|
|
guard let window = self.window, let screen = activeTargetScreen() else { return } |
|
|
|
let screenRect = screen.visibleFrame |
|
|
|
// Center horizontally, positioned comfortably higher above dock |
|
|
|
// Center horizontally, positioned comfortably higher above dock / full-screen bottom edge |
|
|
|
let x = screenRect.midX - (canvasSize / 2.0) |
|
|
|
let y = screenRect.minY + 68 |
|
|
|
window.setFrameOrigin(NSPoint(x: x, y: y)) |
|
|
|
@ -84,8 +112,8 @@ public final class HUDOverlayController { |
|
|
|
self.hideImmediately() |
|
|
|
|
|
|
|
case .recording(let level, let isLagging, let pingQuality): |
|
|
|
if !self.isVisible || window.alphaValue < 0.95 { |
|
|
|
window.orderFrontRegardless() |
|
|
|
if !self.isVisible || window.alphaValue < 0.95 || !window.isOnActiveSpace { |
|
|
|
self.bringToTopOfAllSpaces(window) |
|
|
|
window.alphaValue = 1.0 |
|
|
|
self.isVisible = true |
|
|
|
HotkeyManager.shared.setEscapeMonitoringActive(true) |
|
|
|
@ -93,8 +121,8 @@ public final class HUDOverlayController { |
|
|
|
orb.updateAudioLevel(level, isLagging: isLagging, pingQuality: pingQuality) |
|
|
|
|
|
|
|
case .retrying(let reason): |
|
|
|
if !self.isVisible || window.alphaValue < 0.95 { |
|
|
|
window.orderFrontRegardless() |
|
|
|
if !self.isVisible || window.alphaValue < 0.95 || !window.isOnActiveSpace { |
|
|
|
self.bringToTopOfAllSpaces(window) |
|
|
|
window.alphaValue = 1.0 |
|
|
|
self.isVisible = true |
|
|
|
HotkeyManager.shared.setEscapeMonitoringActive(true) |
|
|
|
@ -102,8 +130,8 @@ public final class HUDOverlayController { |
|
|
|
orb.showRetryState(reason: reason) |
|
|
|
|
|
|
|
case .transcribing: |
|
|
|
if !self.isVisible || window.alphaValue < 0.95 { |
|
|
|
window.orderFrontRegardless() |
|
|
|
if !self.isVisible || window.alphaValue < 0.95 || !window.isOnActiveSpace { |
|
|
|
self.bringToTopOfAllSpaces(window) |
|
|
|
window.alphaValue = 1.0 |
|
|
|
self.isVisible = true |
|
|
|
HotkeyManager.shared.setEscapeMonitoringActive(true) |
|
|
|
@ -111,6 +139,9 @@ public final class HUDOverlayController { |
|
|
|
orb.showTranscribingState() |
|
|
|
|
|
|
|
case .success: |
|
|
|
if !window.isOnActiveSpace { |
|
|
|
self.bringToTopOfAllSpaces(window) |
|
|
|
} |
|
|
|
orb.showSuccessState() |
|
|
|
let work = DispatchWorkItem { [weak self] in |
|
|
|
self?.hide() |
|
|
|
@ -119,8 +150,8 @@ public final class HUDOverlayController { |
|
|
|
DispatchQueue.main.asyncAfter(deadline: .now() + 0.35, execute: work) |
|
|
|
|
|
|
|
case .error(let message): |
|
|
|
if !self.isVisible || window.alphaValue < 0.95 { |
|
|
|
window.orderFrontRegardless() |
|
|
|
if !self.isVisible || window.alphaValue < 0.95 || !window.isOnActiveSpace { |
|
|
|
self.bringToTopOfAllSpaces(window) |
|
|
|
window.alphaValue = 1.0 |
|
|
|
self.isVisible = true |
|
|
|
HotkeyManager.shared.setEscapeMonitoringActive(true) |
|
|
|
|