1#ifndef XCB_CURSOR_H
2#define XCB_CURSOR_H
3
4/* Copyright © 2013 Michael Stapelberg
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 *
23 * Except as contained in this notice, the names of the authors or their
24 * institutions shall not be used in advertising or otherwise to promote the
25 * sale, use or other dealings in this Software without prior written
26 * authorization from the authors.
27 */
28
29#include <xcb/xcb.h>
30
31#ifdef __cplusplus
32extern "C" {
33#endif
34
35/**
36 * @defgroup xcb__cursor_context_t XCB Cursor Functions
37 *
38 * These functions are the equivalent of libXcursor, but re-implemented for
39 * XCB. They respect the user’s configured cursor theme when loading cursors,
40 * specified by the X resources setting "Xcursor.theme".
41 *
42 * Here is how you would use these functions to change the X11 root window
43 * cursor to "watch":
44 * @code
45 * int screennr;
46 * xcb_connection_t *conn = xcb_connect(NULL, &screennr);
47 * if (conn == NULL || xcb_connection_has_error(conn))
48 * err(EXIT_FAILURE, "Could not connect to X11");
49 *
50 * xcb_screen_t *screen = xcb_aux_get_screen(conn, screennr);
51 * xcb_cursor_context_t *ctx;
52 * if (xcb_cursor_context_new(conn, screen, &ctx) < 0)
53 * err(EXIT_FAILURE, "Could not initialize xcb-cursor");
54 *
55 * xcb_cursor_t cid = xcb_cursor_load_cursor(ctx, "watch");
56 *
57 * xcb_screen_t *screen = xcb_setup_roots_iterator(xcb_get_setup(conn)).data;
58 * xcb_change_window_attributes(conn, screen->root, XCB_CW_CURSOR, (uint32_t[]){ cid });
59 * xcb_free_cursor(conn, cid);
60 * xcb_flush(conn);
61 *
62 * xcb_cursor_context_free(ctx);
63 * xcb_disconnect(conn);
64 * @endcode
65 *
66 * @{
67 */
68
69/**
70 * @struct xcb_cursor_context_t
71 * Describes a context for using this library.
72 *
73 * Create a context with @ref xcb_cursor_context_new (), then load one or more
74 * cursors with @ref xcb_cursor_load_cursor () and destroy the context with @ref
75 * xcb_cursor_context_free ().
76 */
77typedef struct xcb_cursor_context_t xcb_cursor_context_t;
78
79/**
80 * Create a new @ref xcb_cursor_context_t.
81 *
82 * @param conn A working XCB connection, which will be used until you destroy
83 * the context with @ref xcb_cursor_context_free ().
84 * @param screen The xcb_screen_t to use (e.g. for getting the RESOURCE_MANAGER
85 * contents, for creating cursors on, for using the size as fallback when
86 * calculating the best cursor size).
87 * @param ctx A pointer to an xcb_cursor_context_t* which will be modified to
88 * refer to the newly created context.
89 * @return 0 on success, a negative error code otherwise.
90 *
91 * @ingroup xcb_cursor_context_t
92 */
93int xcb_cursor_context_new(xcb_connection_t *conn, xcb_screen_t *screen, xcb_cursor_context_t **ctx);
94
95/**
96 * Loads the specified cursor, either from the cursor theme or by falling back
97 * to the X11 "cursor" font.
98 *
99 * @param ctx A cursor context, created with @ref xcb_cursor_context_new ()
100 * @param name The name of the cursor to load, e.g. "watch".
101 * @returns The ID of the created cursor. When you are done using it, use
102 * xcb_free_cursor. Calling @ref xcb_cursor_context_free () will NOT free the
103 * created cursor.
104 *
105 */
106xcb_cursor_t xcb_cursor_load_cursor(xcb_cursor_context_t *ctx, const char *name);
107
108/**
109 * Frees the @ref xcb_cursor_context_t.
110 *
111 * @param ctx The context to free.
112 *
113 */
114void xcb_cursor_context_free(xcb_cursor_context_t *ctx);
115
116/**
117 * @}
118 */
119
120#ifdef __cplusplus
121}
122#endif
123
124#endif
125

source code of include/xcb/xcb_cursor.h