From f9d7ac595cc4fac6537a99147a9ecba8b0246d3a Mon Sep 17 00:00:00 2001 From: Uli Schlachter Date: Sat, 7 Apr 2012 21:32:45 +0200 Subject: [PATCH] Add root.wallpaper() for querying the wallpaper Signed-off-by: Uli Schlachter --- awesome.c | 3 ++- globalconf.h | 4 +++- luadoc/root.lua | 6 ++++++ root.c | 39 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 50 insertions(+), 2 deletions(-) diff --git a/awesome.c b/awesome.c index 3d85cba9..d0e1f235 100644 --- a/awesome.c +++ b/awesome.c @@ -419,9 +419,10 @@ main(int argc, char **argv) fatal("cannot open display"); globalconf.screen = xcb_aux_get_screen(globalconf.connection, globalconf.default_screen); + globalconf.default_visual = a_default_visual(globalconf.screen); /* FIXME The following two assignments were swapped on purpose */ if(!no_argb) - globalconf.visual = a_default_visual(globalconf.screen); + globalconf.visual = globalconf.default_visual; if(!globalconf.visual) globalconf.visual = a_argb_visual(globalconf.screen); globalconf.default_depth = a_visual_depth(globalconf.screen, globalconf.visual->visual_id); diff --git a/globalconf.h b/globalconf.h index f255eb39..0581c0b2 100644 --- a/globalconf.h +++ b/globalconf.h @@ -119,8 +119,10 @@ typedef struct } systray; /** The monitor of startup notifications */ SnMonitorContext *snmonitor; - /** The default visual, used to draw */ + /** The visual, used to draw */ xcb_visualtype_t *visual; + /** The screen's default visual */ + xcb_visualtype_t *default_visual; /** The screen's information */ xcb_screen_t *screen; /** A graphic context. */ diff --git a/luadoc/root.lua b/luadoc/root.lua index 39f88524..7137544c 100644 --- a/luadoc/root.lua +++ b/luadoc/root.lua @@ -38,3 +38,9 @@ module("root") -- @return A table with all wiboxes. -- @name wiboxes -- @class function + +--- Get the wallpaper as a cairo surface. +-- @param - +-- @return A cairo surface or nothing. +-- @name wallpaper +-- @class function diff --git a/root.c b/root.c index 828d1ee5..c6f57041 100644 --- a/root.c +++ b/root.c @@ -22,6 +22,7 @@ #include #include #include +#include #include "globalconf.h" #include "objects/button.h" @@ -249,6 +250,43 @@ luaA_root_drawins(lua_State *L) return 1; } +/** Get the screen's wallpaper + * \param L The Lua VM state. + * \return The number of element pushed on stack. + * \luastack + * \lreturn A cairo surface for the wallpaper. + */ +static int +luaA_root_wallpaper(lua_State *L) +{ + xcb_get_property_cookie_t prop_c; + xcb_get_property_reply_t *prop_r; + xcb_pixmap_t *rootpix; + cairo_surface_t *surface; + int ret; + + prop_c = xcb_get_property_unchecked(globalconf.connection, false, + globalconf.screen->root, _XROOTPMAP_ID, XCB_ATOM_PIXMAP, 0, 1); + prop_r = xcb_get_property_reply(globalconf.connection, prop_c, NULL); + + if (!prop_r || !prop_r->value_len) + return 0; + + rootpix = xcb_get_property_value(prop_r); + if (!rootpix) + 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. + */ + surface = cairo_xcb_surface_create(globalconf.connection, *rootpix, globalconf.default_visual, + globalconf.screen->width_in_pixels, globalconf.screen->height_in_pixels); + ret = oocairo_surface_push(globalconf.L, surface); + cairo_surface_destroy(surface); + return ret; +} + const struct luaL_reg awesome_root_lib[] = { { "buttons", luaA_root_buttons }, @@ -256,6 +294,7 @@ const struct luaL_reg awesome_root_lib[] = { "cursor", luaA_root_cursor }, { "fake_input", luaA_root_fake_input }, { "drawins", luaA_root_drawins }, + { "wallpaper", luaA_root_wallpaper }, { NULL, NULL } };