Skip to content
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions GhosttyTabs.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
A5001500 /* CmuxWebView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A5001510 /* CmuxWebView.swift */; };
A5001501 /* UITestRecorder.swift in Sources */ = {isa = PBXBuildFile; fileRef = A5001511 /* UITestRecorder.swift */; };
A5001226 /* SocketControlSettings.swift in Sources */ = {isa = PBXBuildFile; fileRef = A5001225 /* SocketControlSettings.swift */; };
A5009901 /* QuickTerminalController.swift in Sources */ = {isa = PBXBuildFile; fileRef = A5009902 /* QuickTerminalController.swift */; };
A5001601 /* SentryHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = A5001600 /* SentryHelper.swift */; };
A5001621 /* AppleScriptSupport.swift in Sources */ = {isa = PBXBuildFile; fileRef = A5001620 /* AppleScriptSupport.swift */; };
A5001400 /* Panel.swift in Sources */ = {isa = PBXBuildFile; fileRef = A5001410 /* Panel.swift */; };
Expand Down Expand Up @@ -176,6 +177,7 @@
A5001511 /* UITestRecorder.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UITestRecorder.swift; sourceTree = "<group>"; };
A5001520 /* PostHogAnalytics.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PostHogAnalytics.swift; sourceTree = "<group>"; };
A5001225 /* SocketControlSettings.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SocketControlSettings.swift; sourceTree = "<group>"; };
A5009902 /* QuickTerminalController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = QuickTerminalController.swift; sourceTree = "<group>"; };
A5001410 /* Panel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Panels/Panel.swift; sourceTree = "<group>"; };
A5001411 /* TerminalPanel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Panels/TerminalPanel.swift; sourceTree = "<group>"; };
A5001412 /* BrowserPanel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Panels/BrowserPanel.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -376,6 +378,7 @@
A5001019 /* TerminalController.swift */,
A5001541 /* PortScanner.swift */,
A5001225 /* SocketControlSettings.swift */,
A5009902 /* QuickTerminalController.swift */,
A5001600 /* SentryHelper.swift */,
A5001620 /* AppleScriptSupport.swift */,
A5001090 /* AppDelegate.swift */,
Expand Down Expand Up @@ -649,6 +652,7 @@
A5001007 /* TerminalController.swift in Sources */,
A5001540 /* PortScanner.swift in Sources */,
A5001226 /* SocketControlSettings.swift in Sources */,
A5009901 /* QuickTerminalController.swift in Sources */,
A5001601 /* SentryHelper.swift in Sources */,
A5001621 /* AppleScriptSupport.swift in Sources */,
A5001093 /* AppDelegate.swift in Sources */,
Expand Down
17 changes: 17 additions & 0 deletions Resources/Localizable.xcstrings
Original file line number Diff line number Diff line change
Expand Up @@ -75066,6 +75066,23 @@
}
}
}
},
"quickTerminal.title": {
"extractionState": "manual",
"localizations": {
"en": {
"stringUnit": {
"state": "translated",
"value": "Quick Terminal"
}
},
"ja": {
"stringUnit": {
"state": "translated",
"value": "クイックターミナル"
}
}
}
}
}
}
78 changes: 70 additions & 8 deletions Sources/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2240,6 +2240,10 @@ final class AppDelegate: NSObject, NSApplicationDelegate, UNUserNotificationCent
self?.observeDuplicateLaunches()
}
}
// Load quick terminal config early, before any window creation can
// trigger session restore (which checks visorEnabled).
installQuickTerminal()

NSWindow.allowsAutomaticWindowTabbing = false
disableNativeTabbingShortcut()
ensureApplicationIcon()
Expand Down Expand Up @@ -2487,7 +2491,30 @@ final class AppDelegate: NSObject, NSApplicationDelegate, UNUserNotificationCent
guard let primaryContext = contextForMainTerminalWindow(primaryWindow) else { return }

let startupSnapshot = startupSessionSnapshot
let primaryWindowSnapshot = startupSnapshot?.windows.first

// Ensure quick terminal config is loaded (installQuickTerminal may not
// have run yet since SwiftUI window creation can precede didFinishLaunching).
QuickTerminalController.shared.loadConfiguration()

// Separate quick terminal snapshot from regular windows. If the visor
// hotkey is no longer configured, treat the visor snapshot as a regular
// window so its workspaces aren't silently dropped.
let visorEnabled = QuickTerminalController.shared.keybind != nil
let quickTerminalSnapshot = visorEnabled
? startupSnapshot?.windows.first(where: { $0.isQuickTerminal == true })
: nil
let regularWindows = startupSnapshot?.windows.filter { window in
if visorEnabled { return window.isQuickTerminal != true }
return true
} ?? []

// Stash the visor snapshot for deferred restore when the visor window
// is first created (on toggle or immediately below).
if let quickTerminalSnapshot {
QuickTerminalController.shared.restoreSession(quickTerminalSnapshot)
}

let primaryWindowSnapshot = regularWindows.first
if let primaryWindowSnapshot {
isApplyingStartupSessionRestore = true
#if DEBUG
Expand All @@ -2502,6 +2529,14 @@ final class AppDelegate: NSObject, NSApplicationDelegate, UNUserNotificationCent
to: primaryContext,
window: primaryWindow
)
} else if quickTerminalSnapshot != nil, QuickTerminalController.shared.keybind != nil {
// No regular windows to restore — hide the SwiftUI-created primary
// window and show the visor with the restored session.
primaryWindow.orderOut(nil)
DispatchQueue.main.async {
primaryWindow.close()
QuickTerminalController.shared.toggle()
}
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
} else {
let displays = currentDisplayGeometries()
let fallbackGeometry = persistedWindowGeometry()
Expand All @@ -2516,9 +2551,8 @@ final class AppDelegate: NSObject, NSApplicationDelegate, UNUserNotificationCent
}
}

if let startupSnapshot {
let additionalWindows = Array(startupSnapshot
.windows
if startupSnapshot != nil {
let additionalWindows = Array(regularWindows
.dropFirst()
.prefix(max(0, SessionPersistencePolicy.maxWindowsPerSnapshot - 1)))
#if DEBUG
Expand Down Expand Up @@ -3150,7 +3184,7 @@ final class AppDelegate: NSObject, NSApplicationDelegate, UNUserNotificationCent
return false
}

let persistedGeometryData = snapshot.windows.first.flatMap { primaryWindow in
let persistedGeometryData = snapshot.windows.first(where: { $0.isQuickTerminal != true }).flatMap { primaryWindow in
Self.encodedPersistedWindowGeometryData(
frame: primaryWindow.frame,
display: primaryWindow.display
Expand Down Expand Up @@ -3392,6 +3426,7 @@ final class AppDelegate: NSObject, NSApplicationDelegate, UNUserNotificationCent
.prefix(SessionPersistencePolicy.maxWindowsPerSnapshot)
.map { context in
let window = context.window ?? windowForMainWindowId(context.windowId)
let isQuickTerminal = context.windowId == QuickTerminalController.shared.windowId
return SessionWindowSnapshot(
frame: window.map { SessionRectSnapshot($0.frame) },
display: displaySnapshot(for: window),
Expand All @@ -3400,18 +3435,39 @@ final class AppDelegate: NSObject, NSApplicationDelegate, UNUserNotificationCent
isVisible: context.sidebarState.isVisible,
selection: SessionSidebarSelection(selection: context.sidebarSelectionState.selection),
width: SessionPersistencePolicy.sanitizedSidebarWidth(Double(context.sidebarState.persistedWidth))
)
),
isQuickTerminal: isQuickTerminal ? true : nil
)
}

guard !windows.isEmpty else { return nil }
let windowsWithPendingQuickTerminal = Self.includingPendingQuickTerminalSnapshot(
windows,
pendingQuickTerminalSnapshot: QuickTerminalController.shared.pendingSessionSnapshotForPersistence()
)

guard !windowsWithPendingQuickTerminal.isEmpty else { return nil }
return AppSessionSnapshot(
version: SessionSnapshotSchema.currentVersion,
createdAt: Date().timeIntervalSince1970,
windows: windows
windows: windowsWithPendingQuickTerminal
)
}

nonisolated static func includingPendingQuickTerminalSnapshot(
_ windows: [SessionWindowSnapshot],
pendingQuickTerminalSnapshot: SessionWindowSnapshot?
) -> [SessionWindowSnapshot] {
guard let pendingQuickTerminalSnapshot else { return windows }
guard !windows.contains(where: { $0.isQuickTerminal == true }) else { return windows }

var merged = windows
if merged.count >= SessionPersistencePolicy.maxWindowsPerSnapshot {
merged.removeLast()
Comment thread
cubic-dev-ai[bot] marked this conversation as resolved.
Resolved
}
merged.append(pendingQuickTerminalSnapshot)
return merged
}

#if DEBUG
private func debugLogSessionSaveSnapshot(
_ snapshot: AppSessionSnapshot,
Expand Down Expand Up @@ -7669,6 +7725,12 @@ final class AppDelegate: NSObject, NSApplicationDelegate, UNUserNotificationCent
}
}

private func installQuickTerminal() {
let controller = QuickTerminalController.shared
controller.loadConfiguration()
controller.installGlobalHotkey()
}
Comment on lines +10949 to +10953

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Quick-terminal config will stay stale after a Ghostty reload.

loadConfiguration() is single-shot and the Carbon hotkey is only installed here, so reloading Ghostty config cannot update or disable quick-terminal-* settings until restart. Please add a reconfigure path that unregisters/re-registers the hotkey on .ghosttyConfigDidReload.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@Sources/AppDelegate.swift` around lines 7700 - 7704, The quick-terminal setup
in installQuickTerminal uses QuickTerminalController.shared.loadConfiguration()
and installGlobalHotkey() once, so config reloads don't take effect; add a
reconfigure path subscribed to the .ghosttyConfigDidReload notification that
calls QuickTerminalController.shared.loadConfiguration(), then unregisters and
re-registers the Carbon hotkey (e.g., call an existing
unregisterGlobalHotkey()/installGlobalHotkey() pair or add an unregister method
on QuickTerminalController) to ensure quick-terminal-* settings are updated or
disabled on reload instead of only at startup.


private func installGhosttyConfigObserver() {
guard ghosttyConfigObserver == nil else { return }
ghosttyConfigObserver = NotificationCenter.default.addObserver(
Expand Down
22 changes: 22 additions & 0 deletions Sources/GhosttyConfig.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ struct GhosttyConfig {
var unfocusedSplitFill: NSColor?
var splitDividerColor: NSColor?

// Quick terminal settings
var quickTerminalKeybindRaw: String?
var quickTerminalPosition: String?
var quickTerminalAnimationDuration: Double?
var quickTerminalScreenFraction: Double?

// Colors (from theme or config)
var backgroundColor: NSColor = NSColor(hex: "#272822")!
var backgroundOpacity: Double = 1.0
Expand Down Expand Up @@ -304,6 +310,22 @@ struct GhosttyConfig {
if let opacity = Double(value) {
sidebarTintOpacity = min(max(opacity, 0), 1)
}
case "keybind":
let action = value.split(separator: "=", maxSplits: 1).last?
.trimmingCharacters(in: .whitespaces)
if action == "toggle_quick_terminal" {
quickTerminalKeybindRaw = value
}
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
case "quick-terminal-position":
quickTerminalPosition = value
case "quick-terminal-animation-duration":
if let dur = Double(value) {
quickTerminalAnimationDuration = dur

@cubic-dev-ai cubic-dev-ai Bot Mar 16, 2026 •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2: Validate quick-terminal-animation-duration before storing it; invalid values currently flow into animation timing unchanged.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At Sources/GhosttyConfig.swift, line 323:

<comment>Validate `quick-terminal-animation-duration` before storing it; invalid values currently flow into animation timing unchanged.</comment>

<file context>
@@ -304,6 +310,22 @@ struct GhosttyConfig {
+                    quickTerminalPosition = value
+                case "quick-terminal-animation-duration":
+                    if let dur = Double(value) {
+                        quickTerminalAnimationDuration = dur
+                    }
+                case "quick-terminal-screen-fraction":
</file context>
Suggested change
quickTerminalAnimationDuration = dur
quickTerminalAnimationDuration = dur.isFinite ? max(0, dur) : nil
Fix with Cubic

}
case "quick-terminal-screen-fraction":
if let frac = Double(value) {
quickTerminalScreenFraction = frac
}
default:
break
}
Expand Down
5 changes: 5 additions & 0 deletions Sources/GhosttyTerminalView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2401,6 +2401,11 @@ class GhosttyApp {
}
}
}
case GHOSTTY_ACTION_TOGGLE_QUICK_TERMINAL:
return performOnMain {
QuickTerminalController.shared.toggle()
return true
}
Comment on lines +4219 to +4223

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "== Locate toggle quick-terminal action definitions/usages =="
rg -n -C4 'GHOSTTY_ACTION_TOGGLE_QUICK_TERMINAL|toggle_quick_terminal|GHOSTTY_TARGET_APP|GHOSTTY_TARGET_SURFACE' --type=swift --type=c --type=cpp --type=objc --type=zig

echo
echo "== Inspect action routing handlers =="
rg -n -C6 'func handleAction\(target: ghostty_target_s, action: ghostty_action_s\)|target.tag != GHOSTTY_TARGET_SURFACE|case GHOSTTY_ACTION_TOGGLE_QUICK_TERMINAL' --type=swift

echo
echo "== Check tests for target routing coverage =="
rg -n -C4 'GHOSTTY_ACTION_TOGGLE_QUICK_TERMINAL|toggle_quick_terminal|handleAction\(|GHOSTTY_TARGET_APP' --glob '*test*' --type=swift

Repository: manaflow-ai/cmux

Length of output: 7679


🏁 Script executed:

sed -n '1730,2230p' Sources/GhosttyTerminalView.swift | cat -n

Repository: manaflow-ai/cmux

Length of output: 27007


🏁 Script executed:

# Verify that TOGGLE_QUICK_TERMINAL keybind is marked as global and thus should dispatch with APP target
rg -n -C3 'global.*toggle_quick_terminal|toggle_quick_terminal.*global' Sources/

Repository: manaflow-ai/cmux

Length of output: 668


Move quick-terminal toggle handler outside surface-target guard.

The GHOSTTY_ACTION_TOGGLE_QUICK_TERMINAL action is defined with a global: keybind scope, which means Ghostty will dispatch it with GHOSTTY_TARGET_APP. However, the current handler at line 2212 is only reachable when target.tag == GHOSTTY_TARGET_SURFACE. For APP-target dispatches, the function returns false at line 1783 and the action is dropped.

Move the GHOSTTY_ACTION_TOGGLE_QUICK_TERMINAL case before the surface-target guard (before line 1731) to handle it for all target types:

Proposed fix
     private func handleAction(target: ghostty_target_s, action: ghostty_action_s) -> Bool {
+        if action.tag == GHOSTTY_ACTION_TOGGLE_QUICK_TERMINAL {
+            return performOnMain {
+                QuickTerminalController.shared.toggle()
+                return true
+            }
+        }
+
         if target.tag != GHOSTTY_TARGET_SURFACE {
             if action.tag == GHOSTTY_ACTION_RELOAD_CONFIG ||
                 action.tag == GHOSTTY_ACTION_CONFIG_CHANGE ||
                 action.tag == GHOSTTY_ACTION_COLOR_CHANGE {
                 logAction(action, target: target, tabId: nil, surfaceId: nil)
@@
-        case GHOSTTY_ACTION_TOGGLE_QUICK_TERMINAL:
-            return performOnMain {
-                QuickTerminalController.shared.toggle()
-                return true
-            }
         default:
             return false
         }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
case GHOSTTY_ACTION_TOGGLE_QUICK_TERMINAL:
return performOnMain {
QuickTerminalController.shared.toggle()
return true
}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@Sources/GhosttyTerminalView.swift` around lines 2212 - 2216, The toggle
handler for GHOSTTY_ACTION_TOGGLE_QUICK_TERMINAL is currently inside the branch
guarded by a check for GHOSTTY_TARGET_SURFACE, so APP-scoped dispatches
(GHOSTTY_TARGET_APP) are dropped; move the entire case for
GHOSTTY_ACTION_TOGGLE_QUICK_TERMINAL (which calls performOnMain {
QuickTerminalController.shared.toggle(); return true }) out of that surface-only
block and place it before the surface-target guard (i.e., before the tag ==
GHOSTTY_TARGET_SURFACE check) so it executes for all targets.

default:
return false
}
Expand Down
Loading