From e3b340c6d3c4715936de6a587ba1775fd5ab50d5 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Sat, 28 Sep 2024 15:08:14 -0700 Subject: [PATCH] macos: set initial terminal dimensions --- .../SlideTerminal/SlideTerminalController.swift | 3 +++ .../SlideTerminal/SlideTerminalPosition.swift | 14 ++++++++++++++ .../SlideTerminal/SlideTerminalWindow.swift | 3 +++ 3 files changed, 20 insertions(+) diff --git a/macos/Sources/Features/SlideTerminal/SlideTerminalController.swift b/macos/Sources/Features/SlideTerminal/SlideTerminalController.swift index 5029b22b0..07d7d42ed 100644 --- a/macos/Sources/Features/SlideTerminal/SlideTerminalController.swift +++ b/macos/Sources/Features/SlideTerminal/SlideTerminalController.swift @@ -36,6 +36,9 @@ class SlideTerminalController: BaseTerminalController { // make this restorable, but it isn't currently implemented. window.isRestorable = false + // Setup our initial size based on our configured position + position.setLoaded(window) + // Setup our content window.contentView = NSHostingView(rootView: TerminalView( ghostty: self.ghostty, diff --git a/macos/Sources/Features/SlideTerminal/SlideTerminalPosition.swift b/macos/Sources/Features/SlideTerminal/SlideTerminalPosition.swift index 72f8d9483..d65f02038 100644 --- a/macos/Sources/Features/SlideTerminal/SlideTerminalPosition.swift +++ b/macos/Sources/Features/SlideTerminal/SlideTerminalPosition.swift @@ -3,6 +3,20 @@ import Cocoa enum SlideTerminalPosition { case top + /// Set the loaded state for a window. + func setLoaded(_ window: NSWindow) { + guard let screen = window.screen ?? NSScreen.main else { return } + switch (self) { + case .top: + window.setFrame(.init( + origin: window.frame.origin, + size: .init( + width: screen.frame.width, + height: screen.frame.height / 4) + ), display: false) + } + } + /// Set the initial state for a window for animating out of this position. func setInitial(in window: NSWindow, on screen: NSScreen) { // We always start invisible diff --git a/macos/Sources/Features/SlideTerminal/SlideTerminalWindow.swift b/macos/Sources/Features/SlideTerminal/SlideTerminalWindow.swift index c170b3a8b..fe3426d2b 100644 --- a/macos/Sources/Features/SlideTerminal/SlideTerminalWindow.swift +++ b/macos/Sources/Features/SlideTerminal/SlideTerminalWindow.swift @@ -23,6 +23,9 @@ class SlideTerminalWindow: NSWindow { // and lets us render off screen. self.level = .popUpMenu + // This plus the level above was what was needed for the animation to work, + // because it gets the window off screen properly. Plus we add some fields + // we just want the behavior of. self.collectionBehavior = [ // We want this to be part of every space because it is a singleton. .canJoinAllSpaces,