Little refactor
This commit is contained in:
parent
0d99991827
commit
b5b7ca104b
5 changed files with 16 additions and 11 deletions
7
Cargo.lock
generated
7
Cargo.lock
generated
|
@ -80,6 +80,7 @@ version = "0.1.0"
|
|||
dependencies = [
|
||||
"anyhow",
|
||||
"drm",
|
||||
"glob",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -92,6 +93,12 @@ dependencies = [
|
|||
"windows-sys",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "glob"
|
||||
version = "0.3.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d2fabcfbdc87f4758337ca535fb41a6d701b65693ce38287d856d1674551ec9b"
|
||||
|
||||
[[package]]
|
||||
name = "libc"
|
||||
version = "0.2.159"
|
||||
|
|
|
@ -4,5 +4,6 @@ version = "0.1.0"
|
|||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
glob = "0.3.1"
|
||||
anyhow = "1.0.91"
|
||||
drm = "0.14.1"
|
|
@ -3,19 +3,14 @@ use drm::control::Device as ControlDevice;
|
|||
use std::os::fd::{AsFd, BorrowedFd};
|
||||
use std::fmt::Debug;
|
||||
|
||||
// A simple wrapper for a device node.
|
||||
pub struct Card(std::fs::File);
|
||||
|
||||
/// Implementing [`AsFd`] is a prerequisite to implementing the traits found
|
||||
/// in this crate. Here, we are just calling [`File::as_fd()`] on the inner
|
||||
/// [`File`].
|
||||
impl AsFd for Card {
|
||||
fn as_fd(&self) -> BorrowedFd<'_> {
|
||||
self.0.as_fd()
|
||||
}
|
||||
}
|
||||
|
||||
/// Simple helper methods for opening a `Card`.
|
||||
impl Card {
|
||||
pub fn open(path: &str) -> anyhow::Result<Self> {
|
||||
let mut options = std::fs::OpenOptions::new();
|
2
src/drm_impl/mod.rs
Normal file
2
src/drm_impl/mod.rs
Normal file
|
@ -0,0 +1,2 @@
|
|||
mod card;
|
||||
pub use card::Card;
|
12
src/main.rs
12
src/main.rs
|
@ -1,9 +1,9 @@
|
|||
use drm::control::Device;
|
||||
|
||||
mod card;
|
||||
mod drm_impl;
|
||||
|
||||
fn main() {
|
||||
let gpu = match card::Card::open("/dev/dri/card1") {
|
||||
let gpu = match drm_impl::Card::open("/dev/dri/card1") {
|
||||
Ok(gpu) => gpu,
|
||||
Err(err) => {
|
||||
panic!("Impossible to open DRM file : {:?}", err);
|
||||
|
@ -14,7 +14,7 @@ fn main() {
|
|||
print_connectors(&gpu);
|
||||
}
|
||||
|
||||
fn print_connectors(gpu: &card::Card) {
|
||||
fn print_connectors(gpu: &drm_impl::Card) {
|
||||
let resource_handles = gpu.resource_handles().unwrap();
|
||||
|
||||
println!("Connectors:");
|
||||
|
@ -23,7 +23,7 @@ fn print_connectors(gpu: &card::Card) {
|
|||
}
|
||||
}
|
||||
|
||||
fn print_connector(gpu: &card::Card, connector_handle: &drm::control::connector::Handle) {
|
||||
fn print_connector(gpu: &drm_impl::Card, connector_handle: &drm::control::connector::Handle) {
|
||||
match gpu.get_connector(*connector_handle, false) {
|
||||
Ok(connector) => {
|
||||
println!("\t{} ({:?})", connector.interface().as_str(), connector.state());
|
||||
|
@ -37,7 +37,7 @@ fn print_connector(gpu: &card::Card, connector_handle: &drm::control::connector:
|
|||
};
|
||||
}
|
||||
|
||||
fn format_encoder(gpu: &card::Card, encoder_handle: Option<drm::control::encoder::Handle>) -> String {
|
||||
fn format_encoder(gpu: &drm_impl::Card, encoder_handle: Option<drm::control::encoder::Handle>) -> String {
|
||||
match encoder_handle.and_then(|handle| gpu.get_encoder(handle).ok()) {
|
||||
Some(encoder) => {
|
||||
let crtc_info = format_crtc(&gpu, encoder.crtc());
|
||||
|
@ -48,7 +48,7 @@ fn format_encoder(gpu: &card::Card, encoder_handle: Option<drm::control::encoder
|
|||
}
|
||||
}
|
||||
|
||||
fn format_crtc(gpu: &card::Card, crtc_handle: Option<drm::control::crtc::Handle>) -> String {
|
||||
fn format_crtc(gpu: &drm_impl::Card, crtc_handle: Option<drm::control::crtc::Handle>) -> String {
|
||||
match crtc_handle.and_then(|handle| Some(gpu.get_crtc(handle))) {
|
||||
Some(crtc) => format!("{:?}", crtc),
|
||||
None => format!("No CRTC data")
|
||||
|
|
Loading…
Reference in a new issue