From aaa771f8879e0a16dfcaa7f5f6c60cc356498c18 Mon Sep 17 00:00:00 2001 From: Uli Schlachter Date: Thu, 19 Sep 2013 16:48:10 +0200 Subject: [PATCH] Switch from libXcursor to libxcb-cursor Thanks to Michael Stapelberg, there is now a xcb-only port of libXcursor which does everything we need. This patch switches awesome over to that new library. Since the only reason for using XOpenDisplay() instead of xcb_connect() was so that we can use libXcursor, we can get back to that older state again. This means that this effectively reverts the following commits: 531f8b415c65e9754a907e72f984ab0f6cbfc3a9 "Added initial support for Xlib cursor themes" 77243cd09aa862da10d18f6d549ef10d3c775d2b "Add x11-xcb to the pkg-config checks" 779d43fc462411d84adf757a178e938c6ba9d3b8 "Don't let Xlib own the event queue" 03759b48478eb716af8b62e01ef3b5140c582f58 "Fix keyboard layouts" Signed-off-by: Uli Schlachter --- awesome.c | 21 ++++++--------------- awesomeConfig.cmake | 3 +-- common/xcursor.c | 8 +++++--- common/xcursor.h | 6 ++---- globalconf.h | 5 +++-- mousegrabber.c | 2 +- objects/drawin.c | 4 ++-- root.c | 2 +- 8 files changed, 21 insertions(+), 30 deletions(-) diff --git a/awesome.c b/awesome.c index 01bd9696c..ce0582e16 100644 --- a/awesome.c +++ b/awesome.c @@ -33,9 +33,6 @@ #include #include -#include -#include - #include #include "awesome.h" @@ -86,6 +83,7 @@ awesome_atexit(bool restart) xcb_aux_sync(globalconf.connection); /* Disconnect *after* closing lua */ + xcb_cursor_context_free(globalconf.cursor_ctx); xcb_disconnect(globalconf.connection); } @@ -377,21 +375,11 @@ main(int argc, char **argv) sigemptyset(&sa.sa_mask); sigaction(SIGSEGV, &sa, 0); - /* XLib sucks */ - 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); /* We have no clue where the input focus is right now */ globalconf.focus.need_update = true; - /* Double checking that connection is good and operatable with xcb */ + /* X stuff */ + globalconf.connection = xcb_connect(NULL, &globalconf.default_screen); if(xcb_connection_has_error(globalconf.connection)) fatal("cannot open display"); @@ -419,6 +407,9 @@ main(int argc, char **argv) xcb_prefetch_extension_data(globalconf.connection, &xcb_xinerama_id); xcb_prefetch_extension_data(globalconf.connection, &xcb_shape_id); + if (xcb_cursor_context_new(globalconf.connection, globalconf.screen, &globalconf.cursor_ctx) < 0) + fatal("Failed to initialize xcb-cursor"); + /* Setup the main context */ g_main_context_set_poll_func(g_main_context_default(), &a_glib_poll); diff --git a/awesomeConfig.cmake b/awesomeConfig.cmake index 2dc73b201..3839e9a3d 100644 --- a/awesomeConfig.cmake +++ b/awesomeConfig.cmake @@ -133,8 +133,7 @@ pkg_check_modules(AWESOME_REQUIRED REQUIRED gdk-pixbuf-2.0 cairo x11 - x11-xcb - xcursor + xcb-cursor xcb-randr xcb-xtest xcb-xinerama diff --git a/common/xcursor.c b/common/xcursor.c index 1e6e24e1c..c4c691df5 100644 --- a/common/xcursor.c +++ b/common/xcursor.c @@ -22,6 +22,8 @@ #include "common/xcursor.h" #include "common/util.h" +#include + static char const * const xcursor_font[] = { [XC_X_cursor] = "X_cursor", @@ -129,17 +131,17 @@ xcursor_font_tostr(uint16_t c) /** Equivalent to 'XCreateFontCursor()', error are handled by the * default current error handler. - * \param conn The connection to the X server. + * \param ctx The xcb-cursor context. * \param cursor_font Type of cursor to use. * \return Allocated cursor font. */ xcb_cursor_t -xcursor_new(Display *conn, uint16_t cursor_font) +xcursor_new(xcb_cursor_context_t *ctx, uint16_t cursor_font) { static xcb_cursor_t xcursor[countof(xcursor_font)]; if (!xcursor[cursor_font]) { - xcursor[cursor_font] = XcursorLibraryLoadCursor(conn, xcursor_font_tostr(cursor_font)); + xcursor[cursor_font] = xcb_cursor_load_cursor(ctx, xcursor_font_tostr(cursor_font)); } return xcursor[cursor_font]; diff --git a/common/xcursor.h b/common/xcursor.h index fa4656826..ef56893b8 100644 --- a/common/xcursor.h +++ b/common/xcursor.h @@ -22,14 +22,12 @@ #ifndef AWESOME_COMMON_XCURSORS_H #define AWESOME_COMMON_XCURSORS_H -#include #include - -#include +#include uint16_t xcursor_font_fromstr(const char *); const char * xcursor_font_tostr(uint16_t); -xcb_cursor_t xcursor_new(Display *, uint16_t); +xcb_cursor_t xcursor_new(xcb_cursor_context_t *, uint16_t); #endif // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80 diff --git a/globalconf.h b/globalconf.h index 7c725a82b..ca8c4a3f6 100644 --- a/globalconf.h +++ b/globalconf.h @@ -29,6 +29,7 @@ #include #include +#include #include "objects/key.h" #include "color.h" @@ -64,12 +65,12 @@ ARRAY_TYPE(drawin_t *, drawin) /** Main configuration structure */ typedef struct { - /** Xlib Display */ - Display * display; /** Connection ref */ xcb_connection_t *connection; /** Default screen number */ int default_screen; + /** xcb-cursor context */ + xcb_cursor_context_t *cursor_ctx; /** Keys symbol table */ xcb_key_symbols_t *keysyms; /** Logical screens */ diff --git a/mousegrabber.c b/mousegrabber.c index 98f14ea36..35d87ddab 100644 --- a/mousegrabber.c +++ b/mousegrabber.c @@ -94,7 +94,7 @@ luaA_mousegrabber_run(lua_State *L) if(cfont) { - xcb_cursor_t cursor = xcursor_new(globalconf.display, cfont); + xcb_cursor_t cursor = xcursor_new(globalconf.cursor_ctx, cfont); luaA_registerfct(L, 1, &globalconf.mousegrabber); diff --git a/objects/drawin.c b/objects/drawin.c index 54e1a3332..b570211cb 100644 --- a/objects/drawin.c +++ b/objects/drawin.c @@ -142,7 +142,7 @@ drawin_init(drawin_t *w) | XCB_EVENT_MASK_POINTER_MOTION | XCB_EVENT_MASK_EXPOSURE | XCB_EVENT_MASK_PROPERTY_CHANGE, globalconf.default_cmap, - xcursor_new(globalconf.display, xcursor_font_fromstr(w->cursor)) + xcursor_new(globalconf.cursor_ctx, xcursor_font_fromstr(w->cursor)) }); /* Set the right properties */ @@ -502,7 +502,7 @@ luaA_drawin_set_cursor(lua_State *L, drawin_t *drawin) uint16_t cursor_font = xcursor_font_fromstr(buf); if(cursor_font) { - xcb_cursor_t cursor = xcursor_new(globalconf.display, cursor_font); + xcb_cursor_t cursor = xcursor_new(globalconf.cursor_ctx, cursor_font); p_delete(&drawin->cursor); drawin->cursor = a_strdup(buf); xwindow_set_cursor(drawin->window, cursor); diff --git a/root.c b/root.c index 64aac64ac..7d94622a4 100644 --- a/root.c +++ b/root.c @@ -303,7 +303,7 @@ luaA_root_cursor(lua_State *L) if(cursor_font) { - uint32_t change_win_vals[] = { xcursor_new(globalconf.display, cursor_font) }; + uint32_t change_win_vals[] = { xcursor_new(globalconf.cursor_ctx, cursor_font) }; xcb_change_window_attributes(globalconf.connection, globalconf.screen->root,