Merge pull request #15 from lilyinstarlight/feature/xdg-data-dirs-sessions

Search all XDG_DATA_DIRS and XDG_DATA_HOME for sessions
This commit is contained in:
Jeremy Soller 2024-02-24 21:02:16 -07:00 committed by GitHub
commit df9f2092e8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 27 additions and 9 deletions

1
Cargo.lock generated
View file

@ -825,6 +825,7 @@ dependencies = [
"tokio",
"upower_dbus",
"wayland-client 0.31.1",
"xdg",
"zbus",
]

View file

@ -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"

View file

@ -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<dyn Error>> {
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();