From 069a8e84a2a218c7de69cf5492fa09ae931b7ad1 Mon Sep 17 00:00:00 2001 From: Uli Schlachter Date: Thu, 6 Mar 2014 18:35:17 +0100 Subject: [PATCH] root.wallpaper: Cleanup and correctness fixes Turns out that my rant about "we can't query the pixmap's values" was wrong. This commit makes awesome use a GetGeometry request to get the properties of the (old) root window's back pixmap. This also converts code to p_delete() instead of free() for consistency. Bad me for doing multiple things in one commit... Signed-off-by: Uli Schlachter --- root.c | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/root.c b/root.c index 7d94622a..bbb55541 100644 --- a/root.c +++ b/root.c @@ -63,7 +63,7 @@ root_set_wallpaper_pixmap(xcb_connection_t *c, xcb_pixmap_t p) if (rootpix) xcb_kill_client(c, *rootpix); } - free(prop_r); + p_delete(&prop_r); } static bool @@ -347,6 +347,8 @@ luaA_root_wallpaper(lua_State *L) { xcb_get_property_cookie_t prop_c; xcb_get_property_reply_t *prop_r; + xcb_get_geometry_cookie_t geom_c; + xcb_get_geometry_reply_t *geom_r; xcb_pixmap_t *rootpix; cairo_surface_t *surface; @@ -364,27 +366,37 @@ luaA_root_wallpaper(lua_State *L) if (!prop_r || !prop_r->value_len) { - free(prop_r); + p_delete(&prop_r); return 0; } rootpix = xcb_get_property_value(prop_r); if (!rootpix) { - free(prop_r); + p_delete(&prop_r); return 0; } - /* We can't query the pixmap's values (or even if that pixmap exists at - * all), so let's just assume that it uses the default visual and is as - * large as the root window. Everything else wouldn't make sense. - */ + geom_c = xcb_get_geometry_unchecked(globalconf.connection, *rootpix); + geom_r = xcb_get_geometry_reply(globalconf.connection, geom_c, NULL); + if (!geom_r) + { + p_delete(&prop_r); + return 0; + } + + /* Only the default visual makes sense, so just the default depth */ + if (geom_r->depth != draw_visual_depth(globalconf.screen, globalconf.default_visual->visual_id)) + warn("Got a pixmap with depth %d, but the default depth is %d, continuing anyway", + geom_r->depth, draw_visual_depth(globalconf.screen, globalconf.default_visual->visual_id)); + surface = cairo_xcb_surface_create(globalconf.connection, *rootpix, globalconf.default_visual, - globalconf.screen->width_in_pixels, globalconf.screen->height_in_pixels); + geom_r->width, geom_r->height); /* lua has to make sure this surface gets destroyed */ lua_pushlightuserdata(L, surface); - free(prop_r); + p_delete(&prop_r); + p_delete(&geom_r); return 1; } -- 2.11.4.GIT