drawable: Add property::surface

This new property is used for fixing some missing redraws that the old code had.
Those could be seen via awful.menu. Open and close a submenu repeatedly and the
submenu will appear black.

Signed-off-by: Uli Schlachter <psychon@znc.in>
This commit is contained in:
Uli Schlachter 2012-10-20 22:51:52 +02:00
parent 1115457ac8
commit 1e418cbe3b
5 changed files with 21 additions and 21 deletions

View File

@ -201,10 +201,7 @@ function drawable.new(d, widget_arg)
end end
end end
capi.awesome.connect_signal("wallpaper_changed", ret.draw) capi.awesome.connect_signal("wallpaper_changed", ret.draw)
d:connect_signal("property::x", ret.draw) d:connect_signal("property::surface", ret.draw)
d:connect_signal("property::y", ret.draw)
d:connect_signal("property::width", ret.draw)
d:connect_signal("property::height", ret.draw)
-- Set the default background -- Set the default background
ret:set_bg(beautiful.bg_normal) ret:set_bg(beautiful.bg_normal)

View File

@ -646,7 +646,8 @@ client_resize_do(client_t *c, area_t geometry)
drawable_t *drawable = titlebar_get_drawable(globalconf.L, c, -1, bar); drawable_t *drawable = titlebar_get_drawable(globalconf.L, c, -1, bar);
/* Get rid of the old state */ /* Get rid of the old state */
drawable_set_surface(drawable, NULL); luaA_object_push_item(globalconf.L, -1, drawable);
drawable_set_surface(drawable, -1, NULL);
if (c->titlebar[bar].pixmap != XCB_NONE) if (c->titlebar[bar].pixmap != XCB_NONE)
xcb_free_pixmap(globalconf.connection, c->titlebar[bar].pixmap); xcb_free_pixmap(globalconf.connection, c->titlebar[bar].pixmap);
@ -660,13 +661,12 @@ client_resize_do(client_t *c, area_t geometry)
cairo_surface_t *surface = cairo_xcb_surface_create(globalconf.connection, cairo_surface_t *surface = cairo_xcb_surface_create(globalconf.connection,
c->titlebar[bar].pixmap, globalconf.visual, c->titlebar[bar].pixmap, globalconf.visual,
area.width, area.height); area.width, area.height);
drawable_set_surface(drawable, surface); drawable_set_surface(drawable, -1, surface);
} }
/* Convert to global coordinates */ /* Convert to global coordinates */
area.x += geometry.x; area.x += geometry.x;
area.y += geometry.y; area.y += geometry.y;
luaA_object_push_item(globalconf.L, -1, drawable);
drawable_set_geometry(drawable, -1, area); drawable_set_geometry(drawable, -1, area);
/* Pop the client and the drawable */ /* Pop the client and the drawable */
@ -1361,7 +1361,7 @@ titlebar_get_drawable(lua_State *L, client_t *c, int cl_idx, client_titlebar_t b
if (c->titlebar[bar].drawable == NULL) if (c->titlebar[bar].drawable == NULL)
{ {
cl_idx = luaA_absindex(L, cl_idx); cl_idx = luaA_absindex(L, cl_idx);
drawable_allocator(L, NULL, (drawable_refresh_callback *) client_refresh, c); drawable_allocator(L, (drawable_refresh_callback *) client_refresh, c);
c->titlebar[bar].drawable = luaA_object_ref_item(L, cl_idx, -1); c->titlebar[bar].drawable = luaA_object_ref_item(L, cl_idx, -1);
} }

View File

@ -29,23 +29,26 @@ static lua_class_t drawable_class;
LUA_OBJECT_FUNCS(drawable_class, drawable_t, drawable) LUA_OBJECT_FUNCS(drawable_class, drawable_t, drawable)
drawable_t * drawable_t *
drawable_allocator(lua_State *L, cairo_surface_t *surface, drawable_refresh_callback *callback, void *data) drawable_allocator(lua_State *L, drawable_refresh_callback *callback, void *data)
{ {
drawable_t *d = drawable_new(L); drawable_t *d = drawable_new(L);
d->refresh_callback = callback; d->refresh_callback = callback;
d->refresh_data = data; d->refresh_data = data;
drawable_set_surface(d, surface); d->surface = NULL;
return d; return d;
} }
static void static void
drawable_wipe(drawable_t *d) drawable_wipe(drawable_t *d)
{ {
drawable_set_surface(d, NULL); if (!d->surface)
return;
cairo_surface_finish(d->surface);
cairo_surface_destroy(d->surface);
} }
void void
drawable_set_surface(drawable_t *d, cairo_surface_t *surface) drawable_set_surface(drawable_t *d, int didx, cairo_surface_t *surface)
{ {
if (d->surface) { if (d->surface) {
cairo_surface_finish(d->surface); cairo_surface_finish(d->surface);
@ -54,13 +57,14 @@ drawable_set_surface(drawable_t *d, cairo_surface_t *surface)
d->surface = cairo_surface_reference(surface); d->surface = cairo_surface_reference(surface);
if (d->surface != NULL) if (d->surface)
{ {
/* Make sure the surface doesn't contain garbage by filling it with black */ /* Make sure the surface doesn't contain garbage by filling it with black */
cairo_t *cr = cairo_create(surface); cairo_t *cr = cairo_create(surface);
cairo_set_operator(cr, CAIRO_OPERATOR_CLEAR); cairo_set_operator(cr, CAIRO_OPERATOR_CLEAR);
cairo_paint(cr); cairo_paint(cr);
cairo_destroy(cr); cairo_destroy(cr);
luaA_object_emit_signal(globalconf.L, didx, "property::surface", 0);
} }
} }
@ -157,6 +161,7 @@ drawable_class_setup(lua_State *L)
signal_add(&drawable_class.signals, "property::width"); signal_add(&drawable_class.signals, "property::width");
signal_add(&drawable_class.signals, "property::x"); signal_add(&drawable_class.signals, "property::x");
signal_add(&drawable_class.signals, "property::y"); signal_add(&drawable_class.signals, "property::y");
signal_add(&drawable_class.signals, "property::surface");
} }
// vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80

View File

@ -42,9 +42,8 @@ struct drawable_t
void *refresh_data; void *refresh_data;
}; };
drawable_t *drawable_allocator(lua_State *, cairo_surface_t *, drawable_t *drawable_allocator(lua_State *, drawable_refresh_callback *, void *);
drawable_refresh_callback *, void *); void drawable_set_surface(drawable_t *, int, cairo_surface_t *);
void drawable_set_surface(drawable_t *, cairo_surface_t *);
void drawable_set_geometry(drawable_t *, int, area_t); void drawable_set_geometry(drawable_t *, int, area_t);
void drawable_class_setup(lua_State *); void drawable_class_setup(lua_State *);

View File

@ -96,7 +96,8 @@ drawin_update_drawing(drawin_t *w, int widx)
if(!w->visible) if(!w->visible)
return; return;
/* Clean up old stuff */ /* Clean up old stuff */
drawable_set_surface(w->drawable, NULL); luaA_object_push_item(globalconf.L, widx, w->drawable);
drawable_set_surface(w->drawable, -1, NULL);
if(w->pixmap) if(w->pixmap)
xcb_free_pixmap(globalconf.connection, w->pixmap); xcb_free_pixmap(globalconf.connection, w->pixmap);
@ -109,9 +110,7 @@ drawin_update_drawing(drawin_t *w, int widx)
cairo_surface_t *surface = cairo_xcb_surface_create(globalconf.connection, cairo_surface_t *surface = cairo_xcb_surface_create(globalconf.connection,
w->pixmap, globalconf.visual, w->pixmap, globalconf.visual,
w->geometry.width, w->geometry.height); w->geometry.width, w->geometry.height);
drawable_set_surface(w->drawable, surface); drawable_set_surface(w->drawable, -1, surface);
luaA_object_push_item(globalconf.L, widx, w->drawable);
drawable_set_geometry(w->drawable, -1, w->geometry); drawable_set_geometry(w->drawable, -1, w->geometry);
lua_pop(globalconf.L, 1); lua_pop(globalconf.L, 1);
} }
@ -337,7 +336,7 @@ drawin_allocator(lua_State *L)
w->geometry.height = 1; w->geometry.height = 1;
w->type = _NET_WM_WINDOW_TYPE_NORMAL; w->type = _NET_WM_WINDOW_TYPE_NORMAL;
drawable_allocator(L, NULL, (drawable_refresh_callback *) drawin_refresh_pixmap, w); drawable_allocator(L, (drawable_refresh_callback *) drawin_refresh_pixmap, w);
w->drawable = luaA_object_ref_item(L, -2, -1); w->drawable = luaA_object_ref_item(L, -2, -1);
drawin_init(w); drawin_init(w);