Skip to content

Instantly share code, notes, and snippets.

@CommanderPho
Forked from wonderbit/DockInfo.swift
Created June 10, 2021 22:12
Show Gist options
  • Save CommanderPho/3b7e36a2ead2a3b5d043eceadfbc8a2e to your computer and use it in GitHub Desktop.
Save CommanderPho/3b7e36a2ead2a3b5d043eceadfbc8a2e to your computer and use it in GitHub Desktop.
Get the Dock position, size and hidden state in a Cocoa app
//
// 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