#screenshot #x11 #display #xrandr #shared-memory #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

#225 in Images

Download history 13/week @ 2024-06-17 15/week @ 2024-06-24 26/week @ 2024-07-01 11/week @ 2024-07-08 8/week @ 2024-07-15 24/week @ 2024-07-22 100/week @ 2024-07-29 50/week @ 2024-08-05 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

144 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.8MB
~12K SLoC