From d911c49f4481ac4a853aa3196dce4761a19459a1 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Sun, 17 Sep 2023 12:01:36 -0700 Subject: [PATCH] macos: remove unnecessary call --- macos/Sources/Ghostty/AppState.swift | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/macos/Sources/Ghostty/AppState.swift b/macos/Sources/Ghostty/AppState.swift index f61928f82..e0dab0b75 100644 --- a/macos/Sources/Ghostty/AppState.swift +++ b/macos/Sources/Ghostty/AppState.swift @@ -305,7 +305,8 @@ extension Ghostty { // We only support the standard clipboard if (location != GHOSTTY_CLIPBOARD_STANDARD) { return nil } - guard let appState = self.appState(fromSurface: userdata) else { return nil } + guard let surface = self.surfaceUserdata(from: userdata) else { return nil } + guard let appState = self.appState(fromView: surface) else { return nil } guard let str = NSPasteboard.general.string(forType: .string) else { return nil } // Ghostty requires we cache the string because the pointer we return has to remain @@ -384,8 +385,9 @@ extension Ghostty { static func newTab(_ userdata: UnsafeMutableRawPointer?, config: ghostty_surface_config_s) { guard let surface = self.surfaceUserdata(from: userdata) else { return } - - guard self.appState(fromSurface: userdata)?.windowDecorations else { + + guard let appState = self.appState(fromView: surface) else { return } + guard appState.windowDecorations else { let alert = NSAlert() alert.messageText = "Tabs are disabled" alert.informativeText = "Enable window decorations to use tabs" @@ -417,9 +419,8 @@ extension Ghostty { } /// Returns the GhosttyState from the given userdata value. - static private func appState(fromSurface userdata: UnsafeMutableRawPointer?) -> AppState? { - let surfaceView = Unmanaged.fromOpaque(userdata!).takeUnretainedValue() - guard let surface = surfaceView.surface else { return nil } + static private func appState(fromView view: SurfaceView) -> AppState? { + guard let surface = view.surface else { return nil } guard let app = ghostty_surface_app(surface) else { return nil } guard let app_ud = ghostty_app_userdata(app) else { return nil } return Unmanaged.fromOpaque(app_ud).takeUnretainedValue()