mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-07-14 15:56:13 +03:00
core: detect what desktop environment the user is using
This commit is contained in:
@ -3,6 +3,7 @@ const build_options = @import("build_options");
|
|||||||
const Allocator = std.mem.Allocator;
|
const Allocator = std.mem.Allocator;
|
||||||
const builtin = @import("builtin");
|
const builtin = @import("builtin");
|
||||||
const build_config = @import("../build_config.zig");
|
const build_config = @import("../build_config.zig");
|
||||||
|
const internal_os = @import("../os/main.zig");
|
||||||
const xev = @import("xev");
|
const xev = @import("xev");
|
||||||
const renderer = @import("../renderer.zig");
|
const renderer = @import("../renderer.zig");
|
||||||
const gtk = if (build_config.app_runtime == .gtk) @import("../apprt/gtk/c.zig").c else void;
|
const gtk = if (build_config.app_runtime == .gtk) @import("../apprt/gtk/c.zig").c else void;
|
||||||
@ -36,6 +37,7 @@ pub fn run(alloc: Allocator) !u8 {
|
|||||||
try stdout.print(" - font engine: {}\n", .{build_config.font_backend});
|
try stdout.print(" - font engine: {}\n", .{build_config.font_backend});
|
||||||
try stdout.print(" - renderer : {}\n", .{renderer.Renderer});
|
try stdout.print(" - renderer : {}\n", .{renderer.Renderer});
|
||||||
try stdout.print(" - libxev : {}\n", .{xev.backend});
|
try stdout.print(" - libxev : {}\n", .{xev.backend});
|
||||||
|
try stdout.print(" - desktop env: {s}\n", .{@tagName(internal_os.desktopEnvironment())});
|
||||||
if (comptime build_config.app_runtime == .gtk) {
|
if (comptime build_config.app_runtime == .gtk) {
|
||||||
try stdout.print(" - GTK version:\n", .{});
|
try stdout.print(" - GTK version:\n", .{});
|
||||||
try stdout.print(" build : {d}.{d}.{d}\n", .{
|
try stdout.print(" build : {d}.{d}.{d}\n", .{
|
||||||
|
@ -59,3 +59,28 @@ pub fn launchedFromDesktop() bool {
|
|||||||
else => @compileError("unsupported platform"),
|
else => @compileError("unsupported platform"),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub const DesktopEnvironment = enum {
|
||||||
|
gnome,
|
||||||
|
macos,
|
||||||
|
other,
|
||||||
|
windows,
|
||||||
|
};
|
||||||
|
|
||||||
|
/// Detect what desktop environment we are running under. This is mainly used on
|
||||||
|
/// Linux to enable or disable GTK client-side decorations but there may be more
|
||||||
|
/// uses in the future.
|
||||||
|
pub fn desktopEnvironment() DesktopEnvironment {
|
||||||
|
return switch (comptime builtin.os.tag) {
|
||||||
|
.macos => .macos,
|
||||||
|
.windows => .windows,
|
||||||
|
.linux => de: {
|
||||||
|
// use $XDG_SESSION_DESKTOP to determine what DE we are using on Linux
|
||||||
|
// https://www.freedesktop.org/software/systemd/man/latest/pam_systemd.html#desktop=
|
||||||
|
const de = posix.getenv("XDG_SESSION_DESKTOP") orelse break :de .other;
|
||||||
|
if (std.ascii.eqlIgnoreCase("gnome", de)) break :de .gnome;
|
||||||
|
break :de .other;
|
||||||
|
},
|
||||||
|
else => .other,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
@ -32,6 +32,7 @@ pub const getenv = env.getenv;
|
|||||||
pub const setenv = env.setenv;
|
pub const setenv = env.setenv;
|
||||||
pub const unsetenv = env.unsetenv;
|
pub const unsetenv = env.unsetenv;
|
||||||
pub const launchedFromDesktop = desktop.launchedFromDesktop;
|
pub const launchedFromDesktop = desktop.launchedFromDesktop;
|
||||||
|
pub const desktopEnvironment = desktop.desktopEnvironment;
|
||||||
pub const rlimit = file.rlimit;
|
pub const rlimit = file.rlimit;
|
||||||
pub const fixMaxFiles = file.fixMaxFiles;
|
pub const fixMaxFiles = file.fixMaxFiles;
|
||||||
pub const restoreMaxFiles = file.restoreMaxFiles;
|
pub const restoreMaxFiles = file.restoreMaxFiles;
|
||||||
|
Reference in New Issue
Block a user