Fix disable hdmi when connected but inactive
This commit is contained in:
parent
29329db6fb
commit
c20cebe944
12
src/lib.rs
12
src/lib.rs
|
@ -126,6 +126,9 @@ pub struct Screen {
|
||||||
|
|
||||||
/// Whether the screen is connected or not.
|
/// Whether the screen is connected or not.
|
||||||
pub connected: bool,
|
pub connected: bool,
|
||||||
|
|
||||||
|
/// Whether the screen is active or not.
|
||||||
|
pub active: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Screen {
|
impl Screen {
|
||||||
|
@ -138,6 +141,7 @@ impl Screen {
|
||||||
resolutions: vec![],
|
resolutions: vec![],
|
||||||
primary: line.contains("primary"),
|
primary: line.contains("primary"),
|
||||||
connected: line.contains(" connected"),
|
connected: line.contains(" connected"),
|
||||||
|
active: false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -190,6 +194,10 @@ impl MultiScreen {
|
||||||
.split("_").collect::<Vec<_>>()[0]
|
.split("_").collect::<Vec<_>>()[0]
|
||||||
.split("x").collect::<Vec<_>>();
|
.split("x").collect::<Vec<_>>();
|
||||||
|
|
||||||
|
if split[1].contains("*") {
|
||||||
|
last.active = true;
|
||||||
|
}
|
||||||
|
|
||||||
if let Ok(width) = resolution[0].parse::<u32>() {
|
if let Ok(width) = resolution[0].parse::<u32>() {
|
||||||
if let Ok(height) = resolution[1].parse::<u32>() {
|
if let Ok(height) = resolution[1].parse::<u32>() {
|
||||||
last.resolutions.push((width, height));
|
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.
|
/// If a HDMI screen is detected, puts the sound on it. Otherwise, disables it.
|
||||||
pub fn enable_hdmi_sound_if_present(&self) -> Result<(), Error> {
|
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 {
|
Ok(if hdmi {
|
||||||
enable_hdmi_sound()?
|
enable_hdmi_sound()?
|
||||||
|
|
|
@ -44,6 +44,10 @@ fn main() {
|
||||||
_ => Ok(())
|
_ => Ok(())
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Redetect screen to update active attribute
|
||||||
|
let screens = MultiScreen::detect()
|
||||||
|
.expect("An error happened while finding screens");
|
||||||
|
|
||||||
if sound {
|
if sound {
|
||||||
if let Err(e) = screens.enable_hdmi_sound_if_present() {
|
if let Err(e) = screens.enable_hdmi_sound_if_present() {
|
||||||
eprintln!("Error: couldn't set hdmi sound: {:?}", e);
|
eprintln!("Error: couldn't set hdmi sound: {:?}", e);
|
||||||
|
|
Loading…
Reference in New Issue