pub struct Display {
pub width: u32,
pub height: u32,
/* private fields */
}
Fields§
§width: u32
§height: u32
Implementations§
source§impl Display
impl Display
sourcepub fn monitors(&self) -> Vec<Monitor>
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
impl Display
sourcepub fn root_mouse_position(&self) -> Option<(i32, i32)>
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
impl Display
sourcepub fn new(
display_identifier: impl Into<String>
) -> Result<Self, DisplayCreationError>
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
sourcepub fn capture(&self) -> Result<Image, ()>
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.
sourcepub fn capture_area(
&self,
offset: (u32, u32),
size: (u32, u32)
) -> Result<Image, ()>
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§
Auto Trait Implementations§
impl RefUnwindSafe for Display
impl !Send for Display
impl !Sync for Display
impl Unpin for Display
impl UnwindSafe for Display
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