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:
Serhiy Mytrovtsiy
2022-11-01 14:31:20 +01:00
parent a53de49bae
commit 3ab5958685
3 changed files with 10 additions and 1 deletions

View File

@@ -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)
}
}

View File

@@ -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)

View File

@@ -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
])