WayshotConnection

Struct WayshotConnection 

Source
pub struct WayshotConnection {
    pub conn: Connection,
    pub globals: GlobalList,
    /* private fields */
}
Expand description

Struct to store wayland connection and globals list.

§Example usage

use libwayshot::WayshotConnection;
let wayshot_connection = WayshotConnection::new()?;
let image_buffer = wayshot_connection.screenshot_all()?;

Fields§

§conn: Connection§globals: GlobalList

Implementations§

Source§

impl WayshotConnection

Source

pub fn new() -> Result<Self>

Source

pub fn from_connection(conn: Connection) -> Result<Self>

Recommended if you already have a wayland_client::Connection.

Source

pub fn from_connection_with_dmabuf( conn: Connection, device_path: &str, ) -> Result<Self>

Create a WayshotConnection struct having DMA-BUF support Using this connection is required to make use of the dmabuf functions

§Parameters
  • conn: a Wayland connection
  • device_path: string pointing to the DRI device that is to be used for creating the DMA-BUFs on. For example: “/dev/dri/renderD128”
Source

pub fn get_all_outputs(&self) -> &[OutputInfo]

Fetch all accessible wayland outputs.

Source

pub fn refresh_outputs(&mut self) -> Result<()>

refresh the outputs, to get new outputs

Source

pub fn capture_output_frame_shm_fd<T: AsFd>( &self, cursor_overlay: i32, output: &WlOutput, fd: T, capture_region: Option<EmbeddedRegion>, ) -> Result<(FrameFormat, FrameGuard)>

Get a FrameCopy instance with screenshot pixel data for any wl_output object. Data will be written to fd.

Source

pub unsafe fn bind_output_frame_to_gl_texture( &self, cursor_overlay: bool, output: &WlOutput, capture_region: Option<EmbeddedRegion>, ) -> Result<()>

§Safety

Helper function/wrapper that uses the OpenGL extension OES_EGL_image to convert the EGLImage obtained from WayshotConnection::capture_output_frame_eglimage into a OpenGL texture.

  • The caller is supposed to setup everything required for the texture binding. An example call may look like:
gl::BindTexture(gl::TEXTURE_2D, self.gl_texture);
gl::TexParameteri(gl::TEXTURE_2D, gl::TEXTURE_MIN_FILTER, gl::LINEAR as i32);
wayshot_conn
    .bind_output_frame_to_gl_texture(
        true,
       &wayshot_conn.get_all_outputs()[0].wl_output,
       None)
§Parameters
  • cursor_overlay: A boolean flag indicating whether the cursor should be included in the capture.
  • output: Reference to the WlOutput from which the frame is to be captured.
  • capture_region: Optional region specifying a sub-area of the output to capture. If None, the entire output is captured.
§Returns
  • If the function was found and called, an OK(()), note that this does not necessarily mean that binding was successful, only that the function was called. The caller may check for any OpenGL errors using the standard routes.
  • If the function was not found, Error::EGLImageToTexProcNotFoundError is returned
Source

pub fn capture_output_frame_eglimage<'a, T: EGL1_5>( &self, egl_instance: &'a Instance<T>, cursor_overlay: bool, output: &WlOutput, capture_region: Option<EmbeddedRegion>, ) -> Result<EGLImageGuard<'a, T>>

Obtain a screencapture in the form of a EGLImage. The display on which this image is created is obtained from the Wayland Connection. Uses the dma-buf provisions of the wlr-screencopy copy protocol to avoid VRAM->RAM copies It returns the captured frame as an EGLImage, wrapped in an EGLImageGuard for safe handling and cleanup.

§Parameters
  • egl_instance: Reference to an egl API instance obtained from the khronos_egl crate, which is used to create the EGLImage.
  • cursor_overlay: A boolean flag indicating whether the cursor should be included in the capture.
  • output: Reference to the WlOutput from which the frame is to be captured.
  • capture_region: Optional region specifying a sub-area of the output to capture. If None, the entire output is captured.
§Returns

If successful, an EGLImageGuard which contains a pointer ‘image’ to the created EGLImage On error, the EGL error code is returned via this crates Error type

Source

pub fn capture_output_frame_eglimage_on_display<'a, T: EGL1_5>( &self, egl_instance: &'a Instance<T>, egl_display: Display, cursor_overlay: bool, output: &WlOutput, capture_region: Option<EmbeddedRegion>, ) -> Result<EGLImageGuard<'a, T>>

Obtain a screencapture in the form of a EGLImage on the given EGLDisplay.

Uses the dma-buf provisions of the wlr-screencopy copy protocol to avoid VRAM->RAM copies It returns the captured frame as an EGLImage, wrapped in an EGLImageGuard for safe handling and cleanup.

§Parameters
  • egl_instance: Reference to an EGL1_5 instance, which is used to create the EGLImage.
  • egl_display: The EGLDisplay on which the image should be created.
  • cursor_overlay: A boolean flag indicating whether the cursor should be included in the capture.
  • output: Reference to the WlOutput from which the frame is to be captured.
  • capture_region: Optional region specifying a sub-area of the output to capture. If None, the entire output is captured.
§Returns

If successful, an EGLImageGuard which contains a pointer ‘image’ to the created EGLImage On error, the EGL error code is returned via this crates Error type

Source

pub fn capture_output_frame_dmabuf( &self, cursor_overlay: bool, output: &WlOutput, capture_region: Option<EmbeddedRegion>, ) -> Result<(DMAFrameFormat, DMAFrameGuard, BufferObject<()>)>

Obtain a screencapture in the form of a WlBuffer backed by a GBM Bufferobject on the GPU. Uses the dma-buf provisions of the wlr-screencopy copy protocol to avoid VRAM->RAM copies The captured frame is returned as a tuple containing the frame format, a guard to manage the WlBuffer’s cleanup on drop, and the underlying BufferObject.

  • cursor_overlay: A boolean flag indicating whether the cursor should be included in the capture.
  • output: Reference to the WlOutput from which the frame is to be captured.
  • capture_region: Optional region specifying a sub-area of the output to capture. If None, the entire output is captured.
§Returns

On success, returns a tuple containing the frame format, a guard to manage the frame’s lifecycle, and the GPU-backed BufferObject.

§Errors
  • Returns NoDMAStateError if the DMA-BUF state is not initialized a the time of initialization of this struct.
Source

pub fn capture_output_frame_get_state_shm( &self, cursor_overlay: i32, output: &WlOutput, capture_region: Option<EmbeddedRegion>, ) -> Result<(CaptureFrameState, EventQueue<CaptureFrameState>, ZwlrScreencopyFrameV1, FrameFormat)>

Source

pub fn capture_frame_copies( &self, output_capture_regions: &[(OutputInfo, Option<EmbeddedRegion>)], cursor_overlay: bool, ) -> Result<Vec<(FrameCopy, FrameGuard, OutputInfo)>>

Source

pub fn screenshot( &self, capture_region: LogicalRegion, cursor_overlay: bool, ) -> Result<DynamicImage>

Take a screenshot from the specified region.

Source

pub fn screenshot_freeze<F>( &self, callback: F, cursor_overlay: bool, ) -> Result<DynamicImage>
where F: Fn(&WayshotConnection) -> Result<LogicalRegion> + 'static,

Take a screenshot, overlay the screenshot, run the callback, and then unfreeze the screenshot and return the selected region.

Source

pub fn screenshot_single_output( &self, output_info: &OutputInfo, cursor_overlay: bool, ) -> Result<DynamicImage>

Take a screenshot from one output

Source

pub fn screenshot_outputs( &self, outputs: &[OutputInfo], cursor_overlay: bool, ) -> Result<DynamicImage>

Take a screenshot from all of the specified outputs.

Source

pub fn screenshot_all(&self, cursor_overlay: bool) -> Result<DynamicImage>

Take a screenshot from all accessible outputs.

Trait Implementations§

Source§

impl Debug for WayshotConnection

Source§

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

Formats the value using the given formatter. 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> Downcast<T> for T

Source§

fn downcast(&self) -> &T

Source§

impl<T> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
Source§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
Source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
Source§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

Source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Sync + Send>

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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>,

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.
Source§

impl<T> Upcast<T> for T

Source§

fn upcast(&self) -> Option<&T>

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more