mirror of
https://github.com/morgan9e/macos-stats
synced 2026-04-14 00:04:15 +09:00
feat: improved popup toggling when clicking the same module widgets. When modules have a few widgets enabled and opened popup view, clicking on another widget the popup disappear. Now click will reopen popup view on the target widget, not close the view.
This commit is contained in:
@@ -282,7 +282,13 @@ open class Module: Module_p {
|
||||
let openedWindows = NSApplication.shared.windows.filter{ $0 is NSPanel }
|
||||
openedWindows.forEach{ $0.setIsVisible(false) }
|
||||
|
||||
if popup.occlusionState.rawValue == 8192 {
|
||||
var reopen: Bool = false
|
||||
if let widget = notification.userInfo?["widget"] as? widget_t {
|
||||
reopen = popup.openedBy != nil && popup.openedBy != widget
|
||||
popup.openedBy = widget
|
||||
}
|
||||
|
||||
if popup.occlusionState.rawValue == 8192 || reopen {
|
||||
NSApplication.shared.activate(ignoringOtherApps: true)
|
||||
|
||||
popup.contentView?.invalidateIntrinsicContentSize()
|
||||
@@ -300,6 +306,7 @@ open class Module: Module_p {
|
||||
popup.setIsVisible(true)
|
||||
} else {
|
||||
popup.locked = false
|
||||
popup.openedBy = nil
|
||||
popup.setIsVisible(false)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@ public protocol Popup_p: NSView {
|
||||
internal class PopupWindow: NSWindow, NSWindowDelegate {
|
||||
private let viewController: PopupViewController = PopupViewController()
|
||||
internal var locked: Bool = false
|
||||
internal var openedBy: widget_t? = nil
|
||||
|
||||
init(title: String, view: Popup_p?, visibilityCallback: @escaping (_ state: Bool) -> Void) {
|
||||
self.viewController.setup(title: title, view: view)
|
||||
|
||||
@@ -327,6 +327,7 @@ public class Widget {
|
||||
if let item = self.menuBarItem, let window = item.button?.window {
|
||||
NotificationCenter.default.post(name: .togglePopup, object: nil, userInfo: [
|
||||
"module": self.module,
|
||||
"widget": self.type,
|
||||
"origin": window.frame.origin,
|
||||
"center": window.frame.width/2
|
||||
])
|
||||
|
||||
Reference in New Issue
Block a user