mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-10-03 00:18:35 +00:00
os/xdg: Avoid allocations on non-Windows systems.
os/desktop: Add TODO
This commit is contained in:
@@ -40,6 +40,7 @@ pub fn launchedFromDesktop() bool {
|
|||||||
|
|
||||||
break :linux gio_pid == pid;
|
break :linux gio_pid == pid;
|
||||||
},
|
},
|
||||||
|
//TODO: maybe find a way to check that
|
||||||
.windows => false,
|
.windows => false,
|
||||||
|
|
||||||
else => @compileError("unsupported platform"),
|
else => @compileError("unsupported platform"),
|
||||||
|
@@ -20,22 +20,35 @@ pub const Options = struct {
|
|||||||
|
|
||||||
/// Get the XDG user config directory. The returned value is allocated.
|
/// Get the XDG user config directory. The returned value is allocated.
|
||||||
pub fn config(alloc: Allocator, opts: Options) ![]u8 {
|
pub fn config(alloc: Allocator, opts: Options) ![]u8 {
|
||||||
if (std.process.getEnvVarOwned(alloc, "XDG_CONFIG_HOME")) |env| {
|
if (builtin.os.tag == .windows) {
|
||||||
defer alloc.free(env);
|
if (std.process.getEnvVarOwned(alloc, "XDG_CONFIG_HOME")) |env| {
|
||||||
// If we have a subdir, then we use the env as-is to avoid a copy.
|
// If we have a subdir, then we use the env as-is to avoid a copy.
|
||||||
if (opts.subdir) |subdir| {
|
if (opts.subdir) |subdir| {
|
||||||
return try std.fs.path.join(alloc, &[_][]const u8{
|
defer alloc.free(env);
|
||||||
env,
|
return try std.fs.path.join(alloc, &[_][]const u8{
|
||||||
subdir,
|
env,
|
||||||
});
|
subdir,
|
||||||
}
|
});
|
||||||
|
}
|
||||||
|
|
||||||
return try alloc.dupe(u8, env);
|
// We don't need to dupe since it's already allocated
|
||||||
} else |err| {
|
return env;
|
||||||
switch (err) {
|
} else |err| switch (err) {
|
||||||
error.EnvironmentVariableNotFound => {},
|
error.EnvironmentVariableNotFound => {},
|
||||||
else => return err,
|
else => return err,
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
if (std.os.getenv("XDG_CONFIG_HOME")) |env| {
|
||||||
|
// If we have a subdir, then we use the env as-is to avoid a copy.
|
||||||
|
if (opts.subdir) |subdir| {
|
||||||
|
return try std.fs.path.join(alloc, &[_][]const u8{
|
||||||
|
env,
|
||||||
|
subdir,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return try alloc.dupe(u8, env);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// If we have a cached home dir, use that.
|
// If we have a cached home dir, use that.
|
||||||
|
Reference in New Issue
Block a user