Finally remove X.h from xcb.h, fix broken image tests.
[free-sw/xcb/libxcb] / src / xcb.h
1 /*
2  * Copyright (C) 2001-2006 Bart Massey, Jamey Sharp, and Josh Triplett.
3  * All Rights Reserved.
4  *
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:
11  *
12  * The above copyright notice and this permission notice shall be included in
13  * all copies or substantial portions of the Software.
14  *
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.
21  *
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.
26  */
27
28 #ifndef __XCB_H__
29 #define __XCB_H__
30 #include <sys/types.h>
31
32 /* TODO: check for stdint in config? (HAVE_STDINT) fallback? */
33 #include <stdint.h>
34
35 /* FIXME: these names conflict with those defined in Xmd.h. */
36 #ifndef XMD_H
37 typedef uint8_t  BYTE;
38 typedef uint8_t  BOOL;
39 typedef uint8_t  CARD8;
40 typedef uint16_t CARD16;
41 typedef uint32_t CARD32;
42 typedef int8_t   INT8;
43 typedef int16_t  INT16;
44 typedef int32_t  INT32;
45 #endif /* XMD_H */
46
47 #include <sys/uio.h>
48 #include <pthread.h>
49
50
51 #ifdef __cplusplus
52 extern "C" {
53 #endif
54
55
56 #if (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 1))
57 #define deprecated __attribute__((__deprecated__))
58 #else
59 #define deprecated
60 #endif
61
62
63 /**
64  * @file xcb.h
65  */
66
67 /**
68  * @defgroup XCB_Core_Api XCB Core API
69  * @brief Core API of the XCB library.
70  *
71  * @{
72  */
73
74 /* Pre-defined constants */
75
76 /** Current protocol version */
77 #define X_PROTOCOL 11
78
79 /** Current minor version */
80 #define X_PROTOCOL_REVISION 0
81
82 /** X_TCP_PORT + display number = server port for TCP transport */
83 #define X_TCP_PORT 6000
84
85 #define XCB_TYPE_PAD(T,I) (-(I) & (sizeof(T) > 4 ? 3 : sizeof(T) - 1))
86
87 /* Opaque structures */
88
89 /**
90  * @brief XCB Connection structure.
91  *
92  * A structure that contain all data that  XCB needs to communicate with an X server.
93  */
94 typedef struct XCBConnection XCBConnection;  /**< Opaque structure containing all data that  XCB needs to communicate with an X server. */
95
96
97 /* Other types */
98
99 /**
100  * @brief Generic iterator.
101  *
102  * A generic iterator structure.
103  */
104 typedef struct {
105     void *data;   /**< Data of the current iterator */
106     int rem;    /**< remaining elements */
107     int index;  /**< index of the current iterator */
108 } XCBGenericIter;
109
110 /**
111  * @brief Generic reply.
112  *
113  * A generic reply structure.
114  */
115 typedef struct {
116     BYTE   response_type;  /**< Type of the response */
117     CARD8  pad0;           /**< Padding */
118     CARD16 sequence;       /**< Sequence number */
119     CARD32 length;         /**< Length of the response */
120 } XCBGenericRep;
121
122 /**
123  * @brief Generic event.
124  *
125  * A generic event structure.
126  */
127 typedef struct {
128     BYTE   response_type;  /**< Type of the response */
129     CARD8  pad0;           /**< Padding */
130     CARD16 sequence;       /**< Sequence number */
131     CARD32 pad[7];         /**< Padding */
132     CARD32 full_sequence;
133 } XCBGenericEvent;
134
135 /**
136  * @brief Generic error.
137  *
138  * A generic error structure.
139  */
140 typedef struct {
141     BYTE   response_type;  /**< Type of the response */
142     BYTE   error_code;     /**< Error code */
143     CARD16 sequence;       /**< Sequence number */
144     CARD32 pad[7];         /**< Padding */
145     CARD32 full_sequence;
146 } XCBGenericError;
147
148 /**
149  * @brief Generic cookie.
150  *
151  * A generic cookie structure.
152  */
153 typedef struct {
154     unsigned int sequence;  /**< Sequence number */
155 } XCBVoidCookie;
156
157
158 /* Include the generated xproto header. */
159 #include "xproto.h"
160
161
162 /** XCBNone is the universal null resource or null atom parameter value for many core X requests */
163 #define XCBNone 0L
164
165 /** XCBCopyFromParent can be used for many CreateWindow parameters */
166 #define XCBCopyFromParent 0L
167
168 /** XCBCurrentTime can be used in most requests that take an XCBTIMESTAMP */
169 #define XCBCurrentTime 0L
170
171 /** XCBNoSymbol fills in unused entries in XCBKEYSYM tables */
172 #define XCBNoSymbol 0L
173
174
175 /* xcb_auth.c */
176
177 /**
178  * @brief Container for authorization information.
179  *
180  * A container for authorization information to be sent to the X server.
181  */
182 typedef struct XCBAuthInfo {
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. */
187 } XCBAuthInfo;
188
189 /**
190  * @brief Gets authorization information.
191  * @param fd: The file descriptor.
192  * @param info: The authorisation info to set.
193  * @return @c 0 on failure, 1 otherwise.
194  *
195  * @deprecated This function is deprecated. It must not be used in
196  * newly written code.
197  */
198 int XCBGetAuthInfo(int fd, XCBAuthInfo *info) deprecated;
199
200
201 /* xcb_out.c */
202
203 /**
204  * @brief Forces any buffered output to be written to the server.
205  * @param c: The connection to the X server.
206  * @return > @c 0 on success, <= @c 0 otherwise.
207  *
208  * Forces any buffered output to be written to the server. Blocks
209  * until the write is complete.
210  */
211 int XCBFlush(XCBConnection *c);
212
213 /**
214  * @brief Returns the maximum request length field from the connection
215  * setup data.
216  * @param c: The connection to the X server.
217  * @return The maximum request length field.
218  *
219  * In the absence of the BIG-REQUESTS extension, returns the
220  * maximum request length field from the connection setup data, which
221  * may be as much as 65535. If the server supports BIG-REQUESTS, then
222  * the maximum request length field from the reply to the
223  * BigRequestsEnable request will be returned instead.
224  *
225  * Note that this length is measured in four-byte units, making the
226  * theoretical maximum lengths roughly 256kB without BIG-REQUESTS and
227  * 16GB with.
228  */
229 CARD32 XCBGetMaximumRequestLength(XCBConnection *c);
230
231
232 /* xcb_in.c */
233
234 /**
235  * @brief Returns the next event or error from the server.
236  * @param c: The connection to the X server.
237  * @return The next event from the server.
238  *
239  * @deprecated This function is deprecated. It must not be used in
240  * newly written code.
241  */
242 XCBGenericEvent *XCBWaitEvent(XCBConnection *c) deprecated;
243
244 /**
245  * @brief Returns the next event or error from the server.
246  * @param c: The connection to the X server.
247  * @return The next event from the server.
248  *
249  * Returns the next event or error from the server, or returns null in
250  * the event of an I/O error. Blocks until either an event or error
251  * arrive, or an I/O error occurs.
252  */
253 XCBGenericEvent *XCBWaitForEvent(XCBConnection *c);
254
255 /**
256  * @brief Returns the next event or error from the server.
257  * @param c: The connection to the X server.
258  * @param error: A pointer to an int to be filled in with the I/O
259  * error status of the operation.
260  * @return The next event from the server.
261  *
262  * Returns the next event or error from the server, if one is
263  * available, or returns @c NULL otherwise. If no event is available, that
264  * might be because an I/O error like connection close occurred while
265  * attempting to read the next event. The @p error parameter is a
266  * pointer to an int to be filled in with the I/O error status of the
267  * operation. If @p error is @c NULL, terminates the application when an
268  * I/O error occurs.
269  */
270 XCBGenericEvent *XCBPollForEvent(XCBConnection *c, int *error);
271
272 /**
273  * @brief Returns the last sequence number that the server is known to
274  * have processed.
275  * @param c: The connection to the X server.
276  * @return The last sequence number.
277  *
278  * Returns the last sequence number that the server is known to have
279  * processed. This function enables applications to determine whether
280  * forcing a cookie is going to block.
281  *
282  * @deprecated This function is deprecated in favor of XCBPollForReply.
283  * It must not be used in newly written code.
284  */
285 unsigned int XCBGetRequestRead(XCBConnection *c) deprecated;
286
287
288 /* xcb_ext.c */
289
290 /**
291  * @typedef typedef struct XCBExtension XCBExtension
292  */
293 typedef struct XCBExtension XCBExtension;  /**< Opaque structure used as key for XCBGetExtensionData. */
294
295 /**
296  * @brief Caches reply information from QueryExtension requests.
297  * @param c: The connection.
298  * @param ext: The extension data.
299  * @return A pointer to the XCBQueryExtensionRep for the extension.
300  *
301  * This function is the primary interface to the "extension cache",
302  * which caches reply information from QueryExtension
303  * requests. Invoking this function may cause a call to
304  * XCBQueryExtension to retrieve extension information from the
305  * server, and may block until extension data is received from the
306  * server.
307  *
308  * The result must not be freed. This storage is managed by the cache
309  * itself.
310  */
311 const XCBQueryExtensionRep *XCBGetExtensionData(XCBConnection *c, XCBExtension *ext);
312
313 /**
314  * @brief Prefetch of extension data into the extension cache
315  * @param c: The connection.
316  * @param ext: The extension data.
317  *
318  * This function allows a "prefetch" of extension data into the
319  * extension cache. Invoking the function may cause a call to
320  * XCBQueryExtension, but will not block waiting for the
321  * reply. XCBGetExtensionData will return the prefetched data after
322  * possibly blocking while it is retrieved.
323  */
324 void XCBPrefetchExtensionData(XCBConnection *c, XCBExtension *ext);
325
326
327 /* xcb_conn.c */
328
329 /**
330  * @brief Access the data returned by the server.
331  * @param c: The connection.
332  * @return A pointer to an XCBSetup structure.
333  *
334  * Accessor for the data returned by the server when the XCBConnection
335  * was initialized. This data includes
336  * - the server's required format for images,
337  * - a list of available visuals,
338  * - a list of available screens,
339  * - the server's maximum request length (in the absence of the
340  * BIG-REQUESTS extension),
341  * - and other assorted information.
342  *
343  * See the X protocol specification for more details.
344  *
345  * The result must not be freed.
346  */
347 const XCBSetup *XCBGetSetup(XCBConnection *c);
348
349 /**
350  * @brief Access the file descriptor of the connection.
351  * @param c: The connection.
352  * @return The file descriptor.
353  *
354  * Accessor for the file descriptor that was passed to the
355  * XCBConnectToFD call that returned @p c.
356  */
357 int XCBGetFileDescriptor(XCBConnection *c);
358
359 /**
360  * @brief Connects to the X server.
361  * @param fd: The file descriptor.
362  * @param auth_info: Authentication data.
363  * @return A newly allocated XCBConnection structure.
364  *
365  * Connects to an X server, given the open socket @p fd and the
366  * XCBAuthInfo @p auth_info. The file descriptor @p fd is
367  * bidirectionally connected to an X server. XCBGetTCPFD and
368  * XCBGetUnixFD return appropriate file descriptors. If the connection
369  * should be unauthenticated, @p auth_info must be @c
370  * NULL. XCBGetAuthInfo returns appropriate authentication data.
371  */
372 XCBConnection *XCBConnectToFD(int fd, XCBAuthInfo *auth_info);
373
374 /**
375  * @brief Closes the connection.
376  * @param c: The connection.
377  *
378  * Closes the file descriptor and frees all memory associated with the
379  * connection @c c.
380  */
381 void XCBDisconnect(XCBConnection *c);
382
383
384 /* xcb_util.c */
385
386 /**
387  * @brief Parses a display string name in the form documented by X(7x).
388  * @param displayname: The name of the display.
389  * @param hostp: A pointer to a malloc'd copy of the hostname.
390  * @param displayp: A pointer to the display number.
391  * @param screenp: A pointer to the screen number.
392  * @return 0 on failure, non 0 otherwise.
393  *
394  * Parses the display string name @p display_name in the form
395  * documented by X(7x). Has no side effects on failure. If
396  * @p displayname is @c NULL or empty, it uses the environment
397  * variable DISPLAY. @p hostp is a pointer to a newly allocated string
398  * that contain the host name. @p displayp is set to the display
399  * number and @p screenp to the preferred screen number. @p screenp
400  * can be @c NULL. If @p displayname does not contain a screen number,
401  * it is set to @c 0.
402  */
403 int XCBParseDisplay(const char *name, char **host, int *display, int *screen);
404
405 /**
406  * @brief Open a connection to the X server.
407  * @param host: The host name.
408  * @param display: The display number.
409  * @return The file descriptor.
410  *
411  * @deprecated This function is deprecated. It must not be used in
412  * newly written code.
413  */
414 int XCBOpen(const char *host, int display) deprecated;
415
416 /**
417  * @brief Open a connection to the X server.
418  * @param host: The host name.
419  * @param port: The TCP port.
420  * @return The file descriptor.
421  *
422  * @deprecated This function is deprecated. It must not be used in
423  * newly written code.
424  */
425 int XCBOpenTCP(const char *host, unsigned short port) deprecated;
426
427 /**
428  * @brief Connects to the X server.
429  * @param file: The file name.
430  * @return The file descriptor.
431  *
432  * @deprecated This function is deprecated. It must not be used in
433  * newly written code.
434  */
435 int XCBOpenUnix(const char *file) deprecated;
436
437 /**
438  * @brief Connects to the X server.
439  * @return A newly allocated XCBConnection structure.
440  *
441  * @deprecated This function is deprecated. It must not be used in
442  * newly written code.
443  */
444 XCBConnection *XCBConnectBasic(void) deprecated;
445
446 /**
447  * @brief Connects to the X server.
448  * @param displayname: The name of the display.
449  * @param screenp: A pointer to a preferred screen number.
450  * @return A newly allocated XCBConnection structure.
451  *
452  * Connects to the X server specified by @p displayname. If @p
453  * displayname is @c NULL, uses the value of the DISPLAY environment
454  * variable. If a particular screen on that server is preferred, the
455  * int pointed to by @p screenp (if not @c NULL) will be set to that
456  * screen; otherwise the screen will be set to 0.
457  */
458 XCBConnection *XCBConnect(const char *displayname, int *screenp);
459
460 /**
461  * @brief Connects to the X server, using an authorization information.
462  * @param displayname: The name of the display.
463  * @param auth: The authorization information.
464  * @param screenp: A pointer to a preferred screen number.
465  * @return A newly allocated XCBConnection structure.
466  *
467  * Connects to the X server specified by @p displayname, using the
468  * authorization @p auth. If a particular screen on that server is
469  * preferred, the int pointed to by @p screenp (if not @c NULL) will
470  * be set to that screen; otherwise @p screenp will be set to 0.
471  */
472 XCBConnection *XCBConnectToDisplayWithAuthInfo(const char *display, XCBAuthInfo *auth, int *screen);
473
474 /**
475  * @brief Ensures that all events and errors are avalaible in XCB.
476  * @param c: The connection to the X server.
477  * @param e: A pointer to an error.
478  * @return @c 1 on success, @c 0 otherwise.
479  *
480  * @deprecated This function is deprecated. It must not be used in
481  * newly written code.  XCBFlush is more efficient.
482  * Use XCBAuxSync if absolutely necessary.
483  */
484 int XCBSync(XCBConnection *c, XCBGenericError **e) deprecated;
485
486
487 /**
488  * @}
489  */
490
491
492 /* Old names for connection-setup types, to be removed before 1.0. */
493
494 typedef XCBSetupReq XCBConnSetupReq deprecated;
495 typedef XCBSetupReqIter XCBConnSetupReqIter deprecated;
496 typedef XCBSetupFailed XCBConnSetupFailedRep deprecated;
497 typedef XCBSetupFailedIter XCBConnSetupFailedRepIter deprecated;
498 typedef XCBSetupAuthenticate XCBConnSetupAuthenticateRep deprecated;
499 typedef XCBSetupAuthenticateIter XCBConnSetupAuthenticateRepIter deprecated;
500 typedef XCBSetup XCBConnSetupSuccessRep deprecated;
501 typedef XCBSetupIter XCBConnSetupSuccessRepIter deprecated;
502
503 char *XCBConnSetupReqAuthorizationProtocolName(XCBSetupReq *R) deprecated;
504 int XCBConnSetupReqAuthorizationProtocolNameLength(XCBSetupReq *R) deprecated;
505 XCBGenericIter XCBConnSetupReqAuthorizationProtocolNameEnd(XCBSetupReq *R) deprecated;
506 char *XCBConnSetupReqAuthorizationProtocolData(XCBSetupReq *R) deprecated;
507 int XCBConnSetupReqAuthorizationProtocolDataLength(XCBSetupReq *R) deprecated;
508 XCBGenericIter XCBConnSetupReqAuthorizationProtocolDataEnd(XCBSetupReq *R) deprecated;
509 void XCBConnSetupReqNext(XCBSetupReqIter *i) deprecated;
510 XCBGenericIter XCBConnSetupReqEnd(XCBSetupReqIter i) deprecated;
511 char *XCBConnSetupFailedRepReason(XCBSetupFailed *R) deprecated;
512 int XCBConnSetupFailedRepReasonLength(XCBSetupFailed *R) deprecated;
513 XCBGenericIter XCBConnSetupFailedRepReasonEnd(XCBSetupFailed *R) deprecated;
514 void XCBConnSetupFailedRepNext(XCBSetupFailedIter *i) deprecated;
515 XCBGenericIter XCBConnSetupFailedRepEnd(XCBSetupFailedIter i) deprecated;
516 char *XCBConnSetupAuthenticateRepReason(XCBSetupAuthenticate *R) deprecated;
517 int XCBConnSetupAuthenticateRepReasonLength(XCBSetupAuthenticate *R) deprecated;
518 XCBGenericIter XCBConnSetupAuthenticateRepReasonEnd(XCBSetupAuthenticate *R) deprecated;
519 void XCBConnSetupAuthenticateRepNext(XCBSetupAuthenticateIter *i) deprecated;
520 XCBGenericIter XCBConnSetupAuthenticateRepEnd(XCBSetupAuthenticateIter i) deprecated;
521 char *XCBConnSetupSuccessRepVendor(XCBSetup *R) deprecated;
522 int XCBConnSetupSuccessRepVendorLength(XCBSetup *R) deprecated;
523 XCBGenericIter XCBConnSetupSuccessRepVendorEnd(XCBSetup *R) deprecated;
524 XCBFORMAT *XCBConnSetupSuccessRepPixmapFormats(XCBSetup *R) deprecated;
525 int XCBConnSetupSuccessRepPixmapFormatsLength(XCBSetup *R) deprecated;
526 XCBFORMATIter XCBConnSetupSuccessRepPixmapFormatsIter(XCBSetup *R) deprecated;
527 int XCBConnSetupSuccessRepRootsLength(XCBSetup *R) deprecated;
528 XCBSCREENIter XCBConnSetupSuccessRepRootsIter(XCBSetup *R) deprecated;
529 void XCBConnSetupSuccessRepNext(XCBSetupIter *i) deprecated;
530 XCBGenericIter XCBConnSetupSuccessRepEnd(XCBSetupIter i) deprecated;
531
532
533 #ifdef __cplusplus
534 }
535 #endif
536
537
538 #endif /* __XCB_H__ */