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__)
51 * @defgroup XCB_Core_API XCB Core API
52 * @brief Core API of the XCB library.
57 /* Pre-defined constants */
59 /** Current protocol version */
62 /** Current minor version */
63 #define X_PROTOCOL_REVISION 0
65 /** X_TCP_PORT + display number = server port for TCP transport */
66 #define X_TCP_PORT 6000
68 #define XCB_TYPE_PAD(T,I) (-(I) & (sizeof(T) > 4 ? 3 : sizeof(T) - 1))
70 /* Opaque structures */
73 * @brief XCB Connection structure.
75 * A structure that contain all data that XCB needs to communicate with an X server.
77 typedef struct xcb_connection_t xcb_connection_t; /**< Opaque structure containing all data that XCB needs to communicate with an X server. */
83 * @brief Generic iterator.
85 * A generic iterator structure.
88 void *data; /**< Data of the current iterator */
89 int rem; /**< remaining elements */
90 int index; /**< index of the current iterator */
91 } xcb_generic_iterator_t;
94 * @brief Generic reply.
96 * A generic reply structure.
99 uint8_t response_type; /**< Type of the response */
100 uint8_t pad0; /**< Padding */
101 uint16_t sequence; /**< Sequence number */
102 uint32_t length; /**< Length of the response */
103 } xcb_generic_reply_t;
106 * @brief Generic event.
108 * A generic event structure.
111 uint8_t response_type; /**< Type of the response */
112 uint8_t pad0; /**< Padding */
113 uint16_t sequence; /**< Sequence number */
114 uint32_t pad[7]; /**< Padding */
115 uint32_t full_sequence; /**< full sequence */
116 } xcb_generic_event_t;
121 * An event as sent by the XGE extension. The length field specifies the
122 * number of 4-byte blocks trailing the struct.
125 uint8_t response_type; /**< Type of the response */
126 uint8_t pad0; /**< Padding */
127 uint16_t sequence; /**< Sequence number */
131 uint32_t pad[5]; /**< Padding */
132 uint32_t full_sequence; /**< full sequence */
136 * @brief Generic error.
138 * A generic error structure.
141 uint8_t response_type; /**< Type of the response */
142 uint8_t error_code; /**< Error code */
143 uint16_t sequence; /**< Sequence number */
144 uint32_t pad[7]; /**< Padding */
145 uint32_t full_sequence; /**< full sequence */
146 } xcb_generic_error_t;
149 * @brief Generic cookie.
151 * A generic cookie structure.
154 unsigned int sequence; /**< Sequence number */
158 /* Include the generated xproto header. */
162 /** XCB_NONE is the universal null resource or null atom parameter value for many core X requests */
165 /** XCB_COPY_FROM_PARENT can be used for many xcb_create_window parameters */
166 #define XCB_COPY_FROM_PARENT 0L
168 /** XCB_CURRENT_TIME can be used in most requests that take an xcb_timestamp_t */
169 #define XCB_CURRENT_TIME 0L
171 /** XCB_NO_SYMBOL fills in unused entries in xcb_keysym_t tables */
172 #define XCB_NO_SYMBOL 0L
178 * @brief Container for authorization information.
180 * A container for authorization information to be sent to the X server.
182 typedef struct xcb_auth_info_t {
183 int namelen; /**< Length of the string name (as returned by strlen). */
184 char *name; /**< String containing the authentication protocol name, such as "MIT-MAGIC-COOKIE-1" or "XDM-AUTHORIZATION-1". */
185 int datalen; /**< Length of the data member. */
186 char *data; /**< Data interpreted in a protocol-specific manner. */
193 * @brief Forces any buffered output to be written to the server.
194 * @param c: The connection to the X server.
195 * @return > @c 0 on success, <= @c 0 otherwise.
197 * Forces any buffered output to be written to the server. Blocks
198 * until the write is complete.
200 int xcb_flush(xcb_connection_t *c);
203 * @brief Returns the maximum request length that this server accepts.
204 * @param c: The connection to the X server.
205 * @return The maximum request length field.
207 * In the absence of the BIG-REQUESTS extension, returns the
208 * maximum request length field from the connection setup data, which
209 * may be as much as 65535. If the server supports BIG-REQUESTS, then
210 * the maximum request length field from the reply to the
211 * BigRequestsEnable request will be returned instead.
213 * Note that this length is measured in four-byte units, making the
214 * theoretical maximum lengths roughly 256kB without BIG-REQUESTS and
217 uint32_t xcb_get_maximum_request_length(xcb_connection_t *c);
220 * @brief Prefetch the maximum request length without blocking.
221 * @param c: The connection to the X server.
223 * Without blocking, does as much work as possible toward computing
224 * the maximum request length accepted by the X server.
226 * Invoking this function may cause a call to xcb_big_requests_enable,
227 * but will not block waiting for the reply.
228 * xcb_get_maximum_request_length will return the prefetched data
229 * after possibly blocking while the reply is retrieved.
231 * Note that in order for this function to be fully non-blocking, the
232 * application must previously have called
233 * xcb_prefetch_extension_data(c, &xcb_big_requests_id) and the reply
234 * must have already arrived.
236 void xcb_prefetch_maximum_request_length(xcb_connection_t *c);
242 * @brief Returns the next event or error from the server.
243 * @param c: The connection to the X server.
244 * @return The next event from the server.
246 * Returns the next event or error from the server, or returns null in
247 * the event of an I/O error. Blocks until either an event or error
248 * arrive, or an I/O error occurs.
250 xcb_generic_event_t *xcb_wait_for_event(xcb_connection_t *c);
253 * @brief Returns the next event or error from the server.
254 * @param c: The connection to the X server.
255 * error status of the operation.
256 * @return The next event from the server.
258 * Returns the next event or error from the server, if one is
259 * available, or returns @c NULL otherwise. If no event is available, that
260 * might be because an I/O error like connection close occurred while
261 * attempting to read the next event, in which case the connection is
262 * shut down when this function returns.
264 xcb_generic_event_t *xcb_poll_for_event(xcb_connection_t *c);
267 * @brief Return the error for a request, or NULL if none can ever arrive.
268 * @param c: The connection to the X server.
269 * @param cookie: The request cookie.
270 * @return The error for the request, or NULL if none can ever arrive.
272 * The xcb_void_cookie_t cookie supplied to this function must have resulted
273 * from a call to xcb_[request_name]_checked(). This function will block
274 * until one of two conditions happens. If an error is received, it will be
275 * returned. If a reply to a subsequent request has already arrived, no error
276 * can arrive for this request, so this function will return NULL.
278 * Note that this function will perform a sync if needed to ensure that the
279 * sequence number will advance beyond that provided in cookie; this is a
280 * convenience to avoid races in determining whether the sync is needed.
282 xcb_generic_error_t *xcb_request_check(xcb_connection_t *c, xcb_void_cookie_t cookie);
288 * @typedef typedef struct xcb_extension_t xcb_extension_t
290 typedef struct xcb_extension_t xcb_extension_t; /**< Opaque structure used as key for xcb_get_extension_data_t. */
293 * @brief Caches reply information from QueryExtension requests.
294 * @param c: The connection.
295 * @param ext: The extension data.
296 * @return A pointer to the xcb_query_extension_reply_t for the extension.
298 * This function is the primary interface to the "extension cache",
299 * which caches reply information from QueryExtension
300 * requests. Invoking this function may cause a call to
301 * xcb_query_extension to retrieve extension information from the
302 * server, and may block until extension data is received from the
305 * The result must not be freed. This storage is managed by the cache
308 const xcb_query_extension_reply_t *xcb_get_extension_data(xcb_connection_t *c, xcb_extension_t *ext);
311 * @brief Prefetch of extension data into the extension cache
312 * @param c: The connection.
313 * @param ext: The extension data.
315 * This function allows a "prefetch" of extension data into the
316 * extension cache. Invoking the function may cause a call to
317 * xcb_query_extension, but will not block waiting for the
318 * reply. xcb_get_extension_data will return the prefetched data after
319 * possibly blocking while it is retrieved.
321 void xcb_prefetch_extension_data(xcb_connection_t *c, xcb_extension_t *ext);
327 * @brief Access the data returned by the server.
328 * @param c: The connection.
329 * @return A pointer to an xcb_setup_t structure.
331 * Accessor for the data returned by the server when the xcb_connection_t
332 * was initialized. This data includes
333 * - the server's required format for images,
334 * - a list of available visuals,
335 * - a list of available screens,
336 * - the server's maximum request length (in the absence of the
337 * BIG-REQUESTS extension),
338 * - and other assorted information.
340 * See the X protocol specification for more details.
342 * The result must not be freed.
344 const xcb_setup_t *xcb_get_setup(xcb_connection_t *c);
347 * @brief Access the file descriptor of the connection.
348 * @param c: The connection.
349 * @return The file descriptor.
351 * Accessor for the file descriptor that was passed to the
352 * xcb_connect_to_fd call that returned @p c.
354 int xcb_get_file_descriptor(xcb_connection_t *c);
357 * @brief Test whether the connection has shut down due to a fatal error.
358 * @param c: The connection.
359 * @return 1 if the connection is in an error state; 0 otherwise.
361 * Some errors that occur in the context of an xcb_connection_t
362 * are unrecoverable. When such an error occurs, the
363 * connection is shut down and further operations on the
364 * xcb_connection_t have no effect.
366 * @todo Other functions should document the conditions in
367 * which they shut down the connection.
369 int xcb_connection_has_error(xcb_connection_t *c);
372 * @brief Connects to the X server.
373 * @param fd: The file descriptor.
374 * @param auth_info: Authentication data.
375 * @return A newly allocated xcb_connection_t structure.
377 * Connects to an X server, given the open socket @p fd and the
378 * xcb_auth_info_t @p auth_info. The file descriptor @p fd is
379 * bidirectionally connected to an X server. If the connection
380 * should be unauthenticated, @p auth_info must be @c
383 xcb_connection_t *xcb_connect_to_fd(int fd, xcb_auth_info_t *auth_info);
386 * @brief Closes the connection.
387 * @param c: The connection.
389 * Closes the file descriptor and frees all memory associated with the
392 void xcb_disconnect(xcb_connection_t *c);
398 * @brief Parses a display string name in the form documented by X(7x).
399 * @param name: The name of the display.
400 * @param host: A pointer to a malloc'd copy of the hostname.
401 * @param display: A pointer to the display number.
402 * @param screen: A pointer to the screen number.
403 * @return 0 on failure, non 0 otherwise.
405 * Parses the display string name @p display_name in the form
406 * documented by X(7x). Has no side effects on failure. If
407 * @p displayname is @c NULL or empty, it uses the environment
408 * variable DISPLAY. @p hostp is a pointer to a newly allocated string
409 * that contain the host name. @p displayp is set to the display
410 * number and @p screenp to the preferred screen number. @p screenp
411 * can be @c NULL. If @p displayname does not contain a screen number,
414 int xcb_parse_display(const char *name, char **host, int *display, int *screen);
417 * @brief Connects to the X server.
418 * @param displayname: The name of the display.
419 * @param screenp: A pointer to a preferred screen number.
420 * @return A newly allocated xcb_connection_t structure.
422 * Connects to the X server specified by @p displayname. If @p
423 * displayname is @c NULL, uses the value of the DISPLAY environment
424 * variable. If a particular screen on that server is preferred, the
425 * int pointed to by @p screenp (if not @c NULL) will be set to that
426 * screen; otherwise the screen will be set to 0.
428 xcb_connection_t *xcb_connect(const char *displayname, int *screenp);
431 * @brief Connects to the X server, using an authorization information.
432 * @param display: The name of the display.
433 * @param auth: The authorization information.
434 * @param screen: A pointer to a preferred screen number.
435 * @return A newly allocated xcb_connection_t structure.
437 * Connects to the X server specified by @p displayname, using the
438 * authorization @p auth. If a particular screen on that server is
439 * preferred, the int pointed to by @p screenp (if not @c NULL) will
440 * be set to that screen; otherwise @p screenp will be set to 0.
442 xcb_connection_t *xcb_connect_to_display_with_auth_info(const char *display, xcb_auth_info_t *auth, int *screen);
448 * @brief Allocates an XID for a new object.
449 * @param c: The connection.
450 * @return A newly allocated XID.
452 * Allocates an XID for a new object. Typically used just prior to
453 * various object creation functions, such as xcb_create_window.
455 uint32_t xcb_generate_id(xcb_connection_t *c);
467 #endif /* __XCB_H__ */