client: add content property

Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
Julien Danjou 2008-12-29 15:21:00 +01:00
parent 48d4c41ed9
commit bdbcd9352d
3 changed files with 43 additions and 0 deletions

View File

@ -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)

View File

@ -20,6 +20,7 @@
*/
#include <xcb/xcb_atom.h>
#include <xcb/xcb_image.h>
#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)
{

View File

@ -18,6 +18,7 @@ client
color
Control
conffile
content
Ctrl
cursor
east