From 65cf124e2c8f1dc3578efebb08ea7e8f8ac459d5 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Thu, 11 Dec 2025 16:09:08 -0800 Subject: [PATCH] core: change apprt action to enum value instead of a new one --- include/ghostty.h | 8 ++- macos/Sources/Ghostty/Ghostty.Action.swift | 14 ++++ macos/Sources/Ghostty/Ghostty.App.swift | 79 +++++++++++----------- src/Surface.zig | 6 +- src/apprt/action.zig | 17 ++--- src/apprt/gtk/class/application.zig | 20 ++++-- 6 files changed, 85 insertions(+), 59 deletions(-) diff --git a/include/ghostty.h b/include/ghostty.h index 416db8bab..702a88ecc 100644 --- a/include/ghostty.h +++ b/include/ghostty.h @@ -584,6 +584,12 @@ typedef struct { const char* title; } ghostty_action_set_title_s; +// apprt.action.PromptTitle +typedef enum { + GHOSTTY_PROMPT_TITLE_SURFACE, + GHOSTTY_PROMPT_TITLE_TAB, +} ghostty_action_prompt_title_e; + // apprt.action.Pwd.C typedef struct { const char* pwd; @@ -804,7 +810,6 @@ typedef enum { GHOSTTY_ACTION_DESKTOP_NOTIFICATION, GHOSTTY_ACTION_SET_TITLE, GHOSTTY_ACTION_PROMPT_TITLE, - GHOSTTY_ACTION_PROMPT_TAB_TITLE, GHOSTTY_ACTION_PWD, GHOSTTY_ACTION_MOUSE_SHAPE, GHOSTTY_ACTION_MOUSE_VISIBILITY, @@ -848,6 +853,7 @@ typedef union { ghostty_action_inspector_e inspector; ghostty_action_desktop_notification_s desktop_notification; ghostty_action_set_title_s set_title; + ghostty_action_prompt_title_e prompt_title; ghostty_action_pwd_s pwd; ghostty_action_mouse_shape_e mouse_shape; ghostty_action_mouse_visibility_e mouse_visibility; diff --git a/macos/Sources/Ghostty/Ghostty.Action.swift b/macos/Sources/Ghostty/Ghostty.Action.swift index 8fce2199d..9eb7a8e46 100644 --- a/macos/Sources/Ghostty/Ghostty.Action.swift +++ b/macos/Sources/Ghostty/Ghostty.Action.swift @@ -127,6 +127,20 @@ extension Ghostty.Action { } } } + + enum PromptTitle { + case surface + case tab + + init(_ c: ghostty_action_prompt_title_e) { + switch c { + case GHOSTTY_PROMPT_TITLE_TAB: + self = .tab + default: + self = .surface + } + } + } } // Putting the initializer in an extension preserves the automatic one. diff --git a/macos/Sources/Ghostty/Ghostty.App.swift b/macos/Sources/Ghostty/Ghostty.App.swift index db98d56be..aff3edbc7 100644 --- a/macos/Sources/Ghostty/Ghostty.App.swift +++ b/macos/Sources/Ghostty/Ghostty.App.swift @@ -523,10 +523,7 @@ extension Ghostty { setTitle(app, target: target, v: action.action.set_title) case GHOSTTY_ACTION_PROMPT_TITLE: - return promptTitle(app, target: target) - - case GHOSTTY_ACTION_PROMPT_TAB_TITLE: - return promptTabTitle(app, target: target) + return promptTitle(app, target: target, v: action.action.prompt_title) case GHOSTTY_ACTION_PWD: pwdChanged(app, target: target, v: action.action.pwd) @@ -1353,47 +1350,49 @@ extension Ghostty { private static func promptTitle( _ app: ghostty_app_t, - target: ghostty_target_s) -> Bool { - switch (target.tag) { - case GHOSTTY_TARGET_APP: - Ghostty.logger.warning("set title prompt does nothing with an app target") - return false + target: ghostty_target_s, + v: ghostty_action_prompt_title_e) -> Bool { + let promptTitle = Action.PromptTitle(v) + switch promptTitle { + case .surface: + switch (target.tag) { + case GHOSTTY_TARGET_APP: + Ghostty.logger.warning("set title prompt does nothing with an app target") + return false - case GHOSTTY_TARGET_SURFACE: - guard let surface = target.target.surface else { return false } - guard let surfaceView = self.surfaceView(from: surface) else { return false } - surfaceView.promptTitle() + case GHOSTTY_TARGET_SURFACE: + guard let surface = target.target.surface else { return false } + guard let surfaceView = self.surfaceView(from: surface) else { return false } + surfaceView.promptTitle() + return true - default: - assertionFailure() - } + default: + assertionFailure() + return false + } - return true - } + case .tab: + switch (target.tag) { + case GHOSTTY_TARGET_APP: + guard let window = NSApp.mainWindow ?? NSApp.keyWindow, + let controller = window.windowController as? BaseTerminalController + else { return false } + controller.promptTabTitle() + return true - private static func promptTabTitle( - _ app: ghostty_app_t, - target: ghostty_target_s) -> Bool { - switch (target.tag) { - case GHOSTTY_TARGET_APP: - guard let window = NSApp.mainWindow ?? NSApp.keyWindow, - let controller = window.windowController as? BaseTerminalController - else { return false } - controller.promptTabTitle() - return true + case GHOSTTY_TARGET_SURFACE: + 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.promptTabTitle() + return true - case GHOSTTY_TARGET_SURFACE: - 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.promptTabTitle() - return true - - default: - assertionFailure() - return false + default: + assertionFailure() + return false + } } } diff --git a/src/Surface.zig b/src/Surface.zig index b1919e13f..8cd8d253b 100644 --- a/src/Surface.zig +++ b/src/Surface.zig @@ -5183,13 +5183,13 @@ pub fn performBindingAction(self: *Surface, action: input.Binding.Action) !bool .prompt_surface_title => return try self.rt_app.performAction( .{ .surface = self }, .prompt_title, - {}, + .surface, ), .prompt_tab_title => return try self.rt_app.performAction( .{ .surface = self }, - .prompt_tab_title, - {}, + .prompt_title, + .tab, ), .clear_screen => { diff --git a/src/apprt/action.zig b/src/apprt/action.zig index f29150f13..94965d38c 100644 --- a/src/apprt/action.zig +++ b/src/apprt/action.zig @@ -189,13 +189,9 @@ pub const Action = union(Key) { set_title: SetTitle, /// Set the title of the target to a prompted value. It is up to - /// the apprt to prompt. - prompt_title, - - /// Set the title of the current tab/window to a prompted value. The title - /// set via this prompt overrides any title set by the terminal and persists - /// across focus changes within the tab. It is up to the apprt to prompt. - prompt_tab_title, + /// the apprt to prompt. The value specifies whether to prompt for the + /// surface title or the tab title. + prompt_title: PromptTitle, /// The current working directory has changed for the target terminal. pwd: Pwd, @@ -352,7 +348,6 @@ pub const Action = union(Key) { desktop_notification, set_title, prompt_title, - prompt_tab_title, pwd, mouse_shape, mouse_visibility, @@ -542,6 +537,12 @@ pub const MouseVisibility = enum(c_int) { hidden, }; +/// Whether to prompt for the surface title or tab title. +pub const PromptTitle = enum(c_int) { + surface, + tab, +}; + pub const MouseOverLink = struct { url: [:0]const u8, diff --git a/src/apprt/gtk/class/application.zig b/src/apprt/gtk/class/application.zig index 52a9f1a35..47c2972ac 100644 --- a/src/apprt/gtk/class/application.zig +++ b/src/apprt/gtk/class/application.zig @@ -693,7 +693,7 @@ pub const Application = extern struct { .progress_report => return Action.progressReport(target, value), - .prompt_title => return Action.promptTitle(target), + .prompt_title => return Action.promptTitle(target, value), .quit => self.quit(), @@ -2250,12 +2250,18 @@ const Action = struct { }; } - pub fn promptTitle(target: apprt.Target) bool { - switch (target) { - .app => return false, - .surface => |v| { - v.rt_surface.surface.promptTitle(); - return true; + pub fn promptTitle(target: apprt.Target, value: apprt.action.PromptTitle) bool { + switch (value) { + .surface => switch (target) { + .app => return false, + .surface => |v| { + v.rt_surface.surface.promptTitle(); + return true; + }, + }, + .tab => { + // GTK does not yet support tab title prompting + return false; }, } }