-
-
Save Suhail/3ae62751857ff034a027adcacd350b69 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
gcc ss.c -o ss -lxcb -lxcb-image && ./ss | |
*/ | |
#include <stdio.h> | |
#include <xcb/xcb_image.h> | |
xcb_screen_t* xcb_get_screen(xcb_connection_t* connection){ | |
const xcb_setup_t* setup = xcb_get_setup(connection); // I think we don't need to free/destroy this! | |
return xcb_setup_roots_iterator(setup).data; | |
} | |
void xcb_image_print(xcb_image_t* ximg){ | |
printf( | |
"xcb_image_print() Printing a (%u,%u) `xcb_image_t` of %u bytes, depth: " | |
"%u, bpp: %u\n\n", | |
ximg->width, ximg->height, ximg->size, ximg->depth, ximg->bpp); | |
for(int i=0; i < ximg->size; i += 4){ | |
printf(" "); | |
printf("%02x", ximg->data[i+3]); | |
printf("%02x", ximg->data[i+2]); | |
printf("%02x", ximg->data[i+1]); | |
printf("%02x", ximg->data[i+0]); | |
} | |
puts("\n"); | |
} | |
int main(){ | |
// Connect to the X server | |
xcb_connection_t* connection = xcb_connect(NULL, NULL); | |
xcb_screen_t* screen = xcb_get_screen(connection); | |
// Get pixels! | |
xcb_image_t* ximg = xcb_image_get(connection, screen->root, 0, 0, screen->width_in_pixels, screen->height_in_pixels, 0xffffffff, XCB_IMAGE_FORMAT_Z_PIXMAP); | |
// ... Now all pixels are in ximg->data! | |
xcb_image_print(ximg); | |
// Clean-up | |
xcb_image_destroy(ximg); | |
xcb_disconnect(connection); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment