Use xcb-util-xrm
Instead of using Xlib for parsing resource files, this now uses the dedicated xcb-based library that is meant for exactly this task. Fixes: https://github.com/awesomeWM/awesome/issues/1176 Signed-off-by: Uli Schlachter <psychon@znc.in>
This commit is contained in:
parent
b2e0e55fc0
commit
0e81479a3f
|
@ -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.
|
||||
- |
|
||||
|
|
12
awesome.c
12
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();
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -30,6 +30,7 @@
|
|||
#include <xcb/xcb_icccm.h>
|
||||
#include <xcb/xcb_keysyms.h>
|
||||
#include <xcb/xcb_cursor.h>
|
||||
#include <xcb/xcb_xrm.h>
|
||||
#include <X11/Xresource.h>
|
||||
|
||||
#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 */
|
||||
|
|
50
xrdb.c
50
xrdb.c
|
@ -26,23 +26,6 @@
|
|||
|
||||
#include <string.h>
|
||||
|
||||
/* \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
|
||||
|
|
Loading…
Reference in New Issue