2 #define I3__FILE__ "xcursor.c"
4 * vim:ts=4:sw=4:expandtab
6 * i3 - an improved dynamic tiling window manager
7 * © 2009-2011 Michael Stapelberg and contributors (see also: LICENSE)
9 * xcursor.c: libXcursor support for themed cursors.
13 #include <X11/Xcursor/Xcursor.h>
14 #include <X11/cursorfont.h>
20 static Cursor cursors[XCURSOR_CURSOR_MAX];
22 static const int xcb_cursors[XCURSOR_CURSOR_MAX] = {
24 XCB_CURSOR_SB_H_DOUBLE_ARROW,
25 XCB_CURSOR_SB_V_DOUBLE_ARROW,
29 static Cursor load_cursor(const char *name) {
30 Cursor c = XcursorLibraryLoadCursor(xlibdpy, name);
32 xcursor_supported = false;
36 void xcursor_load_cursors(void) {
37 cursors[XCURSOR_CURSOR_POINTER] = load_cursor("left_ptr");
38 cursors[XCURSOR_CURSOR_RESIZE_HORIZONTAL] = load_cursor("sb_h_double_arrow");
39 cursors[XCURSOR_CURSOR_RESIZE_VERTICAL] = load_cursor("sb_v_double_arrow");
40 cursors[XCURSOR_CURSOR_WATCH] = load_cursor("watch");
41 cursors[XCURSOR_CURSOR_MOVE] = load_cursor("fleur");
42 cursors[XCURSOR_CURSOR_TOP_LEFT_CORNER] = load_cursor("top_left_corner");
43 cursors[XCURSOR_CURSOR_TOP_RIGHT_CORNER] = load_cursor("top_right_corner");
44 cursors[XCURSOR_CURSOR_BOTTOM_LEFT_CORNER] = load_cursor("bottom_left_corner");
45 cursors[XCURSOR_CURSOR_BOTTOM_RIGHT_CORNER] = load_cursor("bottom_right_corner");
49 * Sets the cursor of the root window to the 'pointer' cursor.
51 * This function is called when i3 is initialized, because with some login
52 * managers, the root window will not have a cursor otherwise.
54 * We have a separate xcursor function to use the same X11 connection as the
55 * xcursor_load_cursors() function. If we mix the Xlib and the XCB connection,
56 * races might occur (even though we flush the Xlib connection).
59 void xcursor_set_root_cursor(int cursor_id) {
60 XSetWindowAttributes attributes;
61 attributes.cursor = xcursor_get_cursor(cursor_id);
62 XChangeWindowAttributes(xlibdpy, DefaultRootWindow(xlibdpy), CWCursor, &attributes);
66 Cursor xcursor_get_cursor(enum xcursor_cursor_t c) {
67 assert(c >= 0 && c < XCURSOR_CURSOR_MAX);
71 int xcursor_get_xcb_cursor(enum xcursor_cursor_t c) {
72 assert(c >= 0 && c < XCURSOR_CURSOR_MAX);
73 return xcb_cursors[c];