Struct Display

Source
pub struct Display<'a> { /* private fields */ }
Expand description

A struct that represents a display (index)

Implementations§

Source§

impl Display<'_>

Source

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}
Source

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
Hide additional 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}
Source

pub fn string(&self) -> &str

Source

pub fn key(&self) -> &str

Source

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
Hide additional 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}
Source

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}
Source

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}
Source

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
Hide additional 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§

Source§

impl<'a> Clone for Display<'a>

Source§

fn clone(&self) -> Display<'a>

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'a> Debug for Display<'a>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'a> PartialEq for Display<'a>

Source§

fn eq(&self, other: &Display<'a>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<'a> Eq for Display<'a>

Source§

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.