X-Git-Url: https://git.sur5r.net/?p=i3%2Fi3;a=blobdiff_plain;f=src%2Fxcursor.c;h=cbfe808bcd11e625909db179fe9d68e787ceba20;hp=54ef34d219f397105eac758d412cfaa267db9f23;hb=HEAD;hpb=d8bf633e56783f6ecbcee836d8597854331d8d26 diff --git a/src/xcursor.c b/src/xcursor.c index 54ef34d2..cbfe808b 100644 --- a/src/xcursor.c +++ b/src/xcursor.c @@ -1,43 +1,70 @@ /* * vim:ts=4:sw=4:expandtab + * + * i3 - an improved dynamic tiling window manager + * © 2009 Michael Stapelberg and contributors (see also: LICENSE) + * + * xcursor.c: xcursor support for themed cursors. + * */ +#include + #include -#include -#include +#include #include "i3.h" #include "xcb.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] = { XCB_CURSOR_LEFT_PTR, XCB_CURSOR_SB_H_DOUBLE_ARROW, - XCB_CURSOR_SB_V_DOUBLE_ARROW -}; + XCB_CURSOR_SB_V_DOUBLE_ARROW, + XCB_CURSOR_WATCH}; -static Cursor load_cursor(const char *name) { - Cursor c = XcursorLibraryLoadCursor(xlibdpy, name); - if (c == None) +void xcursor_load_cursors(void) { + if (xcb_cursor_context_new(conn, root_screen, &ctx) < 0) { + ELOG("xcursor support unavailable\n"); xcursor_supported = false; - return c; + return; + } +#define LOAD_CURSOR(constant, name) \ + do { \ + cursors[constant] = xcb_cursor_load_cursor(ctx, name); \ + } 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 } -void xcursor_load_cursors() { - cursors[XCURSOR_CURSOR_POINTER] = load_cursor("left_ptr"); - cursors[XCURSOR_CURSOR_RESIZE_HORIZONTAL] = load_cursor("sb_h_double_arrow"); - cursors[XCURSOR_CURSOR_RESIZE_VERTICAL] = load_cursor("sb_v_double_arrow"); - - XFlush(xlibdpy); +/* + * Sets the cursor of the root window to the 'pointer' cursor. + * + * This function is called when i3 is initialized, because with some login + * managers, the root window will not have a cursor otherwise. + * + */ +void xcursor_set_root_cursor(int cursor_id) { + xcb_change_window_attributes(conn, root, XCB_CW_CURSOR, + (uint32_t[]){xcursor_get_cursor(cursor_id)}); } -Cursor xcursor_get_cursor(enum xcursor_cursor_t c) { - assert(c >= 0 && c < XCURSOR_CURSOR_MAX); +xcb_cursor_t xcursor_get_cursor(enum xcursor_cursor_t c) { + assert(c < XCURSOR_CURSOR_MAX); return cursors[c]; } int xcursor_get_xcb_cursor(enum xcursor_cursor_t c) { - assert(c >= 0 && c < XCURSOR_CURSOR_MAX); + assert(c < XCURSOR_CURSOR_MAX); return xcb_cursors[c]; }