Preserve surface content size across backing updates

pull/9446/head
Daniel Wennberg 2025-11-03 22:51:30 -08:00
parent d678e2e305
commit 9002c5dbd2
1 changed files with 12 additions and 1 deletions

View File

@ -89,6 +89,14 @@ extension Ghostty {
// then the view is moved to a new window.
var initialSize: NSSize? = nil
// A content size received through sizeDidChange that may in some cases
// be different from the frame size.
private var contentSizeBacking: NSSize?
private var contentSize: NSSize {
get { return contentSizeBacking ?? frame.size }
set { contentSizeBacking = newValue }
}
// Set whether the surface is currently on a password input or not. This is
// detected with the set_password_input_cb on the Ghostty state.
var passwordInput: Bool = false {
@ -410,6 +418,8 @@ extension Ghostty {
// The size represents our final size we're going for.
let scaledSize = self.convertToBacking(size)
setSurfaceSize(width: UInt32(scaledSize.width), height: UInt32(scaledSize.height))
// Store this size so we can reuse it when backing properties change
contentSize = size
}
private func setSurfaceSize(width: UInt32, height: UInt32) {
@ -764,7 +774,8 @@ extension Ghostty {
ghostty_surface_set_content_scale(surface, xScale, yScale)
// When our scale factor changes, so does our fb size so we send that too
setSurfaceSize(width: UInt32(fbFrame.size.width), height: UInt32(fbFrame.size.height))
let scaledSize = self.convertToBacking(contentSize)
setSurfaceSize(width: UInt32(scaledSize.width), height: UInt32(scaledSize.height))
}
override func mouseDown(with event: NSEvent) {