switch from libXcursor to xcb-util-cursor

This commit is contained in:
Michael Stapelberg 2013-07-13 10:58:06 +02:00
parent 3216cc79de
commit da20cd397c
6 changed files with 37 additions and 37 deletions

View File

@ -10,6 +10,7 @@
│ pkg-config │ 0.25 │ 0.26 │ http://pkgconfig.freedesktop.org/ │ │ pkg-config │ 0.25 │ 0.26 │ http://pkgconfig.freedesktop.org/ │
│ libxcb │ 1.1.93 │ 1.7 │ http://xcb.freedesktop.org/dist/ │ │ libxcb │ 1.1.93 │ 1.7 │ http://xcb.freedesktop.org/dist/ │
│ xcb-util │ 0.3.3 │ 0.3.8 │ http://xcb.freedesktop.org/dist/ │ │ xcb-util │ 0.3.3 │ 0.3.8 │ http://xcb.freedesktop.org/dist/ │
│ util-cursor³│ 0.0.99 │ 0.0.99 │ http://xcb.freedesktop.org/dist/ │
│ libev │ 4.0 │ 4.11 │ http://libev.schmorp.de/ │ │ libev │ 4.0 │ 4.11 │ http://libev.schmorp.de/ │
│ yajl │ 1.0.8 │ 2.0.1 │ http://lloyd.github.com/yajl/ │ │ yajl │ 1.0.8 │ 2.0.1 │ http://lloyd.github.com/yajl/ │
│ asciidoc │ 8.3.0 │ 8.6.4 │ http://www.methods.co.nz/asciidoc/ │ │ asciidoc │ 8.3.0 │ 8.6.4 │ http://www.methods.co.nz/asciidoc/ │
@ -26,6 +27,8 @@
¹ libsn = libstartup-notification ¹ libsn = libstartup-notification
² Pod::Simple is a Perl module required for converting the testsuite ² Pod::Simple is a Perl module required for converting the testsuite
documentation to HTML. See http://michael.stapelberg.de/cpan/#Pod::Simple documentation to HTML. See http://michael.stapelberg.de/cpan/#Pod::Simple
³ xcb-util-cursor, to be precise. Might be considered part of xcb-util, or not
:-).
i3bar, i3-msg, i3-input, i3-nagbar and i3-config-wizard do not introduce any i3bar, i3-msg, i3-input, i3-nagbar and i3-config-wizard do not introduce any
new dependencies. new dependencies.

View File

@ -111,8 +111,8 @@ X11_CFLAGS := $(call cflags_for_lib, x11)
X11_LIBS := $(call ldflags_for_lib, x11,X11) X11_LIBS := $(call ldflags_for_lib, x11,X11)
# Xcursor # Xcursor
XCURSOR_CFLAGS := $(call cflags_for_lib, xcursor) XCURSOR_CFLAGS := $(call cflags_for_lib, xcb-cursor)
XCURSOR_LIBS := $(call ldflags_for_lib, xcursor,Xcursor) XCURSOR_LIBS := $(call ldflags_for_lib, xcb-cursor,xcb-cursor)
# yajl # yajl
YAJL_CFLAGS := $(call cflags_for_lib, yajl) YAJL_CFLAGS := $(call cflags_for_lib, yajl)

2
debian/control vendored
View File

@ -9,7 +9,7 @@ Build-Depends: debhelper (>= 7.0.50~),
libxcb-xinerama0-dev (>= 1.1), libxcb-xinerama0-dev (>= 1.1),
libxcb-randr0-dev, libxcb-randr0-dev,
libxcb-icccm4-dev, libxcb-icccm4-dev,
libxcursor-dev, libxcb-cursor-dev,
asciidoc (>= 8.4.4), asciidoc (>= 8.4.4),
xmlto, xmlto,
docbook-xml, docbook-xml,

View File

@ -2,7 +2,7 @@
* vim:ts=4:sw=4:expandtab * vim:ts=4:sw=4:expandtab
* *
* i3 - an improved dynamic tiling window manager * i3 - an improved dynamic tiling window manager
* © 2009-2011 Michael Stapelberg and contributors (see also: LICENSE) * © 2009-2013 Michael Stapelberg and contributors (see also: LICENSE)
* *
* xcursor.c: libXcursor support for themed cursors. * xcursor.c: libXcursor support for themed cursors.
* *
@ -10,7 +10,7 @@
#ifndef I3_XCURSOR_CURSOR_H #ifndef I3_XCURSOR_CURSOR_H
#define I3_XCURSOR_CURSOR_H #define I3_XCURSOR_CURSOR_H
#include <X11/Xlib.h> #include <xcb/xcb_cursor.h>
enum xcursor_cursor_t { enum xcursor_cursor_t {
XCURSOR_CURSOR_POINTER = 0, XCURSOR_CURSOR_POINTER = 0,
@ -26,7 +26,7 @@ enum xcursor_cursor_t {
}; };
void xcursor_load_cursors(void); void xcursor_load_cursors(void);
Cursor xcursor_get_cursor(enum xcursor_cursor_t c); xcb_cursor_t xcursor_get_cursor(enum xcursor_cursor_t c);
int xcursor_get_xcb_cursor(enum xcursor_cursor_t c); int xcursor_get_xcb_cursor(enum xcursor_cursor_t c);
/** /**

View File

@ -569,7 +569,7 @@ void drag_pointer(Con *con, const xcb_button_press_event_t *event, xcb_window_t
if (con != NULL) if (con != NULL)
memcpy(&old_rect, &(con->rect), sizeof(Rect)); memcpy(&old_rect, &(con->rect), sizeof(Rect));
Cursor xcursor = (cursor && xcursor_supported) ? xcb_cursor_t xcursor = (cursor && xcursor_supported) ?
xcursor_get_cursor(cursor) : XCB_NONE; xcursor_get_cursor(cursor) : XCB_NONE;
/* Grab the pointer */ /* Grab the pointer */

View File

@ -4,20 +4,20 @@
* vim:ts=4:sw=4:expandtab * vim:ts=4:sw=4:expandtab
* *
* i3 - an improved dynamic tiling window manager * i3 - an improved dynamic tiling window manager
* © 2009-2011 Michael Stapelberg and contributors (see also: LICENSE) * © 2009-2013 Michael Stapelberg and contributors (see also: LICENSE)
* *
* xcursor.c: libXcursor support for themed cursors. * xcursor.c: xcursor support for themed cursors.
* *
*/ */
#include <assert.h> #include <assert.h>
#include <X11/Xcursor/Xcursor.h> #include <xcb/xcb_cursor.h>
#include <X11/cursorfont.h>
#include "i3.h" #include "i3.h"
#include "xcb.h" #include "xcb.h"
#include "xcursor.h" #include "xcursor.h"
static Cursor cursors[XCURSOR_CURSOR_MAX]; static xcb_cursor_context_t *ctx;
static xcb_cursor_t cursors[XCURSOR_CURSOR_MAX];
static const int xcb_cursors[XCURSOR_CURSOR_MAX] = { static const int xcb_cursors[XCURSOR_CURSOR_MAX] = {
XCB_CURSOR_LEFT_PTR, XCB_CURSOR_LEFT_PTR,
@ -26,23 +26,26 @@ static const int xcb_cursors[XCURSOR_CURSOR_MAX] = {
XCB_CURSOR_WATCH XCB_CURSOR_WATCH
}; };
static Cursor load_cursor(const char *name) {
Cursor c = XcursorLibraryLoadCursor(xlibdpy, name);
if (c == None)
xcursor_supported = false;
return c;
}
void xcursor_load_cursors(void) { void xcursor_load_cursors(void) {
cursors[XCURSOR_CURSOR_POINTER] = load_cursor("left_ptr"); if (xcb_cursor_context_new(conn, root_screen, &ctx) < 0) {
cursors[XCURSOR_CURSOR_RESIZE_HORIZONTAL] = load_cursor("sb_h_double_arrow"); ELOG("xcursor support unavailable\n");
cursors[XCURSOR_CURSOR_RESIZE_VERTICAL] = load_cursor("sb_v_double_arrow"); xcursor_supported = false;
cursors[XCURSOR_CURSOR_WATCH] = load_cursor("watch"); return;
cursors[XCURSOR_CURSOR_MOVE] = load_cursor("fleur"); }
cursors[XCURSOR_CURSOR_TOP_LEFT_CORNER] = load_cursor("top_left_corner"); #define LOAD_CURSOR(constant, name) \
cursors[XCURSOR_CURSOR_TOP_RIGHT_CORNER] = load_cursor("top_right_corner"); do { \
cursors[XCURSOR_CURSOR_BOTTOM_LEFT_CORNER] = load_cursor("bottom_left_corner"); cursors[constant] = xcb_cursor_load_cursor(ctx, name); \
cursors[XCURSOR_CURSOR_BOTTOM_RIGHT_CORNER] = load_cursor("bottom_right_corner"); } while (0)
LOAD_CURSOR(XCURSOR_CURSOR_POINTER, "left_ptr");
LOAD_CURSOR(XCURSOR_CURSOR_RESIZE_HORIZONTAL, "sb_h_double_arrow");
LOAD_CURSOR(XCURSOR_CURSOR_RESIZE_VERTICAL, "sb_v_double_arrow");
LOAD_CURSOR(XCURSOR_CURSOR_WATCH, "watch");
LOAD_CURSOR(XCURSOR_CURSOR_MOVE, "fleur");
LOAD_CURSOR(XCURSOR_CURSOR_TOP_LEFT_CORNER, "top_left_corner");
LOAD_CURSOR(XCURSOR_CURSOR_TOP_RIGHT_CORNER, "top_right_corner");
LOAD_CURSOR(XCURSOR_CURSOR_BOTTOM_LEFT_CORNER, "bottom_left_corner");
LOAD_CURSOR(XCURSOR_CURSOR_BOTTOM_RIGHT_CORNER, "bottom_right_corner");
#undef LOAD_CURSOR
} }
/* /*
@ -51,19 +54,13 @@ void xcursor_load_cursors(void) {
* This function is called when i3 is initialized, because with some login * This function is called when i3 is initialized, because with some login
* managers, the root window will not have a cursor otherwise. * managers, the root window will not have a cursor otherwise.
* *
* We have a separate xcursor function to use the same X11 connection as the
* xcursor_load_cursors() function. If we mix the Xlib and the XCB connection,
* races might occur (even though we flush the Xlib connection).
*
*/ */
void xcursor_set_root_cursor(int cursor_id) { void xcursor_set_root_cursor(int cursor_id) {
XSetWindowAttributes attributes; xcb_change_window_attributes(conn, root, XCB_CW_CURSOR,
attributes.cursor = xcursor_get_cursor(cursor_id); (uint32_t[]){ xcursor_get_cursor(cursor_id) });
XChangeWindowAttributes(xlibdpy, DefaultRootWindow(xlibdpy), CWCursor, &attributes);
XFlush(xlibdpy);
} }
Cursor xcursor_get_cursor(enum xcursor_cursor_t c) { xcb_cursor_t xcursor_get_cursor(enum xcursor_cursor_t c) {
assert(c >= 0 && c < XCURSOR_CURSOR_MAX); assert(c >= 0 && c < XCURSOR_CURSOR_MAX);
return cursors[c]; return cursors[c];
} }