#screenshot #x11 #display #xrandr #mouse-position #mit-shm

rxscreen

A wrapper around libx11 to capture screenshots and save them

7 releases

0.1.7 Feb 18, 2024
0.1.6 Feb 13, 2023
0.1.5 Nov 16, 2022
0.1.3 Mar 4, 2021

#230 in Images

Download history 23/week @ 2024-08-12 13/week @ 2024-08-19 36/week @ 2024-08-26 20/week @ 2024-09-02 18/week @ 2024-09-09 33/week @ 2024-09-16 51/week @ 2024-09-23 38/week @ 2024-09-30 24/week @ 2024-10-07 112/week @ 2024-10-14 62/week @ 2024-10-21 42/week @ 2024-10-28 57/week @ 2024-11-04 30/week @ 2024-11-11 82/week @ 2024-11-18 34/week @ 2024-11-25

217 downloads per month

MIT license

76KB
2K SLoC

rxscreen

A simple wrapper over libx11 to take screenshots.

Dependencies

  • libx11
  • libxext (with the shm feature)
  • libxrandr (with the xrandr feature)

Features

  • save (save screenshots directly to file)
  • MIT-SHM (use the MIT-SHM extension to rapidly take screenshots, used for screenrecording and similar)
  • Xrandr (use Xrandr to query monitors connected to the X11 server)
  • Mouse (query the mouse position)

Planned features

  • Graphics, to allow creating own displays and drawing on them.
  • Extend Xrandr support to change display configuration

Similar projects


lib.rs:

rxscreen is designed to be a simple, easy to use library around various functionality of the x11 server and corresponding extensions. Implemented features:

  • X11
  • Xrandr (via the xrandr feature)
  • MIT-SHM (via the shm feature)

Examples

Capture a screenshot of the entire X11 display

if let Ok(display) = Display::new(":0.0") {
   let capture = display.capture()
                    .unwrap();
   // `capture` is now an `Image` containing Bgr8 data of the image.
   // You can now save it to a file, or do whatever you want with it.
}

Capture a screenshot of a specific monitor (requires the "xrandr" feature)

#[cfg(feature = "xrandr")]
#[cfg(feature = "xrandr")]
if let Ok(display) = Display::new(":0.0") {
  if let Some(monitor) = display.monitors()
                             .iter()
                             .find(|monitor| monitor.primary()) {
      let capture = display.capture_area(
              (monitor.x as u32, monitor.y as u32),
              (monitor.width as u32, monitor.height as u32)
          ).unwrap();
      // `capture` is now an `Image` containing the screenshot of the primary monitor as Bgr8 data.
      // You can now save it to a file, or do whatever you want with it.
   }
}

Dependencies

~0–0.9MB
~12K SLoC