Skip to content
281 changes: 171 additions & 110 deletions Sources/AppDelegate.swift

Large diffs are not rendered by default.

40 changes: 20 additions & 20 deletions Sources/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2005,7 +2005,7 @@ struct ContentView: View {
}

static func tmuxWorkspacePaneExactRect(
for panel: Panel,
for panel: any Panel,
in contentView: NSView
) -> CGRect? {
let targetView: NSView?
Expand Down Expand Up @@ -2993,7 +2993,7 @@ struct ContentView: View {
}
})

view = AnyView(view.onChange(of: tabManager.selectedTabId) { newValue in
view = AnyView(view.onChange(of: tabManager.selectedTabId) { _, newValue in
#if DEBUG
if let snapshot = tabManager.debugCurrentWorkspaceSwitchSnapshot() {
let dtMs = (CACurrentMediaTime() - snapshot.startedAt) * 1000
Expand All @@ -3015,11 +3015,11 @@ struct ContentView: View {
updateTitlebarText()
})

view = AnyView(view.onChange(of: selectedTabIds) { _ in
view = AnyView(view.onChange(of: selectedTabIds) {
syncSidebarSelectedWorkspaceIds()
})

view = AnyView(view.onChange(of: tabManager.isWorkspaceCycleHot) { _ in
view = AnyView(view.onChange(of: tabManager.isWorkspaceCycleHot) {
#if DEBUG
if let snapshot = tabManager.debugCurrentWorkspaceSwitchSnapshot() {
let dtMs = (CACurrentMediaTime() - snapshot.startedAt) * 1000
Expand All @@ -3033,7 +3033,7 @@ struct ContentView: View {
reconcileMountedWorkspaceIds()
})

view = AnyView(view.onChange(of: retiringWorkspaceId) { _ in
view = AnyView(view.onChange(of: retiringWorkspaceId) {
reconcileMountedWorkspaceIds()
})

Expand Down Expand Up @@ -3325,11 +3325,11 @@ struct ContentView: View {
}
}))

view = AnyView(view.onChange(of: bgGlassTintHex) { _ in
view = AnyView(view.onChange(of: bgGlassTintHex) {
updateWindowGlassTint()
})

view = AnyView(view.onChange(of: bgGlassTintOpacity) { _ in
view = AnyView(view.onChange(of: bgGlassTintOpacity) {
updateWindowGlassTint()
})

Expand Down Expand Up @@ -3358,7 +3358,7 @@ struct ContentView: View {
updateSidebarResizerBandState()
})

view = AnyView(view.onChange(of: sidebarWidth) { _ in
view = AnyView(view.onChange(of: sidebarWidth) {
let sanitized = normalizedSidebarWidth(sidebarWidth)
if abs(sidebarWidth - sanitized) > 0.5 {
sidebarWidth = sanitized
Expand All @@ -3377,7 +3377,7 @@ struct ContentView: View {
updateSidebarResizerBandState()
})

view = AnyView(view.onChange(of: sidebarState.isVisible) { _ in
view = AnyView(view.onChange(of: sidebarState.isVisible) {
if let observedWindow {
TerminalWindowPortalRegistry.scheduleExternalGeometrySynchronize(for: observedWindow)
} else {
Expand All @@ -3387,7 +3387,7 @@ struct ContentView: View {
syncTrafficLightInset()
})

view = AnyView(view.onChange(of: sidebarMatchTerminalBackground) { _ in
view = AnyView(view.onChange(of: sidebarMatchTerminalBackground) {
guard sidebarState.isVisible,
sidebarBlendMode == SidebarBlendModeOption.withinWindow.rawValue else { return }
if let observedWindow {
Expand All @@ -3401,7 +3401,7 @@ struct ContentView: View {
syncTrafficLightInset()
})

view = AnyView(view.onChange(of: sidebarState.persistedWidth) { newValue in
view = AnyView(view.onChange(of: sidebarState.persistedWidth) { _, newValue in
let sanitized = normalizedSidebarWidth(newValue)
if abs(newValue - sanitized) > 0.5 {
sidebarState.persistedWidth = sanitized
Expand Down Expand Up @@ -4022,7 +4022,7 @@ struct ContentView: View {
),
anchor: commandPaletteScrollTargetAnchor
)
.onChange(of: commandPaletteSelectedResultIndex) { _ in
.onChange(of: commandPaletteSelectedResultIndex) {
updateCommandPaletteScrollTarget(resultCount: visibleResults.count, animated: true)
}

Expand Down Expand Up @@ -4061,7 +4061,7 @@ struct ContentView: View {
updateCommandPaletteScrollTarget(resultCount: commandPaletteVisibleResults.count, animated: false)
syncCommandPaletteDebugStateForObservedWindow()
}
.onChange(of: commandPaletteCurrentSearchFingerprint) { _ in
.onChange(of: commandPaletteCurrentSearchFingerprint) {
Task { @MainActor in
// Let the query-state transition settle first so the forced corpus refresh
// cannot rebuild the old command list after deleting the ">" prefix.
Expand All @@ -4074,7 +4074,7 @@ struct ContentView: View {
syncCommandPaletteDebugStateForObservedWindow()
}
}
.onChange(of: commandPaletteResultsRevision) { _ in
.onChange(of: commandPaletteResultsRevision) {
let resultIDs = cachedCommandPaletteResults.map(\.id)
commandPaletteSelectedResultIndex = Self.commandPaletteResolvedSelectionIndex(
preferredCommandID: commandPaletteSelectionAnchorCommandID,
Expand All @@ -4089,7 +4089,7 @@ struct ContentView: View {
}
syncCommandPaletteDebugStateForObservedWindow()
}
.onChange(of: commandPaletteSelectedResultIndex) { _ in
.onChange(of: commandPaletteSelectedResultIndex) {
syncCommandPaletteDebugStateForObservedWindow()
}
}
Expand Down Expand Up @@ -10107,7 +10107,7 @@ struct VerticalTabsSidebar: View {
reason: "sidebar_disappear"
)
}
.onChange(of: draggedTabId) { newDraggedTabId in
.onChange(of: draggedTabId) { _, newDraggedTabId in
SidebarDragLifecycleNotification.postStateDidChange(
tabId: newDraggedTabId,
reason: "drag_state_change"
Expand All @@ -10125,7 +10125,7 @@ struct VerticalTabsSidebar: View {
dragAutoScrollController.stop()
dropIndicator = nil
}
.onChange(of: tabs.map(\.id)) { tabIds in
.onChange(of: tabs.map(\.id)) { _, tabIds in
guard let frozenTabItemPresentation,
!tabIds.contains(frozenTabItemPresentation.tabId) else { return }
self.frozenTabItemPresentation = nil
Expand Down Expand Up @@ -13025,7 +13025,7 @@ private struct TabItemView: View, Equatable {
.onAppear {
rowHeight = max(proxy.size.height, 1)
}
.onChange(of: proxy.size.height) { newHeight in
.onChange(of: proxy.size.height) { _, newHeight in
rowHeight = max(newHeight, 1)
}
}
Expand Down Expand Up @@ -14084,7 +14084,7 @@ private struct SidebarWorkspaceDescriptionText: View {
)
#endif
}
.onChange(of: markdown) { newValue in
.onChange(of: markdown) { _, newValue in
#if DEBUG
let newlineCount = newValue.reduce(into: 0) { count, character in
if character == "\n" { count += 1 }
Expand Down Expand Up @@ -14335,7 +14335,7 @@ private struct SidebarMetadataMarkdownBlockRow: View {
.contentShape(Rectangle())
.onTapGesture { onFocus() }
.onAppear(perform: renderMarkdown)
.onChange(of: block.markdown) { _ in
.onChange(of: block.markdown) {
renderMarkdown()
}
}
Expand Down
21 changes: 7 additions & 14 deletions Sources/GhosttyTerminalView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1518,14 +1518,7 @@ class GhosttyApp {
// Some GhosttyKit builds import this callback as returning `Void` in Swift even
// though the C ABI returns `bool`. Store the C-compatible shim explicitly so the
// project compiles against both importer variants.
runtimeConfig.read_clipboard_cb = unsafeBitCast(
cmuxRuntimeReadClipboardCallback as @convention(c) (
UnsafeMutableRawPointer?,
ghostty_clipboard_e,
UnsafeMutableRawPointer?
) -> Bool,
to: ghostty_runtime_read_clipboard_cb.self
)
runtimeConfig.read_clipboard_cb = cmuxRuntimeReadClipboardCallback

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Preserve cross-import callback compatibility

Replacing the explicit cast with runtimeConfig.read_clipboard_cb = cmuxRuntimeReadClipboardCallback drops the compatibility shim for GhosttyKit builds that import read_clipboard_cb with a Void return type instead of Bool (the mismatch noted in the adjacent comment). In that environment this assignment is not type-compatible and the project no longer compiles, so this change narrows supported build configurations.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The unsafeBitCast removal is safe. The compiler warned it was unnecessary because the types already match in the current GhosttyKit build. The comment about cross-importer variants is preserved, and if a future build changes the callback signature, it will produce a compile error (not a silent ABI mismatch).

— Claude Code

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Restore cross-import clipboard callback compatibility

Assigning cmuxRuntimeReadClipboardCallback directly narrows support to GhosttyKit importer variants where ghostty_runtime_read_clipboard_cb has a Bool return in Swift. In environments where that callback is imported as Void (the compatibility case documented in the adjacent comment), this line becomes type-incompatible and the project no longer compiles; the previous explicit C-ABI cast/shim avoided that mismatch.

Useful? React with 👍 / 👎.

runtimeConfig.confirm_read_clipboard_cb = { userdata, content, state, _ in
guard let content else { return }
guard let callbackContext = GhosttyApp.callbackContext(from: userdata),
Expand Down Expand Up @@ -3246,9 +3239,9 @@ class GhosttyApp {
FileManager.default.createFile(atPath: backgroundLogURL.path, contents: nil)
}
if let handle = try? FileHandle(forWritingTo: backgroundLogURL) {
defer { try? handle.close() }
try? handle.seekToEnd()
try? handle.write(contentsOf: data)
defer { _ = try? handle.close() }
_ = try? handle.seekToEnd()
_ = try? handle.write(contentsOf: data)
}
}
}
Expand Down Expand Up @@ -4431,7 +4424,7 @@ final class TerminalSurface: Identifiable, ObservableObject {
dlog("forceRefresh: \(id) reason=\(reason) \(viewState)")
#endif
guard let view = attachedView,
let surface,
surface != nil,
view.window != nil,
view.bounds.width > 0,
view.bounds.height > 0 else {
Expand Down Expand Up @@ -5815,7 +5808,7 @@ class GhosttyNSView: NSView, NSUserInterfaceValidations {
let startX = min(1, xMax)
let endX = xMax

let mods = ghostty_input_mods_e(rawValue: GHOSTTY_MODS_NONE.rawValue) ?? GHOSTTY_MODS_NONE
let mods = ghostty_input_mods_e(rawValue: GHOSTTY_MODS_NONE.rawValue)
ghostty_surface_mouse_pos(surface, startX, startY, mods)
guard ghostty_surface_mouse_button(surface, GHOSTTY_MOUSE_PRESS, GHOSTTY_MOUSE_LEFT, mods) else {
return false
Expand Down Expand Up @@ -8344,7 +8337,7 @@ class GhosttyNSView: NSView, NSUserInterfaceValidations {
}

fileprivate func debugRegisteredDropTypes() -> [String] {
(registeredDraggedTypes ?? []).map(\.rawValue)
registeredDraggedTypes.map(\.rawValue)
}
#endif

Expand Down
2 changes: 1 addition & 1 deletion Sources/KeyboardShortcutSettings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -809,7 +809,7 @@ final class SystemWideHotkeyController {
window.deminiaturize(nil)
}

NSRunningApplication.current.activate(options: [.activateAllWindows, .activateIgnoringOtherApps])
NSApp.forceActivate()

let focusWindow = preferredFocusWindow(from: revealTargets)
focusWindow?.makeKeyAndOrderFront(nil)
Expand Down
2 changes: 1 addition & 1 deletion Sources/NotificationsPage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ struct NotificationsPage: View {
.frame(maxWidth: .infinity, maxHeight: .infinity)
.background(Color(nsColor: .windowBackgroundColor))
.onAppear(perform: setInitialFocus)
.onChange(of: notificationStore.notifications.first?.id) { _ in
.onChange(of: notificationStore.notifications.first?.id) {
setInitialFocus()
}
}
Expand Down
29 changes: 18 additions & 11 deletions Sources/Panels/BrowserPanel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1701,7 +1701,7 @@ actor BrowserSearchSuggestionService {
}

/// BrowserPanel provides a WKWebView-based browser panel.
/// All browser panels share a WKProcessPool for cookie sharing.
/// All browser panels share a WKProcessPool and WKWebsiteDataStore for session and cookie persistence.
private enum BrowserInsecureHTTPNavigationIntent {
case currentTab
case newTab
Expand Down Expand Up @@ -1738,7 +1738,11 @@ final class BrowserPanel: Panel, ObservableObject {
"0.0.0.0",
]

/// Shared process pool for cookie sharing across all browser panels
/// Shared process pool across all browser panels. Although Apple deprecated
/// WKProcessPool in macOS 12 ("creating multiple instances no longer has any
/// effect"), removing the shared pool entirely breaks in-memory session/cookie
/// state sharing between panels and popup flows.
@available(macOS, deprecated: 12.0, message: "WKProcessPool is deprecated but removing it breaks session sharing")
private static let sharedProcessPool = WKProcessPool()

/// Popup windows owned by this panel (for lifecycle cleanup)
Expand Down Expand Up @@ -1844,10 +1848,11 @@ final class BrowserPanel: Panel, ObservableObject {
}

private static func isDarkAppearance(
appAppearance: NSAppearance? = NSApp?.effectiveAppearance
appAppearance: NSAppearance? = nil
) -> Bool {
guard let appAppearance else { return false }
return appAppearance.bestMatch(from: [.darkAqua, .aqua]) == .darkAqua
let appearance: NSAppearance? = appAppearance ?? NSApp?.effectiveAppearance
guard let appearance else { return false }
return appearance.bestMatch(from: [.darkAqua, .aqua]) == .darkAqua
}

private static func resolvedGhosttyBackgroundColor(from notification: Notification? = nil) -> NSColor {
Expand All @@ -1869,7 +1874,7 @@ final class BrowserPanel: Panel, ObservableObject {

private static func resolvedBrowserChromeBackgroundColor(
from notification: Notification? = nil,
appAppearance: NSAppearance? = NSApp?.effectiveAppearance
appAppearance: NSAppearance? = nil
) -> NSColor {
if isDarkAppearance(appAppearance: appAppearance) {
return resolvedGhosttyBackgroundColor(from: notification)
Expand Down Expand Up @@ -2771,26 +2776,28 @@ final class BrowserPanel: Panel, ObservableObject {
}

private func beginDownloadActivity() {
let apply = {
let apply = { [weak self] in
guard let self else { return }
self.activeDownloadCount += 1
self.isDownloading = self.activeDownloadCount > 0
}
if Thread.isMainThread {
apply()
} else {
DispatchQueue.main.async(execute: apply)
DispatchQueue.main.async { apply() }
}
}

private func endDownloadActivity() {
let apply = {
let apply = { [weak self] in
guard let self else { return }
self.activeDownloadCount = max(0, self.activeDownloadCount - 1)
self.isDownloading = self.activeDownloadCount > 0
}
if Thread.isMainThread {
apply()
} else {
DispatchQueue.main.async(execute: apply)
DispatchQueue.main.async { apply() }
}
}

Expand Down Expand Up @@ -9210,7 +9217,7 @@ final class BrowserDataImportCoordinator {
#endif

@MainActor
private final class ImportWizardWindowController: NSObject, @preconcurrency NSWindowDelegate {
private final class ImportWizardWindowController: NSObject, NSWindowDelegate {
private final class FlippedDocumentView: NSView {
override var isFlipped: Bool { true }
}
Expand Down
18 changes: 9 additions & 9 deletions Sources/Panels/BrowserPanelView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -677,10 +677,10 @@ struct BrowserPanelView: View {
logBrowserFocusState(event: "view.onAppear")
#endif
}
.onChange(of: panel.focusFlashToken) { _ in
.onChange(of: panel.focusFlashToken) { _, _ in
triggerFocusFlashAnimation()
}
.onChange(of: panel.currentURL) { _ in
.onChange(of: panel.currentURL) { _, _ in
let addressWasEmpty = omnibarState.buffer.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty
syncURLFromPanel()
// If we auto-focused a blank omnibar but then a URL loads programmatically, move focus
Expand All @@ -699,27 +699,27 @@ struct BrowserPanelView: View {
reason: "panel.currentURL.changed"
)
}
.onChange(of: browserThemeModeRaw) { _ in
.onChange(of: browserThemeModeRaw) { _, _ in
let normalizedMode = BrowserThemeSettings.mode(for: browserThemeModeRaw)
if browserThemeModeRaw != normalizedMode.rawValue {
browserThemeModeRaw = normalizedMode.rawValue
}
panel.setBrowserThemeMode(normalizedMode)
}
.onChange(of: colorScheme) { _ in
.onChange(of: colorScheme) { _, _ in
refreshBrowserChromeStyle()
panel.refreshAppearanceDrivenColors()
}
.onChange(of: panel.pendingAddressBarFocusRequestId) { _ in
.onChange(of: panel.pendingAddressBarFocusRequestId) { _, _ in
applyPendingAddressBarFocusRequestIfNeeded()
}
.onChange(of: panel.profileID) { _ in
.onChange(of: panel.profileID) { _, _ in
panel.historyStore.loadIfNeeded()
if addressBarFocused {
refreshSuggestions()
}
}
.onChange(of: isVisibleInUI) { visibleInUI in
.onChange(of: isVisibleInUI) { _, visibleInUI in
if visibleInUI {
panel.cancelPendingDeveloperToolsVisibilityLossCheck()
return
Expand All @@ -736,7 +736,7 @@ struct BrowserPanelView: View {
// an attached-inspector X-close.
panel.scheduleDeveloperToolsVisibilityLossCheck()
}
.onChange(of: isFocused) { focused in
.onChange(of: isFocused) { _, focused in
#if DEBUG
logBrowserFocusState(
event: "panelFocus.onChange",
Expand Down Expand Up @@ -764,7 +764,7 @@ struct BrowserPanelView: View {
isPanelFocusedOverride: focused
)
}
.onChange(of: addressBarFocused) { focused in
.onChange(of: addressBarFocused) { _, focused in
#if DEBUG
logBrowserFocusState(
event: "addressBarFocus.onChange",
Expand Down
Loading
Loading