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. */
42 typedef uint8_t CARD8;
43 typedef uint16_t CARD16;
44 typedef uint32_t CARD32;
46 typedef int16_t INT16;
47 typedef int32_t INT32;
59 #if (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 1))
60 #define deprecated __attribute__((__deprecated__))
71 * @defgroup XCB_Core_Api XCB Core API
72 * @brief Core API of the XCB library.
77 /* Pre-defined constants */
79 /** Current protocol version */
82 /** Current minor version */
83 #define X_PROTOCOL_REVISION 0
85 /** X_TCP_PORT + display number = server port for TCP transport */
86 #define X_TCP_PORT 6000
88 #define XCB_TYPE_PAD(T,I) (-(I) & (sizeof(T) > 4 ? 3 : sizeof(T) - 1))
90 /* Opaque structures */
93 * @brief XCB Connection structure.
95 * A structure that contain all data that XCB needs to communicate with an X server.
97 typedef struct XCBConnection XCBConnection; /**< Opaque structure containing all data that XCB needs to communicate with an X server. */
103 * @brief Generic iterator.
105 * A generic iterator structure.
108 void *data; /**< Data of the current iterator */
109 int rem; /**< remaining elements */
110 int index; /**< index of the current iterator */
114 * @brief Generic reply.
116 * A generic reply structure.
119 BYTE response_type; /**< Type of the response */
120 CARD8 pad0; /**< Padding */
121 CARD16 sequence; /**< Sequence number */
122 CARD32 length; /**< Length of the response */
126 * @brief Generic event.
128 * A generic event structure.
131 BYTE response_type; /**< Type of the response */
132 CARD8 pad0; /**< Padding */
133 CARD16 sequence; /**< Sequence number */
134 CARD32 pad[7]; /**< Padding */
135 CARD32 full_sequence;
139 * @brief Generic error.
141 * A generic error structure.
144 BYTE response_type; /**< Type of the response */
145 BYTE error_code; /**< Error code */
146 CARD16 sequence; /**< Sequence number */
147 CARD32 pad[7]; /**< Padding */
148 CARD32 full_sequence;
152 * @brief Generic cookie.
154 * A generic cookie structure.
157 unsigned int sequence; /**< Sequence number */
161 /* Include the generated xproto header. */
165 /** XCBNone is the universal null resource or null atom parameter value for many core X requests */
168 /** XCBCopyFromParent can be used for many CreateWindow parameters */
169 #define XCBCopyFromParent 0L
171 /** XCBCurrentTime can be used in most requests that take an XCBTIMESTAMP */
172 #define XCBCurrentTime 0L
174 /** XCBNoSymbol fills in unused entries in XCBKEYSYM tables */
175 #define XCBNoSymbol 0L
181 * @brief Container for authorization information.
183 * A container for authorization information to be sent to the X server.
185 typedef struct XCBAuthInfo {
186 int namelen; /**< Length of the string name (as returned by strlen). */
187 char *name; /**< String containing the authentication protocol name, such as "MIT-MAGIC-COOKIE-1" or "XDM-AUTHORIZATION-1". */
188 int datalen; /**< Length of the data member. */
189 char *data; /**< Data interpreted in a protocol-specific manner. */
193 * @brief Gets authorization information.
194 * @param fd: The file descriptor.
195 * @param info: The authorisation info to set.
196 * @return @c 0 on failure, 1 otherwise.
198 * @deprecated This function is deprecated. It must not be used in
199 * newly written code.
201 int XCBGetAuthInfo(int fd, XCBAuthInfo *info) deprecated;
207 * @brief Forces any buffered output to be written to the server.
208 * @param c: The connection to the X server.
209 * @return > @c 0 on success, <= @c 0 otherwise.
211 * Forces any buffered output to be written to the server. Blocks
212 * until the write is complete.
214 int XCBFlush(XCBConnection *c);
217 * @brief Returns the maximum request length field from the connection
219 * @param c: The connection to the X server.
220 * @return The maximum request length field.
222 * In the absence of the BIG-REQUESTS extension, returns the
223 * maximum request length field from the connection setup data, which
224 * may be as much as 65535. If the server supports BIG-REQUESTS, then
225 * the maximum request length field from the reply to the
226 * BigRequestsEnable request will be returned instead.
228 * Note that this length is measured in four-byte units, making the
229 * theoretical maximum lengths roughly 256kB without BIG-REQUESTS and
232 CARD32 XCBGetMaximumRequestLength(XCBConnection *c);
238 * @brief Returns the next event or error from the server.
239 * @param c: The connection to the X server.
240 * @return The next event from the server.
242 * @deprecated This function is deprecated. It must not be used in
243 * newly written code.
245 XCBGenericEvent *XCBWaitEvent(XCBConnection *c) deprecated;
248 * @brief Returns the next event or error from the server.
249 * @param c: The connection to the X server.
250 * @return The next event from the server.
252 * Returns the next event or error from the server, or returns null in
253 * the event of an I/O error. Blocks until either an event or error
254 * arrive, or an I/O error occurs.
256 XCBGenericEvent *XCBWaitForEvent(XCBConnection *c);
259 * @brief Returns the next event or error from the server.
260 * @param c: The connection to the X server.
261 * @param error: A pointer to an int to be filled in with the I/O
262 * error status of the operation.
263 * @return The next event from the server.
265 * Returns the next event or error from the server, if one is
266 * available, or returns @c NULL otherwise. If no event is available, that
267 * might be because an I/O error like connection close occurred while
268 * attempting to read the next event. The @p error parameter is a
269 * pointer to an int to be filled in with the I/O error status of the
270 * operation. If @p error is @c NULL, terminates the application when an
273 XCBGenericEvent *XCBPollForEvent(XCBConnection *c, int *error);
276 * @brief Return the error for a request, or NULL if none can ever arrive.
277 * @param c: The connection to the X server.
278 * @param cookie: The request cookie.
279 * @return The error for the request, or NULL if none can ever arrive.
281 * The XCBVoidCookie cookie supplied to this function must have resulted from
282 * a call to XCB[RequestName]Checked(). This function will block until one of
283 * two conditions happens. If an error is received, it will be returned. If
284 * a reply to a subsequent request has already arrived, no error can arrive
285 * for this request, so this function will return NULL.
287 * Note that this function will perform a sync if needed to ensure that the
288 * sequence number will advance beyond that provided in cookie; this is a
289 * convenience to avoid races in determining whether the sync is needed.
291 XCBGenericError *XCBRequestCheck(XCBConnection *c, XCBVoidCookie cookie);
294 * @brief Returns the last sequence number that the server is known to
296 * @param c: The connection to the X server.
297 * @return The last sequence number.
299 * Returns the last sequence number that the server is known to have
300 * processed. This function enables applications to determine whether
301 * forcing a cookie is going to block.
303 * @deprecated This function is deprecated in favor of XCBPollForReply.
304 * It must not be used in newly written code.
306 unsigned int XCBGetRequestRead(XCBConnection *c) deprecated;
312 * @typedef typedef struct XCBExtension XCBExtension
314 typedef struct XCBExtension XCBExtension; /**< Opaque structure used as key for XCBGetExtensionData. */
317 * @brief Caches reply information from QueryExtension requests.
318 * @param c: The connection.
319 * @param ext: The extension data.
320 * @return A pointer to the XCBQueryExtensionRep for the extension.
322 * This function is the primary interface to the "extension cache",
323 * which caches reply information from QueryExtension
324 * requests. Invoking this function may cause a call to
325 * XCBQueryExtension to retrieve extension information from the
326 * server, and may block until extension data is received from the
329 * The result must not be freed. This storage is managed by the cache
332 const XCBQueryExtensionRep *XCBGetExtensionData(XCBConnection *c, XCBExtension *ext);
335 * @brief Prefetch of extension data into the extension cache
336 * @param c: The connection.
337 * @param ext: The extension data.
339 * This function allows a "prefetch" of extension data into the
340 * extension cache. Invoking the function may cause a call to
341 * XCBQueryExtension, but will not block waiting for the
342 * reply. XCBGetExtensionData will return the prefetched data after
343 * possibly blocking while it is retrieved.
345 void XCBPrefetchExtensionData(XCBConnection *c, XCBExtension *ext);
351 * @brief Access the data returned by the server.
352 * @param c: The connection.
353 * @return A pointer to an XCBSetup structure.
355 * Accessor for the data returned by the server when the XCBConnection
356 * was initialized. This data includes
357 * - the server's required format for images,
358 * - a list of available visuals,
359 * - a list of available screens,
360 * - the server's maximum request length (in the absence of the
361 * BIG-REQUESTS extension),
362 * - and other assorted information.
364 * See the X protocol specification for more details.
366 * The result must not be freed.
368 const XCBSetup *XCBGetSetup(XCBConnection *c);
371 * @brief Access the file descriptor of the connection.
372 * @param c: The connection.
373 * @return The file descriptor.
375 * Accessor for the file descriptor that was passed to the
376 * XCBConnectToFD call that returned @p c.
378 int XCBGetFileDescriptor(XCBConnection *c);
381 * @brief Connects to the X server.
382 * @param fd: The file descriptor.
383 * @param auth_info: Authentication data.
384 * @return A newly allocated XCBConnection structure.
386 * Connects to an X server, given the open socket @p fd and the
387 * XCBAuthInfo @p auth_info. The file descriptor @p fd is
388 * bidirectionally connected to an X server. XCBGetTCPFD and
389 * XCBGetUnixFD return appropriate file descriptors. If the connection
390 * should be unauthenticated, @p auth_info must be @c
391 * NULL. XCBGetAuthInfo returns appropriate authentication data.
393 XCBConnection *XCBConnectToFD(int fd, XCBAuthInfo *auth_info);
396 * @brief Closes the connection.
397 * @param c: The connection.
399 * Closes the file descriptor and frees all memory associated with the
402 void XCBDisconnect(XCBConnection *c);
408 * @brief Parses a display string name in the form documented by X(7x).
409 * @param displayname: The name of the display.
410 * @param hostp: A pointer to a malloc'd copy of the hostname.
411 * @param displayp: A pointer to the display number.
412 * @param screenp: A pointer to the screen number.
413 * @return 0 on failure, non 0 otherwise.
415 * Parses the display string name @p display_name in the form
416 * documented by X(7x). Has no side effects on failure. If
417 * @p displayname is @c NULL or empty, it uses the environment
418 * variable DISPLAY. @p hostp is a pointer to a newly allocated string
419 * that contain the host name. @p displayp is set to the display
420 * number and @p screenp to the preferred screen number. @p screenp
421 * can be @c NULL. If @p displayname does not contain a screen number,
424 int XCBParseDisplay(const char *name, char **host, int *display, int *screen);
427 * @brief Open a connection to the X server.
428 * @param host: The host name.
429 * @param display: The display number.
430 * @return The file descriptor.
432 * @deprecated This function is deprecated. It must not be used in
433 * newly written code.
435 int XCBOpen(const char *host, int display) deprecated;
438 * @brief Open a connection to the X server.
439 * @param host: The host name.
440 * @param port: The TCP port.
441 * @return The file descriptor.
443 * @deprecated This function is deprecated. It must not be used in
444 * newly written code.
446 int XCBOpenTCP(const char *host, unsigned short port) deprecated;
449 * @brief Connects to the X server.
450 * @param file: The file name.
451 * @return The file descriptor.
453 * @deprecated This function is deprecated. It must not be used in
454 * newly written code.
456 int XCBOpenUnix(const char *file) deprecated;
459 * @brief Connects to the X server.
460 * @return A newly allocated XCBConnection structure.
462 * @deprecated This function is deprecated. It must not be used in
463 * newly written code.
465 XCBConnection *XCBConnectBasic(void) deprecated;
468 * @brief Connects to the X server.
469 * @param displayname: The name of the display.
470 * @param screenp: A pointer to a preferred screen number.
471 * @return A newly allocated XCBConnection structure.
473 * Connects to the X server specified by @p displayname. If @p
474 * displayname is @c NULL, uses the value of the DISPLAY environment
475 * variable. If a particular screen on that server is preferred, the
476 * int pointed to by @p screenp (if not @c NULL) will be set to that
477 * screen; otherwise the screen will be set to 0.
479 XCBConnection *XCBConnect(const char *displayname, int *screenp);
482 * @brief Connects to the X server, using an authorization information.
483 * @param displayname: The name of the display.
484 * @param auth: The authorization information.
485 * @param screenp: A pointer to a preferred screen number.
486 * @return A newly allocated XCBConnection structure.
488 * Connects to the X server specified by @p displayname, using the
489 * authorization @p auth. If a particular screen on that server is
490 * preferred, the int pointed to by @p screenp (if not @c NULL) will
491 * be set to that screen; otherwise @p screenp will be set to 0.
493 XCBConnection *XCBConnectToDisplayWithAuthInfo(const char *display, XCBAuthInfo *auth, int *screen);
496 * @brief Ensures that all events and errors are avalaible in XCB.
497 * @param c: The connection to the X server.
498 * @param e: A pointer to an error.
499 * @return @c 1 on success, @c 0 otherwise.
501 * @deprecated This function is deprecated. It must not be used in
502 * newly written code. XCBFlush is more efficient.
503 * Use XCBAuxSync if absolutely necessary.
505 int XCBSync(XCBConnection *c, XCBGenericError **e) deprecated;
513 /* Old names for connection-setup types, to be removed before 1.0. */
515 typedef XCBSetupReq XCBConnSetupReq deprecated;
516 typedef XCBSetupReqIter XCBConnSetupReqIter deprecated;
517 typedef XCBSetupFailed XCBConnSetupFailedRep deprecated;
518 typedef XCBSetupFailedIter XCBConnSetupFailedRepIter deprecated;
519 typedef XCBSetupAuthenticate XCBConnSetupAuthenticateRep deprecated;
520 typedef XCBSetupAuthenticateIter XCBConnSetupAuthenticateRepIter deprecated;
521 typedef XCBSetup XCBConnSetupSuccessRep deprecated;
522 typedef XCBSetupIter XCBConnSetupSuccessRepIter deprecated;
524 char *XCBConnSetupReqAuthorizationProtocolName(XCBSetupReq *R) deprecated;
525 int XCBConnSetupReqAuthorizationProtocolNameLength(XCBSetupReq *R) deprecated;
526 XCBGenericIter XCBConnSetupReqAuthorizationProtocolNameEnd(XCBSetupReq *R) deprecated;
527 char *XCBConnSetupReqAuthorizationProtocolData(XCBSetupReq *R) deprecated;
528 int XCBConnSetupReqAuthorizationProtocolDataLength(XCBSetupReq *R) deprecated;
529 XCBGenericIter XCBConnSetupReqAuthorizationProtocolDataEnd(XCBSetupReq *R) deprecated;
530 void XCBConnSetupReqNext(XCBSetupReqIter *i) deprecated;
531 XCBGenericIter XCBConnSetupReqEnd(XCBSetupReqIter i) deprecated;
532 char *XCBConnSetupFailedRepReason(XCBSetupFailed *R) deprecated;
533 int XCBConnSetupFailedRepReasonLength(XCBSetupFailed *R) deprecated;
534 XCBGenericIter XCBConnSetupFailedRepReasonEnd(XCBSetupFailed *R) deprecated;
535 void XCBConnSetupFailedRepNext(XCBSetupFailedIter *i) deprecated;
536 XCBGenericIter XCBConnSetupFailedRepEnd(XCBSetupFailedIter i) deprecated;
537 char *XCBConnSetupAuthenticateRepReason(XCBSetupAuthenticate *R) deprecated;
538 int XCBConnSetupAuthenticateRepReasonLength(XCBSetupAuthenticate *R) deprecated;
539 XCBGenericIter XCBConnSetupAuthenticateRepReasonEnd(XCBSetupAuthenticate *R) deprecated;
540 void XCBConnSetupAuthenticateRepNext(XCBSetupAuthenticateIter *i) deprecated;
541 XCBGenericIter XCBConnSetupAuthenticateRepEnd(XCBSetupAuthenticateIter i) deprecated;
542 char *XCBConnSetupSuccessRepVendor(XCBSetup *R) deprecated;
543 int XCBConnSetupSuccessRepVendorLength(XCBSetup *R) deprecated;
544 XCBGenericIter XCBConnSetupSuccessRepVendorEnd(XCBSetup *R) deprecated;
545 XCBFORMAT *XCBConnSetupSuccessRepPixmapFormats(XCBSetup *R) deprecated;
546 int XCBConnSetupSuccessRepPixmapFormatsLength(XCBSetup *R) deprecated;
547 XCBFORMATIter XCBConnSetupSuccessRepPixmapFormatsIter(XCBSetup *R) deprecated;
548 int XCBConnSetupSuccessRepRootsLength(XCBSetup *R) deprecated;
549 XCBSCREENIter XCBConnSetupSuccessRepRootsIter(XCBSetup *R) deprecated;
550 void XCBConnSetupSuccessRepNext(XCBSetupIter *i) deprecated;
551 XCBGenericIter XCBConnSetupSuccessRepEnd(XCBSetupIter i) deprecated;
559 #endif /* __XCB_H__ */