i3
Main Page
Data Structures
Files
File List
Globals
src
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
] = {
23
XCB_CURSOR_LEFT_PTR
,
24
XCB_CURSOR_SB_H_DOUBLE_ARROW
,
25
XCB_CURSOR_SB_V_DOUBLE_ARROW
,
26
XCB_CURSOR_WATCH
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
36
void
xcursor_load_cursors
(
void
) {
37
cursors
[
XCURSOR_CURSOR_POINTER
] =
load_cursor
(
"left_ptr"
);
38
cursors
[
XCURSOR_CURSOR_RESIZE_HORIZONTAL
] =
load_cursor
(
"sb_h_double_arrow"
);
39
cursors
[
XCURSOR_CURSOR_RESIZE_VERTICAL
] =
load_cursor
(
"sb_v_double_arrow"
);
40
cursors
[
XCURSOR_CURSOR_WATCH
] =
load_cursor
(
"watch"
);
41
cursors
[
XCURSOR_CURSOR_MOVE
] =
load_cursor
(
"fleur"
);
42
cursors
[
XCURSOR_CURSOR_TOP_LEFT_CORNER
] =
load_cursor
(
"top_left_corner"
);
43
cursors
[
XCURSOR_CURSOR_TOP_RIGHT_CORNER
] =
load_cursor
(
"top_right_corner"
);
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
66
Cursor
xcursor_get_cursor
(
enum
xcursor_cursor_t
c) {
67
assert(c >= 0 && c <
XCURSOR_CURSOR_MAX
);
68
return
cursors
[c];
69
}
70
71
int
xcursor_get_xcb_cursor
(
enum
xcursor_cursor_t
c) {
72
assert(c >= 0 && c <
XCURSOR_CURSOR_MAX
);
73
return
xcb_cursors
[c];
74
}
Generated by
1.8.3