Replace HAVE_* tests with just checking for (__solaris__)
[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 #if defined(__solaris__)
33 #include <inttypes.h>
34 #else
35 #include <stdint.h>
36 #endif
37
38 /* FIXME: these names conflict with those defined in Xmd.h. */
39 #ifndef XMD_H
40 typedef uint8_t  BYTE;
41 typedef uint8_t  BOOL;
42 typedef uint8_t  CARD8;
43 typedef uint16_t CARD16;
44 typedef uint32_t CARD32;
45 typedef int8_t   INT8;
46 typedef int16_t  INT16;
47 typedef int32_t  INT32;
48 #endif /* XMD_H */
49
50 #include <sys/uio.h>
51 #include <pthread.h>
52
53
54 #ifdef __cplusplus
55 extern "C" {
56 #endif
57
58
59 #if (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 1))
60 #define deprecated __attribute__((__deprecated__))
61 #else
62 #define deprecated
63 #endif
64
65
66 /**
67  * @file xcb.h
68  */
69
70 /**
71  * @defgroup XCB_Core_Api XCB Core API
72  * @brief Core API of the XCB library.
73  *
74  * @{
75  */
76
77 /* Pre-defined constants */
78
79 /** Current protocol version */
80 #define X_PROTOCOL 11
81
82 /** Current minor version */
83 #define X_PROTOCOL_REVISION 0
84
85 /** X_TCP_PORT + display number = server port for TCP transport */
86 #define X_TCP_PORT 6000
87
88 #define XCB_TYPE_PAD(T,I) (-(I) & (sizeof(T) > 4 ? 3 : sizeof(T) - 1))
89
90 /* Opaque structures */
91
92 /**
93  * @brief XCB Connection structure.
94  *
95  * A structure that contain all data that  XCB needs to communicate with an X server.
96  */
97 typedef struct XCBConnection XCBConnection;  /**< Opaque structure containing all data that  XCB needs to communicate with an X server. */
98
99
100 /* Other types */
101
102 /**
103  * @brief Generic iterator.
104  *
105  * A generic iterator structure.
106  */
107 typedef struct {
108     void *data;   /**< Data of the current iterator */
109     int rem;    /**< remaining elements */
110     int index;  /**< index of the current iterator */
111 } XCBGenericIter;
112
113 /**
114  * @brief Generic reply.
115  *
116  * A generic reply structure.
117  */
118 typedef struct {
119     BYTE   response_type;  /**< Type of the response */
120     CARD8  pad0;           /**< Padding */
121     CARD16 sequence;       /**< Sequence number */
122     CARD32 length;         /**< Length of the response */
123 } XCBGenericRep;
124
125 /**
126  * @brief Generic event.
127  *
128  * A generic event structure.
129  */
130 typedef struct {
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;
136 } XCBGenericEvent;
137
138 /**
139  * @brief Generic error.
140  *
141  * A generic error structure.
142  */
143 typedef struct {
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;
149 } XCBGenericError;
150
151 /**
152  * @brief Generic cookie.
153  *
154  * A generic cookie structure.
155  */
156 typedef struct {
157     unsigned int sequence;  /**< Sequence number */
158 } XCBVoidCookie;
159
160
161 /* Include the generated xproto header. */
162 #include "xproto.h"
163
164
165 /** XCBNone is the universal null resource or null atom parameter value for many core X requests */
166 #define XCBNone 0L
167
168 /** XCBCopyFromParent can be used for many CreateWindow parameters */
169 #define XCBCopyFromParent 0L
170
171 /** XCBCurrentTime can be used in most requests that take an XCBTIMESTAMP */
172 #define XCBCurrentTime 0L
173
174 /** XCBNoSymbol fills in unused entries in XCBKEYSYM tables */
175 #define XCBNoSymbol 0L
176
177
178 /* xcb_auth.c */
179
180 /**
181  * @brief Container for authorization information.
182  *
183  * A container for authorization information to be sent to the X server.
184  */
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. */
190 } XCBAuthInfo;
191
192 /**
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.
197  *
198  * @deprecated This function is deprecated. It must not be used in
199  * newly written code.
200  */
201 int XCBGetAuthInfo(int fd, XCBAuthInfo *info) deprecated;
202
203
204 /* xcb_out.c */
205
206 /**
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.
210  *
211  * Forces any buffered output to be written to the server. Blocks
212  * until the write is complete.
213  */
214 int XCBFlush(XCBConnection *c);
215
216 /**
217  * @brief Returns the maximum request length field from the connection
218  * setup data.
219  * @param c: The connection to the X server.
220  * @return The maximum request length field.
221  *
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.
227  *
228  * Note that this length is measured in four-byte units, making the
229  * theoretical maximum lengths roughly 256kB without BIG-REQUESTS and
230  * 16GB with.
231  */
232 CARD32 XCBGetMaximumRequestLength(XCBConnection *c);
233
234
235 /* xcb_in.c */
236
237 /**
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.
241  *
242  * @deprecated This function is deprecated. It must not be used in
243  * newly written code.
244  */
245 XCBGenericEvent *XCBWaitEvent(XCBConnection *c) deprecated;
246
247 /**
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.
251  *
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.
255  */
256 XCBGenericEvent *XCBWaitForEvent(XCBConnection *c);
257
258 /**
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.
264  *
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
271  * I/O error occurs.
272  */
273 XCBGenericEvent *XCBPollForEvent(XCBConnection *c, int *error);
274
275 /**
276  * @brief Returns the last sequence number that the server is known to
277  * have processed.
278  * @param c: The connection to the X server.
279  * @return The last sequence number.
280  *
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.
284  *
285  * @deprecated This function is deprecated in favor of XCBPollForReply.
286  * It must not be used in newly written code.
287  */
288 unsigned int XCBGetRequestRead(XCBConnection *c) deprecated;
289
290
291 /* xcb_ext.c */
292
293 /**
294  * @typedef typedef struct XCBExtension XCBExtension
295  */
296 typedef struct XCBExtension XCBExtension;  /**< Opaque structure used as key for XCBGetExtensionData. */
297
298 /**
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.
303  *
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
309  * server.
310  *
311  * The result must not be freed. This storage is managed by the cache
312  * itself.
313  */
314 const XCBQueryExtensionRep *XCBGetExtensionData(XCBConnection *c, XCBExtension *ext);
315
316 /**
317  * @brief Prefetch of extension data into the extension cache
318  * @param c: The connection.
319  * @param ext: The extension data.
320  *
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.
326  */
327 void XCBPrefetchExtensionData(XCBConnection *c, XCBExtension *ext);
328
329
330 /* xcb_conn.c */
331
332 /**
333  * @brief Access the data returned by the server.
334  * @param c: The connection.
335  * @return A pointer to an XCBSetup structure.
336  *
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.
345  *
346  * See the X protocol specification for more details.
347  *
348  * The result must not be freed.
349  */
350 const XCBSetup *XCBGetSetup(XCBConnection *c);
351
352 /**
353  * @brief Access the file descriptor of the connection.
354  * @param c: The connection.
355  * @return The file descriptor.
356  *
357  * Accessor for the file descriptor that was passed to the
358  * XCBConnectToFD call that returned @p c.
359  */
360 int XCBGetFileDescriptor(XCBConnection *c);
361
362 /**
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.
367  *
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.
374  */
375 XCBConnection *XCBConnectToFD(int fd, XCBAuthInfo *auth_info);
376
377 /**
378  * @brief Closes the connection.
379  * @param c: The connection.
380  *
381  * Closes the file descriptor and frees all memory associated with the
382  * connection @c c.
383  */
384 void XCBDisconnect(XCBConnection *c);
385
386
387 /* xcb_util.c */
388
389 /**
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.
396  *
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,
404  * it is set to @c 0.
405  */
406 int XCBParseDisplay(const char *name, char **host, int *display, int *screen);
407
408 /**
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.
413  *
414  * @deprecated This function is deprecated. It must not be used in
415  * newly written code.
416  */
417 int XCBOpen(const char *host, int display) deprecated;
418
419 /**
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.
424  *
425  * @deprecated This function is deprecated. It must not be used in
426  * newly written code.
427  */
428 int XCBOpenTCP(const char *host, unsigned short port) deprecated;
429
430 /**
431  * @brief Connects to the X server.
432  * @param file: The file name.
433  * @return The file descriptor.
434  *
435  * @deprecated This function is deprecated. It must not be used in
436  * newly written code.
437  */
438 int XCBOpenUnix(const char *file) deprecated;
439
440 /**
441  * @brief Connects to the X server.
442  * @return A newly allocated XCBConnection structure.
443  *
444  * @deprecated This function is deprecated. It must not be used in
445  * newly written code.
446  */
447 XCBConnection *XCBConnectBasic(void) deprecated;
448
449 /**
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.
454  *
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.
460  */
461 XCBConnection *XCBConnect(const char *displayname, int *screenp);
462
463 /**
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.
469  *
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.
474  */
475 XCBConnection *XCBConnectToDisplayWithAuthInfo(const char *display, XCBAuthInfo *auth, int *screen);
476
477 /**
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.
482  *
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.
486  */
487 int XCBSync(XCBConnection *c, XCBGenericError **e) deprecated;
488
489
490 /**
491  * @}
492  */
493
494
495 /* Old names for connection-setup types, to be removed before 1.0. */
496
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;
505
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;
534
535
536 #ifdef __cplusplus
537 }
538 #endif
539
540
541 #endif /* __XCB_H__ */