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