From cb8762180eaafc4ff6d9a48789624a520345807a Mon Sep 17 00:00:00 2001 From: Lily Foster Date: Mon, 19 Feb 2024 22:08:02 -0500 Subject: [PATCH] Search all XDG_DATA_DIRS and XDG_DATA_HOME for sessions --- Cargo.lock | 1 + Cargo.toml | 1 + src/greeter.rs | 34 +++++++++++++++++++++++++--------- 3 files changed, 27 insertions(+), 9 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 5167d12..2c1d045 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -825,6 +825,7 @@ dependencies = [ "tokio", "upower_dbus", "wayland-client 0.31.1", + "xdg", "zbus", ] diff --git a/Cargo.toml b/Cargo.toml index bc69503..b5d913b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,6 +16,7 @@ pam-client = "0.5.0" pwd.workspace = true ron.workspace = true shlex = "1.2.0" +xdg = "2.5.2" #TODO: reduce features tokio = { workspace = true, features = ["full"] } wayland-client = "0.31.1" diff --git a/src/greeter.rs b/src/greeter.rs index afd41b4..0165b6e 100644 --- a/src/greeter.rs +++ b/src/greeter.rs @@ -25,7 +25,15 @@ use cosmic::{ }; use cosmic_greeter_daemon::{UserData, WallpaperData}; use greetd_ipc::{codec::SyncCodec, AuthMessageType, Request, Response}; -use std::{collections::HashMap, env, error::Error, fs, io, path::Path, process, sync::Arc}; +use std::{ + collections::HashMap, + env, + error::Error, + fs, io, + path::{Path, PathBuf}, + process, + sync::Arc, +}; use tokio::{net::UnixStream, time}; use wayland_client::{protocol::wl_output::WlOutput, Proxy}; use zbus::{dbus_proxy, Connection}; @@ -116,14 +124,22 @@ pub fn main() -> Result<(), Box> { Wayland, } - //TODO: allow custom directories? - let session_dirs = &[ - ( - Path::new("/usr/share/wayland-sessions"), - SessionType::Wayland, - ), - (Path::new("/usr/share/xsessions"), SessionType::X11), - ]; + let session_dirs = xdg::BaseDirectories::with_prefix("wayland-sessions") + .map_or( + vec![PathBuf::from("/usr/share/wayland-sessions")], + |xdg_dirs| xdg_dirs.get_data_dirs(), + ) + .into_iter() + .map(|dir| (dir, SessionType::Wayland)) + .chain( + xdg::BaseDirectories::with_prefix("xsessions") + .map_or( + vec![PathBuf::from("/usr/share/xsessions")], + |xdg_dirs| xdg_dirs.get_data_dirs(), + ) + .into_iter() + .map(|dir| (dir, SessionType::X11)), + ); let sessions = { let mut sessions = HashMap::new();