macos: make sliding logic a bit more extensible

This commit is contained in:
Mitchell Hashimoto
2024-09-22 21:28:57 -07:00
parent bdd0070ffd
commit 63456d28a5
2 changed files with 50 additions and 9 deletions

View File

@@ -12,9 +12,7 @@ enum SlideTerminalPosition {
switch (self) {
case .top:
window.setFrame(.init(
origin: .init(
x: 0,
y: screen.frame.maxY),
origin: initialOrigin(for: window, on: screen),
size: .init(
width: screen.frame.width,
height: window.frame.height)
@@ -31,11 +29,25 @@ enum SlideTerminalPosition {
switch (self) {
case .top:
window.setFrame(.init(
origin: .init(
x: window.frame.origin.x,
y: screen.visibleFrame.maxY - window.frame.height),
origin: finalOrigin(for: window, on: screen),
size: window.frame.size
), display: true)
}
}
/// The initial point origin for this position.
func initialOrigin(for window: NSWindow, on screen: NSScreen) -> CGPoint {
switch (self) {
case .top:
return .init(x: 0, y: screen.frame.maxY)
}
}
/// The final point origin for this position.
func finalOrigin(for window: NSWindow, on screen: NSScreen) -> CGPoint {
switch (self) {
case .top:
return .init(x: window.frame.origin.x, y: screen.visibleFrame.maxY - window.frame.height)
}
}
}