mirror of
https://github.com/gosticks/Popover.git
synced 2025-10-16 11:55:38 +00:00
Enable showing the popover without taking application focus and keeping the popover visible without disabling right click
This commit is contained in:
parent
b30566900b
commit
dee3296f9e
@ -12,11 +12,7 @@ public class Popover: NSObject {
|
|||||||
return popoverWindowController?.window
|
return popoverWindowController?.window
|
||||||
}
|
}
|
||||||
|
|
||||||
public var keepPopoverVisible: Bool = false {
|
public var keepPopoverVisible: Bool = false
|
||||||
didSet {
|
|
||||||
keepPopoverVisible ? removeMonitors() : setupMonitors()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@objc dynamic var item: NSStatusItem! {
|
@objc dynamic var item: NSStatusItem! {
|
||||||
didSet {
|
didSet {
|
||||||
@ -90,10 +86,14 @@ public class Popover: NSObject {
|
|||||||
localEventMonitor?.start()
|
localEventMonitor?.start()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Shows the Popover with no animation
|
|
||||||
public func show() {
|
public func show() {
|
||||||
|
self.show(withFocus: true)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Shows the Popover with no animation
|
||||||
|
public func show(withFocus: Bool) {
|
||||||
guard !isPopoverWindowVisible else { return }
|
guard !isPopoverWindowVisible else { return }
|
||||||
popoverWindowController?.show()
|
popoverWindowController?.show(withFocus: withFocus)
|
||||||
globalEventMonitor?.start()
|
globalEventMonitor?.start()
|
||||||
|
|
||||||
guard let button = item.button else { return }
|
guard let button = item.button else { return }
|
||||||
@ -117,7 +117,9 @@ public class Popover: NSObject {
|
|||||||
private func setupMonitors() {
|
private func setupMonitors() {
|
||||||
globalEventMonitor = EventMonitor(monitorType: .global, mask: [.leftMouseDown, .rightMouseDown], globalHandler: { [weak self] _ in
|
globalEventMonitor = EventMonitor(monitorType: .global, mask: [.leftMouseDown, .rightMouseDown], globalHandler: { [weak self] _ in
|
||||||
guard let self = self else { return }
|
guard let self = self else { return }
|
||||||
self.dismiss()
|
if (!self.keepPopoverVisible) {
|
||||||
|
self.dismiss()
|
||||||
|
}
|
||||||
}, localHandler: nil)
|
}, localHandler: nil)
|
||||||
|
|
||||||
if menuItems != nil, menuItems?.isNotEmpty ?? false {
|
if menuItems != nil, menuItems?.isNotEmpty ?? false {
|
||||||
@ -167,7 +169,7 @@ public class Popover: NSObject {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@objc private func handleStatusItemButtonAction(_ sender: Any?) {
|
@objc private func handleStatusItemButtonAction(_ sender: Any?) {
|
||||||
isPopoverWindowVisible ? dismiss() : show()
|
isPopoverWindowVisible ? dismiss() : show(withFocus: true)
|
||||||
}
|
}
|
||||||
|
|
||||||
private func setTargetAction(for button: NSButton) {
|
private func setTargetAction(for button: NSButton) {
|
||||||
|
|||||||
@ -28,14 +28,18 @@ class PopoverWindowController: NSWindowController, NSWindowDelegate {
|
|||||||
fatalError("init(coder:) has not been implemented")
|
fatalError("init(coder:) has not been implemented")
|
||||||
}
|
}
|
||||||
|
|
||||||
func show() {
|
func show(withFocus: Bool) {
|
||||||
guard !isAnimating else { return }
|
guard !isAnimating else { return }
|
||||||
|
|
||||||
updateWindowFrame()
|
updateWindowFrame()
|
||||||
|
|
||||||
showWindow(nil)
|
if (withFocus) {
|
||||||
|
showWindow(nil)
|
||||||
|
window?.makeKey()
|
||||||
|
} else {
|
||||||
|
window?.orderFrontRegardless()
|
||||||
|
}
|
||||||
windowIsOpen = true
|
windowIsOpen = true
|
||||||
window?.makeKey()
|
|
||||||
// TODO: animation
|
// TODO: animation
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user