diff --git a/structs.h b/structs.h index e07b521bf..3c1e5f39d 100644 --- a/structs.h +++ b/structs.h @@ -108,6 +108,8 @@ typedef struct bool need_update; /** Cursor */ char *cursor; + /** Background image */ + image_t *bg_image; /** Button bindings */ button_array_t buttons; } wibox_t; diff --git a/wibox.c b/wibox.c index 0593be8f2..92cef0bd2 100644 --- a/wibox.c +++ b/wibox.c @@ -861,6 +861,12 @@ luaA_wibox_index(lua_State *L) case A_TK_BG: luaA_pushcolor(L, &(*wibox)->sw.ctx.bg); break; + case A_TK_BG_IMAGE: + if((*wibox)->bg_image) + luaA_image_userdata_new(L, (*wibox)->bg_image); + else + return 0; + break; case A_TK_POSITION: lua_pushstring(L, position_tostr((*wibox)->position)); break; @@ -976,6 +982,23 @@ luaA_wibox_newindex(lua_State *L) if(xcolor_init_reply(xcolor_init_unchecked(&(*wibox)->sw.ctx.bg, buf, len))) (*wibox)->need_update = true; break; + case A_TK_BG_IMAGE: + { + if(lua_isnil(L, 3)) + { + 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; case A_TK_ALIGN: buf = luaL_checklstring(L, 3, &len); (*wibox)->align = draw_align_fromstr(buf, len); diff --git a/widget.c b/widget.c index ebda7fd6d..91f25c9b2 100644 --- a/widget.c +++ b/widget.c @@ -270,9 +270,14 @@ widget_render(wibox_t *wibox) left += widgets->tab[i].geometry.width; } - /* draw everything! */ + /* draw background image, only if the background color is not opaque */ + if(wibox->bg_image && ctx->bg.alpha != 0xffff) + draw_image(ctx, 0, 0, 1.0, wibox->bg_image); + + /* draw background color */ draw_rectangle(ctx, rectangle, 1.0, true, &ctx->bg); + /* draw everything! */ for(int i = 0; i < widgets->len; i++) if(widgets->tab[i].widget->isvisible) {