pub struct Display<'a> { /* private fields */ }
Expand description
A struct that represents a display (index)
Implementations§
Source§impl Display<'_>
impl Display<'_>
Sourcepub fn index(&self) -> usize
pub fn index(&self) -> usize
Examples found in repository?
examples/find.rs (line 20)
4fn main() -> Result<(), Box<dyn std::error::Error>> {
5 let display_set = query_displays()?;
6 println!("Discovered displays:\n{}", display_set);
7
8 // find a display by filtering
9 match display_set
10 .displays()
11 .find(|display| display.name() == "\\\\.\\DISPLAY3")
12 {
13 Some(display) => println!("Display3 found. Is primary? {}", display.is_primary()),
14 None => println!("Display 3 not found"),
15 }
16
17 println!(
18 "Primary is `{}` with index `{}`",
19 display_set.primary().name(),
20 display_set.primary().index()
21 );
22
23 // getting the displays properties by index
24 if let Some(new_primary) = display_set.get(0) {
25 if let Some(settings) = new_primary.settings() {
26 println!(
27 "Position of display with index 0: {}",
28 (*settings.borrow()).position
29 );
30 }
31 }
32
33 Ok(())
34}
Sourcepub fn name(&self) -> &str
pub fn name(&self) -> &str
Examples found in repository?
examples/primary.rs (line 11)
4fn main() -> Result<(), Box<dyn std::error::Error>> {
5 let display_set = query_displays()?;
6 println!("Discovered displays:\n{}", display_set);
7
8 // find a display by filtering by name
9 let display = display_set
10 .displays()
11 .find(|display| display.name() == "\\\\.\\DISPLAY2");
12
13 // set display primary
14 if let Some(display) = display {
15 display.set_primary()?;
16 // display_set.set_primary(&display)?; // this works, too
17 }
18
19 // apply the changed settings
20 display_set.apply()?;
21 refresh()?;
22
23 Ok(())
24}
More examples
examples/find.rs (line 11)
4fn main() -> Result<(), Box<dyn std::error::Error>> {
5 let display_set = query_displays()?;
6 println!("Discovered displays:\n{}", display_set);
7
8 // find a display by filtering
9 match display_set
10 .displays()
11 .find(|display| display.name() == "\\\\.\\DISPLAY3")
12 {
13 Some(display) => println!("Display3 found. Is primary? {}", display.is_primary()),
14 None => println!("Display 3 not found"),
15 }
16
17 println!(
18 "Primary is `{}` with index `{}`",
19 display_set.primary().name(),
20 display_set.primary().index()
21 );
22
23 // getting the displays properties by index
24 if let Some(new_primary) = display_set.get(0) {
25 if let Some(settings) = new_primary.settings() {
26 println!(
27 "Position of display with index 0: {}",
28 (*settings.borrow()).position
29 );
30 }
31 }
32
33 Ok(())
34}
pub fn string(&self) -> &str
pub fn key(&self) -> &str
Sourcepub fn settings(&self) -> &Option<RefCell<DisplaySettings>>
pub fn settings(&self) -> &Option<RefCell<DisplaySettings>>
Examples found in repository?
examples/resolution.rs (line 8)
4fn main() -> Result<(), Box<dyn std::error::Error>> {
5 let display_set = query_displays()?;
6 println!("Discovered displays:\n{}", display_set);
7
8 if let Some(settings) = display_set.primary().settings() {
9 let res = (*settings).borrow().resolution;
10 println!("Current resolution: {:?}", res);
11
12 if res.height == 1080 {
13 println!("Resolution is 1080p, changing to 720p");
14 (*settings).borrow_mut().resolution = Resolution::new(1280, 720);
15 } else {
16 println!("Resolution is 720p, changing to 1080p");
17 (*settings).borrow_mut().resolution = Resolution::new(1920, 1080);
18 }
19 } else {
20 eprintln!("Primary display has no settings");
21 }
22
23 display_set.primary().apply()?;
24 refresh()?;
25
26 Ok(())
27}
More examples
examples/find.rs (line 25)
4fn main() -> Result<(), Box<dyn std::error::Error>> {
5 let display_set = query_displays()?;
6 println!("Discovered displays:\n{}", display_set);
7
8 // find a display by filtering
9 match display_set
10 .displays()
11 .find(|display| display.name() == "\\\\.\\DISPLAY3")
12 {
13 Some(display) => println!("Display3 found. Is primary? {}", display.is_primary()),
14 None => println!("Display 3 not found"),
15 }
16
17 println!(
18 "Primary is `{}` with index `{}`",
19 display_set.primary().name(),
20 display_set.primary().index()
21 );
22
23 // getting the displays properties by index
24 if let Some(new_primary) = display_set.get(0) {
25 if let Some(settings) = new_primary.settings() {
26 println!(
27 "Position of display with index 0: {}",
28 (*settings.borrow()).position
29 );
30 }
31 }
32
33 Ok(())
34}
examples/upside-down.rs (line 8)
4fn main() -> Result<(), Box<dyn std::error::Error>> {
5 let display_set = query_displays()?;
6 println!("Discovered displays:\n{}", display_set);
7
8 if let Some(settings) = display_set.primary().settings() {
9 {
10 let settings = &mut *settings.borrow_mut();
11 println!("Current orientation: {:?}", settings.orientation);
12
13 settings.orientation = match settings.orientation {
14 Orientation::PortraitFlipped => Orientation::Portrait,
15 Orientation::Portrait => Orientation::PortraitFlipped,
16 Orientation::Landscape => Orientation::LandscapeFlipped,
17 Orientation::LandscapeFlipped => Orientation::Landscape,
18 };
19
20 println!("New orientation: {:?}", settings.orientation);
21 }
22 } else {
23 eprintln!("Primary display has no settings");
24 }
25
26 display_set.primary().apply()?;
27 refresh()?;
28
29 Ok(())
30}
Sourcepub fn is_primary(&self) -> bool
pub fn is_primary(&self) -> bool
Examples found in repository?
examples/find.rs (line 13)
4fn main() -> Result<(), Box<dyn std::error::Error>> {
5 let display_set = query_displays()?;
6 println!("Discovered displays:\n{}", display_set);
7
8 // find a display by filtering
9 match display_set
10 .displays()
11 .find(|display| display.name() == "\\\\.\\DISPLAY3")
12 {
13 Some(display) => println!("Display3 found. Is primary? {}", display.is_primary()),
14 None => println!("Display 3 not found"),
15 }
16
17 println!(
18 "Primary is `{}` with index `{}`",
19 display_set.primary().name(),
20 display_set.primary().index()
21 );
22
23 // getting the displays properties by index
24 if let Some(new_primary) = display_set.get(0) {
25 if let Some(settings) = new_primary.settings() {
26 println!(
27 "Position of display with index 0: {}",
28 (*settings.borrow()).position
29 );
30 }
31 }
32
33 Ok(())
34}
Sourcepub fn set_primary(&self) -> Result<(), DisplayError>
pub fn set_primary(&self) -> Result<(), DisplayError>
Examples found in repository?
examples/primary.rs (line 15)
4fn main() -> Result<(), Box<dyn std::error::Error>> {
5 let display_set = query_displays()?;
6 println!("Discovered displays:\n{}", display_set);
7
8 // find a display by filtering by name
9 let display = display_set
10 .displays()
11 .find(|display| display.name() == "\\\\.\\DISPLAY2");
12
13 // set display primary
14 if let Some(display) = display {
15 display.set_primary()?;
16 // display_set.set_primary(&display)?; // this works, too
17 }
18
19 // apply the changed settings
20 display_set.apply()?;
21 refresh()?;
22
23 Ok(())
24}
Sourcepub fn apply(&self) -> Result<(), DisplayError>
pub fn apply(&self) -> Result<(), DisplayError>
Examples found in repository?
examples/resolution.rs (line 23)
4fn main() -> Result<(), Box<dyn std::error::Error>> {
5 let display_set = query_displays()?;
6 println!("Discovered displays:\n{}", display_set);
7
8 if let Some(settings) = display_set.primary().settings() {
9 let res = (*settings).borrow().resolution;
10 println!("Current resolution: {:?}", res);
11
12 if res.height == 1080 {
13 println!("Resolution is 1080p, changing to 720p");
14 (*settings).borrow_mut().resolution = Resolution::new(1280, 720);
15 } else {
16 println!("Resolution is 720p, changing to 1080p");
17 (*settings).borrow_mut().resolution = Resolution::new(1920, 1080);
18 }
19 } else {
20 eprintln!("Primary display has no settings");
21 }
22
23 display_set.primary().apply()?;
24 refresh()?;
25
26 Ok(())
27}
More examples
examples/upside-down.rs (line 26)
4fn main() -> Result<(), Box<dyn std::error::Error>> {
5 let display_set = query_displays()?;
6 println!("Discovered displays:\n{}", display_set);
7
8 if let Some(settings) = display_set.primary().settings() {
9 {
10 let settings = &mut *settings.borrow_mut();
11 println!("Current orientation: {:?}", settings.orientation);
12
13 settings.orientation = match settings.orientation {
14 Orientation::PortraitFlipped => Orientation::Portrait,
15 Orientation::Portrait => Orientation::PortraitFlipped,
16 Orientation::Landscape => Orientation::LandscapeFlipped,
17 Orientation::LandscapeFlipped => Orientation::Landscape,
18 };
19
20 println!("New orientation: {:?}", settings.orientation);
21 }
22 } else {
23 eprintln!("Primary display has no settings");
24 }
25
26 display_set.primary().apply()?;
27 refresh()?;
28
29 Ok(())
30}
Trait Implementations§
impl<'a> Eq for Display<'a>
impl<'a> StructuralPartialEq for Display<'a>
Auto Trait Implementations§
impl<'a> Freeze for Display<'a>
impl<'a> !RefUnwindSafe for Display<'a>
impl<'a> !Send for Display<'a>
impl<'a> !Sync for Display<'a>
impl<'a> Unpin for Display<'a>
impl<'a> !UnwindSafe for Display<'a>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more