diff --git a/src/lib.rs b/src/lib.rs index f20c030..fb0a354 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -126,6 +126,9 @@ pub struct Screen { /// Whether the screen is connected or not. pub connected: bool, + + /// Whether the screen is active or not. + pub active: bool, } impl Screen { @@ -138,6 +141,7 @@ impl Screen { resolutions: vec![], primary: line.contains("primary"), connected: line.contains(" connected"), + active: false, } } @@ -190,6 +194,10 @@ impl MultiScreen { .split("_").collect::>()[0] .split("x").collect::>(); + if split[1].contains("*") { + last.active = true; + } + if let Ok(width) = resolution[0].parse::() { if let Ok(height) = resolution[1].parse::() { last.resolutions.push((width, height)); @@ -364,7 +372,9 @@ impl MultiScreen { /// If a HDMI screen is detected, puts the sound on it. Otherwise, disables it. pub fn enable_hdmi_sound_if_present(&self) -> Result<(), Error> { - let hdmi = self.screens.iter().fold(false, |acc, x| acc || x.name.to_lowercase().contains("hdmi")); + let hdmi = self.screens + .iter() + .fold(false, |acc, x| acc || x.name.to_lowercase().contains("hdmi") && x.active); Ok(if hdmi { enable_hdmi_sound()? diff --git a/src/tv.rs b/src/tv.rs index 3188253..aa1957e 100644 --- a/src/tv.rs +++ b/src/tv.rs @@ -44,6 +44,10 @@ fn main() { _ => Ok(()) }; + // Redetect screen to update active attribute + let screens = MultiScreen::detect() + .expect("An error happened while finding screens"); + if sound { if let Err(e) = screens.enable_hdmi_sound_if_present() { eprintln!("Error: couldn't set hdmi sound: {:?}", e);