4 Commits
Author SHA1 Message Date
Ivan Sapozhnik f1f68383d8 Version Increased 2021-08-05 13:28:27 +02:00
Sapozhnik Ivan 9f92012270 Merge pull request #7 from summonco/master
Enable showing the popover without taking application focus and keeping the popover visible without disabling right click
2021-08-05 13:24:19 +02:00
Islam Sharabash dee3296f9e Enable showing the popover without taking application focus and keeping the popover visible without disabling right click 2021-05-13 12:32:14 -07:00
Sapozhnik Ivan b30566900b Update README.md 2020-05-31 23:37:58 +02:00
3 changed files with 19 additions and 13 deletions
+1 -1
View File
@@ -21,7 +21,7 @@ Update your `Package.swift` dependencies:
```
dependencies: [
.package(url: "https://github.com/iSapozhnik/Popover", from: "1.0.8")
.package(url: "https://github.com/iSapozhnik/Popover", from: "1.1.1")
]
```
+11 -9
View File
@@ -12,11 +12,7 @@ public class Popover: NSObject {
return popoverWindowController?.window
}
public var keepPopoverVisible: Bool = false {
didSet {
keepPopoverVisible ? removeMonitors() : setupMonitors()
}
}
public var keepPopoverVisible: Bool = false
@objc dynamic var item: NSStatusItem! {
didSet {
@@ -90,10 +86,14 @@ public class Popover: NSObject {
localEventMonitor?.start()
}
/// Shows the Popover with no animation
public func show() {
self.show(withFocus: true)
}
/// Shows the Popover with no animation
public func show(withFocus: Bool) {
guard !isPopoverWindowVisible else { return }
popoverWindowController?.show()
popoverWindowController?.show(withFocus: withFocus)
globalEventMonitor?.start()
guard let button = item.button else { return }
@@ -117,7 +117,9 @@ public class Popover: NSObject {
private func setupMonitors() {
globalEventMonitor = EventMonitor(monitorType: .global, mask: [.leftMouseDown, .rightMouseDown], globalHandler: { [weak self] _ in
guard let self = self else { return }
self.dismiss()
if (!self.keepPopoverVisible) {
self.dismiss()
}
}, localHandler: nil)
if menuItems != nil, menuItems?.isNotEmpty ?? false {
@@ -167,7 +169,7 @@ public class Popover: NSObject {
}
@objc private func handleStatusItemButtonAction(_ sender: Any?) {
isPopoverWindowVisible ? dismiss() : show()
isPopoverWindowVisible ? dismiss() : show(withFocus: true)
}
private func setTargetAction(for button: NSButton) {
@@ -28,14 +28,18 @@ class PopoverWindowController: NSWindowController, NSWindowDelegate {
fatalError("init(coder:) has not been implemented")
}
func show() {
func show(withFocus: Bool) {
guard !isAnimating else { return }
updateWindowFrame()
showWindow(nil)
if (withFocus) {
showWindow(nil)
window?.makeKey()
} else {
window?.orderFrontRegardless()
}
windowIsOpen = true
window?.makeKey()
// TODO: animation
}