Last active
March 28, 2025 13:09
-
-
Save zats/233d63b8e7845f62c7c200a359b3c076 to your computer and use it in GitHub Desktop.
Revisions
-
zats revised this gist
Mar 28, 2025 . 1 changed file with 25 additions and 10 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,29 +1,44 @@ import AppKit struct DockInfo { let position: DockPosition let frame: CGRect } enum DockPosition { case bottom case left case right case hiddenOrUnknown } func detectDockInfo() -> DockInfo? { for screen in NSScreen.screens { let full = screen.frame let visible = screen.visibleFrame let deltaLeft = visible.minX - full.minX let deltaBottom = visible.minY - full.minY let deltaRight = full.maxX - visible.maxX let deltaTop = full.maxY - visible.maxY // menu bar // Assume menu bar is always at top, subtract that first let menuBarHeight = deltaTop if deltaBottom > 0 { let height = deltaBottom let frame = CGRect(x: full.minX, y: full.minY, width: full.width, height: height) return DockInfo(position: .bottom, frame: frame) } else if deltaLeft > 0 { let width = deltaLeft let frame = CGRect(x: full.minX, y: full.minY, width: width, height: full.height - menuBarHeight) return DockInfo(position: .left, frame: frame) } else if deltaRight > 0 { let width = deltaRight let frame = CGRect(x: full.maxX - width, y: full.minY, width: width, height: full.height - menuBarHeight) return DockInfo(position: .right, frame: frame) } } return nil } -
zats renamed this gist
Mar 28, 2025 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
zats created this gist
Mar 28, 2025 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,29 @@ enum DockPosition { case bottom(NSScreen) case left(NSScreen) case right(NSScreen) case hiddenOrUnknown } func detectDockPosition() -> DockPosition { for screen in NSScreen.screens { let visible = screen.visibleFrame let full = screen.frame let deltaLeft = visible.minX - full.minX let deltaBottom = visible.minY - full.minY let deltaRight = full.maxX - visible.maxX // Top delta is menu bar, ignore if deltaBottom > 0 { return .bottom(screen) } else if deltaLeft > 0 { return .left(screen) } else if deltaRight > 0 { return .right(screen) } } return .hiddenOrUnknown }