Skip to content

Commit

Permalink
fix(GPU): use XDG to get hwdata path
Browse files Browse the repository at this point in the history
  • Loading branch information
ShadowApex committed Dec 10, 2024
1 parent 7dd6310 commit b81c0c3
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 2 deletions.
9 changes: 8 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ tokio = { version = "*", features = ["full"] }
zbus = { version = "3.14.1", default-features = false, features = ["tokio"] }
zbus_macros = "3.14.1"
rog_platform = { git = "https://gitlab.com/asus-linux/asusctl.git", default-features = true }
xdg = "2.5.2"

[profile.release]
debug = false
Expand Down
24 changes: 23 additions & 1 deletion src/performance/gpu/dbus/gpu.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use std::fs::{self, File};
use std::io::{prelude::*, BufReader};
use std::path::PathBuf;
use std::sync::Arc;
use zbus::fdo;
use zbus::zvariant::ObjectPath;
Expand Down Expand Up @@ -301,7 +302,7 @@ pub async fn get_gpu(path: String) -> Result<GPUDBusInterface, std::io::Error> {
.to_lowercase();

// Open the file that contains hardware ID mappings
let hw_ids_file = File::open(PCI_IDS_PATH)?;
let hw_ids_file = File::open(get_pci_ids_path())?;
let reader = BufReader::new(hw_ids_file);

// Set the class based on class ID
Expand Down Expand Up @@ -464,3 +465,24 @@ pub fn get_connectors(gpu_name: String) -> Vec<Connector> {
log::debug!("Finished finding connectors");
connectors
}

/// Returns the path to the PCI id's file from hwdata
fn get_pci_ids_path() -> PathBuf {
let Ok(base_dirs) = xdg::BaseDirectories::with_prefix("hwdata") else {
log::warn!("Unable to determine config base path. Using fallback path.");
return PathBuf::from(PCI_IDS_PATH);
};

// Get the data directories in preference order
let data_dirs = base_dirs.get_data_dirs();
for dir in data_dirs {
if dir.exists() {
let mut path = dir.into_os_string();
path.push("/pci.ids");
return path.into();
}
}

log::warn!("Config base path not found. Using fallback path.");
PathBuf::from(PCI_IDS_PATH)
}

0 comments on commit b81c0c3

Please sign in to comment.