Set XDG_SESSION_TYPE

This commit is contained in:
Jeremy Soller 2024-02-06 10:32:56 -07:00
parent 24ed38e3f8
commit c3e530434d
No known key found for this signature in database
GPG key ID: D02FD439211AF56F

View file

@ -48,15 +48,23 @@ pub fn main() -> Result<(), Box<dyn std::error::Error>> {
.collect() .collect()
}; };
enum SessionType {
X11,
Wayland,
}
//TODO: allow custom directories? //TODO: allow custom directories?
let session_dirs = &[ let session_dirs = &[
(Path::new("/usr/share/wayland-sessions"), false), (
(Path::new("/usr/share/xsessions"), true), Path::new("/usr/share/wayland-sessions"),
SessionType::Wayland,
),
(Path::new("/usr/share/xsessions"), SessionType::X11),
]; ];
let sessions = { let sessions = {
let mut sessions = HashMap::new(); let mut sessions = HashMap::new();
for (session_dir, x_wrapper) in session_dirs { for (session_dir, session_type) in session_dirs {
let read_dir = match fs::read_dir(&session_dir) { let read_dir = match fs::read_dir(&session_dir) {
Ok(ok) => ok, Ok(ok) => ok,
Err(err) => { Err(err) => {
@ -116,15 +124,26 @@ pub fn main() -> Result<(), Box<dyn std::error::Error>> {
} }
}; };
let mut command = if *x_wrapper { let mut command = match session_type {
vec!["startx".to_string(), "/usr/bin/env".to_string()] SessionType::X11 => {
} else { //TODO: xinit may be better, but more complicated to set up
vec![] vec![
"startx".to_string(),
"/usr/bin/env".to_string(),
"XDG_SESSION_TYPE=x11".to_string(),
]
}
SessionType::Wayland => {
vec![
"/usr/bin/env".to_string(),
"XDG_SESSION_TYPE=wayland".to_string(),
]
}
}; };
match shlex::split(exec) { match shlex::split(exec) {
Some(split) => { Some(args) => {
for arg in split { for arg in args {
command.push(arg) command.push(arg)
} }
} }