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