Last active
March 28, 2025 13:09
-
-
Save zats/233d63b8e7845f62c7c200a359b3c076 to your computer and use it in GitHub Desktop.
Detect dock position on the screen for sandboxed macOS apps
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 characters
| 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 | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment