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_subsystem("drm")?;
enumerator.match_sysname("card[0-9]*")?; enumerator.match_sysname("card[0-9]*")?;
let mut result = None; if let Some(path) = enumerator
for device in enumerator.scan_devices()? { .scan_devices()?
if device .filter_map(|device| {
.property_value("ID_SEAT") if device
.map(|x| x.to_os_string()) .property_value("ID_SEAT")
.unwrap_or_else(|| OsString::from("seat0")) .map(|x| x.to_os_string())
== *seat.as_ref() .unwrap_or_else(|| OsString::from("seat0"))
{ == *seat.as_ref()
if let Some(pci) = device.parent_with_subsystem(Path::new("pci"))? { {
if let Some(id) = pci.attribute_value("boot_vga") { if let Ok(Some(pci)) = device.parent_with_subsystem(Path::new("pci")) {
if id == "1" { if let Some(id) = pci.attribute_value("boot_vga") {
result = Some(device); if id == "1" {
return Some(device);
}
} }
} }
} else if result.is_none() { };
result = Some(device); None
} })
} .flat_map(|device| device.devnode().map(PathBuf::from))
.next()
{
Ok(Some(path))
} else {
all_gpus(seat).map(|all| all.into_iter().next())
} }
Ok(result.and_then(|device| device.devnode().map(PathBuf::from)))
} }
/// Returns the paths of all available GPU devices /// Returns the paths of all available GPU devices