Repository navigation
Add quick terminal (quake/visor mode) support #1523
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 5 commits
9fd6d64
5df34e1
f0810fa
1f1bb99
a5fb47e
1f93ac8
4b41fb8
994cdec
f8f875c
39f4c58
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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() | ||
|
|
@@ -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 | ||
|
|
@@ -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() | ||
| } | ||
| } else { | ||
| let displays = currentDisplayGeometries() | ||
| let fallbackGeometry = persistedWindowGeometry() | ||
|
|
@@ -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 | ||
|
|
@@ -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 | ||
|
|
@@ -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), | ||
|
|
@@ -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() | ||
|
cubic-dev-ai[bot] marked this conversation as resolved.
Resolved
|
||
| } | ||
| merged.append(pendingQuickTerminalSnapshot) | ||
| return merged | ||
| } | ||
|
|
||
| #if DEBUG | ||
| private func debugLogSessionSaveSnapshot( | ||
| _ snapshot: AppSessionSnapshot, | ||
|
|
@@ -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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Quick-terminal config will stay stale after a Ghostty reload.
🤖 Prompt for AI Agents |
||
|
|
||
| private func installGhosttyConfigObserver() { | ||
| guard ghosttyConfigObserver == nil else { return } | ||
| ghosttyConfigObserver = NotificationCenter.default.addObserver( | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -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 | ||||||
|
|
@@ -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 | ||||||
| } | ||||||
|
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 | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P2: Validate Prompt for AI agents
Suggested change
|
||||||
| } | ||||||
| case "quick-terminal-screen-fraction": | ||||||
| if let frac = Double(value) { | ||||||
| quickTerminalScreenFraction = frac | ||||||
| } | ||||||
| default: | ||||||
| break | ||||||
| } | ||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 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=swiftRepository: manaflow-ai/cmux Length of output: 7679 🏁 Script executed: sed -n '1730,2230p' Sources/GhosttyTerminalView.swift | cat -nRepository: 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 Move the 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
Suggested change
🤖 Prompt for AI Agents |
||||||||||||
| default: | ||||||||||||
| return false | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
Uh oh!
There was an error while loading. Please reload this page.