From 0860a4cd7bdc826b32425bdcdc29dcfdbc12bc7b Mon Sep 17 00:00:00 2001 From: Florian RICHER Date: Fri, 4 Oct 2024 00:13:27 +0200 Subject: [PATCH] Refactor encoder info --- src/main.rs | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/src/main.rs b/src/main.rs index 5d6aa56..47e021a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -20,19 +20,7 @@ fn main() { Ok(connector) => { println!("\t{} ({:?})", connector.interface().as_str(), connector.state()); - let current_encoder = connector - .current_encoder() - .and_then(|encoder_handle| gpu.get_encoder(encoder_handle).ok()); - - let encoder_info = match current_encoder { - Some(encoder) => { - - let crtc_info = format_crtc(&gpu, encoder.crtc()); - - format!("{:?}, {}", encoder.kind(), crtc_info) - } - None => format!("No encoder found") - }; + let encoder_info = format_encoder(&gpu, connector.current_encoder()); println!("\t\tEncoder: {}", encoder_info); @@ -43,6 +31,17 @@ fn main() { } } +fn format_encoder(gpu: &card::Card, encoder_handle: Option) -> String { + match encoder_handle.and_then(|handle| gpu.get_encoder(handle).ok()) { + Some(encoder) => { + let crtc_info = format_crtc(&gpu, encoder.crtc()); + + format!("{:?}, {}", encoder.kind(), crtc_info) + } + None => format!("No encoder found") + } +} + fn format_crtc(gpu: &card::Card, crtc_handle: Option) -> String { match crtc_handle.and_then(|handle| Some(gpu.get_crtc(handle))) { Some(crtc) => format!("{:?}", crtc),