diff --git a/src/cli/version.zig b/src/cli/version.zig index 29ab7f63fa..99f03384b4 100644 --- a/src/cli/version.zig +++ b/src/cli/version.zig @@ -3,6 +3,7 @@ const build_options = @import("build_options"); const Allocator = std.mem.Allocator; const builtin = @import("builtin"); const build_config = @import("../build_config.zig"); +const internal_os = @import("../os/main.zig"); const xev = @import("xev"); const renderer = @import("../renderer.zig"); const gtk = if (build_config.app_runtime == .gtk) @import("../apprt/gtk/c.zig").c else void; @@ -37,6 +38,7 @@ pub fn run(alloc: Allocator) !u8 { try stdout.print(" - renderer : {}\n", .{renderer.Renderer}); try stdout.print(" - libxev : {}\n", .{xev.backend}); if (comptime build_config.app_runtime == .gtk) { + try stdout.print(" - desktop env: {s}\n", .{@tagName(internal_os.desktopEnvironment())}); try stdout.print(" - GTK version:\n", .{}); try stdout.print(" build : {d}.{d}.{d}\n", .{ gtk.GTK_MAJOR_VERSION, diff --git a/src/os/desktop.zig b/src/os/desktop.zig index 103127dfa1..3a61e2eaa4 100644 --- a/src/os/desktop.zig +++ b/src/os/desktop.zig @@ -59,3 +59,29 @@ pub fn launchedFromDesktop() bool { 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: { + if (@inComptime()) @compileError("Checking for the desktop environment on Linux must be done at runtime."); + // 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, + }; +} diff --git a/src/os/main.zig b/src/os/main.zig index b529a470d1..e652a7981b 100644 --- a/src/os/main.zig +++ b/src/os/main.zig @@ -32,6 +32,7 @@ pub const getenv = env.getenv; pub const setenv = env.setenv; pub const unsetenv = env.unsetenv; pub const launchedFromDesktop = desktop.launchedFromDesktop; +pub const desktopEnvironment = desktop.desktopEnvironment; pub const rlimit = file.rlimit; pub const fixMaxFiles = file.fixMaxFiles; pub const restoreMaxFiles = file.restoreMaxFiles;