I\'m trying to make a screenshot using Xlib and Cairo, however I\'m not sure to do it the good way, \"stride\" is really confusing me.
Instead of doing all this complicated magic, let cairo do it for you:
#include
#include
#include
int main(int argc, char** argv) {
Display *disp;
Window root;
cairo_surface_t *surface;
int scr;
disp = XOpenDisplay(NULL);
scr = DefaultScreen(disp);
root = DefaultRootWindow(disp);
surface = cairo_xlib_surface_create(disp, root, DefaultVisual(disp, scr),
DisplayWidth(disp, scr), DisplayHeight(disp, scr));
cairo_surface_write_to_png(
surface,
"test.png");
cairo_surface_destroy(surface);
return 0;
}