i3
Main Page
Data Structures
Files
File List
Globals
src
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-2011 Michael Stapelberg and contributors (see also: LICENSE)
6
*
7
* xcursor.c: libXcursor support for themed cursors.
8
*
9
*/
10
#include <assert.h>
11
#include <X11/Xcursor/Xcursor.h>
12
#include <X11/cursorfont.h>
13
14
#include "
i3.h
"
15
#include "
xcb.h
"
16
#include "
xcursor.h
"
17
18
static
Cursor
cursors
[
XCURSOR_CURSOR_MAX
];
19
20
static
const
int
xcb_cursors
[
XCURSOR_CURSOR_MAX
] = {
21
XCB_CURSOR_LEFT_PTR
,
22
XCB_CURSOR_SB_H_DOUBLE_ARROW
,
23
XCB_CURSOR_SB_V_DOUBLE_ARROW
,
24
XCB_CURSOR_WATCH
25
};
26
27
static
Cursor
load_cursor
(
const
char
*
name
) {
28
Cursor c = XcursorLibraryLoadCursor(
xlibdpy
, name);
29
if
(c == None)
30
xcursor_supported
=
false
;
31
return
c;
32
}
33
34
void
xcursor_load_cursors
(
void
) {
35
cursors
[
XCURSOR_CURSOR_POINTER
] =
load_cursor
(
"left_ptr"
);
36
cursors
[
XCURSOR_CURSOR_RESIZE_HORIZONTAL
] =
load_cursor
(
"sb_h_double_arrow"
);
37
cursors
[
XCURSOR_CURSOR_RESIZE_VERTICAL
] =
load_cursor
(
"sb_v_double_arrow"
);
38
cursors
[
XCURSOR_CURSOR_WATCH
] =
load_cursor
(
"watch"
);
39
}
40
41
/*
42
* Sets the cursor of the root window to the 'pointer' cursor.
43
*
44
* This function is called when i3 is initialized, because with some login
45
* managers, the root window will not have a cursor otherwise.
46
*
47
* We have a separate xcursor function to use the same X11 connection as the
48
* xcursor_load_cursors() function. If we mix the Xlib and the XCB connection,
49
* races might occur (even though we flush the Xlib connection).
50
*
51
*/
52
void
xcursor_set_root_cursor
(
int
cursor_id) {
53
XSetWindowAttributes attributes;
54
attributes.cursor =
xcursor_get_cursor
(cursor_id);
55
XChangeWindowAttributes(
xlibdpy
, DefaultRootWindow(
xlibdpy
), CWCursor, &attributes);
56
XFlush(
xlibdpy
);
57
}
58
59
Cursor
xcursor_get_cursor
(
enum
xcursor_cursor_t
c) {
60
assert(c >= 0 && c <
XCURSOR_CURSOR_MAX
);
61
return
cursors
[c];
62
}
63
64
int
xcursor_get_xcb_cursor
(
enum
xcursor_cursor_t
c) {
65
assert(c >= 0 && c <
XCURSOR_CURSOR_MAX
);
66
return
xcb_cursors
[c];
67
}
Generated by
1.8.1.1