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