Best resolution for only secondary screen

This commit is contained in:
Thomas Forgione 2019-04-08 14:15:39 +02:00
parent db7e6bfa42
commit 150588628e
No known key found for this signature in database
GPG Key ID: 203DAEA747F48F41
1 changed files with 21 additions and 26 deletions

View File

@ -143,22 +143,9 @@ impl Screen {
/// Finds the best common resolution between two screens.
fn best_common_resolution(&self, other: &Screen) -> Option<(u32, u32)> {
let self_res: HashSet<(u32, u32)> = self.resolutions.clone().into_iter().collect();
let other_res: HashSet<(u32, u32)> = other.resolutions.clone().into_iter().collect();
let intersection = self_res.intersection(&other_res);
let mut output = None;
for element in intersection {
match output {
None => output = Some(*element),
Some(res) if &res < element => output = Some(*element),
_ => (),
}
}
output
self_res.intersection(&other_res).into_iter().max().cloned()
}
}
@ -311,18 +298,26 @@ impl MultiScreen {
/// Returns the arguments for enabling only the second screen.
pub fn only_secondary_args(&self) -> Option<Vec<String>> {
if let Some((ref main, ref second)) = self.main_screens() {
let (main, second) = match self.main_screens() {
Some(x) => x,
None => return None,
};
let (width, height) = match second.resolutions.iter().max() {
Some(x) => x,
None => return None,
};
Some(vec![
"--output".to_owned(),
main.name.clone(),
"--off".to_owned(),
"--output".to_owned(),
second.name.clone(),
"--auto".to_owned(),
"--mode".to_owned(),
format!("{}x{}", width, height),
])
} else {
None
}
}
/// Calls the xrandr program to disable all screens except the primary.