i3
xcursor.c
Go to the documentation of this file.
1/*
2 * vim:ts=4:sw=4:expandtab
3 *
4 * i3 - an improved tiling window manager
5 * © 2009 Michael Stapelberg and contributors (see also: LICENSE)
6 *
7 * xcursor.c: xcursor support for themed cursors.
8 *
9 */
10#include <config.h>
11
12#include "all.h"
13
14#include <assert.h>
15#include <err.h>
16
17#include <xcb/xcb_cursor.h>
18
19static xcb_cursor_context_t *ctx;
20static xcb_cursor_t cursors[XCURSOR_CURSOR_MAX];
21
23 if (xcb_cursor_context_new(conn, root_screen, &ctx) < 0) {
24 errx(EXIT_FAILURE, "Cannot allocate xcursor context");
25 }
26#define LOAD_CURSOR(constant, name) \
27 do { \
28 cursors[constant] = xcb_cursor_load_cursor(ctx, name); \
29 } while (0)
32 LOAD_CURSOR(XCURSOR_CURSOR_RESIZE_VERTICAL, "sb_v_double_arrow");
38 LOAD_CURSOR(XCURSOR_CURSOR_BOTTOM_RIGHT_CORNER, "bottom_right_corner");
39#undef LOAD_CURSOR
40}
41
42/*
43 * Sets the cursor of the root window to the 'pointer' cursor.
44 *
45 * This function is called when i3 is initialized, because with some login
46 * managers, the root window will not have a cursor otherwise.
47 *
48 */
49void xcursor_set_root_cursor(int cursor_id) {
50 xcb_change_window_attributes(conn, root, XCB_CW_CURSOR,
51 (uint32_t[]){xcursor_get_cursor(cursor_id)});
52}
53
55 assert(c < XCURSOR_CURSOR_MAX);
56 return cursors[c];
57}
static xcb_cursor_t cursors[XCURSOR_CURSOR_MAX]
Definition xcursor.c:20
#define LOAD_CURSOR(constant, name)
xcb_cursor_t xcursor_get_cursor(enum xcursor_cursor_t c)
Definition xcursor.c:54
static xcb_cursor_context_t * ctx
Definition xcursor.c:19
void xcursor_load_cursors(void)
Definition xcursor.c:22
void xcursor_set_root_cursor(int cursor_id)
Sets the cursor of the root window to the 'pointer' cursor.
Definition xcursor.c:49
xcb_connection_t * conn
XCB connection and root screen.
Definition main.c:54
xcb_window_t root
Definition main.c:67
xcb_screen_t * root_screen
Definition main.c:66
xcursor_cursor_t
Definition xcursor.h:16
@ XCURSOR_CURSOR_TOP_LEFT_CORNER
Definition xcursor.h:20
@ XCURSOR_CURSOR_RESIZE_HORIZONTAL
Definition xcursor.h:18
@ XCURSOR_CURSOR_BOTTOM_RIGHT_CORNER
Definition xcursor.h:23
@ XCURSOR_CURSOR_MOVE
Definition xcursor.h:25
@ XCURSOR_CURSOR_RESIZE_VERTICAL
Definition xcursor.h:19
@ XCURSOR_CURSOR_TOP_RIGHT_CORNER
Definition xcursor.h:21
@ XCURSOR_CURSOR_WATCH
Definition xcursor.h:24
@ XCURSOR_CURSOR_POINTER
Definition xcursor.h:17
@ XCURSOR_CURSOR_MAX
Definition xcursor.h:26
@ XCURSOR_CURSOR_BOTTOM_LEFT_CORNER
Definition xcursor.h:22