Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion panel/Panel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -961,6 +961,7 @@ final class PanelController: NSObject, NSApplicationDelegate, PanelKeyDelegate,
}

func showPanel() {
positionPanel() // re-resolve in case the user moved to a different display
NSApp.activate(ignoringOtherApps: true)
panel.makeKeyAndOrderFront(nil)
}
Expand All @@ -975,7 +976,7 @@ final class PanelController: NSObject, NSApplicationDelegate, PanelKeyDelegate,
// MARK: - Setup helpers

private func positionPanel() {
guard let screen = NSScreen.main else { return }
let screen = activeScreen()
let visible = screen.visibleFrame
let size = panel.frame.size
let origin = NSPoint(
Expand All @@ -985,6 +986,19 @@ final class PanelController: NSObject, NSApplicationDelegate, PanelKeyDelegate,
panel.setFrameOrigin(origin)
}

// Pick the screen the user is most likely looking at: the one under
// the mouse cursor. Falls back to NSScreen.main if for some reason we
// can't resolve a screen (e.g., headless or screens just being
// reconfigured). Cursor location works regardless of which app or
// window has focus, and is what most multi-screen mac apps use.
private func activeScreen() -> NSScreen {
let mouse = NSEvent.mouseLocation
if let match = NSScreen.screens.first(where: { $0.frame.contains(mouse) }) {
return match
}
return NSScreen.main ?? NSScreen.screens.first ?? panel.screen ?? NSScreen()
}

private func startListener() {
let installDir = ("~/.stack-nudge" as NSString).expandingTildeInPath
try? FileManager.default.createDirectory(
Expand Down