mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-07-21 11:16:08 +03:00
xdg-terminal-exec invocations set title based on command
Fixes #1724 See background in #1724. The general idea is that for Ghostty invocations via xdg-terminal-exec, we set the initial title to the command automatically so that window managers can modify the styling. We only do this for xdg-terminal-exec because that protocol/spec is specifically for the scenario that the terminal is being used to launch a command from the desktop environment.
This commit is contained in:
@ -513,7 +513,27 @@ pub fn init(
|
||||
};
|
||||
}
|
||||
|
||||
if (config.title) |title| try rt_surface.setTitle(title);
|
||||
if (config.title) |title| {
|
||||
try rt_surface.setTitle(title);
|
||||
} else if ((comptime builtin.os.tag == .linux) and
|
||||
config.@"_xdg-terminal-exec")
|
||||
xdg: {
|
||||
// For xdg-terminal-exec execution we special-case and set the window
|
||||
// title to the command being executed. This allows window managers
|
||||
// to set custom styling based on the command being executed.
|
||||
const command = config.command orelse break :xdg;
|
||||
if (command.len > 0) {
|
||||
const title = alloc.dupeZ(u8, command) catch |err| {
|
||||
log.warn(
|
||||
"error copying command for title, title will not be set err={}",
|
||||
.{err},
|
||||
);
|
||||
break :xdg;
|
||||
};
|
||||
defer alloc.free(title);
|
||||
try rt_surface.setTitle(title);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn deinit(self: *Surface) void {
|
||||
|
@ -1108,6 +1108,9 @@ _errors: ErrorList = .{},
|
||||
/// as loadTheme which has more details on why.
|
||||
_replay_steps: std.ArrayListUnmanaged(Replay.Step) = .{},
|
||||
|
||||
/// Set to true if Ghostty was executed as xdg-terminal-exec on Linux.
|
||||
@"_xdg-terminal-exec": bool = false,
|
||||
|
||||
pub fn deinit(self: *Config) void {
|
||||
if (self._arena) |arena| arena.deinit();
|
||||
self.* = undefined;
|
||||
@ -1654,6 +1657,14 @@ pub fn loadCliArgs(self: *Config, alloc_gpa: Allocator) !void {
|
||||
// On Linux, we have a special case where if the executing
|
||||
// program is "xdg-terminal-exec" then we treat all CLI
|
||||
// args as if they are a command to execute.
|
||||
//
|
||||
// In this mode, we also behave slightly differently:
|
||||
//
|
||||
// - The initial window title is set to the full command. This
|
||||
// can be used with window managers to modify positioning,
|
||||
// styling, etc. based on the command.
|
||||
//
|
||||
// See: https://github.com/Vladimir-csp/xdg-terminal-exec
|
||||
if (comptime builtin.os.tag == .linux) xdg: {
|
||||
if (!std.mem.eql(
|
||||
u8,
|
||||
@ -1679,6 +1690,7 @@ pub fn loadCliArgs(self: *Config, alloc_gpa: Allocator) !void {
|
||||
try command.append(' ');
|
||||
}
|
||||
|
||||
self.@"_xdg-terminal-exec" = true;
|
||||
self.command = command.items[0 .. command.items.len - 1];
|
||||
return;
|
||||
}
|
||||
|
Reference in New Issue
Block a user