Removed GNU make dependency.
[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 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.
280  *
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.
286  *
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.
290  */
291 XCBGenericError *XCBRequestCheck(XCBConnection *c, XCBVoidCookie cookie);
292
293 /**
294  * @brief Returns the last sequence number that the server is known to
295  * have processed.
296  * @param c: The connection to the X server.
297  * @return The last sequence number.
298  *
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.
302  *
303  * @deprecated This function is deprecated in favor of XCBPollForReply.
304  * It must not be used in newly written code.
305  */
306 unsigned int XCBGetRequestRead(XCBConnection *c) deprecated;
307
308
309 /* xcb_ext.c */
310
311 /**
312  * @typedef typedef struct XCBExtension XCBExtension
313  */
314 typedef struct XCBExtension XCBExtension;  /**< Opaque structure used as key for XCBGetExtensionData. */
315
316 /**
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.
321  *
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
327  * server.
328  *
329  * The result must not be freed. This storage is managed by the cache
330  * itself.
331  */
332 const XCBQueryExtensionRep *XCBGetExtensionData(XCBConnection *c, XCBExtension *ext);
333
334 /**
335  * @brief Prefetch of extension data into the extension cache
336  * @param c: The connection.
337  * @param ext: The extension data.
338  *
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.
344  */
345 void XCBPrefetchExtensionData(XCBConnection *c, XCBExtension *ext);
346
347
348 /* xcb_conn.c */
349
350 /**
351  * @brief Access the data returned by the server.
352  * @param c: The connection.
353  * @return A pointer to an XCBSetup structure.
354  *
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.
363  *
364  * See the X protocol specification for more details.
365  *
366  * The result must not be freed.
367  */
368 const XCBSetup *XCBGetSetup(XCBConnection *c);
369
370 /**
371  * @brief Access the file descriptor of the connection.
372  * @param c: The connection.
373  * @return The file descriptor.
374  *
375  * Accessor for the file descriptor that was passed to the
376  * XCBConnectToFD call that returned @p c.
377  */
378 int XCBGetFileDescriptor(XCBConnection *c);
379
380 /**
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.
385  *
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.
392  */
393 XCBConnection *XCBConnectToFD(int fd, XCBAuthInfo *auth_info);
394
395 /**
396  * @brief Closes the connection.
397  * @param c: The connection.
398  *
399  * Closes the file descriptor and frees all memory associated with the
400  * connection @c c.
401  */
402 void XCBDisconnect(XCBConnection *c);
403
404
405 /* xcb_util.c */
406
407 /**
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.
414  *
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,
422  * it is set to @c 0.
423  */
424 int XCBParseDisplay(const char *name, char **host, int *display, int *screen);
425
426 /**
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.
431  *
432  * @deprecated This function is deprecated. It must not be used in
433  * newly written code.
434  */
435 int XCBOpen(const char *host, int display) deprecated;
436
437 /**
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.
442  *
443  * @deprecated This function is deprecated. It must not be used in
444  * newly written code.
445  */
446 int XCBOpenTCP(const char *host, unsigned short port) deprecated;
447
448 /**
449  * @brief Connects to the X server.
450  * @param file: The file name.
451  * @return The file descriptor.
452  *
453  * @deprecated This function is deprecated. It must not be used in
454  * newly written code.
455  */
456 int XCBOpenUnix(const char *file) deprecated;
457
458 /**
459  * @brief Connects to the X server.
460  * @return A newly allocated XCBConnection structure.
461  *
462  * @deprecated This function is deprecated. It must not be used in
463  * newly written code.
464  */
465 XCBConnection *XCBConnectBasic(void) deprecated;
466
467 /**
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.
472  *
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.
478  */
479 XCBConnection *XCBConnect(const char *displayname, int *screenp);
480
481 /**
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.
487  *
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.
492  */
493 XCBConnection *XCBConnectToDisplayWithAuthInfo(const char *display, XCBAuthInfo *auth, int *screen);
494
495 /**
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.
500  *
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.
504  */
505 int XCBSync(XCBConnection *c, XCBGenericError **e) deprecated;
506
507
508 /**
509  * @}
510  */
511
512
513 /* Old names for connection-setup types, to be removed before 1.0. */
514
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;
523
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;
552
553
554 #ifdef __cplusplus
555 }
556 #endif
557
558
559 #endif /* __XCB_H__ */