Convert a client's icon to a cairo surface

Signed-off-by: Uli Schlachter <psychon@znc.in>
This commit is contained in:
Uli Schlachter 2010-08-20 13:56:34 +02:00
parent 8fbffcd2fb
commit 146a5dd67c
3 changed files with 18 additions and 9 deletions

2
ewmh.c
View File

@ -657,7 +657,7 @@ ewmh_window_icon_from_reply(xcb_get_property_reply_t *r)
if (!data[0] || !data[1] || len > r->length - 2) if (!data[0] || !data[1] || len > r->length - 2)
return 0; return 0;
return image_new_from_argb32(globalconf.L, data[0], data[1], data + 2); return luaA_surface_from_data(globalconf.L, data[0], data[1], data + 2);
} }
/** Get NET_WM_ICON. /** Get NET_WM_ICON.

View File

@ -50,6 +50,8 @@ client_wipe(client_t *c)
p_delete(&c->alt_icon_name); p_delete(&c->alt_icon_name);
p_delete(&c->name); p_delete(&c->name);
p_delete(&c->alt_name); p_delete(&c->alt_name);
if(c->icon)
cairo_surface_destroy(c->icon);
} }
/** Change the clients urgency flag. /** Change the clients urgency flag.
@ -1092,12 +1094,17 @@ void
client_set_icon(lua_State *L, int cidx, int iidx) client_set_icon(lua_State *L, int cidx, int iidx)
{ {
client_t *c = luaA_checkudata(L, cidx, &client_class); client_t *c = luaA_checkudata(L, cidx, &client_class);
/* convert index to absolute */ if(lua_isnil(L, iidx))
cidx = luaA_absindex(L, cidx); {
iidx = luaA_absindex(L, iidx); if(c->icon)
luaA_checkudata(L, iidx, &image_class); cairo_surface_destroy(c->icon);
luaA_object_unref_item(L, cidx, c->icon); c->icon = NULL;
c->icon = luaA_object_ref_item(L, cidx, iidx); } else {
cairo_surface_t *surface = luaA_image_to_surface(L, iidx);
if(c->icon)
cairo_surface_destroy(c->icon);
c->icon = surface;
}
luaA_object_emit_signal(L, cidx < iidx ? cidx : cidx - 1, "property::icon", 0); luaA_object_emit_signal(L, cidx < iidx ? cidx : cidx - 1, "property::icon", 0);
} }
@ -1464,7 +1471,9 @@ luaA_client_get_screen(lua_State *L, client_t *c)
static int static int
luaA_client_get_icon(lua_State *L, client_t *c) luaA_client_get_icon(lua_State *L, client_t *c)
{ {
return luaA_object_push_item(L, -2, c->icon); if(c->icon)
return oocairo_surface_push(L, c->icon);
return 0;
} }
static int static int

View File

@ -87,7 +87,7 @@ struct client_t
/** Key bindings */ /** Key bindings */
key_array_t keys; key_array_t keys;
/** Icon */ /** Icon */
image_t *icon; cairo_surface_t *icon;
/** Size hints */ /** Size hints */
xcb_size_hints_t size_hints; xcb_size_hints_t size_hints;
bool size_hints_honor; bool size_hints_honor;