screen_read_display()

Updated: October 26, 2022

Take a screenshot of the display and store the resulting image in the specified buffer

Synopsis:

#include <screen/screen.h>
int screen_read_display(screen_display_t disp,
                        screen_buffer_t buf,
                        int count,
                        const int *read_rects,
                        int flags)

Arguments:

disp
The handle of the display that's the target of the screenshot.
buf
The buffer where the resulting image is stored.
count
If read_rects is provided, set to 1. Otherwise, set to 0 for a screen shot of the entire display.
read_rects
A pointer to an array of integers {x,y,w,h}, containing the x,y coordinates of the top left corner, width, and height of the rectangle respectively to capture.
flags
For future use. Pass 0 for now.

Library:

libscreen

Description:

Function Type: Immediate Execution

This function takes a screenshot of a display and stores the result in a user-provided buffer. The buffer can be a pixmap buffer or a window buffer. The buffer must have been created with the usage flag SCREEN_USAGE_NATIVE in order for the operation to succeed. You need to be working within a privileged context so that you have full access to the display properties of the system. Therefore, a context which was created with the type SCREEN_DISPLAY_MANAGER_CONTEXT must be used. When capturing screenshots of multiple displays, you will need to make one screen_read_display() function call per display. This function blocks until the operation is completed. If count is 0 and read_rects is NULL, the entire display is grabbed. Otherwise, set count to 1 and read_rects must point to the array of integers defining the rectangle and display coordinates that need to be grabbed. Note that the buffer size doesn't have to match the display size. Scaling is applied to make the screenshot fit into the buffer that's provided.

Returns:

0 if successful, or -1 if an error occurred (errno is set; refer to errno.h for more details).