-
-
Save CommanderPho/3b7e36a2ead2a3b5d043eceadfbc8a2e to your computer and use it in GitHub Desktop.
Get the Dock position, size and hidden state in a Cocoa app
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
// | |
// DockInfo.swift | |
// | |
// Created by Wessley Roche on 28/11/2016. | |
// | |
import Foundation | |
enum WBDockPosition: Int { | |
case bottom = 0 | |
case left = 1 | |
case right = 2 | |
} | |
func getDockPosition() -> WBDockPosition { | |
if NSScreen.main()!.visibleFrame.origin.y == 0 { | |
if NSScreen.main()!.visibleFrame.origin.x == 0 { | |
return .right | |
} else { | |
return .left | |
} | |
} else { | |
return .bottom | |
} | |
} | |
func getDockSize() -> CGFloat { | |
let dockPosition = getDockPosition() | |
switch dockPosition { | |
case .right: | |
let size = NSScreen.main()!.frame.width - NSScreen.main()!.visibleFrame.width | |
return size | |
case .left: | |
let size = NSScreen.main()!.visibleFrame.origin.x | |
return size | |
case .bottom: | |
let size = NSScreen.main()!.visibleFrame.origin.y | |
return size | |
} | |
} | |
func isDockHidden() -> Bool { | |
let dockSize = getDockSize() | |
if dockSize < 25 { | |
return true | |
} else { | |
return false | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment