i3
xcursor.c
Go to the documentation of this file.
1 #undef I3__FILE__
2 #define I3__FILE__ "xcursor.c"
3 /*
4  * vim:ts=4:sw=4:expandtab
5  *
6  * i3 - an improved dynamic tiling window manager
7  * © 2009-2011 Michael Stapelberg and contributors (see also: LICENSE)
8  *
9  * xcursor.c: libXcursor support for themed cursors.
10  *
11  */
12 #include <assert.h>
13 #include <X11/Xcursor/Xcursor.h>
14 #include <X11/cursorfont.h>
15 
16 #include "i3.h"
17 #include "xcb.h"
18 #include "xcursor.h"
19 
20 static Cursor cursors[XCURSOR_CURSOR_MAX];
21 
22 static const int xcb_cursors[XCURSOR_CURSOR_MAX] = {
27 };
28 
29 static Cursor load_cursor(const char *name) {
30  Cursor c = XcursorLibraryLoadCursor(xlibdpy, name);
31  if (c == None)
32  xcursor_supported = false;
33  return c;
34 }
35 
39  cursors[XCURSOR_CURSOR_RESIZE_VERTICAL] = load_cursor("sb_v_double_arrow");
44  cursors[XCURSOR_CURSOR_BOTTOM_LEFT_CORNER] = load_cursor("bottom_left_corner");
45  cursors[XCURSOR_CURSOR_BOTTOM_RIGHT_CORNER] = load_cursor("bottom_right_corner");
46 }
47 
48 /*
49  * Sets the cursor of the root window to the 'pointer' cursor.
50  *
51  * This function is called when i3 is initialized, because with some login
52  * managers, the root window will not have a cursor otherwise.
53  *
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).
57  *
58  */
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);
63  XFlush(xlibdpy);
64 }
65 
67  assert(c >= 0 && c < XCURSOR_CURSOR_MAX);
68  return cursors[c];
69 }
70 
72  assert(c >= 0 && c < XCURSOR_CURSOR_MAX);
73  return xcb_cursors[c];
74 }
xcursor_cursor_t
Definition: xcursor.h:15
Cursor xcursor_get_cursor(enum xcursor_cursor_t c)
Definition: xcursor.c:66
void xcursor_set_root_cursor(int cursor_id)
Sets the cursor of the root window to the &#39;pointer&#39; cursor.
Definition: xcursor.c:59
void xcursor_load_cursors(void)
Definition: xcursor.c:36
#define XCB_CURSOR_WATCH
Definition: xcb.h:25
char * name
Definition: x.c:55
#define XCB_CURSOR_LEFT_PTR
This is the equivalent of XC_left_ptr.
Definition: xcb.h:22
Display * xlibdpy
Definition: main.c:69
int xcursor_get_xcb_cursor(enum xcursor_cursor_t c)
Definition: xcursor.c:71
#define XCB_CURSOR_SB_H_DOUBLE_ARROW
Definition: xcb.h:23
static Cursor load_cursor(const char *name)
Definition: xcursor.c:29
bool xcursor_supported
Definition: main.c:91
#define XCB_CURSOR_SB_V_DOUBLE_ARROW
Definition: xcb.h:24
static const int xcb_cursors[XCURSOR_CURSOR_MAX]
Definition: xcursor.c:22
static Cursor cursors[XCURSOR_CURSOR_MAX]
Definition: xcursor.c:20