diff --git a/src/main.rs b/src/main.rs index a99488a435..a389d5eb48 100644 --- a/src/main.rs +++ b/src/main.rs @@ -78,6 +78,36 @@ pub fn run(file: &Path) -> Result<()> { println!("init: failed to run: no argument"); }, "run.d" => if let Some(new_dir) = args.next() { + // On startup, the VESA display driver is started which basically makes use of the framebuffer + // provided by the firmware. The GPU device are latter started by `pcid` (such as `virtio-gpu`). + let mut devices = vec![]; + let schemes = std::fs::read_dir(":").unwrap(); + + for entry in schemes { + let path = entry.unwrap().path(); + let path_str = path + .into_os_string() + .into_string() + .expect("init: failed to convert path to string"); + + if path_str.contains("display") { + println!("init: found display scheme {}", path_str); + devices.push(path_str); + } + } + + let device = devices.iter().filter(|d| !d.contains("vesa")).collect::>(); + let device = if device.is_empty() { + // No GPU available, fallback to VESA display which *should* always be accessible. + "vesa" + } else { + // :/display/virtio-gpu + // ^^^^^^^^^^ + device[0].split("/").nth(2).unwrap() + }; + + std::env::set_var("DISPLAY", &format!("display/{}:3/activate", device)); + let mut entries = vec![]; match read_dir(&new_dir) { Ok(list) => for entry_res in list {