diff --git a/ModuleKit/module.swift b/ModuleKit/module.swift index 2682f5f6..0fd9eb14 100644 --- a/ModuleKit/module.swift +++ b/ModuleKit/module.swift @@ -227,7 +227,7 @@ open class Module: Module_p { self.settings?.setActiveWidget(self.widget) } - @objc private func togglePopup(_ sender: Any?) { + @objc private func togglePopup(_ sender: NSStatusBarButton) { let openedWindows = NSApplication.shared.windows.filter{ $0 is NSPanel } openedWindows.forEach{ $0.setIsVisible(false) } @@ -242,15 +242,9 @@ open class Module: Module_p { var x = buttonOrigin!.x - windowCenter + buttonCenter let y = buttonOrigin!.y - self.popup.contentView!.intrinsicContentSize.height - 3 - if let screen = NSScreen.main { - let width = screen.frame.size.width - - if x + self.popup.frame.width > width { - x = width - self.popup.frame.width - } - } - if buttonOrigin!.x - self.popup.frame.width < 0 { - x = 0 + let maxWidth = NSScreen.screens.map{ $0.frame.width }.reduce(0, +) + if x + self.popup.frame.width > maxWidth { + x = maxWidth - self.popup.frame.width - 3 } self.popup.setFrameOrigin(NSPoint(x: x, y: y)) diff --git a/ModuleKit/popup.swift b/ModuleKit/popup.swift index b83e742d..99c65402 100644 --- a/ModuleKit/popup.swift +++ b/ModuleKit/popup.swift @@ -25,13 +25,14 @@ internal class PopupWindow: NSPanel, NSWindowDelegate { defer: true ) - self.contentViewController = viewController + self.contentViewController = self.viewController self.backingType = .buffered self.isFloatingPanel = true + self.worksWhenModal = true self.becomesKeyOnlyIfNeeded = true self.styleMask = .borderless self.animationBehavior = .default - self.collectionBehavior = .transient + self.collectionBehavior = .moveToActiveSpace self.backgroundColor = .clear self.hasShadow = true self.setIsVisible(false) diff --git a/Stats/Views/Settings.swift b/Stats/Views/Settings.swift index f4e81cc7..692e3538 100644 --- a/Stats/Views/Settings.swift +++ b/Stats/Views/Settings.swift @@ -31,7 +31,7 @@ class SettingsWindow: NSWindow, NSWindowDelegate { self.contentViewController = self.viewController self.animationBehavior = .default - self.collectionBehavior = .transient + self.collectionBehavior = .moveToActiveSpace self.titlebarAppearsTransparent = true self.appearance = NSAppearance(named: .darkAqua) self.center()