Merge pull request #192 from Smithay/fix/primary_gpu

Fix primary_gpu
This commit is contained in:
Victor Brekenfeld 2020-04-18 18:26:49 +02:00 committed by GitHub
commit 2101f17b7b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 23 additions and 17 deletions

View File

@ -174,26 +174,32 @@ pub fn primary_gpu<S: AsRef<str>>(seat: S) -> IoResult<Option<PathBuf>> {
enumerator.match_subsystem("drm")?;
enumerator.match_sysname("card[0-9]*")?;
let mut result = None;
for device in enumerator.scan_devices()? {
if let Some(path) = enumerator
.scan_devices()?
.filter_map(|device| {
if device
.property_value("ID_SEAT")
.map(|x| x.to_os_string())
.unwrap_or_else(|| OsString::from("seat0"))
== *seat.as_ref()
{
if let Some(pci) = device.parent_with_subsystem(Path::new("pci"))? {
if let Ok(Some(pci)) = device.parent_with_subsystem(Path::new("pci")) {
if let Some(id) = pci.attribute_value("boot_vga") {
if id == "1" {
result = Some(device);
}
}
} else if result.is_none() {
result = Some(device);
return Some(device);
}
}
}
Ok(result.and_then(|device| device.devnode().map(PathBuf::from)))
};
None
})
.flat_map(|device| device.devnode().map(PathBuf::from))
.next()
{
Ok(Some(path))
} else {
all_gpus(seat).map(|all| all.into_iter().next())
}
}
/// Returns the paths of all available GPU devices