diff --git a/.travis.yml b/.travis.yml index f9b6e5e27..20b8d958e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -40,6 +40,10 @@ install: # Deps for functional tests. - sudo apt-get install -y dbus-x11 xterm xdotool xterm xvfb + # Need xorg-macros + - sudo apt-get install -y xutils-dev + - git clone --recursive https://github.com/Airblader/xcb-util-xrm.git && cd xcb-util-xrm && ./autogen.sh --prefix=/usr && make && sudo make install && cd - + # Install Lua (per env). # Note that Lua 5.3 is installed manually, because it is not available in Ubuntu Trusty. - | diff --git a/awesome.c b/awesome.c index 6a289842e..2befbfc83 100644 --- a/awesome.c +++ b/awesome.c @@ -587,12 +587,7 @@ main(int argc, char **argv) XkbIgnoreExtension(True); /* X stuff */ - globalconf.display = XOpenDisplay(NULL); - if (globalconf.display == NULL) - fatal("Cannot open display"); - XSetEventQueueOwner(globalconf.display, XCBOwnsEventQueue); - globalconf.default_screen = XDefaultScreen(globalconf.display); - globalconf.connection = XGetXCBConnection(globalconf.display);; + globalconf.connection = xcb_connect(NULL, &globalconf.default_screen); if(xcb_connection_has_error(globalconf.connection)) fatal("cannot open display (error %d)", xcb_connection_has_error(globalconf.connection)); @@ -622,6 +617,11 @@ main(int argc, char **argv) if (xcb_cursor_context_new(globalconf.connection, globalconf.screen, &globalconf.cursor_ctx) < 0) fatal("Failed to initialize xcb-cursor"); + globalconf.xrmdb = xcb_xrm_database_from_default(globalconf.connection); + if (globalconf.xrmdb == NULL) + globalconf.xrmdb = xcb_xrm_database_from_string(""); + if (globalconf.xrmdb == NULL) + fatal("Failed to initialize xcb-xrm"); /* Did we get some usable data from the above X11 setup? */ draw_test_cairo_xcb(); diff --git a/awesomeConfig.cmake b/awesomeConfig.cmake index fde932a77..65ccb8805 100644 --- a/awesomeConfig.cmake +++ b/awesomeConfig.cmake @@ -112,7 +112,6 @@ pkg_check_modules(AWESOME_REQUIRED REQUIRED gdk-pixbuf-2.0 cairo x11 - x11-xcb xcb-cursor xcb-randr xcb-xtest @@ -129,7 +128,8 @@ pkg_check_modules(AWESOME_REQUIRED REQUIRED cairo-xcb libstartup-notification-1.0>=0.10 xproto>=7.0.15 - libxdg-basedir>=1.0.0) + libxdg-basedir>=1.0.0 + xcb-xrm) if(NOT AWESOME_REQUIRED_FOUND OR NOT AWESOME_COMMON_REQUIRED_FOUND) message(FATAL_ERROR) diff --git a/globalconf.h b/globalconf.h index cab3364d6..53dc40f04 100644 --- a/globalconf.h +++ b/globalconf.h @@ -30,6 +30,7 @@ #include #include #include +#include #include #include "objects/key.h" @@ -73,12 +74,10 @@ DO_ARRAY(xcb_window_t, window, DO_NOTHING) /** Main configuration structure */ typedef struct { - /** Xlib Display */ - Display *display; - /** X Resources DB */ - XrmDatabase xrmdb; /** Connection ref */ xcb_connection_t *connection; + /** X Resources DB */ + xcb_xrm_database_t *xrmdb; /** Default screen number */ int default_screen; /** xcb-cursor context */ diff --git a/xrdb.c b/xrdb.c index 2c4002739..65df0a27f 100644 --- a/xrdb.c +++ b/xrdb.c @@ -26,23 +26,6 @@ #include -/* \brief open X display and X Resources DB - */ -static void xrdb_init(void) { - XrmInitialize(); // @TODO: it works without it but in docs it's said what it's - // needed - if (!(globalconf.xrmdb = XrmGetDatabase(globalconf.display))) { - - /* taken from xpbiff: */ - /* >> what a hack; need to initialize dpy->db */ - (void)XGetDefault(globalconf.display, "", ""); - /**/ - - if (!(globalconf.xrmdb = XrmGetDatabase(globalconf.display))) - warn("Cannot open xrdb."); - } -} - /* \brief get value from X Resources DataBase * \param L The Lua VM state. * \return The number of elements pushed on stack. @@ -52,27 +35,22 @@ static void xrdb_init(void) { * \lreturn string xrdb value or nil if not exists. \ */ int luaA_xrdb_get_value(lua_State *L) { - if (!globalconf.xrmdb) - xrdb_init(); + const char *resource_class = luaL_checkstring(L, 1); + const char *resource_name = luaL_checkstring(L, 2); + char *result = NULL; - char *resource_type; - int resource_code; - XrmValue resource_value; - const char *resource_class = luaL_checkstring(L, 1); - const char *resource_name = luaL_checkstring(L, 2); + if (xcb_xrm_resource_get_string(globalconf.xrmdb, resource_name, resource_class, &result) < 0 ) { + if (strlen(resource_class)) + luaA_warn(L, "Failed to get xrdb value '%s' (class '%s').", resource_name, resource_class); + else + luaA_warn(L, "Failed to get xrdb value '%s'.", resource_name); + lua_pushnil(L); + } else { + lua_pushstring(L, result); + p_delete(&result); + } - resource_code = XrmGetResource(globalconf.xrmdb, resource_name, resource_class, - &resource_type, &resource_value); - if (resource_code && (strcmp(resource_type, "String") == 0)) { - lua_pushstring(L, (char *)resource_value.addr); - } else { - if (strlen(resource_class)) - luaA_warn(L, "Failed to get xrdb value '%s' (class '%s').", resource_name, resource_class); - else - luaA_warn(L, "Failed to get xrdb value '%s'.", resource_name); - lua_pushnil(L); - } - return 1; + return 1; } // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80