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:

531f8b415c "Added initial support for Xlib cursor themes"
77243cd09a "Add x11-xcb to the pkg-config checks"
779d43fc46 "Don't let Xlib own the event queue"
03759b4847 "Fix keyboard layouts"

Signed-off-by: Uli Schlachter <psychon@znc.in>
This commit is contained in:
Uli Schlachter 2013-09-19 16:48:10 +02:00
parent d82342e386
commit aaa771f887
8 changed files with 21 additions and 30 deletions

View File

@ -33,9 +33,6 @@
#include <xcb/xtest.h>
#include <xcb/shape.h>
#include <X11/Xlib-xcb.h>
#include <X11/XKBlib.h>
#include <glib-unix.h>
#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);

View File

@ -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

View File

@ -22,6 +22,8 @@
#include "common/xcursor.h"
#include "common/util.h"
#include <X11/cursorfont.h>
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];

View File

@ -22,14 +22,12 @@
#ifndef AWESOME_COMMON_XCURSORS_H
#define AWESOME_COMMON_XCURSORS_H
#include <X11/cursorfont.h>
#include <xcb/xcb.h>
#include <X11/Xcursor/Xcursor.h>
#include <xcb/xcb_cursor.h>
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

View File

@ -29,6 +29,7 @@
#include <xcb/xcb_icccm.h>
#include <xcb/xcb_keysyms.h>
#include <xcb/xcb_cursor.h>
#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 */

View File

@ -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);

View File

@ -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);

2
root.c
View File

@ -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,