Struct rxscreen::Display

source ·
pub struct Display {
    pub width: u32,
    pub height: u32,
    /* private fields */
}

Fields§

§width: u32§height: u32

Implementations§

source§

impl Display

source

pub fn monitors(&self) -> Vec<Monitor>

Query every monitor connected to the display

if let Ok(display) = Display::new(":0.0") {
   let monitors = display.monitors();
   for monitor in monitors {
       println!("Monitor: {}", monitor.name());
       println!("\tPrimary: {}", monitor.primary());
       println!("\tSize: {}x{}", monitor.width, monitor.height);
       println!("\tPosition: {}x{}", monitor.x, monitor.y);
   }
}
source§

impl Display

source

pub fn shm(&self) -> ShmBuilder<'_>

source§

impl Display

source

pub fn root_mouse_position(&self) -> Option<(i32, i32)>

Query the mouse position relative to the root window

if let Ok(display) = Display::new(":0.0") {
   let Some((mouse_x, mouse_y)) = display.root_mouse_position() else {
        println!("Failed to get mouse position");
   }
   println!("Mouse Pos: {}, {}", mouse_x, mouse_y);
}
source§

impl Display

source

pub fn new( display_identifier: impl Into<String> ) -> Result<Self, DisplayCreationError>

Open a display to X server using XOpenDisplay at specified display domain

if let Ok(display) = Display::new(":0.0") {
    // do something with display
}
§Errors

If the call to XOpenDisplay fails, or if display_identifier couldn’t be converted to a C String, then this function will return a DisplayCreationError with details

source

pub fn capture(&self) -> Result<Image, ()>

Take a screenshot of the display.

if let Ok(display) = Display::new(":0.0") {
    let capture = display.capture();
    #[cfg(feature = "save")]
    // With "save" feature enabled
    capture.unwrap().save_as("./capture.png");
    #[cfg(not(feature = "save"))]
    // Access to raw image data without "save" feature
    let raw_data = unsafe { capture.unwrap().as_raw_slice() };
}
§Errors

This function fails silently if the call to XGetImage fails for some reason.

source

pub fn capture_area( &self, offset: (u32, u32), size: (u32, u32) ) -> Result<Image, ()>

Take a screenshot of the provided area.

if let Ok(display) = Display::new(":0.0") {
    // Capture a 300x300 area of the display, starting at `1920 / 2 - 300` (x)
    // and `1080 / 2 - 300` (y)
    // i.e. the 300px in the center of the display (if it's a 1920x1080 display)
    let capture = display.capture_area((1920 / 2 - 300, 1080 / 2 - 300), (300, 300));
}
§Errors

This function fails silently if the call to XGetImage fails for some reason.

Trait Implementations§

source§

impl Drop for Display

source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

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> 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, U> TryFrom<U> for T
where U: Into<T>,

§

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>,

§

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.