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");
41 }
42 
43 /*
44  * Sets the cursor of the root window to the 'pointer' cursor.
45  *
46  * This function is called when i3 is initialized, because with some login
47  * managers, the root window will not have a cursor otherwise.
48  *
49  * We have a separate xcursor function to use the same X11 connection as the
50  * xcursor_load_cursors() function. If we mix the Xlib and the XCB connection,
51  * races might occur (even though we flush the Xlib connection).
52  *
53  */
54 void xcursor_set_root_cursor(int cursor_id) {
55  XSetWindowAttributes attributes;
56  attributes.cursor = xcursor_get_cursor(cursor_id);
57  XChangeWindowAttributes(xlibdpy, DefaultRootWindow(xlibdpy), CWCursor, &attributes);
58  XFlush(xlibdpy);
59 }
60 
62  assert(c >= 0 && c < XCURSOR_CURSOR_MAX);
63  return cursors[c];
64 }
65 
67  assert(c >= 0 && c < XCURSOR_CURSOR_MAX);
68  return xcb_cursors[c];
69 }