mirror of
https://github.com/sindresorhus/touch-bar-simulator
synced 2025-02-17 13:18:24 +00:00
Auto-adjust docked position to match available screen space (#39)
This commit is contained in:
parent
71785b3d85
commit
c184ba5cc5
3 changed files with 24 additions and 5 deletions
|
@ -184,7 +184,6 @@
|
|||
developmentRegion = en;
|
||||
hasScannedForEncodings = 0;
|
||||
knownRegions = (
|
||||
en,
|
||||
Base,
|
||||
);
|
||||
mainGroup = E3FE2CB61E726CE800C6713A;
|
||||
|
|
|
@ -9,14 +9,22 @@ final class TouchBarWindow: NSPanel {
|
|||
switch self {
|
||||
case .floating:
|
||||
window.addTitlebar()
|
||||
case .dockedToTop:
|
||||
window.removeTitlebar()
|
||||
case .dockedToBottom:
|
||||
window.removeTitlebar()
|
||||
}
|
||||
reposition(window: window)
|
||||
}
|
||||
func reposition(window: NSWindow) {
|
||||
switch self {
|
||||
case .floating:
|
||||
if let prevPosition = defaults[.lastFloatingPosition] {
|
||||
window.setFrameOrigin(prevPosition)
|
||||
}
|
||||
case .dockedToTop:
|
||||
window.removeTitlebar()
|
||||
window.moveTo(x: .center, y: .top)
|
||||
case .dockedToBottom:
|
||||
window.removeTitlebar()
|
||||
window.moveTo(x: .center, y: .bottom)
|
||||
}
|
||||
}
|
||||
|
@ -50,6 +58,11 @@ final class TouchBarWindow: NSPanel {
|
|||
}
|
||||
}
|
||||
|
||||
@objc
|
||||
func didChangeScreenParameters(_ notification: Notification) {
|
||||
docking.reposition(window: self)
|
||||
}
|
||||
|
||||
var showOnAllDesktops: Bool = false {
|
||||
didSet {
|
||||
if showOnAllDesktops {
|
||||
|
@ -350,6 +363,8 @@ final class TouchBarWindow: NSPanel {
|
|||
if !dockBehavior {
|
||||
orderFront(nil)
|
||||
}
|
||||
|
||||
NotificationCenter.default.addObserver(self, selector: #selector(didChangeScreenParameters(_:)), name: NSApplication.didChangeScreenParametersNotification, object: nil)
|
||||
}
|
||||
|
||||
deinit {
|
||||
|
|
|
@ -57,9 +57,10 @@ extension NSWindow {
|
|||
}
|
||||
|
||||
func moveTo(x xPositioning: MoveXPositioning, y yPositioning: MoveYPositioning) {
|
||||
guard let visibleFrame = NSScreen.main?.visibleFrame else {
|
||||
guard let screen = NSScreen.main else {
|
||||
return
|
||||
}
|
||||
let visibleFrame = screen.visibleFrame
|
||||
|
||||
let x: CGFloat, y: CGFloat
|
||||
switch xPositioning {
|
||||
|
@ -72,7 +73,11 @@ extension NSWindow {
|
|||
}
|
||||
switch yPositioning {
|
||||
case .top:
|
||||
y = visibleFrame.maxY - frame.height
|
||||
// Defect fix: keep docked windows below menubar area
|
||||
// Previously, the window would obstruct menubar clicks when the menubar was set to auto-hide.
|
||||
// Now, the window stays below that area.
|
||||
let menubarThickness = NSStatusBar.system.thickness
|
||||
y = min(visibleFrame.maxY - frame.height, screen.frame.maxY - menubarThickness - frame.height)
|
||||
case .center:
|
||||
y = visibleFrame.midY - frame.height / 2
|
||||
case .bottom:
|
||||
|
|
Loading…
Add table
Reference in a new issue