summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeffrey C. Ollie <jeff@ocjtech.us>2025-01-01 18:06:31 -0600
committerJeffrey C. Ollie <jeff@ocjtech.us>2025-01-02 18:29:31 -0600
commit5c39d09053c360bb58b91dbc71c3151c3b23d99e (patch)
tree178950ad12b9d63eccaffb9afb7f91c9ab5674e9
parentcde8b7e8101d181b792a045e2a2c9bc07f97e824 (diff)
core: detect what desktop environment the user is using
-rw-r--r--src/cli/version.zig2
-rw-r--r--src/os/desktop.zig25
-rw-r--r--src/os/main.zig1
3 files changed, 28 insertions, 0 deletions
diff --git a/src/cli/version.zig b/src/cli/version.zig
index 29ab7f63f..177558ac9 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;
@@ -36,6 +37,7 @@ pub fn run(alloc: Allocator) !u8 {
try stdout.print(" - font engine: {}\n", .{build_config.font_backend});
try stdout.print(" - renderer : {}\n", .{renderer.Renderer});
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) {
try stdout.print(" - GTK version:\n", .{});
try stdout.print(" build : {d}.{d}.{d}\n", .{
diff --git a/src/os/desktop.zig b/src/os/desktop.zig
index 103127dfa..20738f191 100644
--- a/src/os/desktop.zig
+++ b/src/os/desktop.zig
@@ -59,3 +59,28 @@ 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: {
+ // 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 b529a470d..e652a7981 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;