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_flush(conn);
60 *
61 * xcb_cursor_context_free(ctx);
62 * xcb_disconnect(conn);
63 * @endcode
64 *
65 * @{
66 */
67
68/**
69 * @struct xcb_cursor_context_t
70 * Describes a context for using this library.
71 *
72 * Create a context with @ref xcb_cursor_context_new (), then load one or more
73 * cursors with @ref xcb_cursor_load_cursor () and destroy the context with @ref
74 * xcb_cursor_context_free ().
75 */
76typedef struct xcb_cursor_context_t xcb_cursor_context_t;
77
78/**
79 * Create a new @ref xcb_cursor_context_t.
80 *
81 * @param conn A working XCB connection, which will be used until you destroy
82 * the context with @ref xcb_cursor_context_free ().
83 * @param screen The xcb_screen_t to use (e.g. for getting the RESOURCE_MANAGER
84 * contents, for creating cursors on, for using the size as fallback when
85 * calculating the best cursor size).
86 * @param ctx A pointer to an xcb_cursor_context_t* which will be modified to
87 * refer to the newly created context.
88 * @return 0 on success, a negative error code otherwise.
89 *
90 * @ingroup xcb_cursor_context_t
91 */
92int xcb_cursor_context_new(xcb_connection_t *conn, xcb_screen_t *screen, xcb_cursor_context_t **ctx);
93
94/**
95 * Loads the specified cursor, either from the cursor theme or by falling back
96 * to the X11 "cursor" font.
97 *
98 * @param ctx A cursor context, created with @ref xcb_cursor_context_new ()
99 * @param name The name of the cursor to load, e.g. "watch".
100 * @returns The ID of the created cursor. When you are done using it, use
101 * xcb_free_cursor. Calling @ref xcb_cursor_context_free () will NOT free the
102 * created cursor.
103 *
104 */
105xcb_cursor_t xcb_cursor_load_cursor(xcb_cursor_context_t *ctx, const char *name);
106
107/**
108 * Frees the @ref xcb_cursor_context_t.
109 *
110 * @param ctx The context to free.
111 *
112 */
113void xcb_cursor_context_free(xcb_cursor_context_t *ctx);
114
115/**
116 * @}
117 */
118
119#ifdef __cplusplus
120}
121#endif
122
123#endif
124

source code of include/xcb/xcb_cursor.h