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 /* TODO: check for stdint in config? (HAVE_STDINT) fallback? */
35 /* FIXME: these names conflict with those defined in Xmd.h. */
39 typedef uint8_t CARD8;
40 typedef uint16_t CARD16;
41 typedef uint32_t CARD32;
43 typedef int16_t INT16;
44 typedef int32_t INT32;
57 #if (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 1))
58 #define deprecated __attribute__((__deprecated__))
69 * @defgroup XCB_Core_Api XCB Core API
70 * @brief Core API of the XCB library.
75 /* Pre-defined constants */
77 /** Current protocol version */
80 /** Current minor version */
81 #define X_PROTOCOL_REVISION 0
83 /** X_TCP_PORT + display number = server port for TCP transport */
84 #define X_TCP_PORT 6000
86 #define XCB_TYPE_PAD(T,I) (-(I) & (sizeof(T) > 4 ? 3 : sizeof(T) - 1))
88 /* Opaque structures */
91 * @brief XCB Connection structure.
93 * A structure that contain all data that XCB needs to communicate with an X server.
95 typedef struct XCBConnection XCBConnection; /**< Opaque structure containing all data that XCB needs to communicate with an X server. */
101 * @brief Generic iterator.
103 * A generic iterator structure.
106 void *data; /**< Data of the current iterator */
107 int rem; /**< remaining elements */
108 int index; /**< index of the current iterator */
112 * @brief Generic reply.
114 * A generic reply structure.
117 BYTE response_type; /**< Type of the response */
118 CARD8 pad0; /**< Padding */
119 CARD16 sequence; /**< Sequence number */
120 CARD32 length; /**< Length of the response */
124 * @brief Generic event.
126 * A generic event structure.
129 BYTE response_type; /**< Type of the response */
130 CARD8 pad0; /**< Padding */
131 CARD16 sequence; /**< Sequence number */
132 CARD32 pad[7]; /**< Padding */
133 CARD32 full_sequence;
137 * @brief Generic error.
139 * A generic error structure.
142 BYTE response_type; /**< Type of the response */
143 BYTE error_code; /**< Error code */
144 CARD16 sequence; /**< Sequence number */
145 CARD32 pad[7]; /**< Padding */
146 CARD32 full_sequence;
150 * @brief Generic cookie.
152 * A generic cookie structure.
155 unsigned int sequence; /**< Sequence number */
159 /* Include the generated xproto header. */
163 /** XCBNone is the universal null resource or null atom parameter value for many core X requests */
166 /** XCBCopyFromParent can be used for many CreateWindow parameters */
167 #define XCBCopyFromParent 0L
169 /** XCBCurrentTime can be used in most requests that take an XCBTIMESTAMP */
170 #define XCBCurrentTime 0L
172 /** XCBNoSymbol fills in unused entries in XCBKEYSYM tables */
173 #define XCBNoSymbol 0L
179 * @brief Container for authorization information.
181 * A container for authorization information to be sent to the X server.
183 typedef struct XCBAuthInfo {
184 int namelen; /**< Length of the string name (as returned by strlen). */
185 char *name; /**< String containing the authentication protocol name, such as "MIT-MAGIC-COOKIE-1" or "XDM-AUTHORIZATION-1". */
186 int datalen; /**< Length of the data member. */
187 char *data; /**< Data interpreted in a protocol-specific manner. */
191 * @brief Gets authorization information.
192 * @param fd: The file descriptor.
193 * @param info: The authorisation info to set.
194 * @return @c 0 on failure, 1 otherwise.
196 * @deprecated This function is deprecated. It must not be used in
197 * newly written code.
199 int XCBGetAuthInfo(int fd, XCBAuthInfo *info) deprecated;
205 * @brief Forces any buffered output to be written to the server.
206 * @param c: The connection to the X server.
207 * @return > @c 0 on success, <= @c 0 otherwise.
209 * Forces any buffered output to be written to the server. Blocks
210 * until the write is complete.
212 int XCBFlush(XCBConnection *c);
215 * @brief Returns the maximum request length field from the connection
217 * @param c: The connection to the X server.
218 * @return The maximum request length field.
220 * In the absence of the BIG-REQUESTS extension, returns the
221 * maximum request length field from the connection setup data, which
222 * may be as much as 65535. If the server supports BIG-REQUESTS, then
223 * the maximum request length field from the reply to the
224 * BigRequestsEnable request will be returned instead.
226 * Note that this length is measured in four-byte units, making the
227 * theoretical maximum lengths roughly 256kB without BIG-REQUESTS and
230 CARD32 XCBGetMaximumRequestLength(XCBConnection *c);
236 * @brief Returns the next event or error from the server.
237 * @param c: The connection to the X server.
238 * @return The next event from the server.
240 * @deprecated This function is deprecated. It must not be used in
241 * newly written code.
243 XCBGenericEvent *XCBWaitEvent(XCBConnection *c) deprecated;
246 * @brief Returns the next event or error from the server.
247 * @param c: The connection to the X server.
248 * @return The next event from the server.
250 * Returns the next event or error from the server, or returns null in
251 * the event of an I/O error. Blocks until either an event or error
252 * arrive, or an I/O error occurs.
254 XCBGenericEvent *XCBWaitForEvent(XCBConnection *c);
257 * @brief Returns the next event or error from the server.
258 * @param c: The connection to the X server.
259 * @param error: A pointer to an int to be filled in with the I/O
260 * error status of the operation.
261 * @return The next event from the server.
263 * Returns the next event or error from the server, if one is
264 * available, or returns @c NULL otherwise. If no event is available, that
265 * might be because an I/O error like connection close occurred while
266 * attempting to read the next event. The @p error parameter is a
267 * pointer to an int to be filled in with the I/O error status of the
268 * operation. If @p error is @c NULL, terminates the application when an
271 XCBGenericEvent *XCBPollForEvent(XCBConnection *c, int *error);
274 * @brief Returns the last sequence number that the server is known to
276 * @param c: The connection to the X server.
277 * @return The last sequence number.
279 * Returns the last sequence number that the server is known to have
280 * processed. This function enables applications to determine whether
281 * forcing a cookie is going to block.
283 * @deprecated This function is deprecated in favor of XCBPollForReply.
284 * It must not be used in newly written code.
286 unsigned int XCBGetRequestRead(XCBConnection *c) deprecated;
292 * @typedef typedef struct XCBExtension XCBExtension
294 typedef struct XCBExtension XCBExtension; /**< Opaque structure used as key for XCBGetExtensionData. */
297 * @brief Caches reply information from QueryExtension requests.
298 * @param c: The connection.
299 * @param ext: The extension data.
300 * @return A pointer to the XCBQueryExtensionRep for the extension.
302 * This function is the primary interface to the "extension cache",
303 * which caches reply information from QueryExtension
304 * requests. Invoking this function may cause a call to
305 * XCBQueryExtension to retrieve extension information from the
306 * server, and may block until extension data is received from the
309 * The result must not be freed. This storage is managed by the cache
312 const XCBQueryExtensionRep *XCBGetExtensionData(XCBConnection *c, XCBExtension *ext);
315 * @brief Prefetch of extension data into the extension cache
316 * @param c: The connection.
317 * @param ext: The extension data.
319 * This function allows a "prefetch" of extension data into the
320 * extension cache. Invoking the function may cause a call to
321 * XCBQueryExtension, but will not block waiting for the
322 * reply. XCBGetExtensionData will return the prefetched data after
323 * possibly blocking while it is retrieved.
325 void XCBPrefetchExtensionData(XCBConnection *c, XCBExtension *ext);
331 * @brief Access the data returned by the server.
332 * @param c: The connection.
333 * @return A pointer to an XCBSetup structure.
335 * Accessor for the data returned by the server when the XCBConnection
336 * was initialized. This data includes
337 * - the server's required format for images,
338 * - a list of available visuals,
339 * - a list of available screens,
340 * - the server's maximum request length (in the absence of the
341 * BIG-REQUESTS extension),
342 * - and other assorted information.
344 * See the X protocol specification for more details.
346 * The result must not be freed.
348 const XCBSetup *XCBGetSetup(XCBConnection *c);
351 * @brief Access the file descriptor of the connection.
352 * @param c: The connection.
353 * @return The file descriptor.
355 * Accessor for the file descriptor that was passed to the
356 * XCBConnectToFD call that returned @p c.
358 int XCBGetFileDescriptor(XCBConnection *c);
361 * @brief Connects to the X server.
362 * @param fd: The file descriptor.
363 * @param auth_info: Authentication data.
364 * @return A newly allocated XCBConnection structure.
366 * Connects to an X server, given the open socket @p fd and the
367 * XCBAuthInfo @p auth_info. The file descriptor @p fd is
368 * bidirectionally connected to an X server. XCBGetTCPFD and
369 * XCBGetUnixFD return appropriate file descriptors. If the connection
370 * should be unauthenticated, @p auth_info must be @c
371 * NULL. XCBGetAuthInfo returns appropriate authentication data.
373 XCBConnection *XCBConnectToFD(int fd, XCBAuthInfo *auth_info);
376 * @brief Closes the connection.
377 * @param c: The connection.
379 * Closes the file descriptor and frees all memory associated with the
382 void XCBDisconnect(XCBConnection *c);
388 * @brief Parses a display string name in the form documented by X(7x).
389 * @param displayname: The name of the display.
390 * @param hostp: A pointer to a malloc'd copy of the hostname.
391 * @param displayp: A pointer to the display number.
392 * @param screenp: A pointer to the screen number.
393 * @return 0 on failure, non 0 otherwise.
395 * Parses the display string name @p display_name in the form
396 * documented by X(7x). Has no side effects on failure. If
397 * @p displayname is @c NULL or empty, it uses the environment
398 * variable DISPLAY. @p hostp is a pointer to a newly allocated string
399 * that contain the host name. @p displayp is set to the display
400 * number and @p screenp to the preferred screen number. @p screenp
401 * can be @c NULL. If @p displayname does not contain a screen number,
404 int XCBParseDisplay(const char *name, char **host, int *display, int *screen);
407 * @brief Open a connection to the X server.
408 * @param host: The host name.
409 * @param display: The display number.
410 * @return The file descriptor.
412 * @deprecated This function is deprecated. It must not be used in
413 * newly written code.
415 int XCBOpen(const char *host, int display) deprecated;
418 * @brief Open a connection to the X server.
419 * @param host: The host name.
420 * @param port: The TCP port.
421 * @return The file descriptor.
423 * @deprecated This function is deprecated. It must not be used in
424 * newly written code.
426 int XCBOpenTCP(const char *host, unsigned short port) deprecated;
429 * @brief Connects to the X server.
430 * @param file: The file name.
431 * @return The file descriptor.
433 * @deprecated This function is deprecated. It must not be used in
434 * newly written code.
436 int XCBOpenUnix(const char *file) deprecated;
439 * @brief Connects to the X server.
440 * @return A newly allocated XCBConnection structure.
442 * @deprecated This function is deprecated. It must not be used in
443 * newly written code.
445 XCBConnection *XCBConnectBasic(void) deprecated;
448 * @brief Connects to the X server.
449 * @param displayname: The name of the display.
450 * @param screenp: A pointer to a preferred screen number.
451 * @return A newly allocated XCBConnection structure.
453 * Connects to the X server specified by @p displayname. If @p
454 * displayname is @c NULL, uses the value of the DISPLAY environment
455 * variable. If a particular screen on that server is preferred, the
456 * int pointed to by @p screenp (if not @c NULL) will be set to that
457 * screen; otherwise the screen will be set to 0.
459 XCBConnection *XCBConnect(const char *displayname, int *screenp);
462 * @brief Connects to the X server, using an authorization information.
463 * @param displayname: The name of the display.
464 * @param auth: The authorization information.
465 * @param screenp: A pointer to a preferred screen number.
466 * @return A newly allocated XCBConnection structure.
468 * Connects to the X server specified by @p displayname, using the
469 * authorization @p auth. If a particular screen on that server is
470 * preferred, the int pointed to by @p screenp (if not @c NULL) will
471 * be set to that screen; otherwise @p screenp will be set to 0.
473 XCBConnection *XCBConnectToDisplayWithAuthInfo(const char *display, XCBAuthInfo *auth, int *screen);
476 * @brief Ensures that all events and errors are avalaible in XCB.
477 * @param c: The connection to the X server.
478 * @param e: A pointer to an error.
479 * @return @c 1 on success, @c 0 otherwise.
481 * @deprecated This function is deprecated. It must not be used in
482 * newly written code. XCBFlush is more efficient.
483 * Use XCBAuxSync if absolutely necessary.
485 int XCBSync(XCBConnection *c, XCBGenericError **e) deprecated;
493 /* Old names for connection-setup types, to be removed before 1.0. */
495 typedef XCBSetupReq XCBConnSetupReq deprecated;
496 typedef XCBSetupReqIter XCBConnSetupReqIter deprecated;
497 typedef XCBSetupFailed XCBConnSetupFailedRep deprecated;
498 typedef XCBSetupFailedIter XCBConnSetupFailedRepIter deprecated;
499 typedef XCBSetupAuthenticate XCBConnSetupAuthenticateRep deprecated;
500 typedef XCBSetupAuthenticateIter XCBConnSetupAuthenticateRepIter deprecated;
501 typedef XCBSetup XCBConnSetupSuccessRep deprecated;
502 typedef XCBSetupIter XCBConnSetupSuccessRepIter deprecated;
504 char *XCBConnSetupReqAuthorizationProtocolName(XCBSetupReq *R) deprecated;
505 int XCBConnSetupReqAuthorizationProtocolNameLength(XCBSetupReq *R) deprecated;
506 XCBGenericIter XCBConnSetupReqAuthorizationProtocolNameEnd(XCBSetupReq *R) deprecated;
507 char *XCBConnSetupReqAuthorizationProtocolData(XCBSetupReq *R) deprecated;
508 int XCBConnSetupReqAuthorizationProtocolDataLength(XCBSetupReq *R) deprecated;
509 XCBGenericIter XCBConnSetupReqAuthorizationProtocolDataEnd(XCBSetupReq *R) deprecated;
510 void XCBConnSetupReqNext(XCBSetupReqIter *i) deprecated;
511 XCBGenericIter XCBConnSetupReqEnd(XCBSetupReqIter i) deprecated;
512 char *XCBConnSetupFailedRepReason(XCBSetupFailed *R) deprecated;
513 int XCBConnSetupFailedRepReasonLength(XCBSetupFailed *R) deprecated;
514 XCBGenericIter XCBConnSetupFailedRepReasonEnd(XCBSetupFailed *R) deprecated;
515 void XCBConnSetupFailedRepNext(XCBSetupFailedIter *i) deprecated;
516 XCBGenericIter XCBConnSetupFailedRepEnd(XCBSetupFailedIter i) deprecated;
517 char *XCBConnSetupAuthenticateRepReason(XCBSetupAuthenticate *R) deprecated;
518 int XCBConnSetupAuthenticateRepReasonLength(XCBSetupAuthenticate *R) deprecated;
519 XCBGenericIter XCBConnSetupAuthenticateRepReasonEnd(XCBSetupAuthenticate *R) deprecated;
520 void XCBConnSetupAuthenticateRepNext(XCBSetupAuthenticateIter *i) deprecated;
521 XCBGenericIter XCBConnSetupAuthenticateRepEnd(XCBSetupAuthenticateIter i) deprecated;
522 char *XCBConnSetupSuccessRepVendor(XCBSetup *R) deprecated;
523 int XCBConnSetupSuccessRepVendorLength(XCBSetup *R) deprecated;
524 XCBGenericIter XCBConnSetupSuccessRepVendorEnd(XCBSetup *R) deprecated;
525 XCBFORMAT *XCBConnSetupSuccessRepPixmapFormats(XCBSetup *R) deprecated;
526 int XCBConnSetupSuccessRepPixmapFormatsLength(XCBSetup *R) deprecated;
527 XCBFORMATIter XCBConnSetupSuccessRepPixmapFormatsIter(XCBSetup *R) deprecated;
528 int XCBConnSetupSuccessRepRootsLength(XCBSetup *R) deprecated;
529 XCBSCREENIter XCBConnSetupSuccessRepRootsIter(XCBSetup *R) deprecated;
530 void XCBConnSetupSuccessRepNext(XCBSetupIter *i) deprecated;
531 XCBGenericIter XCBConnSetupSuccessRepEnd(XCBSetupIter i) deprecated;
539 #endif /* __XCB_H__ */