mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-07-14 15:56:13 +03:00
Merge pull request #1231 from mitchellh/macos-winsize
macos: set initial window size in controller window init
This commit is contained in:
@ -164,6 +164,23 @@ class TerminalController: NSWindowController, NSWindowDelegate,
|
|||||||
// covered in thie GitHub issue: https://github.com/mitchellh/ghostty/pull/376
|
// covered in thie GitHub issue: https://github.com/mitchellh/ghostty/pull/376
|
||||||
window.colorSpace = NSColorSpace.sRGB
|
window.colorSpace = NSColorSpace.sRGB
|
||||||
|
|
||||||
|
// If we have only a single surface (no splits) and that surface requested
|
||||||
|
// an initial size then we set it here now.
|
||||||
|
if case let .leaf(leaf) = surfaceTree {
|
||||||
|
if let initialSize = leaf.surface.initialSize {
|
||||||
|
// Setup our frame. We need to first subtract the views frame so that we can
|
||||||
|
// just get the chrome frame so that we only affect the surface view size.
|
||||||
|
var frame = window.frame
|
||||||
|
frame.size.width -= leaf.surface.frame.size.width
|
||||||
|
frame.size.height -= leaf.surface.frame.size.height
|
||||||
|
frame.size.width += initialSize.width
|
||||||
|
frame.size.height += initialSize.height
|
||||||
|
|
||||||
|
// We have no tabs and we are not a split, so set the initial size of the window.
|
||||||
|
window.setFrame(frame, display: true)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Center the window to start, we'll move the window frame automatically
|
// Center the window to start, we'll move the window frame automatically
|
||||||
// when cascading.
|
// when cascading.
|
||||||
window.center()
|
window.center()
|
||||||
|
@ -534,9 +534,6 @@ extension Ghostty {
|
|||||||
override func viewDidMoveToWindow() {
|
override func viewDidMoveToWindow() {
|
||||||
// Set our background blur if requested
|
// Set our background blur if requested
|
||||||
setWindowBackgroundBlur(window)
|
setWindowBackgroundBlur(window)
|
||||||
|
|
||||||
// Try to set the initial window size if we have one
|
|
||||||
setInitialWindowSize()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// This function sets the window background to blur if it is configured on the surface.
|
/// This function sets the window background to blur if it is configured on the surface.
|
||||||
@ -568,37 +565,6 @@ extension Ghostty {
|
|||||||
ghostty_set_window_background_blur(surface, Unmanaged.passUnretained(window).toOpaque())
|
ghostty_set_window_background_blur(surface, Unmanaged.passUnretained(window).toOpaque())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Sets the initial window size requested by the Ghostty config.
|
|
||||||
///
|
|
||||||
/// This only works under certain conditions:
|
|
||||||
/// - The window must be "uninitialized"
|
|
||||||
/// - The window must have no tabs
|
|
||||||
/// - Ghostty must have requested an initial size
|
|
||||||
///
|
|
||||||
private func setInitialWindowSize() {
|
|
||||||
guard let initialSize = initialSize else { return }
|
|
||||||
|
|
||||||
// If we have tabs, then do not change the window size
|
|
||||||
guard let window = self.window else { return }
|
|
||||||
guard let windowControllerRaw = window.windowController else { return }
|
|
||||||
guard let windowController = windowControllerRaw as? TerminalController else { return }
|
|
||||||
guard case .leaf = windowController.surfaceTree else { return }
|
|
||||||
|
|
||||||
// If our window is full screen, we do not set the frame
|
|
||||||
guard !window.styleMask.contains(.fullScreen) else { return }
|
|
||||||
|
|
||||||
// Setup our frame. We need to first subtract the views frame so that we can
|
|
||||||
// just get the chrome frame so that we only affect the surface view size.
|
|
||||||
var frame = window.frame
|
|
||||||
frame.size.width -= self.frame.size.width
|
|
||||||
frame.size.height -= self.frame.size.height
|
|
||||||
frame.size.width += initialSize.width
|
|
||||||
frame.size.height += initialSize.height
|
|
||||||
|
|
||||||
// We have no tabs and we are not a split, so set the initial size of the window.
|
|
||||||
window.setFrame(frame, display: true)
|
|
||||||
}
|
|
||||||
|
|
||||||
override func becomeFirstResponder() -> Bool {
|
override func becomeFirstResponder() -> Bool {
|
||||||
let result = super.becomeFirstResponder()
|
let result = super.becomeFirstResponder()
|
||||||
if (result) { focused = true }
|
if (result) { focused = true }
|
||||||
|
Reference in New Issue
Block a user