diff --git a/draw.c b/draw.c index 72d3541ce..83d3d3559 100644 --- a/draw.c +++ b/draw.c @@ -81,7 +81,7 @@ draw_surface_from_data(int width, int height, uint32_t *data) * \param buf The pixbuf * \return Number of items pushed on the lua stack. */ -static cairo_surface_t * +cairo_surface_t * draw_surface_from_pixbuf(GdkPixbuf *buf) { int width = gdk_pixbuf_get_width(buf); diff --git a/draw.h b/draw.h index d2a0f7e0f..867296cfe 100644 --- a/draw.h +++ b/draw.h @@ -30,6 +30,9 @@ #include "common/array.h" #include "common/util.h" +/* Forward definition */ +typedef struct _GdkPixbuf GdkPixbuf; + typedef struct area_t area_t; struct area_t { @@ -57,6 +60,7 @@ DO_ARRAY(cairo_surface_t *, cairo_surface, cairo_surface_array_destroy_surface) cairo_surface_t *draw_surface_from_data(int width, int height, uint32_t *data); cairo_surface_t *draw_dup_image_surface(cairo_surface_t *surface); cairo_surface_t *draw_load_image(lua_State *L, const char *path, GError **error); +cairo_surface_t *draw_surface_from_pixbuf(GdkPixbuf *buf); xcb_visualtype_t *draw_find_visual(const xcb_screen_t *s, xcb_visualid_t visual); xcb_visualtype_t *draw_default_visual(const xcb_screen_t *s); diff --git a/luaa.c b/luaa.c index 8a5b0f65c..29c7ec06a 100644 --- a/luaa.c +++ b/luaa.c @@ -281,6 +281,23 @@ luaA_sync(lua_State *L) return 0; } +/** Translate a GdkPixbuf to a cairo image surface.. + * + * @param pixbuf The pixbuf as a light user datum. + * @return A cairo surface as light user datum. + * @function pixbuf_to_surface + */ +static int +luaA_pixbuf_to_surface(lua_State *L) +{ + GdkPixbuf *pixbuf = (GdkPixbuf *) lua_touserdata(L, 1); + cairo_surface_t *surface = draw_surface_from_pixbuf(pixbuf); + + /* lua has to make sure to free the ref or we have a leak */ + lua_pushlightuserdata(L, surface); + return 1; +} + /** Load an image from a given path. * * @param name The file name. @@ -292,6 +309,10 @@ luaA_sync(lua_State *L) static int luaA_load_image(lua_State *L) { + /* TODO: Deprecate this function, Lua can use GdkPixbuf directly plus + * awesome.pixbuf_to_surface + */ + GError *error = NULL; const char *filename = luaL_checkstring(L, 1); cairo_surface_t *surface = draw_load_image(L, filename, &error); @@ -776,6 +797,7 @@ luaA_init(xdgHandle* xdg, string_array_t *searchpath) { "emit_signal", luaA_awesome_emit_signal }, { "systray", luaA_systray }, { "load_image", luaA_load_image }, + { "pixbuf_to_surface", luaA_pixbuf_to_surface }, { "set_preferred_icon_size", luaA_set_preferred_icon_size }, { "register_xproperty", luaA_register_xproperty }, { "set_xproperty", luaA_set_xproperty },