2 * Copyright (C) 2001-2006 Bart Massey, Jamey Sharp, and Josh Triplett.
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
12 * The above copyright notice and this permission notice shall be included in
13 * all copies or substantial portions of the Software.
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 * AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
19 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 * Except as contained in this notice, the names of the authors or their
23 * institutions shall not be used in advertising or otherwise to promote the
24 * sale, use or other dealings in this Software without prior written
25 * authorization from the authors.
30 #include <sys/types.h>
32 #if defined(__solaris__)
38 /* FIXME: these names conflict with those defined in Xmd.h. */
40 typedef uint8_t uint8_t;
41 typedef uint8_t uint8_t;
42 typedef uint8_t uint8_t;
43 typedef uint16_t uint16_t;
44 typedef uint32_t uint32_t;
45 typedef int8_t int8_t;
46 typedef int16_t int16_t;
47 typedef int32_t int32_t;
63 * @defgroup xcb__core_api_t XCB Core API
64 * @brief Core API of the XCB library.
69 /* Pre-defined constants */
71 /** Current protocol version */
74 /** Current minor version */
75 #define X_PROTOCOL_REVISION 0
77 /** X_TCP_PORT + display number = server port for TCP transport */
78 #define X_TCP_PORT 6000
80 #define XCB_TYPE_PAD(T,I) (-(I) & (sizeof(T) > 4 ? 3 : sizeof(T) - 1))
82 /* Opaque structures */
85 * @brief XCB Connection structure.
87 * A structure that contain all data that XCB needs to communicate with an X server.
89 typedef struct xcb_connection_t xcb_connection_t; /**< Opaque structure containing all data that XCB needs to communicate with an X server. */
95 * @brief Generic iterator.
97 * A generic iterator structure.
100 void *data; /**< Data of the current iterator */
101 int rem; /**< remaining elements */
102 int index; /**< index of the current iterator */
103 } xcb_generic_iterator_t;
106 * @brief Generic reply.
108 * A generic reply structure.
111 uint8_t response_type; /**< Type of the response */
112 uint8_t pad0; /**< Padding */
113 uint16_t sequence; /**< Sequence number */
114 uint32_t length; /**< Length of the response */
115 } xcb_generic_reply_t;
118 * @brief Generic event.
120 * A generic event structure.
123 uint8_t response_type; /**< Type of the response */
124 uint8_t pad0; /**< Padding */
125 uint16_t sequence; /**< Sequence number */
126 uint32_t pad[7]; /**< Padding */
127 uint32_t full_sequence;
128 } xcb_generic_event_t;
131 * @brief Generic error.
133 * A generic error structure.
136 uint8_t response_type; /**< Type of the response */
137 uint8_t error_code; /**< Error code */
138 uint16_t sequence; /**< Sequence number */
139 uint32_t pad[7]; /**< Padding */
140 uint32_t full_sequence;
141 } xcb_generic_error_t;
144 * @brief Generic cookie.
146 * A generic cookie structure.
149 unsigned int sequence; /**< Sequence number */
153 /* Include the generated xproto header. */
157 /** XCB_NONE is the universal null resource or null atom parameter value for many core X requests */
160 /** XCB_COPY_FROM_PARENT can be used for many CreateWindow parameters */
161 #define XCB_COPY_FROM_PARENT 0L
163 /** XCB_CURRENT_TIME can be used in most requests that take an xcb_timestamp_t */
164 #define XCB_CURRENT_TIME 0L
166 /** XCB_NO_SYMBOL fills in unused entries in xcb_keysym_t tables */
167 #define XCB_NO_SYMBOL 0L
173 * @brief Container for authorization information.
175 * A container for authorization information to be sent to the X server.
177 typedef struct xcb_auth_info_t {
178 int namelen; /**< Length of the string name (as returned by strlen). */
179 char *name; /**< String containing the authentication protocol name, such as "MIT-MAGIC-COOKIE-1" or "XDM-AUTHORIZATION-1". */
180 int datalen; /**< Length of the data member. */
181 char *data; /**< Data interpreted in a protocol-specific manner. */
188 * @brief Forces any buffered output to be written to the server.
189 * @param c: The connection to the X server.
190 * @return > @c 0 on success, <= @c 0 otherwise.
192 * Forces any buffered output to be written to the server. Blocks
193 * until the write is complete.
195 int xcb_flush(xcb_connection_t *c);
198 * @brief Returns the maximum request length field from the connection
200 * @param c: The connection to the X server.
201 * @return The maximum request length field.
203 * In the absence of the BIG-REQUESTS extension, returns the
204 * maximum request length field from the connection setup data, which
205 * may be as much as 65535. If the server supports BIG-REQUESTS, then
206 * the maximum request length field from the reply to the
207 * BigRequestsEnable request will be returned instead.
209 * Note that this length is measured in four-byte units, making the
210 * theoretical maximum lengths roughly 256kB without BIG-REQUESTS and
213 uint32_t xcb_get_maximum_request_length(xcb_connection_t *c);
219 * @brief Returns the next event or error from the server.
220 * @param c: The connection to the X server.
221 * @return The next event from the server.
223 * Returns the next event or error from the server, or returns null in
224 * the event of an I/O error. Blocks until either an event or error
225 * arrive, or an I/O error occurs.
227 xcb_generic_event_t *xcb_wait_for_event(xcb_connection_t *c);
230 * @brief Returns the next event or error from the server.
231 * @param c: The connection to the X server.
232 * @param error: A pointer to an int to be filled in with the I/O
233 * error status of the operation.
234 * @return The next event from the server.
236 * Returns the next event or error from the server, if one is
237 * available, or returns @c NULL otherwise. If no event is available, that
238 * might be because an I/O error like connection close occurred while
239 * attempting to read the next event. The @p error parameter is a
240 * pointer to an int to be filled in with the I/O error status of the
241 * operation. If @p error is @c NULL, terminates the application when an
244 xcb_generic_event_t *xcb_poll_for_event(xcb_connection_t *c, int *error);
247 * @brief Return the error for a request, or NULL if none can ever arrive.
248 * @param c: The connection to the X server.
249 * @param cookie: The request cookie.
250 * @return The error for the request, or NULL if none can ever arrive.
252 * The xcb_void_cookie_t cookie supplied to this function must have resulted from
253 * a call to XCB[RequestName]Checked(). This function will block until one of
254 * two conditions happens. If an error is received, it will be returned. If
255 * a reply to a subsequent request has already arrived, no error can arrive
256 * for this request, so this function will return NULL.
258 * Note that this function will perform a sync if needed to ensure that the
259 * sequence number will advance beyond that provided in cookie; this is a
260 * convenience to avoid races in determining whether the sync is needed.
262 xcb_generic_error_t *xcb_request_check(xcb_connection_t *c, xcb_void_cookie_t cookie);
268 * @typedef typedef struct xcb_extension_t xcb_extension_t
270 typedef struct xcb_extension_t xcb_extension_t; /**< Opaque structure used as key for xcb_get_extension_data_t. */
273 * @brief Caches reply information from QueryExtension requests.
274 * @param c: The connection.
275 * @param ext: The extension data.
276 * @return A pointer to the xcb_query_extension_reply_t for the extension.
278 * This function is the primary interface to the "extension cache",
279 * which caches reply information from QueryExtension
280 * requests. Invoking this function may cause a call to
281 * xcb_query_extension_t to retrieve extension information from the
282 * server, and may block until extension data is received from the
285 * The result must not be freed. This storage is managed by the cache
288 const xcb_query_extension_reply_t *xcb_get_extension_data(xcb_connection_t *c, xcb_extension_t *ext);
291 * @brief Prefetch of extension data into the extension cache
292 * @param c: The connection.
293 * @param ext: The extension data.
295 * This function allows a "prefetch" of extension data into the
296 * extension cache. Invoking the function may cause a call to
297 * xcb_query_extension_t, but will not block waiting for the
298 * reply. xcb_get_extension_data_t will return the prefetched data after
299 * possibly blocking while it is retrieved.
301 void xcb_prefetch_extension_data(xcb_connection_t *c, xcb_extension_t *ext);
307 * @brief Access the data returned by the server.
308 * @param c: The connection.
309 * @return A pointer to an xcb_setup_t structure.
311 * Accessor for the data returned by the server when the xcb_connection_t
312 * was initialized. This data includes
313 * - the server's required format for images,
314 * - a list of available visuals,
315 * - a list of available screens,
316 * - the server's maximum request length (in the absence of the
317 * BIG-REQUESTS extension),
318 * - and other assorted information.
320 * See the X protocol specification for more details.
322 * The result must not be freed.
324 const xcb_setup_t *xcb_get_setup(xcb_connection_t *c);
327 * @brief Access the file descriptor of the connection.
328 * @param c: The connection.
329 * @return The file descriptor.
331 * Accessor for the file descriptor that was passed to the
332 * xcb_connect_to_fd_t call that returned @p c.
334 int xcb_get_file_descriptor(xcb_connection_t *c);
337 * @brief Test whether the connection has shut down due to a fatal error.
338 * @param c: The connection.
339 * @return 1 if the connection is in an error state; 0 otherwise.
341 * Some errors that occur in the context of an xcb_connection_t
342 * are unrecoverable. When such an error occurs, the
343 * connection is shut down and further operations on the
344 * xcb_connection_t have no effect.
346 * @todo Other functions should document the conditions in
347 * which they shut down the connection.
349 int xcb_connection_has_error(xcb_connection_t *c);
352 * @brief Connects to the X server.
353 * @param fd: The file descriptor.
354 * @param auth_info: Authentication data.
355 * @return A newly allocated xcb_connection_t structure.
357 * Connects to an X server, given the open socket @p fd and the
358 * xcb_auth_info_t @p auth_info. The file descriptor @p fd is
359 * bidirectionally connected to an X server. xcb_get_tcpfd_t and
360 * xcb_get_unix_fd_t return appropriate file descriptors. If the connection
361 * should be unauthenticated, @p auth_info must be @c
362 * NULL. xcb_get_auth_info_t returns appropriate authentication data.
364 xcb_connection_t *xcb_connect_to_fd(int fd, xcb_auth_info_t *auth_info);
367 * @brief Closes the connection.
368 * @param c: The connection.
370 * Closes the file descriptor and frees all memory associated with the
373 void xcb_disconnect(xcb_connection_t *c);
379 * @brief Parses a display string name in the form documented by X(7x).
380 * @param displayname: The name of the display.
381 * @param hostp: A pointer to a malloc'd copy of the hostname.
382 * @param displayp: A pointer to the display number.
383 * @param screenp: A pointer to the screen number.
384 * @return 0 on failure, non 0 otherwise.
386 * Parses the display string name @p display_name in the form
387 * documented by X(7x). Has no side effects on failure. If
388 * @p displayname is @c NULL or empty, it uses the environment
389 * variable DISPLAY. @p hostp is a pointer to a newly allocated string
390 * that contain the host name. @p displayp is set to the display
391 * number and @p screenp to the preferred screen number. @p screenp
392 * can be @c NULL. If @p displayname does not contain a screen number,
395 int xcb_parse_display(const char *name, char **host, int *display, int *screen);
398 * @brief Connects to the X server.
399 * @param displayname: The name of the display.
400 * @param screenp: A pointer to a preferred screen number.
401 * @return A newly allocated xcb_connection_t structure.
403 * Connects to the X server specified by @p displayname. If @p
404 * displayname is @c NULL, uses the value of the DISPLAY environment
405 * variable. If a particular screen on that server is preferred, the
406 * int pointed to by @p screenp (if not @c NULL) will be set to that
407 * screen; otherwise the screen will be set to 0.
409 xcb_connection_t *xcb_connect(const char *displayname, int *screenp);
412 * @brief Connects to the X server, using an authorization information.
413 * @param displayname: The name of the display.
414 * @param auth: The authorization information.
415 * @param screenp: A pointer to a preferred screen number.
416 * @return A newly allocated xcb_connection_t structure.
418 * Connects to the X server specified by @p displayname, using the
419 * authorization @p auth. If a particular screen on that server is
420 * preferred, the int pointed to by @p screenp (if not @c NULL) will
421 * be set to that screen; otherwise @p screenp will be set to 0.
423 xcb_connection_t *xcb_connect_to_display_with_auth_info(const char *display, xcb_auth_info_t *auth, int *screen);
435 #endif /* __XCB_H__ */