From 360e1a5f92bdb1a2fcfb24af3ad2a4f7d26498ae Mon Sep 17 00:00:00 2001 From: Uli Schlachter Date: Sun, 23 Feb 2014 12:14:50 +0100 Subject: [PATCH] Add awesome.composite_manager_running Signed-off-by: Uli Schlachter --- luaa.c | 45 +++++++++++++++++++++++++++++++++++++++++++++ luadoc/awesome.lua | 1 + 2 files changed, 46 insertions(+) diff --git a/luaa.c b/luaa.c index c86a0e8bb..b174996f6 100644 --- a/luaa.c +++ b/luaa.c @@ -27,6 +27,8 @@ #include +#include + #include "awesome.h" #include "config.h" #include "objects/timer.h" @@ -60,6 +62,43 @@ extern const struct luaL_Reg awesome_screen_meta[]; /** Path to config file */ static char *conffile; +/** Check whether a composite manager is running. + * \return True if such a manager is running. + */ +static bool +composite_manager_running(void) +{ + xcb_intern_atom_reply_t *atom_r; + xcb_get_selection_owner_reply_t *selection_r; + char *atom_name; + bool result; + + if(!(atom_name = xcb_atom_name_by_screen("_NET_WM_CM", globalconf.default_screen))) + { + warn("error getting composite manager atom"); + return false; + } + + atom_r = xcb_intern_atom_reply(globalconf.connection, + xcb_intern_atom_unchecked(globalconf.connection, false, + a_strlen(atom_name), atom_name), + NULL); + p_delete(&atom_name); + if(!atom_r) + return false; + + selection_r = xcb_get_selection_owner_reply(globalconf.connection, + xcb_get_selection_owner_unchecked(globalconf.connection, + atom_r->atom), + NULL); + p_delete(&atom_r); + + result = selection_r != NULL && selection_r->owner != XCB_NONE; + p_delete(&selection_r); + + return result; +} + /** Quit awesome. * \param L The Lua VM state. * \return The number of elements pushed on stack. @@ -423,6 +462,12 @@ luaA_awesome_index(lua_State *L) return 1; } + if(A_STREQ(buf, "composite_manager_running")) + { + lua_pushboolean(L, composite_manager_running()); + return 1; + } + return 0; } diff --git a/luadoc/awesome.lua b/luadoc/awesome.lua index c6b86d9bf..ea07ec804 100644 --- a/luadoc/awesome.lua +++ b/luadoc/awesome.lua @@ -11,6 +11,7 @@ module("awesome") -- @field version The version of awesome. -- @field release The release name of awesome. -- @field conffile The configuration file which has been loaded. +-- @field composite_manager_running True if a composite manager is running. -- @class table -- @name awesome