fix popup position with few displays

This commit is contained in:
Serhiy Mytrovtsiy
2020-06-24 14:18:06 +02:00
parent d88f5d1e1a
commit a2d702b6c7
3 changed files with 8 additions and 13 deletions

View File

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

View File

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

View File

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