-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathresolution.rs
27 lines (22 loc) · 922 Bytes
/
resolution.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
use displayz::{Resolution, query_displays, refresh};
/// Prints and changes the current resolution of the primary display
fn main() -> Result<(), Box<dyn std::error::Error>> {
let display_set = query_displays()?;
println!("Discovered displays:\n{}", display_set);
if let Some(settings) = display_set.primary().settings() {
let res = (*settings).borrow().resolution;
println!("Current resolution: {:?}", res);
if res.height == 1080 {
println!("Resolution is 1080p, changing to 720p");
(*settings).borrow_mut().resolution = Resolution::new(1280, 720);
} else {
println!("Resolution is 720p, changing to 1080p");
(*settings).borrow_mut().resolution = Resolution::new(1920, 1080);
}
} else {
eprintln!("Primary display has no settings");
}
display_set.primary().apply()?;
refresh()?;
Ok(())
}