[Backport] Check for session file name in autologin

Signed-off-by: AnErrupTion <anerruption@disroot.org>
This commit is contained in:
AnErrupTion
2025-12-30 17:45:29 +01:00
parent 066acf91e6
commit 08b4a49729
3 changed files with 6 additions and 11 deletions

View File

@@ -14,9 +14,9 @@ pub const DesktopEntry = struct {
pub const Entry = struct { @"Desktop Entry": DesktopEntry = .{} }; pub const Entry = struct { @"Desktop Entry": DesktopEntry = .{} };
entry_ini: ?Ini(Entry) = null, entry_ini: ?Ini(Entry) = null,
file_name: []const u8 = "",
name: []const u8 = "", name: []const u8 = "",
xdg_session_desktop: ?[]const u8 = null, xdg_session_desktop: ?[]const u8 = null,
xdg_session_desktop_owned: bool = false,
xdg_desktop_names: ?[]const u8 = null, xdg_desktop_names: ?[]const u8 = null,
cmd: ?[]const u8 = null, cmd: ?[]const u8 = null,
specifier: []const u8 = "", specifier: []const u8 = "",

View File

@@ -1251,10 +1251,10 @@ fn crawl(session: *Session, lang: Lang, path: []const u8, display_server: Displa
}); });
errdefer entry_ini.deinit(); errdefer entry_ini.deinit();
const file_name = try session.label.allocator.dupe(u8, std.fs.path.stem(item.name));
const entry = entry_ini.data.@"Desktop Entry"; const entry = entry_ini.data.@"Desktop Entry";
var maybe_xdg_session_desktop: ?[]const u8 = null; var maybe_xdg_session_desktop: ?[]const u8 = null;
var maybe_xdg_desktop_names: ?[]const u8 = null; var maybe_xdg_desktop_names: ?[]const u8 = null;
var xdg_session_desktop_owned = false;
// Prepare the XDG_SESSION_DESKTOP and XDG_CURRENT_DESKTOP environment // Prepare the XDG_SESSION_DESKTOP and XDG_CURRENT_DESKTOP environment
// variables here // variables here
@@ -1268,18 +1268,14 @@ fn crawl(session: *Session, lang: Lang, path: []const u8, display_server: Displa
} else if (display_server != .custom) { } else if (display_server != .custom) {
// If DesktopNames is empty, and this isn't a custom session entry, // If DesktopNames is empty, and this isn't a custom session entry,
// we'll take the name of the session file // we'll take the name of the session file
const stem = std.fs.path.stem(item.name); if (file_name.len > 0) maybe_xdg_session_desktop = file_name;
if (stem.len > 0) {
maybe_xdg_session_desktop = try session.label.allocator.dupe(u8, stem);
xdg_session_desktop_owned = true;
}
} }
try session.addEnvironment(.{ try session.addEnvironment(.{
.entry_ini = entry_ini, .entry_ini = entry_ini,
.file_name = file_name,
.name = entry.Name, .name = entry.Name,
.xdg_session_desktop = maybe_xdg_session_desktop, .xdg_session_desktop = maybe_xdg_session_desktop,
.xdg_session_desktop_owned = xdg_session_desktop_owned,
.xdg_desktop_names = maybe_xdg_desktop_names, .xdg_desktop_names = maybe_xdg_desktop_names,
.cmd = entry.Exec, .cmd = entry.Exec,
.specifier = switch (display_server) { .specifier = switch (display_server) {
@@ -1310,6 +1306,7 @@ fn findSessionByName(session: *Session, name: []const u8) ?usize {
if (std.ascii.eqlIgnoreCase(session_desktop_name, name)) return i; if (std.ascii.eqlIgnoreCase(session_desktop_name, name)) return i;
} }
if (std.ascii.eqlIgnoreCase(env.environment.name, name)) return i; if (std.ascii.eqlIgnoreCase(env.environment.name, name)) return i;
if (std.ascii.eqlIgnoreCase(env.environment.file_name, name)) return i;
} }
return null; return null;
} }

View File

@@ -29,9 +29,7 @@ pub fn init(allocator: Allocator, buffer: *TerminalBuffer, user_list: *UserList)
pub fn deinit(self: *Session) void { pub fn deinit(self: *Session) void {
for (self.label.list.items) |*env| { for (self.label.list.items) |*env| {
if (env.environment.entry_ini) |*entry_ini| entry_ini.deinit(); if (env.environment.entry_ini) |*entry_ini| entry_ini.deinit();
if (env.environment.xdg_session_desktop_owned) { self.label.allocator.free(env.environment.file_name);
self.label.allocator.free(env.environment.xdg_session_desktop.?);
}
} }
self.label.deinit(); self.label.deinit();