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 Returns the last sequence number that the server is known to
278 * @param c: The connection to the X server.
279 * @return The last sequence number.
281 * Returns the last sequence number that the server is known to have
282 * processed. This function enables applications to determine whether
283 * forcing a cookie is going to block.
285 * @deprecated This function is deprecated in favor of XCBPollForReply.
286 * It must not be used in newly written code.
288 unsigned int XCBGetRequestRead(XCBConnection *c) deprecated;
294 * @typedef typedef struct XCBExtension XCBExtension
296 typedef struct XCBExtension XCBExtension; /**< Opaque structure used as key for XCBGetExtensionData. */
299 * @brief Caches reply information from QueryExtension requests.
300 * @param c: The connection.
301 * @param ext: The extension data.
302 * @return A pointer to the XCBQueryExtensionRep for the extension.
304 * This function is the primary interface to the "extension cache",
305 * which caches reply information from QueryExtension
306 * requests. Invoking this function may cause a call to
307 * XCBQueryExtension to retrieve extension information from the
308 * server, and may block until extension data is received from the
311 * The result must not be freed. This storage is managed by the cache
314 const XCBQueryExtensionRep *XCBGetExtensionData(XCBConnection *c, XCBExtension *ext);
317 * @brief Prefetch of extension data into the extension cache
318 * @param c: The connection.
319 * @param ext: The extension data.
321 * This function allows a "prefetch" of extension data into the
322 * extension cache. Invoking the function may cause a call to
323 * XCBQueryExtension, but will not block waiting for the
324 * reply. XCBGetExtensionData will return the prefetched data after
325 * possibly blocking while it is retrieved.
327 void XCBPrefetchExtensionData(XCBConnection *c, XCBExtension *ext);
333 * @brief Access the data returned by the server.
334 * @param c: The connection.
335 * @return A pointer to an XCBSetup structure.
337 * Accessor for the data returned by the server when the XCBConnection
338 * was initialized. This data includes
339 * - the server's required format for images,
340 * - a list of available visuals,
341 * - a list of available screens,
342 * - the server's maximum request length (in the absence of the
343 * BIG-REQUESTS extension),
344 * - and other assorted information.
346 * See the X protocol specification for more details.
348 * The result must not be freed.
350 const XCBSetup *XCBGetSetup(XCBConnection *c);
353 * @brief Access the file descriptor of the connection.
354 * @param c: The connection.
355 * @return The file descriptor.
357 * Accessor for the file descriptor that was passed to the
358 * XCBConnectToFD call that returned @p c.
360 int XCBGetFileDescriptor(XCBConnection *c);
363 * @brief Connects to the X server.
364 * @param fd: The file descriptor.
365 * @param auth_info: Authentication data.
366 * @return A newly allocated XCBConnection structure.
368 * Connects to an X server, given the open socket @p fd and the
369 * XCBAuthInfo @p auth_info. The file descriptor @p fd is
370 * bidirectionally connected to an X server. XCBGetTCPFD and
371 * XCBGetUnixFD return appropriate file descriptors. If the connection
372 * should be unauthenticated, @p auth_info must be @c
373 * NULL. XCBGetAuthInfo returns appropriate authentication data.
375 XCBConnection *XCBConnectToFD(int fd, XCBAuthInfo *auth_info);
378 * @brief Closes the connection.
379 * @param c: The connection.
381 * Closes the file descriptor and frees all memory associated with the
384 void XCBDisconnect(XCBConnection *c);
390 * @brief Parses a display string name in the form documented by X(7x).
391 * @param displayname: The name of the display.
392 * @param hostp: A pointer to a malloc'd copy of the hostname.
393 * @param displayp: A pointer to the display number.
394 * @param screenp: A pointer to the screen number.
395 * @return 0 on failure, non 0 otherwise.
397 * Parses the display string name @p display_name in the form
398 * documented by X(7x). Has no side effects on failure. If
399 * @p displayname is @c NULL or empty, it uses the environment
400 * variable DISPLAY. @p hostp is a pointer to a newly allocated string
401 * that contain the host name. @p displayp is set to the display
402 * number and @p screenp to the preferred screen number. @p screenp
403 * can be @c NULL. If @p displayname does not contain a screen number,
406 int XCBParseDisplay(const char *name, char **host, int *display, int *screen);
409 * @brief Open a connection to the X server.
410 * @param host: The host name.
411 * @param display: The display number.
412 * @return The file descriptor.
414 * @deprecated This function is deprecated. It must not be used in
415 * newly written code.
417 int XCBOpen(const char *host, int display) deprecated;
420 * @brief Open a connection to the X server.
421 * @param host: The host name.
422 * @param port: The TCP port.
423 * @return The file descriptor.
425 * @deprecated This function is deprecated. It must not be used in
426 * newly written code.
428 int XCBOpenTCP(const char *host, unsigned short port) deprecated;
431 * @brief Connects to the X server.
432 * @param file: The file name.
433 * @return The file descriptor.
435 * @deprecated This function is deprecated. It must not be used in
436 * newly written code.
438 int XCBOpenUnix(const char *file) deprecated;
441 * @brief Connects to the X server.
442 * @return A newly allocated XCBConnection structure.
444 * @deprecated This function is deprecated. It must not be used in
445 * newly written code.
447 XCBConnection *XCBConnectBasic(void) deprecated;
450 * @brief Connects to the X server.
451 * @param displayname: The name of the display.
452 * @param screenp: A pointer to a preferred screen number.
453 * @return A newly allocated XCBConnection structure.
455 * Connects to the X server specified by @p displayname. If @p
456 * displayname is @c NULL, uses the value of the DISPLAY environment
457 * variable. If a particular screen on that server is preferred, the
458 * int pointed to by @p screenp (if not @c NULL) will be set to that
459 * screen; otherwise the screen will be set to 0.
461 XCBConnection *XCBConnect(const char *displayname, int *screenp);
464 * @brief Connects to the X server, using an authorization information.
465 * @param displayname: The name of the display.
466 * @param auth: The authorization information.
467 * @param screenp: A pointer to a preferred screen number.
468 * @return A newly allocated XCBConnection structure.
470 * Connects to the X server specified by @p displayname, using the
471 * authorization @p auth. If a particular screen on that server is
472 * preferred, the int pointed to by @p screenp (if not @c NULL) will
473 * be set to that screen; otherwise @p screenp will be set to 0.
475 XCBConnection *XCBConnectToDisplayWithAuthInfo(const char *display, XCBAuthInfo *auth, int *screen);
478 * @brief Ensures that all events and errors are avalaible in XCB.
479 * @param c: The connection to the X server.
480 * @param e: A pointer to an error.
481 * @return @c 1 on success, @c 0 otherwise.
483 * @deprecated This function is deprecated. It must not be used in
484 * newly written code. XCBFlush is more efficient.
485 * Use XCBAuxSync if absolutely necessary.
487 int XCBSync(XCBConnection *c, XCBGenericError **e) deprecated;
495 /* Old names for connection-setup types, to be removed before 1.0. */
497 typedef XCBSetupReq XCBConnSetupReq deprecated;
498 typedef XCBSetupReqIter XCBConnSetupReqIter deprecated;
499 typedef XCBSetupFailed XCBConnSetupFailedRep deprecated;
500 typedef XCBSetupFailedIter XCBConnSetupFailedRepIter deprecated;
501 typedef XCBSetupAuthenticate XCBConnSetupAuthenticateRep deprecated;
502 typedef XCBSetupAuthenticateIter XCBConnSetupAuthenticateRepIter deprecated;
503 typedef XCBSetup XCBConnSetupSuccessRep deprecated;
504 typedef XCBSetupIter XCBConnSetupSuccessRepIter deprecated;
506 char *XCBConnSetupReqAuthorizationProtocolName(XCBSetupReq *R) deprecated;
507 int XCBConnSetupReqAuthorizationProtocolNameLength(XCBSetupReq *R) deprecated;
508 XCBGenericIter XCBConnSetupReqAuthorizationProtocolNameEnd(XCBSetupReq *R) deprecated;
509 char *XCBConnSetupReqAuthorizationProtocolData(XCBSetupReq *R) deprecated;
510 int XCBConnSetupReqAuthorizationProtocolDataLength(XCBSetupReq *R) deprecated;
511 XCBGenericIter XCBConnSetupReqAuthorizationProtocolDataEnd(XCBSetupReq *R) deprecated;
512 void XCBConnSetupReqNext(XCBSetupReqIter *i) deprecated;
513 XCBGenericIter XCBConnSetupReqEnd(XCBSetupReqIter i) deprecated;
514 char *XCBConnSetupFailedRepReason(XCBSetupFailed *R) deprecated;
515 int XCBConnSetupFailedRepReasonLength(XCBSetupFailed *R) deprecated;
516 XCBGenericIter XCBConnSetupFailedRepReasonEnd(XCBSetupFailed *R) deprecated;
517 void XCBConnSetupFailedRepNext(XCBSetupFailedIter *i) deprecated;
518 XCBGenericIter XCBConnSetupFailedRepEnd(XCBSetupFailedIter i) deprecated;
519 char *XCBConnSetupAuthenticateRepReason(XCBSetupAuthenticate *R) deprecated;
520 int XCBConnSetupAuthenticateRepReasonLength(XCBSetupAuthenticate *R) deprecated;
521 XCBGenericIter XCBConnSetupAuthenticateRepReasonEnd(XCBSetupAuthenticate *R) deprecated;
522 void XCBConnSetupAuthenticateRepNext(XCBSetupAuthenticateIter *i) deprecated;
523 XCBGenericIter XCBConnSetupAuthenticateRepEnd(XCBSetupAuthenticateIter i) deprecated;
524 char *XCBConnSetupSuccessRepVendor(XCBSetup *R) deprecated;
525 int XCBConnSetupSuccessRepVendorLength(XCBSetup *R) deprecated;
526 XCBGenericIter XCBConnSetupSuccessRepVendorEnd(XCBSetup *R) deprecated;
527 XCBFORMAT *XCBConnSetupSuccessRepPixmapFormats(XCBSetup *R) deprecated;
528 int XCBConnSetupSuccessRepPixmapFormatsLength(XCBSetup *R) deprecated;
529 XCBFORMATIter XCBConnSetupSuccessRepPixmapFormatsIter(XCBSetup *R) deprecated;
530 int XCBConnSetupSuccessRepRootsLength(XCBSetup *R) deprecated;
531 XCBSCREENIter XCBConnSetupSuccessRepRootsIter(XCBSetup *R) deprecated;
532 void XCBConnSetupSuccessRepNext(XCBSetupIter *i) deprecated;
533 XCBGenericIter XCBConnSetupSuccessRepEnd(XCBSetupIter i) deprecated;
541 #endif /* __XCB_H__ */