input: add direct set_surface_title and set_tab_title actions

Fixes #11316

This mirrors the `prompt` actions (hence why there is no window action
here) and enables setting titles via keybind actions which importantly
lets this work via command palettes, App Intents, AppleScript, etc.
This commit is contained in:
Mitchell Hashimoto
2026-03-11 09:25:08 -07:00
parent 660767c77d
commit 86c2a2e87f
7 changed files with 117 additions and 0 deletions

View File

@@ -539,6 +539,9 @@ extension Ghostty {
case GHOSTTY_ACTION_SET_TITLE:
setTitle(app, target: target, v: action.action.set_title)
case GHOSTTY_ACTION_SET_TAB_TITLE:
return setTabTitle(app, target: target, v: action.action.set_tab_title)
case GHOSTTY_ACTION_PROMPT_TITLE:
return promptTitle(app, target: target, v: action.action.prompt_title)
@@ -1602,6 +1605,33 @@ extension Ghostty {
}
}
private static func setTabTitle(
_ app: ghostty_app_t,
target: ghostty_target_s,
v: ghostty_action_set_title_s
) -> Bool {
switch target.tag {
case GHOSTTY_TARGET_APP:
Ghostty.logger.warning("set tab title does nothing with an app target")
return false
case GHOSTTY_TARGET_SURFACE:
guard let title = String(cString: v.title!, encoding: .utf8) else { return false }
let titleOverride = title.isEmpty ? nil : title
guard let surface = target.target.surface else { return false }
guard let surfaceView = self.surfaceView(from: surface) else { return false }
guard let window = surfaceView.window,
let controller = window.windowController as? BaseTerminalController
else { return false }
controller.titleOverride = titleOverride
return true
default:
assertionFailure()
return false
}
}
private static func copyTitleToClipboard(
_ app: ghostty_app_t,
target: ghostty_target_s) -> Bool {