i3
xcursor.c
Go to the documentation of this file.
1 /*
2  * vim:ts=4:sw=4:expandtab
3  *
4  * i3 - an improved dynamic 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 <assert.h>
13 #include <xcb/xcb_cursor.h>
14 
15 #include "i3.h"
16 #include "xcb.h"
17 #include "xcursor.h"
18 
19 static xcb_cursor_context_t *ctx;
20 static xcb_cursor_t cursors[XCURSOR_CURSOR_MAX];
21 
22 static const int xcb_cursors[XCURSOR_CURSOR_MAX] = {
27 
29  if (xcb_cursor_context_new(conn, root_screen, &ctx) < 0) {
30  ELOG("xcursor support unavailable\n");
31  xcursor_supported = false;
32  return;
33  }
34 #define LOAD_CURSOR(constant, name) \
35  do { \
36  cursors[constant] = xcb_cursor_load_cursor(ctx, name); \
37  } while (0)
39  LOAD_CURSOR(XCURSOR_CURSOR_RESIZE_HORIZONTAL, "sb_h_double_arrow");
40  LOAD_CURSOR(XCURSOR_CURSOR_RESIZE_VERTICAL, "sb_v_double_arrow");
43  LOAD_CURSOR(XCURSOR_CURSOR_TOP_LEFT_CORNER, "top_left_corner");
44  LOAD_CURSOR(XCURSOR_CURSOR_TOP_RIGHT_CORNER, "top_right_corner");
45  LOAD_CURSOR(XCURSOR_CURSOR_BOTTOM_LEFT_CORNER, "bottom_left_corner");
46  LOAD_CURSOR(XCURSOR_CURSOR_BOTTOM_RIGHT_CORNER, "bottom_right_corner");
47 #undef LOAD_CURSOR
48 }
49 
50 /*
51  * Sets the cursor of the root window to the 'pointer' cursor.
52  *
53  * This function is called when i3 is initialized, because with some login
54  * managers, the root window will not have a cursor otherwise.
55  *
56  */
57 void xcursor_set_root_cursor(int cursor_id) {
58  xcb_change_window_attributes(conn, root, XCB_CW_CURSOR,
59  (uint32_t[]){xcursor_get_cursor(cursor_id)});
60 }
61 
62 xcb_cursor_t xcursor_get_cursor(enum xcursor_cursor_t c) {
63  assert(c < XCURSOR_CURSOR_MAX);
64  return cursors[c];
65 }
66 
68  assert(c < XCURSOR_CURSOR_MAX);
69  return xcb_cursors[c];
70 }
XCURSOR_CURSOR_MOVE
@ XCURSOR_CURSOR_MOVE
Definition: xcursor.h:25
XCURSOR_CURSOR_BOTTOM_RIGHT_CORNER
@ XCURSOR_CURSOR_BOTTOM_RIGHT_CORNER
Definition: xcursor.h:23
xcursor.h
XCB_CURSOR_SB_H_DOUBLE_ARROW
#define XCB_CURSOR_SB_H_DOUBLE_ARROW
Definition: xcb.h:24
XCURSOR_CURSOR_RESIZE_HORIZONTAL
@ XCURSOR_CURSOR_RESIZE_HORIZONTAL
Definition: xcursor.h:18
XCB_CURSOR_SB_V_DOUBLE_ARROW
#define XCB_CURSOR_SB_V_DOUBLE_ARROW
Definition: xcb.h:25
XCB_CURSOR_WATCH
#define XCB_CURSOR_WATCH
Definition: xcb.h:26
XCURSOR_CURSOR_POINTER
@ XCURSOR_CURSOR_POINTER
Definition: xcursor.h:17
cursors
static xcb_cursor_t cursors[XCURSOR_CURSOR_MAX]
Definition: xcursor.c:20
XCURSOR_CURSOR_RESIZE_VERTICAL
@ XCURSOR_CURSOR_RESIZE_VERTICAL
Definition: xcursor.h:19
xcursor_get_xcb_cursor
int xcursor_get_xcb_cursor(enum xcursor_cursor_t c)
Definition: xcursor.c:67
xcursor_load_cursors
void xcursor_load_cursors(void)
Definition: xcursor.c:28
ELOG
#define ELOG(fmt,...)
Definition: libi3.h:99
xcursor_cursor_t
xcursor_cursor_t
Definition: xcursor.h:16
XCURSOR_CURSOR_WATCH
@ XCURSOR_CURSOR_WATCH
Definition: xcursor.h:24
XCB_CURSOR_LEFT_PTR
#define XCB_CURSOR_LEFT_PTR
This is the equivalent of XC_left_ptr.
Definition: xcb.h:23
XCURSOR_CURSOR_TOP_LEFT_CORNER
@ XCURSOR_CURSOR_TOP_LEFT_CORNER
Definition: xcursor.h:20
xcursor_supported
bool xcursor_supported
Definition: main.c:90
XCURSOR_CURSOR_MAX
@ XCURSOR_CURSOR_MAX
Definition: xcursor.h:26
XCURSOR_CURSOR_TOP_RIGHT_CORNER
@ XCURSOR_CURSOR_TOP_RIGHT_CORNER
Definition: xcursor.h:21
xcursor_set_root_cursor
void xcursor_set_root_cursor(int cursor_id)
Sets the cursor of the root window to the 'pointer' cursor.
Definition: xcursor.c:57
root_screen
xcb_screen_t * root_screen
Definition: main.c:56
xcb_cursors
static const int xcb_cursors[XCURSOR_CURSOR_MAX]
Definition: xcursor.c:22
xcb.h
i3.h
xcursor_get_cursor
xcb_cursor_t xcursor_get_cursor(enum xcursor_cursor_t c)
Definition: xcursor.c:62
LOAD_CURSOR
#define LOAD_CURSOR(constant, name)
ctx
static xcb_cursor_context_t * ctx
Definition: xcursor.c:19
conn
xcb_connection_t * conn
XCB connection and root screen.
Definition: main.c:44
root
xcb_window_t root
Definition: main.c:57
XCURSOR_CURSOR_BOTTOM_LEFT_CORNER
@ XCURSOR_CURSOR_BOTTOM_LEFT_CORNER
Definition: xcursor.h:22