2 * vim:ts=4:sw=4:expandtab
5 #include <X11/Xcursor/Xcursor.h>
6 #include <X11/cursorfont.h>
12 static Cursor cursors[XCURSOR_CURSOR_MAX];
14 static const int xcb_cursors[XCURSOR_CURSOR_MAX] = {
16 XCB_CURSOR_SB_H_DOUBLE_ARROW,
17 XCB_CURSOR_SB_V_DOUBLE_ARROW
20 static Cursor load_cursor(const char *name) {
21 Cursor c = XcursorLibraryLoadCursor(xlibdpy, name);
23 xcursor_supported = false;
27 void xcursor_load_cursors() {
28 cursors[XCURSOR_CURSOR_POINTER] = load_cursor("left_ptr");
29 cursors[XCURSOR_CURSOR_RESIZE_HORIZONTAL] = load_cursor("sb_h_double_arrow");
30 cursors[XCURSOR_CURSOR_RESIZE_VERTICAL] = load_cursor("sb_v_double_arrow");
34 * Sets the cursor of the root window to the 'pointer' cursor.
36 * This function is called when i3 is initialized, because with some login
37 * managers, the root window will not have a cursor otherwise.
39 * We have a separate xcursor function to use the same X11 connection as the
40 * xcursor_load_cursors() function. If we mix the Xlib and the XCB connection,
41 * races might occur (even though we flush the Xlib connection).
44 void xcursor_set_root_cursor() {
45 XSetWindowAttributes attributes;
46 attributes.cursor = xcursor_get_cursor(XCURSOR_CURSOR_POINTER);
47 XChangeWindowAttributes(xlibdpy, DefaultRootWindow(xlibdpy), CWCursor, &attributes);
51 Cursor xcursor_get_cursor(enum xcursor_cursor_t c) {
52 assert(c >= 0 && c < XCURSOR_CURSOR_MAX);
56 int xcursor_get_xcb_cursor(enum xcursor_cursor_t c) {
57 assert(c >= 0 && c < XCURSOR_CURSOR_MAX);
58 return xcb_cursors[c];