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 module std.c.linux.X11.xcb.xcb; 
29 /* Include the generated xproto module. */
30 import std.c.linux.X11.xcb.xproto;
31 /*#include <sys/uio.h>
32 #include <pthread.h>*/
33 
34 /**
35  * @file xcb.d
36  */
37 
38 /**
39  * @defgroup XCB_Core_API XCB Core API
40  * @brief Core API of the XCB library.
41  *
42  * @{
43  */
44 
45 /* Pre-defined constants */
46 
47 /** Current protocol version */
48 const int X_PROTOCOL=11;
49 
50 /** Current minor version */
51 const int X_PROTOCOL_REVISION=0;
52 
53 /** X_TCP_PORT + display number = server port for TCP transport */
54 const int X_TCP_PORT =6000;
55 
56 int XCB_TYPE_PAD(T)(T t,int i) { return -(i) & (t.sizeof > 4 ? 3 : t.sizeof - 1);}
57 
58 /* Opaque structures */
59 
60 /**
61  * @brief XCB Connection structure.
62  *
63  * A structure that contain all data that  XCB needs to communicate with an X server.
64  */
65 struct xcb_connection_t{};  /**< Opaque structure containing all data that  XCB needs to communicate with an X server. */
66 
67 
68 /* Other types */
69 
70 /**
71  * @brief Generic iterator.
72  *
73  * A generic iterator structure.
74  */
75 struct xcb_generic_iterator_t{
76     void *data;   /**< Data of the current iterator */
77     int rem;    /**< remaining elements */
78     int index;  /**< index of the current iterator */
79 } ;
80 
81 /**
82  * @brief Generic reply.
83  *
84  * A generic reply structure.
85  */
86 struct xcb_generic_reply_t{
87     ubyte   response_type;  /**< Type of the response */
88     ubyte  pad0;           /**< Padding */
89     ushort sequence;       /**< Sequence number */
90     uint length;         /**< Length of the response */
91 };
92 
93 /**
94  * @brief Generic event.
95  *
96  * A generic event structure.
97  */
98 struct xcb_generic_event_t{
99     ubyte   response_type;  /**< Type of the response */
100     ubyte  pad0;           /**< Padding */
101     ushort sequence;       /**< Sequence number */
102     uint pad[7];         /**< Padding */
103     uint full_sequence;  /**< full sequence */
104 };
105 
106 /**
107  * @brief Generic error.
108  *
109  * A generic error structure.
110  */
111 struct xcb_generic_error_t{
112     ubyte   response_type;  /**< Type of the response */
113     ubyte   error_code;     /**< Error code */
114     ushort sequence;       /**< Sequence number */
115     uint pad[7];         /**< Padding */
116     uint full_sequence;  /**< full sequence */
117 };
118 
119 /**
120  * @brief Generic cookie.
121  *
122  * A generic cookie structure.
123  */
124 struct xcb_void_cookie_t{
125     uint sequence;  /**< Sequence number */
126 };
127 
128 /** XCB_NONE is the universal null resource or null atom parameter value for many core X requests */
129 const int XCB_NONE=0L;
130 
131 /** XCB_COPY_FROM_PARENT can be used for many xcb_create_window parameters */
132 const int XCB_COPY_FROM_PARENT=0L;
133 
134 /** XCB_CURRENT_TIME can be used in most requests that take an xcb_timestamp_t */
135 const int XCB_CURRENT_TIME=0L;
136 
137 /** XCB_NO_SYMBOL fills in unused entries in xcb_keysym_t tables */
138 const int XCB_NO_SYMBOL=0L;
139 
140 
141 /* xcb_auth.c */
142 
143 /**
144  * @brief Container for authorization information.
145  *
146  * A container for authorization information to be sent to the X server.
147  */
148 struct xcb_auth_info_t {
149     int   namelen;  /**< Length of the string name (as returned by strlen). */
150     char *name;     /**< String containing the authentication protocol name, such as "MIT-MAGIC-COOKIE-1" or "XDM-AUTHORIZATION-1". */
151     int   datalen;  /**< Length of the data member. */
152     char *data;   /**< Data interpreted in a protocol-specific manner. */
153 };
154 
155 
156 /* xcb_out.c */
157 extern(C){
158 /**
159  * @brief Forces any buffered output to be written to the server.
160  * @param c: The connection to the X server.
161  * @return > @c 0 on success, <= @c 0 otherwise.
162  *
163  * Forces any buffered output to be written to the server. Blocks
164  * until the write is complete.
165  */
166  int xcb_flush(xcb_connection_t *c);
167 
168 /**
169  * @brief Returns the maximum request length that this server accepts.
170  * @param c: The connection to the X server.
171  * @return The maximum request length field.
172  *
173  * In the absence of the BIG-REQUESTS extension, returns the
174  * maximum request length field from the connection setup data, which
175  * may be as much as 65535. If the server supports BIG-REQUESTS, then
176  * the maximum request length field from the reply to the
177  * BigRequestsEnable request will be returned instead.
178  *
179  * Note that this length is measured in four-byte units, making the
180  * theoretical maximum lengths roughly 256kB without BIG-REQUESTS and
181  * 16GB with.
182  */
183 uint xcb_get_maximum_request_length(xcb_connection_t *c);
184 
185 /**
186  * @brief Prefetch the maximum request length without blocking.
187  * @param c: The connection to the X server.
188  *
189  * Without blocking, does as much work as possible toward computing
190  * the maximum request length accepted by the X server.
191  *
192  * Invoking this function may cause a call to xcb_big_requests_enable,
193  * but will not block waiting for the reply.
194  * xcb_get_maximum_request_length will return the prefetched data
195  * after possibly blocking while the reply is retrieved.
196  *
197  * Note that in order for this function to be fully non-blocking, the
198  * application must previously have called
199  * xcb_prefetch_extension_data(c, &xcb_big_requests_id) and the reply
200  * must have already arrived.
201  */
202 void xcb_prefetch_maximum_request_length(xcb_connection_t *c);
203 
204 
205 /* xcb_in.c */
206 
207 /**
208  * @brief Returns the next event or error from the server.
209  * @param c: The connection to the X server.
210  * @return The next event from the server.
211  *
212  * Returns the next event or error from the server, or returns null in
213  * the event of an I/O error. Blocks until either an event or error
214  * arrive, or an I/O error occurs.
215  */
216 xcb_generic_event_t *xcb_wait_for_event(xcb_connection_t *c);
217 
218 /**
219  * @brief Returns the next event or error from the server.
220  * @param c: The connection to the X server.
221  * error status of the operation.
222  * @return The next event from the server.
223  *
224  * Returns the next event or error from the server, if one is
225  * available, or returns @c NULL otherwise. If no event is available, that
226  * might be because an I/O error like connection close occurred while
227  * attempting to read the next event, in which case the connection is
228  * shut down when this function returns.
229  */
230 xcb_generic_event_t *xcb_poll_for_event(xcb_connection_t *c);
231 
232 /**
233  * @brief Return the error for a request, or NULL if none can ever arrive.
234  * @param c: The connection to the X server.
235  * @param cookie: The request cookie.
236  * @return The error for the request, or NULL if none can ever arrive.
237  *
238  * The xcb_void_cookie_t cookie supplied to this function must have resulted
239  * from a call to xcb_[request_name]_checked().  This function will block
240  * until one of two conditions happens.  If an error is received, it will be
241  * returned.  If a reply to a subsequent request has already arrived, no error
242  * can arrive for this request, so this function will return NULL.
243  *
244  * Note that this function will perform a sync if needed to ensure that the
245  * sequence number will advance beyond that provided in cookie; this is a
246  * convenience to avoid races in determining whether the sync is needed.
247  */
248 xcb_generic_error_t *xcb_request_check(xcb_connection_t *c, xcb_void_cookie_t cookie);
249 }
250 /* xcb_ext.c */
251 
252 /**
253  * @typedef typedef struct xcb_extension_t xcb_extension_t
254  */
255 struct xcb_extension_t{};  /**< Opaque structure used as key for xcb_get_extension_data_t. */
256 
257 extern(C){
258 /**
259  * @brief Caches reply information from QueryExtension requests.
260  * @param c: The connection.
261  * @param ext: The extension data.
262  * @return A pointer to the xcb_query_extension_reply_t for the extension.
263  *
264  * This function is the primary interface to the "extension cache",
265  * which caches reply information from QueryExtension
266  * requests. Invoking this function may cause a call to
267  * xcb_query_extension to retrieve extension information from the
268  * server, and may block until extension data is received from the
269  * server.
270  *
271  * The result must not be freed. This storage is managed by the cache
272  * itself.
273  */
274 /+const+/ xcb_query_extension_reply_t *xcb_get_extension_data(xcb_connection_t *c, xcb_extension_t *ext);
275 
276 /**
277  * @brief Prefetch of extension data into the extension cache
278  * @param c: The connection.
279  * @param ext: The extension data.
280  *
281  * This function allows a "prefetch" of extension data into the
282  * extension cache. Invoking the function may cause a call to
283  * xcb_query_extension, but will not block waiting for the
284  * reply. xcb_get_extension_data will return the prefetched data after
285  * possibly blocking while it is retrieved.
286  */
287 void xcb_prefetch_extension_data(xcb_connection_t *c, xcb_extension_t *ext);
288 
289 
290 /* xcb_conn.c */
291 
292 /**
293  * @brief Access the data returned by the server.
294  * @param c: The connection.
295  * @return A pointer to an xcb_setup_t structure.
296  *
297  * Accessor for the data returned by the server when the xcb_connection_t
298  * was initialized. This data includes
299  * - the server's required format for images,
300  * - a list of available visuals,
301  * - a list of available screens,
302  * - the server's maximum request length (in the absence of the
303  * BIG-REQUESTS extension),
304  * - and other assorted information.
305  *
306  * See the X protocol specification for more details.
307  *
308  * The result must not be freed.
309  */
310 /+const+/ xcb_setup_t *xcb_get_setup(xcb_connection_t *c);
311 
312 /**
313  * @brief Access the file descriptor of the connection.
314  * @param c: The connection.
315  * @return The file descriptor.
316  *
317  * Accessor for the file descriptor that was passed to the
318  * xcb_connect_to_fd call that returned @p c.
319  */
320 int xcb_get_file_descriptor(xcb_connection_t *c);
321 
322 /**
323  * @brief Test whether the connection has shut down due to a fatal error.
324  * @param c: The connection.
325  * @return 1 if the connection is in an error state; 0 otherwise.
326  *
327  * Some errors that occur in the context of an xcb_connection_t
328  * are unrecoverable. When such an error occurs, the
329  * connection is shut down and further operations on the
330  * xcb_connection_t have no effect.
331  *
332  * @todo Other functions should document the conditions in
333  * which they shut down the connection.
334  */
335 int xcb_connection_has_error(xcb_connection_t *c);
336 
337 /**
338  * @brief Connects to the X server.
339  * @param fd: The file descriptor.
340  * @param auth_info: Authentication data.
341  * @return A newly allocated xcb_connection_t structure.
342  *
343  * Connects to an X server, given the open socket @p fd and the
344  * xcb_auth_info_t @p auth_info. The file descriptor @p fd is
345  * bidirectionally connected to an X server. If the connection
346  * should be unauthenticated, @p auth_info must be @c
347  * NULL.
348  */
349 xcb_connection_t *xcb_connect_to_fd(int fd, xcb_auth_info_t *auth_info);
350 
351 /**
352  * @brief Closes the connection.
353  * @param c: The connection.
354  *
355  * Closes the file descriptor and frees all memory associated with the
356  * connection @c c.
357  */
358 void xcb_disconnect(xcb_connection_t *c);
359 
360 
361 /* xcb_util.c */
362 
363 /**
364  * @brief Parses a display string name in the form documented by X(7x).
365  * @param name: The name of the display.
366  * @param host: A pointer to a malloc'd copy of the hostname.
367  * @param display: A pointer to the display number.
368  * @param screen: A pointer to the screen number.
369  * @return 0 on failure, non 0 otherwise.
370  *
371  * Parses the display string name @p display_name in the form
372  * documented by X(7x). Has no side effects on failure. If
373  * @p displayname is @c NULL or empty, it uses the environment
374  * variable DISPLAY. @p hostp is a pointer to a newly allocated string
375  * that contain the host name. @p displayp is set to the display
376  * number and @p screenp to the preferred screen number. @p screenp
377  * can be @c NULL. If @p displayname does not contain a screen number,
378  * it is set to @c 0.
379  */
380 int xcb_parse_display(/+const+/ char *name, char **host, int *display, int *screen);
381 
382 /**
383  * @brief Connects to the X server.
384  * @param displayname: The name of the display.
385  * @param screenp: A pointer to a preferred screen number.
386  * @return A newly allocated xcb_connection_t structure.
387  *
388  * Connects to the X server specified by @p displayname. If @p
389  * displayname is @c NULL, uses the value of the DISPLAY environment
390  * variable. If a particular screen on that server is preferred, the
391  * int pointed to by @p screenp (if not @c NULL) will be set to that
392  * screen; otherwise the screen will be set to 0.
393  */
394 xcb_connection_t *xcb_connect(/+const+/ char *displayname, int *screenp);
395 
396 /**
397  * @brief Connects to the X server, using an authorization information.
398  * @param display: The name of the display.
399  * @param auth: The authorization information.
400  * @param screen: A pointer to a preferred screen number.
401  * @return A newly allocated xcb_connection_t structure.
402  *
403  * Connects to the X server specified by @p displayname, using the
404  * authorization @p auth. If a particular screen on that server is
405  * preferred, the int pointed to by @p screenp (if not @c NULL) will
406  * be set to that screen; otherwise @p screenp will be set to 0.
407  */
408 xcb_connection_t *xcb_connect_to_display_with_auth_info(/+const+/ char *display, xcb_auth_info_t *auth, int *screen);
409 
410 
411 /* xcb_xid.c */
412 
413 /**
414  * @brief Allocates an XID for a new object.
415  * @param c: The connection.
416  * @return A newly allocated XID.
417  *
418  * Allocates an XID for a new object. Typically used just prior to
419  * various object creation functions, such as xcb_create_window.
420  */
421 uint xcb_generate_id(xcb_connection_t *c);
422 
423 }
424 /**
425  * @}
426  */