Best resolution for only secondary screen
This commit is contained in:
parent
db7e6bfa42
commit
150588628e
33
src/lib.rs
33
src/lib.rs
|
@ -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() {
|
|
||||||
|
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![
|
Some(vec![
|
||||||
"--output".to_owned(),
|
"--output".to_owned(),
|
||||||
main.name.clone(),
|
main.name.clone(),
|
||||||
"--off".to_owned(),
|
"--off".to_owned(),
|
||||||
"--output".to_owned(),
|
"--output".to_owned(),
|
||||||
second.name.clone(),
|
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.
|
/// Calls the xrandr program to disable all screens except the primary.
|
||||||
|
|
Loading…
Reference in New Issue