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__)
41 #include "xcb_windefs.h"
55 * @defgroup XCB_Core_API XCB Core API
56 * @brief Core API of the XCB library.
61 /* Pre-defined constants */
63 /** Current protocol version */
66 /** Current minor version */
67 #define X_PROTOCOL_REVISION 0
69 /** X_TCP_PORT + display number = server port for TCP transport */
70 #define X_TCP_PORT 6000
72 /** xcb connection errors because of socket, pipe and other stream errors. */
73 #define XCB_CONN_ERROR 1
75 /** xcb connection shutdown because of extension not supported */
76 #define XCB_CONN_CLOSED_EXT_NOTSUPPORTED 2
78 /** malloc(), calloc() and realloc() error upon failure, for eg ENOMEM */
79 #define XCB_CONN_CLOSED_MEM_INSUFFICIENT 3
81 /** Connection closed, exceeding request length that server accepts. */
82 #define XCB_CONN_CLOSED_REQ_LEN_EXCEED 4
84 /** Connection closed, error during parsing display string. */
85 #define XCB_CONN_CLOSED_PARSE_ERR 5
87 /** Connection closed because the server does not have a screen matching the display. */
88 #define XCB_CONN_CLOSED_INVALID_SCREEN 6
90 /** Connection closed because some FD passing operation failed */
91 #define XCB_CONN_CLOSED_FDPASSING_FAILED 7
93 #define XCB_TYPE_PAD(T,I) (-(I) & (sizeof(T) > 4 ? 3 : sizeof(T) - 1))
95 /* Opaque structures */
98 * @brief XCB Connection structure.
100 * A structure that contain all data that XCB needs to communicate with an X server.
102 typedef struct xcb_connection_t xcb_connection_t; /**< Opaque structure containing all data that XCB needs to communicate with an X server. */
108 * @brief Generic iterator.
110 * A generic iterator structure.
113 void *data; /**< Data of the current iterator */
114 int rem; /**< remaining elements */
115 int index; /**< index of the current iterator */
116 } xcb_generic_iterator_t;
119 * @brief Generic reply.
121 * A generic reply structure.
124 uint8_t response_type; /**< Type of the response */
125 uint8_t pad0; /**< Padding */
126 uint16_t sequence; /**< Sequence number */
127 uint32_t length; /**< Length of the response */
128 } xcb_generic_reply_t;
131 * @brief Generic event.
133 * A generic event structure.
136 uint8_t response_type; /**< Type of the response */
137 uint8_t pad0; /**< Padding */
138 uint16_t sequence; /**< Sequence number */
139 uint32_t pad[7]; /**< Padding */
140 uint32_t full_sequence; /**< full sequence */
141 } xcb_generic_event_t;
146 * An event as sent by the XGE extension. The length field specifies the
147 * number of 4-byte blocks trailing the struct.
149 * @deprecated Since some fields in this struct have unfortunate names, it is
150 * recommended to use xcb_ge_generic_event_t instead.
153 uint8_t response_type; /**< Type of the response */
154 uint8_t pad0; /**< Padding */
155 uint16_t sequence; /**< Sequence number */
159 uint32_t pad[5]; /**< Padding */
160 uint32_t full_sequence; /**< full sequence */
164 * @brief Generic error.
166 * A generic error structure.
169 uint8_t response_type; /**< Type of the response */
170 uint8_t error_code; /**< Error code */
171 uint16_t sequence; /**< Sequence number */
172 uint32_t resource_id; /** < Resource ID for requests with side effects only */
173 uint16_t minor_code; /** < Minor opcode of the failed request */
174 uint8_t major_code; /** < Major opcode of the failed request */
176 uint32_t pad[5]; /**< Padding */
177 uint32_t full_sequence; /**< full sequence */
178 } xcb_generic_error_t;
181 * @brief Generic cookie.
183 * A generic cookie structure.
186 unsigned int sequence; /**< Sequence number */
190 /* Include the generated xproto header. */
194 /** XCB_NONE is the universal null resource or null atom parameter value for many core X requests */
197 /** XCB_COPY_FROM_PARENT can be used for many xcb_create_window parameters */
198 #define XCB_COPY_FROM_PARENT 0L
200 /** XCB_CURRENT_TIME can be used in most requests that take an xcb_timestamp_t */
201 #define XCB_CURRENT_TIME 0L
203 /** XCB_NO_SYMBOL fills in unused entries in xcb_keysym_t tables */
204 #define XCB_NO_SYMBOL 0L
210 * @brief Container for authorization information.
212 * A container for authorization information to be sent to the X server.
214 typedef struct xcb_auth_info_t {
215 int namelen; /**< Length of the string name (as returned by strlen). */
216 char *name; /**< String containing the authentication protocol name, such as "MIT-MAGIC-COOKIE-1" or "XDM-AUTHORIZATION-1". */
217 int datalen; /**< Length of the data member. */
218 char *data; /**< Data interpreted in a protocol-specific manner. */
225 * @brief Forces any buffered output to be written to the server.
226 * @param c: The connection to the X server.
227 * @return > @c 0 on success, <= @c 0 otherwise.
229 * Forces any buffered output to be written to the server. Blocks
230 * until the write is complete.
232 int xcb_flush(xcb_connection_t *c);
235 * @brief Returns the maximum request length that this server accepts.
236 * @param c: The connection to the X server.
237 * @return The maximum request length field.
239 * In the absence of the BIG-REQUESTS extension, returns the
240 * maximum request length field from the connection setup data, which
241 * may be as much as 65535. If the server supports BIG-REQUESTS, then
242 * the maximum request length field from the reply to the
243 * BigRequestsEnable request will be returned instead.
245 * Note that this length is measured in four-byte units, making the
246 * theoretical maximum lengths roughly 256kB without BIG-REQUESTS and
249 uint32_t xcb_get_maximum_request_length(xcb_connection_t *c);
252 * @brief Prefetch the maximum request length without blocking.
253 * @param c: The connection to the X server.
255 * Without blocking, does as much work as possible toward computing
256 * the maximum request length accepted by the X server.
258 * Invoking this function may cause a call to xcb_big_requests_enable,
259 * but will not block waiting for the reply.
260 * xcb_get_maximum_request_length will return the prefetched data
261 * after possibly blocking while the reply is retrieved.
263 * Note that in order for this function to be fully non-blocking, the
264 * application must previously have called
265 * xcb_prefetch_extension_data(c, &xcb_big_requests_id) and the reply
266 * must have already arrived.
268 void xcb_prefetch_maximum_request_length(xcb_connection_t *c);
274 * @brief Returns the next event or error from the server.
275 * @param c: The connection to the X server.
276 * @return The next event from the server.
278 * Returns the next event or error from the server, or returns null in
279 * the event of an I/O error. Blocks until either an event or error
280 * arrive, or an I/O error occurs.
282 xcb_generic_event_t *xcb_wait_for_event(xcb_connection_t *c);
285 * @brief Returns the next event or error from the server.
286 * @param c: The connection to the X server.
287 * @return The next event from the server.
289 * Returns the next event or error from the server, if one is
290 * available, or returns @c NULL otherwise. If no event is available, that
291 * might be because an I/O error like connection close occurred while
292 * attempting to read the next event, in which case the connection is
293 * shut down when this function returns.
295 xcb_generic_event_t *xcb_poll_for_event(xcb_connection_t *c);
298 * @brief Returns the next event without reading from the connection.
299 * @param c: The connection to the X server.
300 * @return The next already queued event from the server.
302 * This is a version of xcb_poll_for_event that only examines the
303 * event queue for new events. The function doesn't try to read new
304 * events from the connection if no queued events are found.
306 * This function is useful for callers that know in advance that all
307 * interesting events have already been read from the connection. For
308 * example, callers might use xcb_wait_for_reply and be interested
309 * only of events that preceded a specific reply.
311 xcb_generic_event_t *xcb_poll_for_queued_event(xcb_connection_t *c);
313 typedef struct xcb_special_event xcb_special_event_t;
316 * @brief Returns the next event from a special queue
318 xcb_generic_event_t *xcb_poll_for_special_event(xcb_connection_t *c,
319 xcb_special_event_t *se);
322 * @brief Returns the next event from a special queue, blocking until one arrives
324 xcb_generic_event_t *xcb_wait_for_special_event(xcb_connection_t *c,
325 xcb_special_event_t *se);
327 * @typedef typedef struct xcb_extension_t xcb_extension_t
329 typedef struct xcb_extension_t xcb_extension_t; /**< Opaque structure used as key for xcb_get_extension_data_t. */
333 * @brief Listen for a special event
335 xcb_special_event_t *xcb_register_for_special_xge(xcb_connection_t *c,
336 xcb_extension_t *ext,
341 * @brief Stop listening for a special event
343 void xcb_unregister_for_special_event(xcb_connection_t *c,
344 xcb_special_event_t *se);
347 * @brief Return the error for a request, or NULL if none can ever arrive.
348 * @param c: The connection to the X server.
349 * @param cookie: The request cookie.
350 * @return The error for the request, or NULL if none can ever arrive.
352 * The xcb_void_cookie_t cookie supplied to this function must have resulted
353 * from a call to xcb_[request_name]_checked(). This function will block
354 * until one of two conditions happens. If an error is received, it will be
355 * returned. If a reply to a subsequent request has already arrived, no error
356 * can arrive for this request, so this function will return NULL.
358 * Note that this function will perform a sync if needed to ensure that the
359 * sequence number will advance beyond that provided in cookie; this is a
360 * convenience to avoid races in determining whether the sync is needed.
362 xcb_generic_error_t *xcb_request_check(xcb_connection_t *c, xcb_void_cookie_t cookie);
365 * @brief Discards the reply for a request.
366 * @param c: The connection to the X server.
367 * @param sequence: The request sequence number from a cookie.
369 * Discards the reply for a request. Additionally, any error generated
370 * by the request is also discarded (unless it was an _unchecked request
371 * and the error has already arrived).
373 * This function will not block even if the reply is not yet available.
375 * Note that the sequence really does have to come from an xcb cookie;
376 * this function is not designed to operate on socket-handoff replies.
378 void xcb_discard_reply(xcb_connection_t *c, unsigned int sequence);
384 * @brief Caches reply information from QueryExtension requests.
385 * @param c: The connection.
386 * @param ext: The extension data.
387 * @return A pointer to the xcb_query_extension_reply_t for the extension.
389 * This function is the primary interface to the "extension cache",
390 * which caches reply information from QueryExtension
391 * requests. Invoking this function may cause a call to
392 * xcb_query_extension to retrieve extension information from the
393 * server, and may block until extension data is received from the
396 * The result must not be freed. This storage is managed by the cache
399 const xcb_query_extension_reply_t *xcb_get_extension_data(xcb_connection_t *c, xcb_extension_t *ext);
402 * @brief Prefetch of extension data into the extension cache
403 * @param c: The connection.
404 * @param ext: The extension data.
406 * This function allows a "prefetch" of extension data into the
407 * extension cache. Invoking the function may cause a call to
408 * xcb_query_extension, but will not block waiting for the
409 * reply. xcb_get_extension_data will return the prefetched data after
410 * possibly blocking while it is retrieved.
412 void xcb_prefetch_extension_data(xcb_connection_t *c, xcb_extension_t *ext);
418 * @brief Access the data returned by the server.
419 * @param c: The connection.
420 * @return A pointer to an xcb_setup_t structure.
422 * Accessor for the data returned by the server when the xcb_connection_t
423 * was initialized. This data includes
424 * - the server's required format for images,
425 * - a list of available visuals,
426 * - a list of available screens,
427 * - the server's maximum request length (in the absence of the
428 * BIG-REQUESTS extension),
429 * - and other assorted information.
431 * See the X protocol specification for more details.
433 * The result must not be freed.
435 const xcb_setup_t *xcb_get_setup(xcb_connection_t *c);
438 * @brief Access the file descriptor of the connection.
439 * @param c: The connection.
440 * @return The file descriptor.
442 * Accessor for the file descriptor that was passed to the
443 * xcb_connect_to_fd call that returned @p c.
445 int xcb_get_file_descriptor(xcb_connection_t *c);
448 * @brief Test whether the connection has shut down due to a fatal error.
449 * @param c: The connection.
450 * @return > 0 if the connection is in an error state; 0 otherwise.
452 * Some errors that occur in the context of an xcb_connection_t
453 * are unrecoverable. When such an error occurs, the
454 * connection is shut down and further operations on the
455 * xcb_connection_t have no effect.
457 * @return XCB_CONN_ERROR, because of socket errors, pipe errors or other stream errors.
458 * @return XCB_CONN_CLOSED_EXT_NOTSUPPORTED, when extension not supported.
459 * @return XCB_CONN_CLOSED_MEM_INSUFFICIENT, when memory not available.
460 * @return XCB_CONN_CLOSED_REQ_LEN_EXCEED, exceeding request length that server accepts.
461 * @return XCB_CONN_CLOSED_PARSE_ERR, error during parsing display string.
462 * @return XCB_CONN_CLOSED_INVALID_SCREEN, because the server does not have a screen matching the display.
464 int xcb_connection_has_error(xcb_connection_t *c);
467 * @brief Connects to the X server.
468 * @param fd: The file descriptor.
469 * @param auth_info: Authentication data.
470 * @return A newly allocated xcb_connection_t structure.
472 * Connects to an X server, given the open socket @p fd and the
473 * xcb_auth_info_t @p auth_info. The file descriptor @p fd is
474 * bidirectionally connected to an X server. If the connection
475 * should be unauthenticated, @p auth_info must be @c
478 xcb_connection_t *xcb_connect_to_fd(int fd, xcb_auth_info_t *auth_info);
481 * @brief Closes the connection.
482 * @param c: The connection.
484 * Closes the file descriptor and frees all memory associated with the
487 void xcb_disconnect(xcb_connection_t *c);
493 * @brief Parses a display string name in the form documented by X(7x).
494 * @param name: The name of the display.
495 * @param host: A pointer to a malloc'd copy of the hostname.
496 * @param display: A pointer to the display number.
497 * @param screen: A pointer to the screen number.
498 * @return 0 on failure, non 0 otherwise.
500 * Parses the display string name @p display_name in the form
501 * documented by X(7x). Has no side effects on failure. If
502 * @p displayname is @c NULL or empty, it uses the environment
503 * variable DISPLAY. @p hostp is a pointer to a newly allocated string
504 * that contain the host name. @p displayp is set to the display
505 * number and @p screenp to the preferred screen number. @p screenp
506 * can be @c NULL. If @p displayname does not contain a screen number,
509 int xcb_parse_display(const char *name, char **host, int *display, int *screen);
512 * @brief Connects to the X server.
513 * @param displayname: The name of the display.
514 * @param screenp: A pointer to a preferred screen number.
515 * @return A newly allocated xcb_connection_t structure.
517 * Connects to the X server specified by @p displayname. If @p
518 * displayname is @c NULL, uses the value of the DISPLAY environment
519 * variable. If a particular screen on that server is preferred, the
520 * int pointed to by @p screenp (if not @c NULL) will be set to that
521 * screen; otherwise the screen will be set to 0.
523 xcb_connection_t *xcb_connect(const char *displayname, int *screenp);
526 * @brief Connects to the X server, using an authorization information.
527 * @param display: The name of the display.
528 * @param auth: The authorization information.
529 * @param screen: A pointer to a preferred screen number.
530 * @return A newly allocated xcb_connection_t structure.
532 * Connects to the X server specified by @p displayname, using the
533 * authorization @p auth. If a particular screen on that server is
534 * preferred, the int pointed to by @p screenp (if not @c NULL) will
535 * be set to that screen; otherwise @p screenp will be set to 0.
537 xcb_connection_t *xcb_connect_to_display_with_auth_info(const char *display, xcb_auth_info_t *auth, int *screen);
543 * @brief Allocates an XID for a new object.
544 * @param c: The connection.
545 * @return A newly allocated XID.
547 * Allocates an XID for a new object. Typically used just prior to
548 * various object creation functions, such as xcb_create_window.
550 uint32_t xcb_generate_id(xcb_connection_t *c);
562 #endif /* __XCB_H__ */