Fix ARC workspace inheritance crash and native Zig helper builds (#2283)
* Fix ARC workspace inheritance crash and native Zig helper builds * Fix Nightly Cmd+N workspace creation crash * Restore safe terminal config snapshots for Intel Nightly
This commit is contained in:
parent
f0c3ccc314
commit
c4bc18d906
6 changed files with 265 additions and 213 deletions
|
|
@ -8,6 +8,40 @@ import Darwin
|
|||
import Network
|
||||
import CoreText
|
||||
|
||||
struct CmuxSurfaceConfigTemplate {
|
||||
var fontSize: Float32 = 0
|
||||
var workingDirectory: String?
|
||||
var command: String?
|
||||
var environmentVariables: [String: String] = [:]
|
||||
var initialInput: String?
|
||||
var waitAfterCommand: Bool = false
|
||||
|
||||
init() {}
|
||||
|
||||
init(cConfig: ghostty_surface_config_s) {
|
||||
fontSize = cConfig.font_size
|
||||
if let workingDirectory = cConfig.working_directory {
|
||||
self.workingDirectory = String(cString: workingDirectory, encoding: .utf8)
|
||||
}
|
||||
if let command = cConfig.command {
|
||||
self.command = String(cString: command, encoding: .utf8)
|
||||
}
|
||||
if let initialInput = cConfig.initial_input {
|
||||
self.initialInput = String(cString: initialInput, encoding: .utf8)
|
||||
}
|
||||
if cConfig.env_var_count > 0, let envVars = cConfig.env_vars {
|
||||
for index in 0..<Int(cConfig.env_var_count) {
|
||||
let envVar = envVars[index]
|
||||
if let key = String(cString: envVar.key, encoding: .utf8),
|
||||
let value = String(cString: envVar.value, encoding: .utf8) {
|
||||
environmentVariables[key] = value
|
||||
}
|
||||
}
|
||||
}
|
||||
waitAfterCommand = cConfig.wait_after_command
|
||||
}
|
||||
}
|
||||
|
||||
func cmuxSurfaceContextName(_ context: ghostty_surface_context_e) -> String {
|
||||
switch context {
|
||||
case GHOSTTY_SURFACE_CONTEXT_WINDOW:
|
||||
|
|
@ -54,21 +88,21 @@ func cmuxCurrentSurfaceFontSizePoints(_ surface: ghostty_surface_t) -> Float? {
|
|||
func cmuxInheritedSurfaceConfig(
|
||||
sourceSurface: ghostty_surface_t,
|
||||
context: ghostty_surface_context_e
|
||||
) -> ghostty_surface_config_s {
|
||||
) -> CmuxSurfaceConfigTemplate {
|
||||
let inherited = ghostty_surface_inherited_config(sourceSurface, context)
|
||||
var config = inherited
|
||||
var config = CmuxSurfaceConfigTemplate(cConfig: inherited)
|
||||
|
||||
// Make runtime zoom inheritance explicit, even when Ghostty's
|
||||
// inherit-font-size config is disabled.
|
||||
let runtimePoints = cmuxCurrentSurfaceFontSizePoints(sourceSurface)
|
||||
if let points = runtimePoints {
|
||||
config.font_size = points
|
||||
config.fontSize = points
|
||||
}
|
||||
|
||||
#if DEBUG
|
||||
let inheritedText = String(format: "%.2f", inherited.font_size)
|
||||
let runtimeText = runtimePoints.map { String(format: "%.2f", $0) } ?? "nil"
|
||||
let finalText = String(format: "%.2f", config.font_size)
|
||||
let finalText = String(format: "%.2f", config.fontSize)
|
||||
dlog(
|
||||
"zoom.inherit context=\(cmuxSurfaceContextName(context)) " +
|
||||
"inherited=\(inheritedText) runtime=\(runtimeText) final=\(finalText)"
|
||||
|
|
@ -5664,7 +5698,7 @@ final class Workspace: Identifiable, ObservableObject {
|
|||
title: String = "Terminal",
|
||||
workingDirectory: String? = nil,
|
||||
portOrdinal: Int = 0,
|
||||
configTemplate: ghostty_surface_config_s? = nil,
|
||||
configTemplate: CmuxSurfaceConfigTemplate? = nil,
|
||||
initialTerminalCommand: String? = nil,
|
||||
initialTerminalEnvironment: [String: String] = [:]
|
||||
) {
|
||||
|
|
@ -7221,9 +7255,9 @@ final class Workspace: Identifiable, ObservableObject {
|
|||
|
||||
private func seedTerminalInheritanceFontPoints(
|
||||
panelId: UUID,
|
||||
configTemplate: ghostty_surface_config_s?
|
||||
configTemplate: CmuxSurfaceConfigTemplate?
|
||||
) {
|
||||
guard let fontPoints = configTemplate?.font_size, fontPoints > 0 else { return }
|
||||
guard let fontPoints = configTemplate?.fontSize, fontPoints > 0 else { return }
|
||||
terminalInheritanceFontPointsByPanelId[panelId] = fontPoints
|
||||
lastTerminalConfigInheritanceFontPoints = fontPoints
|
||||
}
|
||||
|
|
@ -7231,7 +7265,7 @@ final class Workspace: Identifiable, ObservableObject {
|
|||
private func resolvedTerminalInheritanceFontPoints(
|
||||
for terminalPanel: TerminalPanel,
|
||||
sourceSurface: ghostty_surface_t,
|
||||
inheritedConfig: ghostty_surface_config_s
|
||||
inheritedConfig: CmuxSurfaceConfigTemplate
|
||||
) -> Float? {
|
||||
let runtimePoints = cmuxCurrentSurfaceFontSizePoints(sourceSurface)
|
||||
if let rooted = terminalInheritanceFontPointsByPanelId[terminalPanel.id], rooted > 0 {
|
||||
|
|
@ -7242,8 +7276,8 @@ final class Workspace: Identifiable, ObservableObject {
|
|||
}
|
||||
return rooted
|
||||
}
|
||||
if inheritedConfig.font_size > 0 {
|
||||
return inheritedConfig.font_size
|
||||
if inheritedConfig.fontSize > 0 {
|
||||
return inheritedConfig.fontSize
|
||||
}
|
||||
return runtimePoints
|
||||
}
|
||||
|
|
@ -7341,14 +7375,20 @@ final class Workspace: Identifiable, ObservableObject {
|
|||
private func inheritedTerminalConfig(
|
||||
preferredPanelId: UUID? = nil,
|
||||
inPane preferredPaneId: PaneID? = nil
|
||||
) -> ghostty_surface_config_s? {
|
||||
) -> CmuxSurfaceConfigTemplate? {
|
||||
// Walk candidates in priority order and use the first panel that still exposes
|
||||
// a runtime surface pointer.
|
||||
for terminalPanel in terminalPanelConfigInheritanceCandidates(
|
||||
preferredPanelId: preferredPanelId,
|
||||
inPane: preferredPaneId
|
||||
) {
|
||||
guard let sourceSurface = terminalPanel.surface.surface else { continue }
|
||||
// Pin the panel and its TerminalSurface wrapper for the duration of
|
||||
// this iteration. The raw ghostty_surface_t extracted below is owned
|
||||
// by `surface` (the TerminalSurface) — ARC must not release it while
|
||||
// ghostty_surface_inherited_config or cmuxCurrentSurfaceFontSizePoints
|
||||
// is still reading through the pointer.
|
||||
let surface = terminalPanel.surface
|
||||
guard let sourceSurface = surface.surface else { continue }
|
||||
var config = cmuxInheritedSurfaceConfig(
|
||||
sourceSurface: sourceSurface,
|
||||
context: GHOSTTY_SURFACE_CONTEXT_SPLIT
|
||||
|
|
@ -7358,19 +7398,21 @@ final class Workspace: Identifiable, ObservableObject {
|
|||
sourceSurface: sourceSurface,
|
||||
inheritedConfig: config
|
||||
), rootedFontPoints > 0 {
|
||||
config.font_size = rootedFontPoints
|
||||
config.fontSize = rootedFontPoints
|
||||
terminalInheritanceFontPointsByPanelId[terminalPanel.id] = rootedFontPoints
|
||||
}
|
||||
// Prevent ARC from releasing panel/surface before the C calls above complete.
|
||||
withExtendedLifetime((terminalPanel, surface)) {}
|
||||
rememberTerminalConfigInheritanceSource(terminalPanel)
|
||||
if config.font_size > 0 {
|
||||
lastTerminalConfigInheritanceFontPoints = config.font_size
|
||||
if config.fontSize > 0 {
|
||||
lastTerminalConfigInheritanceFontPoints = config.fontSize
|
||||
}
|
||||
return config
|
||||
}
|
||||
|
||||
if let fallbackFontPoints = lastTerminalConfigInheritanceFontPoints {
|
||||
var config = ghostty_surface_config_new()
|
||||
config.font_size = fallbackFontPoints
|
||||
var config = CmuxSurfaceConfigTemplate()
|
||||
config.fontSize = fallbackFontPoints
|
||||
#if DEBUG
|
||||
dlog(
|
||||
"zoom.inherit fallback=lastKnownFont context=split font=\(String(format: "%.2f", fallbackFontPoints))"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue