feat: show stippled centering guides while dragging launcher
This commit is contained in:
@@ -15,6 +15,7 @@ final class LauncherWindowController: NSWindowController, NSWindowDelegate, NSSe
|
||||
private var discoveryTask: Task<Void, Never>?
|
||||
private var isLaunching = false
|
||||
private var previousApplication: NSRunningApplication?
|
||||
private var alignmentGuides: LauncherAlignmentGuides?
|
||||
|
||||
init(history: LaunchHistory = LaunchHistory()) {
|
||||
self.history = history
|
||||
@@ -39,6 +40,7 @@ final class LauncherWindowController: NSWindowController, NSWindowDelegate, NSSe
|
||||
window.delegate = self
|
||||
window.navigateSelection = { [weak self] offset in self?.moveSelection(by: offset) }
|
||||
window.dismiss = { [weak self] in self?.dismiss() }
|
||||
window.dragEnded = { [weak self] in self?.alignmentGuides?.end() }
|
||||
}
|
||||
|
||||
required init?(coder: NSCoder) {
|
||||
@@ -72,6 +74,7 @@ final class LauncherWindowController: NSWindowController, NSWindowDelegate, NSSe
|
||||
|
||||
func dismiss(restoringFocus: Bool = true) {
|
||||
guard !restoringFocus || (!isLaunching && window?.attachedSheet == nil) else { return }
|
||||
alignmentGuides?.end()
|
||||
let previous = previousApplication
|
||||
previousApplication = nil
|
||||
window?.orderOut(nil)
|
||||
@@ -81,6 +84,18 @@ final class LauncherWindowController: NSWindowController, NSWindowDelegate, NSSe
|
||||
}
|
||||
}
|
||||
|
||||
func windowWillMove(_ notification: Notification) {
|
||||
guard let window else { return }
|
||||
let guides = alignmentGuides ?? LauncherAlignmentGuides()
|
||||
alignmentGuides = guides
|
||||
guides.begin(for: window)
|
||||
}
|
||||
|
||||
func windowDidMove(_ notification: Notification) {
|
||||
guard let window else { return }
|
||||
alignmentGuides?.update(for: window)
|
||||
}
|
||||
|
||||
func windowDidResignKey(_ notification: Notification) {
|
||||
guard !isLaunching, window?.attachedSheet == nil else { return }
|
||||
dismiss(restoringFocus: false)
|
||||
@@ -473,6 +488,7 @@ private final class LauncherPanel: NSPanel {
|
||||
override var canBecomeMain: Bool { true }
|
||||
var navigateSelection: ((Int) -> Void)?
|
||||
var dismiss: (() -> Void)?
|
||||
var dragEnded: (() -> Void)?
|
||||
|
||||
override func sendEvent(_ event: NSEvent) {
|
||||
if event.type == .keyDown, attachedSheet == nil,
|
||||
@@ -489,6 +505,9 @@ private final class LauncherPanel: NSPanel {
|
||||
}
|
||||
}
|
||||
super.sendEvent(event)
|
||||
if event.type == .leftMouseDown || event.type == .leftMouseUp {
|
||||
dragEnded?()
|
||||
}
|
||||
}
|
||||
|
||||
override func performClose(_ sender: Any?) {
|
||||
|
||||
Reference in New Issue
Block a user