config: support quick terminal position

This commit is contained in:
Mitchell Hashimoto
2024-09-28 18:42:13 -07:00
parent 13eb8ac6e2
commit 11d5ec7dc1
5 changed files with 72 additions and 24 deletions

View File

@@ -1,19 +1,30 @@
import Cocoa
enum QuickTerminalPosition {
enum QuickTerminalPosition : String {
case top
case bottom
case left
case right
/// Set the loaded state for a window.
func setLoaded(_ window: NSWindow) {
guard let screen = window.screen ?? NSScreen.main else { return }
switch (self) {
case .top:
case .top, .bottom:
window.setFrame(.init(
origin: window.frame.origin,
size: .init(
width: screen.frame.width,
height: screen.frame.height / 4)
), display: false)
case .left, .right:
window.setFrame(.init(
origin: window.frame.origin,
size: .init(
width: screen.frame.width / 4,
height: screen.frame.height)
), display: false)
}
}
@@ -23,15 +34,10 @@ enum QuickTerminalPosition {
window.alphaValue = 0
// Position depends
switch (self) {
case .top:
window.setFrame(.init(
origin: initialOrigin(for: window, on: screen),
size: .init(
width: screen.frame.width,
height: window.frame.height)
), display: false)
}
window.setFrame(.init(
origin: initialOrigin(for: window, on: screen),
size: window.frame.size
), display: false)
}
/// Set the final state for a window in this position.
@@ -40,21 +46,21 @@ enum QuickTerminalPosition {
window.alphaValue = 1
// Position depends
switch (self) {
case .top:
window.setFrame(.init(
origin: finalOrigin(for: window, on: screen),
size: window.frame.size
), display: true)
}
window.setFrame(.init(
origin: finalOrigin(for: window, on: screen),
size: window.frame.size
), display: true)
}
/// Restrict the frame size during resizing.
func restrictFrameSize(_ size: NSSize, on screen: NSScreen) -> NSSize {
var finalSize = size
switch (self) {
case .top:
case .top, .bottom:
finalSize.width = screen.frame.width
case .left, .right:
finalSize.height = screen.frame.height
}
return finalSize
@@ -65,6 +71,15 @@ enum QuickTerminalPosition {
switch (self) {
case .top:
return .init(x: 0, y: screen.frame.maxY)
case .bottom:
return .init(x: 0, y: -window.frame.height)
case .left:
return .init(x: -window.frame.width, y: 0)
case .right:
return .init(x: screen.frame.maxX, y: 0)
}
}
@@ -73,6 +88,15 @@ enum QuickTerminalPosition {
switch (self) {
case .top:
return .init(x: window.frame.origin.x, y: screen.visibleFrame.maxY - window.frame.height)
case .bottom:
return .init(x: window.frame.origin.x, y: 0)
case .left:
return .init(x: 0, y: window.frame.origin.y)
case .right:
return .init(x: screen.visibleFrame.maxX - window.frame.width, y: window.frame.origin.y)
}
}
}