From 5845a7bd29b981585ff60ec3c90a534c90b35ef9 Mon Sep 17 00:00:00 2001 From: Daniel Wennberg Date: Sat, 8 Nov 2025 22:20:02 -0800 Subject: [PATCH] macOS: Update core surface size when scroller style changes --- macos/Sources/Ghostty/SurfaceScrollView.swift | 41 +++++++++++++------ 1 file changed, 28 insertions(+), 13 deletions(-) diff --git a/macos/Sources/Ghostty/SurfaceScrollView.swift b/macos/Sources/Ghostty/SurfaceScrollView.swift index 70e22b648..237139e7b 100644 --- a/macos/Sources/Ghostty/SurfaceScrollView.swift +++ b/macos/Sources/Ghostty/SurfaceScrollView.swift @@ -104,6 +104,14 @@ class SurfaceScrollView: NSView { self?.handleLiveScroll() }) + observers.append(NotificationCenter.default.addObserver( + forName: NSScroller.preferredScrollerStyleDidChangeNotification, + object: nil, + queue: .main + ) { [weak self] _ in + self?.handleScrollerStyleChange() + }) + // Listen for frame change events. See the docstring for // handleFrameChange for why this is necessary. observers.append(NotificationCenter.default.addObserver( @@ -154,19 +162,7 @@ class SurfaceScrollView: NSView { // When our scrollview changes make sure our scroller and surface views are synchronized synchronizeScrollView() synchronizeSurfaceView() - - // Inform the actual pty of our size change. This doesn't change the actual view - // frame because we do want to render the whole thing, but it will prevent our - // rows/cols from going into the non-content area. - // - // Only update the pty if we have a valid (non-zero) content size. The content size - // can be zero when this is added early to a view, or to an invisible hierarchy. - // Practically, this happened in the quick terminal. - let width = surfaceContentWidth() - let height = surfaceView.frame.height - if width > 0 && height > 0 { - surfaceView.sizeDidChange(CGSize(width: width, height: height)) - } + synchronizeCoreSurface() } // MARK: Scrolling @@ -186,6 +182,20 @@ class SurfaceScrollView: NSView { surfaceView.frame.origin = visibleRect.origin } + /// Inform the actual pty of our size change. This doesn't change the actual view + /// frame because we do want to render the whole thing, but it will prevent our + /// rows/cols from going into the non-content area. + private func synchronizeCoreSurface() { + // Only update the pty if we have a valid (non-zero) content size. The content size + // can be zero when this is added early to a view, or to an invisible hierarchy. + // Practically, this happened in the quick terminal. + let width = surfaceContentWidth() + let height = surfaceView.frame.height + if width > 0 && height > 0 { + surfaceView.sizeDidChange(CGSize(width: width, height: height)) + } + } + /// Sizes the document view and scrolls the content view according to the scrollbar state private func synchronizeScrollView() { // Update the document height to give our scroller the correct proportions @@ -217,6 +227,11 @@ class SurfaceScrollView: NSView { private func handleScrollChange(_ notification: Notification) { synchronizeSurfaceView() } + + /// Handles scrollbar style changes + private func handleScrollerStyleChange() { + synchronizeCoreSurface() + } /// Handles live scroll events (user actively dragging the scrollbar). ///