Properly set XDG_CURRENT_DESKTOP

Signed-off-by: AnErrupTion <anerruption@disroot.org>
pull/603/head
AnErrupTion 2 months ago
parent 7c71dee3db
commit 0803de8ad3
No known key found for this signature in database
GPG Key ID: 3E85EB44F610AD7F

@ -27,7 +27,11 @@ pub fn authenticate(allocator: Allocator, config: Config, desktop: Desktop, logi
// Set the XDG environment variables // Set the XDG environment variables
setXdgSessionEnv(current_environment.display_server); setXdgSessionEnv(current_environment.display_server);
try setXdgEnv(allocator, tty_str, current_environment.xdg_name); if (current_environment.entry_ini) |entry| {
try setXdgEnv(allocator, tty_str, entry.DesktopNames);
} else {
try setXdgEnv(allocator, tty_str, "");
}
// Open the PAM session // Open the PAM session
const login_text_z = try allocator.dupeZ(u8, login.text.items); const login_text_z = try allocator.dupeZ(u8, login.text.items);
@ -227,18 +231,21 @@ fn setXdgSessionEnv(display_server: enums.DisplayServer) void {
} }
fn setXdgEnv(allocator: Allocator, tty_str: [:0]u8, desktop_name: []const u8) !void { fn setXdgEnv(allocator: Allocator, tty_str: [:0]u8, desktop_name: []const u8) !void {
const desktop_name_z = try allocator.dupeZ(u8, desktop_name);
defer allocator.free(desktop_name_z);
const uid = interop.getuid(); const uid = interop.getuid();
var uid_buffer: [10 + @sizeOf(u32) + 1]u8 = undefined; var uid_buffer: [10 + @sizeOf(u32) + 1]u8 = undefined;
const uid_str = try std.fmt.bufPrintZ(&uid_buffer, "/run/user/{d}", .{uid}); const uid_str = try std.fmt.bufPrintZ(&uid_buffer, "/run/user/{d}", .{uid});
_ = interop.setenv("XDG_CURRENT_DESKTOP", desktop_name_z.ptr, 0); if (desktop_name.len > 0) {
const desktop_name_z = try allocator.dupeZ(u8, desktop_name);
defer allocator.free(desktop_name_z);
_ = interop.setenv("XDG_CURRENT_DESKTOP", desktop_name_z.ptr, 0);
_ = interop.setenv("XDG_SESSION_DESKTOP", desktop_name_z.ptr, 0);
}
_ = interop.setenv("XDG_RUNTIME_DIR", uid_str.ptr, 0); _ = interop.setenv("XDG_RUNTIME_DIR", uid_str.ptr, 0);
_ = interop.setenv("XDG_SESSION_CLASS", "user", 0); _ = interop.setenv("XDG_SESSION_CLASS", "user", 0);
_ = interop.setenv("XDG_SESSION_ID", "1", 0); _ = interop.setenv("XDG_SESSION_ID", "1", 0);
_ = interop.setenv("XDG_SESSION_DESKTOP", desktop_name_z.ptr, 0);
_ = interop.setenv("XDG_SEAT", "seat0", 0); _ = interop.setenv("XDG_SEAT", "seat0", 0);
_ = interop.setenv("XDG_VTNR", tty_str.ptr, 0); _ = interop.setenv("XDG_VTNR", tty_str.ptr, 0);
} }

@ -18,7 +18,6 @@ const Desktop = @This();
pub const Environment = struct { pub const Environment = struct {
entry_ini: ?Ini(Entry) = null, entry_ini: ?Ini(Entry) = null,
name: []const u8 = "", name: []const u8 = "",
xdg_name: []const u8 = "",
cmd: []const u8 = "", cmd: []const u8 = "",
specifier: []const u8 = "", specifier: []const u8 = "",
display_server: DisplayServer = .wayland, display_server: DisplayServer = .wayland,
@ -27,6 +26,7 @@ pub const Environment = struct {
const DesktopEntry = struct { const DesktopEntry = struct {
Exec: []const u8 = "", Exec: []const u8 = "",
Name: []const u8 = "", Name: []const u8 = "",
DesktopNames: []const u8 = "",
}; };
pub const Entry = struct { Desktop_Entry: DesktopEntry = DesktopEntry{} }; pub const Entry = struct { Desktop_Entry: DesktopEntry = DesktopEntry{} };
@ -71,7 +71,6 @@ pub fn addEnvironment(self: *Desktop, name: []const u8, cmd: []const u8, display
try self.environments.append(.{ try self.environments.append(.{
.entry_ini = null, .entry_ini = null,
.name = name, .name = name,
.xdg_name = getXdgName(name),
.cmd = cmd, .cmd = cmd,
.specifier = switch (display_server) { .specifier = switch (display_server) {
.wayland => self.lang.wayland, .wayland => self.lang.wayland,
@ -88,7 +87,6 @@ pub fn addEnvironmentWithIni(self: *Desktop, entry_ini: Ini(Entry), name: []cons
try self.environments.append(.{ try self.environments.append(.{
.entry_ini = entry_ini, .entry_ini = entry_ini,
.name = name, .name = name,
.xdg_name = getXdgName(name),
.cmd = cmd, .cmd = cmd,
.specifier = switch (display_server) { .specifier = switch (display_server) {
.wayland => self.lang.wayland, .wayland => self.lang.wayland,
@ -173,8 +171,3 @@ fn goRight(self: *Desktop) void {
self.current += 1; self.current += 1;
} }
fn getXdgName(name: []const u8) []const u8 {
// TODO
return name;
}

Loading…
Cancel
Save