mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-10-01 15:38:35 +00:00
feat: focus terminal in basic cases
This commit is contained in:
35
macos/Sources/Features/App Intents/FocusTerminalIntent.swift
Normal file
35
macos/Sources/Features/App Intents/FocusTerminalIntent.swift
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
import AppKit
|
||||||
|
import AppIntents
|
||||||
|
import GhosttyKit
|
||||||
|
|
||||||
|
struct FocusTerminalIntent: AppIntent {
|
||||||
|
static var title: LocalizedStringResource = "Focus Terminal"
|
||||||
|
static var description = IntentDescription("Move focus to an existing terminal.")
|
||||||
|
|
||||||
|
@Parameter(
|
||||||
|
title: "Terminal",
|
||||||
|
description: "The terminal to focus.",
|
||||||
|
)
|
||||||
|
var terminal: TerminalEntity
|
||||||
|
|
||||||
|
@available(macOS 26.0, *)
|
||||||
|
static var supportedModes: IntentModes = .background
|
||||||
|
|
||||||
|
@MainActor
|
||||||
|
func perform() async throws -> some IntentResult {
|
||||||
|
guard await requestIntentPermission() else {
|
||||||
|
throw GhosttyIntentError.permissionDenied
|
||||||
|
}
|
||||||
|
|
||||||
|
guard let surfaceView = terminal.surfaceView else {
|
||||||
|
throw GhosttyIntentError.surfaceNotFound
|
||||||
|
}
|
||||||
|
|
||||||
|
guard let controller = surfaceView.window?.windowController as? BaseTerminalController else {
|
||||||
|
return .result()
|
||||||
|
}
|
||||||
|
|
||||||
|
controller.focusSurface(surfaceView)
|
||||||
|
return .result()
|
||||||
|
}
|
||||||
|
}
|
@@ -233,6 +233,16 @@ class BaseTerminalController: NSWindowController,
|
|||||||
return newView
|
return newView
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func focusSurface(_ view: Ghostty.SurfaceView) {
|
||||||
|
guard surfaceTree.contains(view) else { return }
|
||||||
|
|
||||||
|
DispatchQueue.main.async {
|
||||||
|
Ghostty.moveFocus(to: view, from: self.focusedSurface)
|
||||||
|
view.window?.makeKeyAndOrderFront(nil)
|
||||||
|
NSApp.activate(ignoringOtherApps: true)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Called when the surfaceTree variable changed.
|
/// Called when the surfaceTree variable changed.
|
||||||
///
|
///
|
||||||
/// Subclasses should call super first.
|
/// Subclasses should call super first.
|
||||||
|
Reference in New Issue
Block a user