2 #define I3__FILE__ "xcursor.c"
4 * vim:ts=4:sw=4:expandtab
6 * i3 - an improved dynamic tiling window manager
7 * © 2009-2013 Michael Stapelberg and contributors (see also: LICENSE)
9 * xcursor.c: xcursor support for themed cursors.
13 #include <xcb/xcb_cursor.h>
19 static xcb_cursor_context_t *ctx;
20 static xcb_cursor_t 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 void xcursor_load_cursors(void) {
30 if (xcb_cursor_context_new(conn, root_screen, &ctx) < 0) {
31 ELOG("xcursor support unavailable\n");
32 xcursor_supported = false;
35 #define LOAD_CURSOR(constant, name) \
37 cursors[constant] = xcb_cursor_load_cursor(ctx, name); \
39 LOAD_CURSOR(XCURSOR_CURSOR_POINTER, "left_ptr");
40 LOAD_CURSOR(XCURSOR_CURSOR_RESIZE_HORIZONTAL, "sb_h_double_arrow");
41 LOAD_CURSOR(XCURSOR_CURSOR_RESIZE_VERTICAL, "sb_v_double_arrow");
42 LOAD_CURSOR(XCURSOR_CURSOR_WATCH, "watch");
43 LOAD_CURSOR(XCURSOR_CURSOR_MOVE, "fleur");
44 LOAD_CURSOR(XCURSOR_CURSOR_TOP_LEFT_CORNER, "top_left_corner");
45 LOAD_CURSOR(XCURSOR_CURSOR_TOP_RIGHT_CORNER, "top_right_corner");
46 LOAD_CURSOR(XCURSOR_CURSOR_BOTTOM_LEFT_CORNER, "bottom_left_corner");
47 LOAD_CURSOR(XCURSOR_CURSOR_BOTTOM_RIGHT_CORNER, "bottom_right_corner");
52 * Sets the cursor of the root window to the 'pointer' cursor.
54 * This function is called when i3 is initialized, because with some login
55 * managers, the root window will not have a cursor otherwise.
58 void xcursor_set_root_cursor(int cursor_id) {
59 xcb_change_window_attributes(conn, root, XCB_CW_CURSOR,
60 (uint32_t[]){ xcursor_get_cursor(cursor_id) });
63 xcb_cursor_t xcursor_get_cursor(enum xcursor_cursor_t c) {
64 assert(c >= 0 && c < XCURSOR_CURSOR_MAX);
68 int xcursor_get_xcb_cursor(enum xcursor_cursor_t c) {
69 assert(c >= 0 && c < XCURSOR_CURSOR_MAX);
70 return xcb_cursors[c];