diff --git a/awesomeConfig.cmake b/awesomeConfig.cmake index c148bcd7..1cbccb02 100644 --- a/awesomeConfig.cmake +++ b/awesomeConfig.cmake @@ -142,6 +142,7 @@ pkg_check_modules(AWESOME_REQUIRED REQUIRED xcb-atom>=0.3.0 xcb-keysyms>=0.3.0 xcb-icccm>=0.3.0 + xcb-image>=0.3.0 cairo-xcb xproto>=7.0.11 imlib2) diff --git a/client.c b/client.c index 5dde6c50..8e1415eb 100644 --- a/client.c +++ b/client.c @@ -20,6 +20,7 @@ */ #include +#include #include "cnode.h" #include "tag.h" @@ -129,6 +130,40 @@ client_maybevisible(client_t *c, int screen) return false; } +/** Return the content of a client as an image. + * That's just take a screenshot. + * \param c The client. + * \return An image. + */ +static image_t * +client_getcontent(client_t *c) +{ + xcb_image_t *ximage = xcb_image_get(globalconf.connection, + c->win, + 0, 0, + c->geometries.internal.width, + c->geometries.internal.height, + ~0, XCB_IMAGE_FORMAT_Z_PIXMAP); + + if(!ximage || ximage->bpp < 24) + return NULL; + + uint32_t *data = p_alloca(uint32_t, ximage->width * ximage->height); + + for(int y = 0; y < ximage->height; y++) + for(int x = 0; x < ximage->width; x++) + { + data[y * ximage->width + x] = xcb_image_get_pixel(ximage, x, y); + data[y * ximage->width + x] |= 0xff000000; /* set alpha to 0xff */ + } + + image_t *image = image_new_from_argb32(ximage->width, ximage->height, data); + + xcb_image_destroy(ximage); + + return image; +} + /** Get a client by its window. * \param w The client window to find. * \return A client pointer if found, NULL otherwise. @@ -1556,6 +1591,8 @@ luaA_client_index(lua_State *L) switch(a_tokenize(buf, len)) { + image_t *image; + case A_TK_NAME: lua_pushstring(L, (*c)->name); break; @@ -1566,6 +1603,10 @@ luaA_client_index(lua_State *L) case A_TK_SKIP_TASKBAR: lua_pushboolean(L, (*c)->skiptb); break; + case A_TK_CONTENT: + if((image = client_getcontent(*c))) + return luaA_image_userdata_new(L, image); + return 0; case A_TK_TYPE: switch((*c)->type) { diff --git a/common/tokenize.gperf b/common/tokenize.gperf index 947ccdcb..97df714c 100644 --- a/common/tokenize.gperf +++ b/common/tokenize.gperf @@ -18,6 +18,7 @@ client color Control conffile +content Ctrl cursor east