image: use new object system

Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
Julien Danjou 2009-04-09 11:38:56 +02:00
parent 38a79ca9f0
commit 541d4f565f
9 changed files with 104 additions and 170 deletions

View File

@ -93,9 +93,9 @@ client_maybevisible(client_t *c, int screen)
/** Return the content of a client as an image. /** Return the content of a client as an image.
* That's just take a screenshot. * That's just take a screenshot.
* \param c The client. * \param c The client.
* \return An image. * \return 1 if the image has been pushed on stack, false otherwise.
*/ */
static image_t * static int
client_getcontent(client_t *c) client_getcontent(client_t *c)
{ {
xcb_image_t *ximage = xcb_image_get(globalconf.connection, xcb_image_t *ximage = xcb_image_get(globalconf.connection,
@ -104,24 +104,27 @@ client_getcontent(client_t *c)
c->geometries.internal.width, c->geometries.internal.width,
c->geometries.internal.height, c->geometries.internal.height,
~0, XCB_IMAGE_FORMAT_Z_PIXMAP); ~0, XCB_IMAGE_FORMAT_Z_PIXMAP);
int retval = 0;
if(!ximage || ximage->bpp < 24) if(ximage)
return NULL; {
if(ximage->bpp >= 24)
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); uint32_t *data = p_alloca(uint32_t, ximage->width * ximage->height);
data[y * ximage->width + x] |= 0xff000000; /* set alpha to 0xff */
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 */
}
retval = image_new_from_argb32(ximage->width, ximage->height, data);
} }
xcb_image_destroy(ximage);
}
image_t *image = image_new_from_argb32(ximage->width, ximage->height, data); return retval;
xcb_image_destroy(ximage);
return image;
} }
/** Get a client by its window. /** Get a client by its window.
@ -425,7 +428,6 @@ client_manage(xcb_window_t w, xcb_get_geometry_reply_t *wgeom, int phys_screen,
{ {
xcb_get_property_cookie_t ewmh_icon_cookie; xcb_get_property_cookie_t ewmh_icon_cookie;
client_t *c, *tc = NULL; client_t *c, *tc = NULL;
image_t *icon;
int screen; int screen;
const uint32_t select_input_val[] = { CLIENT_SELECT_INPUT_EVENT_MASK }; const uint32_t select_input_val[] = { CLIENT_SELECT_INPUT_EVENT_MASK };
@ -457,8 +459,9 @@ client_manage(xcb_window_t w, xcb_get_geometry_reply_t *wgeom, int phys_screen,
c->geometries.internal.width = wgeom->width; c->geometries.internal.width = wgeom->width;
c->geometries.internal.height = wgeom->height; c->geometries.internal.height = wgeom->height;
client_setborder(c, wgeom->border_width); client_setborder(c, wgeom->border_width);
if((icon = ewmh_window_icon_get_reply(ewmh_icon_cookie)))
c->icon = image_ref(&icon); if(ewmh_window_icon_get_reply(ewmh_icon_cookie))
c->icon = image_ref(globalconf.L);
/* we honor size hints by default */ /* we honor size hints by default */
c->size_hints_honor = true; c->size_hints_honor = true;
@ -1650,7 +1653,6 @@ luaA_client_newindex(lua_State *L)
double d; double d;
int i; int i;
wibox_t **t = NULL; wibox_t **t = NULL;
image_t **image;
if((*c)->invalid) if((*c)->invalid)
luaL_error(L, "client is invalid\n"); luaL_error(L, "client is invalid\n");
@ -1687,10 +1689,8 @@ luaA_client_newindex(lua_State *L)
client_setmaxvert(*c, luaA_checkboolean(L, 3)); client_setmaxvert(*c, luaA_checkboolean(L, 3));
break; break;
case A_TK_ICON: case A_TK_ICON:
image = luaA_checkudata(L, 3, "image"); image_unref(L, (*c)->icon);
image_unref(&(*c)->icon); (*c)->icon = image_ref(L);
image_ref(image);
(*c)->icon = *image;
/* execute hook */ /* execute hook */
hooks_property(*c, "icon"); hooks_property(*c, "icon");
break; break;
@ -1808,8 +1808,6 @@ luaA_client_index(lua_State *L)
switch(a_tokenize(buf, len)) switch(a_tokenize(buf, len))
{ {
image_t *image;
case A_TK_NAME: case A_TK_NAME:
lua_pushstring(L, (*c)->name); lua_pushstring(L, (*c)->name);
break; break;
@ -1821,9 +1819,7 @@ luaA_client_index(lua_State *L)
lua_pushboolean(L, (*c)->skiptb); lua_pushboolean(L, (*c)->skiptb);
break; break;
case A_TK_CONTENT: case A_TK_CONTENT:
if((image = client_getcontent(*c))) return client_getcontent(*c);
return luaA_image_userdata_new(L, image);
return 0;
case A_TK_TYPE: case A_TK_TYPE:
switch((*c)->type) switch((*c)->type)
{ {
@ -1937,10 +1933,7 @@ luaA_client_index(lua_State *L)
lua_pushboolean(L, (*c)->ismaxvert); lua_pushboolean(L, (*c)->ismaxvert);
break; break;
case A_TK_ICON: case A_TK_ICON:
if((*c)->icon) image_push(L, (*c)->icon);
luaA_image_userdata_new(L, (*c)->icon);
else
return 0;
break; break;
case A_TK_OPACITY: case A_TK_OPACITY:
if((d = window_opacity_get((*c)->win)) >= 0) if((d = window_opacity_get((*c)->win)) >= 0)

19
ewmh.c
View File

@ -656,32 +656,29 @@ ewmh_window_icon_get_unchecked(xcb_window_t w)
_NET_WM_ICON, CARDINAL, 0, UINT32_MAX); _NET_WM_ICON, CARDINAL, 0, UINT32_MAX);
} }
image_t * int
ewmh_window_icon_from_reply(xcb_get_property_reply_t *r) ewmh_window_icon_from_reply(xcb_get_property_reply_t *r)
{ {
uint32_t *data; uint32_t *data;
if(!r || r->type != CARDINAL || r->format != 32 || r->length < 2 || if(r && r->type == CARDINAL && r->format == 32 && r->length >= 2 &&
!(data = (uint32_t *) xcb_get_property_value(r))) (data = (uint32_t *) xcb_get_property_value(r)) && data[0] && data[1])
return NULL;
if(data[0] && data[1])
return image_new_from_argb32(data[0], data[1], data + 2); return image_new_from_argb32(data[0], data[1], data + 2);
return NULL; return 0;
} }
/** Get NET_WM_ICON. /** Get NET_WM_ICON.
* \param cookie The cookie. * \param cookie The cookie.
* \return A draw_image_t structure which must be deleted after usage. * \return The number of elements on stack.
*/ */
image_t * int
ewmh_window_icon_get_reply(xcb_get_property_cookie_t cookie) ewmh_window_icon_get_reply(xcb_get_property_cookie_t cookie)
{ {
xcb_get_property_reply_t *r = xcb_get_property_reply(globalconf.connection, cookie, NULL); xcb_get_property_reply_t *r = xcb_get_property_reply(globalconf.connection, cookie, NULL);
image_t *icon = ewmh_window_icon_from_reply(r); int ret = ewmh_window_icon_from_reply(r);
p_delete(&r); p_delete(&r);
return icon; return ret;
} }
// vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80

4
ewmh.h
View File

@ -39,8 +39,8 @@ void ewmh_update_workarea(int);
void ewmh_process_client_strut(client_t *, xcb_get_property_reply_t *); void ewmh_process_client_strut(client_t *, xcb_get_property_reply_t *);
void ewmh_update_client_strut(client_t *c); void ewmh_update_client_strut(client_t *c);
xcb_get_property_cookie_t ewmh_window_icon_get_unchecked(xcb_window_t); xcb_get_property_cookie_t ewmh_window_icon_get_unchecked(xcb_window_t);
image_t *ewmh_window_icon_from_reply(xcb_get_property_reply_t *); int ewmh_window_icon_from_reply(xcb_get_property_reply_t *);
image_t *ewmh_window_icon_get_reply(xcb_get_property_cookie_t); int ewmh_window_icon_get_reply(xcb_get_property_cookie_t);
#endif #endif
// vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80

97
image.c
View File

@ -1,7 +1,7 @@
/* /*
* image.c - image object * image.c - image object
* *
* Copyright © 2008 Julien Danjou <julien@danjou.info> * Copyright © 2008-2009 Julien Danjou <julien@danjou.info>
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -21,9 +21,17 @@
#include "structs.h" #include "structs.h"
DO_LUA_NEW(extern, image_t, image, "image", image_ref) DO_LUA_TOSTRING(image_t, image, "image");
DO_LUA_GC(image_t, image, "image", image_unref)
DO_LUA_EQ(image_t, image, "image") static int
luaA_image_gc(lua_State *L)
{
image_t *p = luaL_checkudata(L, 1, "image");
imlib_context_set_image(p->image);
imlib_free_image();
p_delete(&p->data);
return 0;
}
static const char * static const char *
image_imlib_load_strerror(Imlib_Load_Error e) image_imlib_load_strerror(Imlib_Load_Error e)
@ -104,31 +112,31 @@ image_compute(image_t *image)
* \param width The image width. * \param width The image width.
* \param height The image height. * \param height The image height.
* \param data The image data. * \param data The image data.
* \return A brand new image. * \return 1 if an image has been pushed on stack, 0 otherwise.
*/ */
image_t * int
image_new_from_argb32(int width, int height, uint32_t *data) image_new_from_argb32(int width, int height, uint32_t *data)
{ {
Imlib_Image imimage; Imlib_Image imimage;
image_t *image = NULL;
if((imimage = imlib_create_image_using_copied_data(width, height, data))) if((imimage = imlib_create_image_using_copied_data(width, height, data)))
{ {
imlib_context_set_image(imimage); imlib_context_set_image(imimage);
imlib_image_set_has_alpha(true); imlib_image_set_has_alpha(true);
image = p_new(image_t, 1); image_t *image = image_new(globalconf.L);
image->image = imimage; image->image = imimage;
image_compute(image); image_compute(image);
return 1;
} }
return image; return 0;
} }
/** Load an image from filename. /** Load an image from filename.
* \param filename The image file to load. * \param filename The image file to load.
* \return A new image. * \return 1 if image is loaded and on stack, 0 otherwise.
*/ */
static image_t * static int
image_new_from_file(const char *filename) image_new_from_file(const char *filename)
{ {
Imlib_Image imimage; Imlib_Image imimage;
@ -136,20 +144,20 @@ image_new_from_file(const char *filename)
image_t *image; image_t *image;
if(!filename) if(!filename)
return NULL; return 0;
if(!(imimage = imlib_load_image_with_error_return(filename, &e))) if(!(imimage = imlib_load_image_with_error_return(filename, &e)))
{ {
warn("cannot load image %s: %s", filename, image_imlib_load_strerror(e)); warn("cannot load image %s: %s", filename, image_imlib_load_strerror(e));
return NULL; return 0;
} }
image = p_new(image_t, 1); image = image_new(globalconf.L);
image->image = imimage; image->image = imimage;
image_compute(image); image_compute(image);
return image; return 1;
} }
/** Create a new image object. /** Create a new image object.
@ -167,11 +175,7 @@ luaA_image_new(lua_State *L)
const char *filename; const char *filename;
if((filename = lua_tostring(L, 2))) if((filename = lua_tostring(L, 2)))
{ return image_new_from_file(filename);
image_t *image;
if((image = image_new_from_file(filename)))
return luaA_image_userdata_new(L, image);
}
else if(lua_isnil(L, 2)) else if(lua_isnil(L, 2))
{ {
int width = luaL_checknumber(L, 3); int width = luaL_checknumber(L, 3);
@ -181,10 +185,10 @@ luaA_image_new(lua_State *L)
luaL_error(L, "request image has invalid size"); luaL_error(L, "request image has invalid size");
Imlib_Image imimage = imlib_create_image(width, height); Imlib_Image imimage = imlib_create_image(width, height);
image_t *image = p_new(image_t, 1); image_t *image = image_new(L);
image->image = imimage; image->image = imimage;
image_compute(image); image_compute(image);
return luaA_image_userdata_new(L, image); return 1;
} }
return 0; return 0;
@ -203,7 +207,6 @@ static int
luaA_image_argb32_new(lua_State *L) luaA_image_argb32_new(lua_State *L)
{ {
size_t len; size_t len;
image_t *image;
unsigned int width = luaL_checknumber(L, 1); unsigned int width = luaL_checknumber(L, 1);
unsigned int height = luaL_checknumber(L, 2); unsigned int height = luaL_checknumber(L, 2);
const char *data = luaL_checklstring(L, 3, &len); const char *data = luaL_checklstring(L, 3, &len);
@ -211,10 +214,7 @@ luaA_image_argb32_new(lua_State *L)
if(width * height * 4 != len) if(width * height * 4 != len)
luaL_error(L, "string size does not match image size"); luaL_error(L, "string size does not match image size");
if((image = image_new_from_argb32(width, height, (uint32_t *) data))) return image_new_from_argb32(width, height, (uint32_t *) data);
return luaA_image_userdata_new(L, image);
return 0;
} }
/** Performs 90 degree rotations on the current image. Passing 0 orientation /** Performs 90 degree rotations on the current image. Passing 0 orientation
@ -229,13 +229,13 @@ luaA_image_argb32_new(lua_State *L)
static int static int
luaA_image_orientate(lua_State *L) luaA_image_orientate(lua_State *L)
{ {
image_t **image = luaA_checkudata(L, 1, "image"); image_t *image = luaL_checkudata(L, 1, "image");
int orientation = luaL_checknumber(L, 2); int orientation = luaL_checknumber(L, 2);
imlib_context_set_image((*image)->image); imlib_context_set_image(image->image);
imlib_image_orientate(orientation); imlib_image_orientate(orientation);
image_compute(*image); image_compute(image);
return 0; return 0;
} }
@ -251,17 +251,17 @@ luaA_image_orientate(lua_State *L)
static int static int
luaA_image_rotate(lua_State *L) luaA_image_rotate(lua_State *L)
{ {
image_t **image = luaA_checkudata(L, 1, "image"), *new; image_t *image = luaL_checkudata(L, 1, "image"), *new;
double angle = luaL_checknumber(L, 2); double angle = luaL_checknumber(L, 2);
new = p_new(image_t, 1); new = image_new(L);
imlib_context_set_image((*image)->image); imlib_context_set_image(image->image);
new->image = imlib_create_rotated_image(angle); new->image = imlib_create_rotated_image(angle);
image_compute(new); image_compute(new);
return luaA_image_userdata_new(L, new); return 1;
} }
/** Crop an image to the given rectangle. /** Crop an image to the given rectangle.
@ -277,20 +277,20 @@ luaA_image_rotate(lua_State *L)
static int static int
luaA_image_crop(lua_State *L) luaA_image_crop(lua_State *L)
{ {
image_t **image = luaA_checkudata(L, 1, "image"), *new; image_t *image = luaL_checkudata(L, 1, "image"), *new;
int x = luaL_checkint(L, 2); int x = luaL_checkint(L, 2);
int y = luaL_checkint(L, 3); int y = luaL_checkint(L, 3);
int w = luaL_checkint(L, 4); int w = luaL_checkint(L, 4);
int h = luaL_checkint(L, 5); int h = luaL_checkint(L, 5);
new = p_new(image_t, 1); new = image_new(L);
imlib_context_set_image((*image)->image); imlib_context_set_image(image->image);
new->image = imlib_create_cropped_image(x, y, w, h); new->image = imlib_create_cropped_image(x, y, w, h);
image_compute(new); image_compute(new);
return luaA_image_userdata_new(L, new); return 1;
} }
/** Crop the image to the given rectangle and scales it. /** Crop the image to the given rectangle and scales it.
@ -309,7 +309,7 @@ luaA_image_crop(lua_State *L)
static int static int
luaA_image_crop_and_scale(lua_State *L) luaA_image_crop_and_scale(lua_State *L)
{ {
image_t **image = luaA_checkudata(L, 1, "image"), *new; image_t *image = luaL_checkudata(L, 1, "image"), *new;
int source_x = luaL_checkint(L, 2); int source_x = luaL_checkint(L, 2);
int source_y = luaL_checkint(L, 3); int source_y = luaL_checkint(L, 3);
int w = luaL_checkint(L, 4); int w = luaL_checkint(L, 4);
@ -317,9 +317,9 @@ luaA_image_crop_and_scale(lua_State *L)
int dest_w = luaL_checkint(L, 6); int dest_w = luaL_checkint(L, 6);
int dest_h = luaL_checkint(L, 7); int dest_h = luaL_checkint(L, 7);
new = p_new(image_t, 1); new = image_new(L);
imlib_context_set_image((*image)->image); imlib_context_set_image(image->image);
new->image = imlib_create_cropped_scaled_image(source_x, new->image = imlib_create_cropped_scaled_image(source_x,
source_y, source_y,
w, h, w, h,
@ -327,7 +327,7 @@ luaA_image_crop_and_scale(lua_State *L)
image_compute(new); image_compute(new);
return luaA_image_userdata_new(L, new); return 1;
} }
/** Saves the image to the given path. The file extension (e.g. .png or .jpg) /** Saves the image to the given path. The file extension (e.g. .png or .jpg)
@ -341,11 +341,11 @@ luaA_image_crop_and_scale(lua_State *L)
static int static int
luaA_image_save(lua_State *L) luaA_image_save(lua_State *L)
{ {
image_t **image = luaA_checkudata(L, 1, "image"); image_t *image = luaL_checkudata(L, 1, "image");
const char *path = luaL_checkstring(L, 2); const char *path = luaL_checkstring(L, 2);
Imlib_Load_Error err; Imlib_Load_Error err;
imlib_context_set_image((*image)->image); imlib_context_set_image(image->image);
imlib_save_image_with_error_return(path, &err); imlib_save_image_with_error_return(path, &err);
if(err != IMLIB_LOAD_ERROR_NONE) if(err != IMLIB_LOAD_ERROR_NONE)
@ -368,22 +368,22 @@ luaA_image_index(lua_State *L)
if(luaA_usemetatable(L, 1, 2)) if(luaA_usemetatable(L, 1, 2))
return 1; return 1;
image_t **image = luaA_checkudata(L, 1, "image"); image_t *image = luaL_checkudata(L, 1, "image");
size_t len; size_t len;
const char *attr = luaL_checklstring(L, 2, &len); const char *attr = luaL_checklstring(L, 2, &len);
switch(a_tokenize(attr, len)) switch(a_tokenize(attr, len))
{ {
case A_TK_WIDTH: case A_TK_WIDTH:
imlib_context_set_image((*image)->image); imlib_context_set_image(image->image);
lua_pushnumber(L, imlib_image_get_width()); lua_pushnumber(L, imlib_image_get_width());
break; break;
case A_TK_HEIGHT: case A_TK_HEIGHT:
imlib_context_set_image((*image)->image); imlib_context_set_image(image->image);
lua_pushnumber(L, imlib_image_get_height()); lua_pushnumber(L, imlib_image_get_height());
break; break;
case A_TK_ALPHA: case A_TK_ALPHA:
imlib_context_set_image((*image)->image); imlib_context_set_image(image->image);
lua_pushboolean(L, imlib_image_has_alpha()); lua_pushboolean(L, imlib_image_has_alpha());
break; break;
default: default:
@ -408,7 +408,6 @@ const struct luaL_reg awesome_image_meta[] =
{ "crop_and_scale", luaA_image_crop_and_scale }, { "crop_and_scale", luaA_image_crop_and_scale },
{ "save", luaA_image_save }, { "save", luaA_image_save },
{ "__gc", luaA_image_gc }, { "__gc", luaA_image_gc },
{ "__eq", luaA_image_eq },
{ "__tostring", luaA_image_tostring }, { "__tostring", luaA_image_tostring },
{ NULL, NULL } { NULL, NULL }
}; };

25
image.h
View File

@ -22,16 +22,15 @@
#ifndef AWESOME_IMAGE_H #ifndef AWESOME_IMAGE_H
#define AWESOME_IMAGE_H #define AWESOME_IMAGE_H
#include <lua.h>
#include <Imlib2.h> #include <Imlib2.h>
#include "common/util.h" #include "common/util.h"
#include "common/refcount.h" #include "common/luaobject.h"
typedef struct typedef struct
{ {
/** Reference counter */ /** Lua references */
int refcount; luaA_ref_array_t refs;
/** Imlib2 image */ /** Imlib2 image */
Imlib_Image image; Imlib_Image image;
/** Image width */ /** Image width */
@ -42,23 +41,9 @@ typedef struct
uint8_t *data; uint8_t *data;
} image_t; } image_t;
static inline void LUA_OBJECT_FUNCS(image_t, image, "image")
image_delete(image_t **i)
{
if(*i)
{
imlib_context_set_image((*i)->image);
imlib_free_image();
p_delete(&(*i)->data);
p_delete(i);
}
}
DO_RCNT(image_t, image, image_delete) int image_new_from_argb32(int, int, uint32_t *);
image_t * image_new_from_argb32(int, int, uint32_t *);
int luaA_image_userdata_new(lua_State *, image_t *);
#endif #endif
// vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80

View File

@ -336,11 +336,9 @@ property_handle_net_wm_icon(void *data,
if(c) if(c)
{ {
image_t *icon; image_unref(globalconf.L, c->icon);
image_unref(&c->icon); if(ewmh_window_icon_from_reply(reply))
icon = ewmh_window_icon_from_reply(reply); c->icon = image_ref(globalconf.L);
c->icon = icon ? image_ref(&icon) : NULL;
/* execute hook */ /* execute hook */
hooks_property(c, "icon"); hooks_property(c, "icon");
} }

23
wibox.c
View File

@ -875,10 +875,7 @@ luaA_wibox_index(lua_State *L)
luaA_pushcolor(L, &(*wibox)->sw.ctx.bg); luaA_pushcolor(L, &(*wibox)->sw.ctx.bg);
break; break;
case A_TK_BG_IMAGE: case A_TK_BG_IMAGE:
if((*wibox)->bg_image) image_push(L, (*wibox)->bg_image);
luaA_image_userdata_new(L, (*wibox)->bg_image);
else
return 0;
break; break;
case A_TK_POSITION: case A_TK_POSITION:
lua_pushstring(L, position_tostr((*wibox)->position)); lua_pushstring(L, position_tostr((*wibox)->position));
@ -996,21 +993,9 @@ luaA_wibox_newindex(lua_State *L)
(*wibox)->need_update = true; (*wibox)->need_update = true;
break; break;
case A_TK_BG_IMAGE: case A_TK_BG_IMAGE:
{ image_unref(L, (*wibox)->bg_image);
if(lua_isnil(L, 3)) (*wibox)->bg_image = image_ref(L);
{ (*wibox)->need_update = true;
image_unref(&(*wibox)->bg_image);
(*wibox)->bg_image = NULL;
(*wibox)->need_update = true;
}
else
{
image_t **img = luaA_checkudata(L, 3, "image");
image_unref(&(*wibox)->bg_image);
(*wibox)->bg_image = image_ref(img);
(*wibox)->need_update = true;
}
}
break; break;
case A_TK_ALIGN: case A_TK_ALIGN:
buf = luaL_checklstring(L, 3, &len); buf = luaL_checklstring(L, 3, &len);

View File

@ -115,7 +115,7 @@ static void
imagebox_destructor(widget_t *w) imagebox_destructor(widget_t *w)
{ {
imagebox_data_t *d = w->data; imagebox_data_t *d = w->data;
image_unref(&d->image); image_unref(globalconf.L, d->image);
p_delete(&d); p_delete(&d);
} }
@ -138,10 +138,8 @@ luaA_imagebox_index(lua_State *L, awesome_token_t token)
switch(token) switch(token)
{ {
case A_TK_IMAGE: case A_TK_IMAGE:
if(d->image) image_push(L, d->image);
return luaA_image_userdata_new(L, d->image); break;
else
return 0;
case A_TK_BG: case A_TK_BG:
luaA_pushcolor(L, &d->bg); luaA_pushcolor(L, &d->bg);
break; break;
@ -167,7 +165,6 @@ static int
luaA_imagebox_newindex(lua_State *L, awesome_token_t token) luaA_imagebox_newindex(lua_State *L, awesome_token_t token)
{ {
widget_t **widget = luaA_checkudata(L, 1, "widget"); widget_t **widget = luaA_checkudata(L, 1, "widget");
image_t **image = NULL;
imagebox_data_t *d = (*widget)->data; imagebox_data_t *d = (*widget)->data;
switch(token) switch(token)
@ -176,16 +173,8 @@ luaA_imagebox_newindex(lua_State *L, awesome_token_t token)
size_t len; size_t len;
case A_TK_IMAGE: case A_TK_IMAGE:
if(lua_isnil(L, 3) image_unref(L, d->image);
|| (image = luaA_checkudata(L, 3, "image"))) d->image = image_ref(L);
{
/* unref image */
image_unref(&d->image);
if(image)
d->image = image_ref(image);
else
d->image = NULL;
}
break; break;
case A_TK_BG: case A_TK_BG:
if(lua_isnil(L, 3)) if(lua_isnil(L, 3))

View File

@ -184,10 +184,7 @@ luaA_textbox_index(lua_State *L, awesome_token_t token)
lua_pushstring(L, draw_align_tostr(d->bg_align)); lua_pushstring(L, draw_align_tostr(d->bg_align));
return 1; return 1;
case A_TK_BG_IMAGE: case A_TK_BG_IMAGE:
if(d->bg_image) return image_push(L, d->bg_image);
return luaA_image_userdata_new(L, d->bg_image);
else
return 0;
case A_TK_BG: case A_TK_BG:
return luaA_pushcolor(L, &d->bg); return luaA_pushcolor(L, &d->bg);
case A_TK_MARGIN: case A_TK_MARGIN:
@ -257,7 +254,6 @@ luaA_textbox_newindex(lua_State *L, awesome_token_t token)
widget_t **widget = luaA_checkudata(L, 1, "widget"); widget_t **widget = luaA_checkudata(L, 1, "widget");
const char *buf = NULL; const char *buf = NULL;
textbox_data_t *d = (*widget)->data; textbox_data_t *d = (*widget)->data;
image_t **image = NULL;
switch(token) switch(token)
{ {
@ -269,16 +265,8 @@ luaA_textbox_newindex(lua_State *L, awesome_token_t token)
d->bg_resize = luaA_checkboolean(L, 3); d->bg_resize = luaA_checkboolean(L, 3);
break; break;
case A_TK_BG_IMAGE: case A_TK_BG_IMAGE:
if(lua_isnil(L, 3) image_unref(L, d->bg_image);
|| (image = luaA_checkudata(L, 3, "image"))) d->bg_image = image_ref(L);
{
/* unref image */
image_unref(&d->bg_image);
if(image)
d->bg_image = image_ref(image);
else
d->bg_image = NULL;
}
break; break;
case A_TK_BG: case A_TK_BG:
if(lua_isnil(L, 3)) if(lua_isnil(L, 3))