From 955be3658b29407efa4b3aa93349e38887327a7e Mon Sep 17 00:00:00 2001 From: o9000 Date: Sun, 27 Mar 2016 23:27:34 +0200 Subject: [PATCH] Use imlib2 for taking screenshot; if it fails, use Xlib (issue #574) --- src/tint.c | 39 ++++++++++++++++++++------------------- 1 file changed, 20 insertions(+), 19 deletions(-) diff --git a/src/tint.c b/src/tint.c index 484cd0e..058b6d5 100644 --- a/src/tint.c +++ b/src/tint.c @@ -567,30 +567,31 @@ void get_snapshot(const char *path) XSync(server.display, False); - Imlib_Image img = NULL; - XImage *ximg = - XGetImage(server.display, panel->temp_pmap, 0, 0, panel->area.width, panel->area.height, AllPlanes, ZPixmap); + imlib_context_set_drawable(panel->temp_pmap); + Imlib_Image img = imlib_create_image_from_drawable(0, 0, 0, panel->area.width, panel->area.height, 1); - if (ximg) { - DATA32 *pixels = calloc(panel->area.width * panel->area.height, sizeof(DATA32)); - for (int x = 0; x < panel->area.width; x++) { - for (int y = 0; y < panel->area.height; y++) { - DATA32 xpixel = XGetPixel(ximg, x, y); + if (!img) { + XImage *ximg = + XGetImage(server.display, panel->temp_pmap, 0, 0, panel->area.width, panel->area.height, AllPlanes, ZPixmap); - DATA32 r = (xpixel >> 16) & 0xff; - DATA32 g = (xpixel >> 8) & 0xff; - DATA32 b = (xpixel >> 0) & 0xff; - DATA32 a = 0x0; + if (ximg) { + DATA32 *pixels = calloc(panel->area.width * panel->area.height, sizeof(DATA32)); + for (int x = 0; x < panel->area.width; x++) { + for (int y = 0; y < panel->area.height; y++) { + DATA32 xpixel = XGetPixel(ximg, x, y); - DATA32 argb = (a << 24) | (r << 16) | (g << 8) | b; - pixels[y * panel->area.width + x] = argb; + DATA32 r = (xpixel >> 16) & 0xff; + DATA32 g = (xpixel >> 8) & 0xff; + DATA32 b = (xpixel >> 0) & 0xff; + DATA32 a = 0x0; + + DATA32 argb = (a << 24) | (r << 16) | (g << 8) | b; + pixels[y * panel->area.width + x] = argb; + } } + XDestroyImage(ximg); + img = imlib_create_image_using_data(panel->area.width, panel->area.height, pixels); } - XDestroyImage(ximg); - img = imlib_create_image_using_data(panel->area.width, panel->area.height, pixels); - } else { - imlib_context_set_drawable(panel->temp_pmap); - img = imlib_create_image_from_drawable(0, 0, 0, panel->area.width, panel->area.height, 1); } if (img) {