jpayne@69: /* jpayne@69: * Copyright (C) 2001-2004 Bart Massey and Jamey Sharp. jpayne@69: * All Rights Reserved. jpayne@69: * jpayne@69: * Permission is hereby granted, free of charge, to any person obtaining a jpayne@69: * copy of this software and associated documentation files (the "Software"), jpayne@69: * to deal in the Software without restriction, including without limitation jpayne@69: * the rights to use, copy, modify, merge, publish, distribute, sublicense, jpayne@69: * and/or sell copies of the Software, and to permit persons to whom the jpayne@69: * Software is furnished to do so, subject to the following conditions: jpayne@69: * jpayne@69: * The above copyright notice and this permission notice shall be included in jpayne@69: * all copies or substantial portions of the Software. jpayne@69: * jpayne@69: * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR jpayne@69: * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, jpayne@69: * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE jpayne@69: * AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN jpayne@69: * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN jpayne@69: * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. jpayne@69: * jpayne@69: * Except as contained in this notice, the names of the authors or their jpayne@69: * institutions shall not be used in advertising or otherwise to promote the jpayne@69: * sale, use or other dealings in this Software without prior written jpayne@69: * authorization from the authors. jpayne@69: */ jpayne@69: jpayne@69: #ifndef __XCBEXT_H jpayne@69: #define __XCBEXT_H jpayne@69: jpayne@69: #include "xcb.h" jpayne@69: jpayne@69: #ifdef __cplusplus jpayne@69: extern "C" { jpayne@69: #endif jpayne@69: jpayne@69: /* xcb_ext.c */ jpayne@69: jpayne@69: struct xcb_extension_t { jpayne@69: const char *name; jpayne@69: int global_id; jpayne@69: }; jpayne@69: jpayne@69: jpayne@69: /* xcb_out.c */ jpayne@69: jpayne@69: typedef struct { jpayne@69: size_t count; jpayne@69: xcb_extension_t *ext; jpayne@69: uint8_t opcode; jpayne@69: uint8_t isvoid; jpayne@69: } xcb_protocol_request_t; jpayne@69: jpayne@69: enum xcb_send_request_flags_t { jpayne@69: XCB_REQUEST_CHECKED = 1 << 0, jpayne@69: XCB_REQUEST_RAW = 1 << 1, jpayne@69: XCB_REQUEST_DISCARD_REPLY = 1 << 2, jpayne@69: XCB_REQUEST_REPLY_FDS = 1 << 3 jpayne@69: }; jpayne@69: jpayne@69: /** jpayne@69: * @brief Send a request to the server. jpayne@69: * @param c The connection to the X server. jpayne@69: * @param flags A combination of flags from the xcb_send_request_flags_t enumeration. jpayne@69: * @param vector Data to send; must have two iovecs before start for internal use. jpayne@69: * @param request Information about the request to be sent. jpayne@69: * @return The request's sequence number on success, 0 otherwise. jpayne@69: * jpayne@69: * This function sends a new request to the X server. The data of the request is jpayne@69: * given as an array of @c iovecs in the @p vector argument. The length of that jpayne@69: * array and the necessary management information are given in the @p request jpayne@69: * argument. jpayne@69: * jpayne@69: * When this function returns, the request might or might not be sent already. jpayne@69: * Use xcb_flush() to make sure that it really was sent. jpayne@69: * jpayne@69: * Please note that this function is not the preferred way for sending requests. jpayne@69: * It's better to use the generated wrapper functions. jpayne@69: * jpayne@69: * Please note that xcb might use index -1 and -2 of the @p vector array internally, jpayne@69: * so they must be valid! jpayne@69: */ jpayne@69: unsigned int xcb_send_request(xcb_connection_t *c, int flags, struct iovec *vector, const xcb_protocol_request_t *request); jpayne@69: jpayne@69: /** jpayne@69: * @brief Send a request to the server. jpayne@69: * @param c The connection to the X server. jpayne@69: * @param flags A combination of flags from the xcb_send_request_flags_t enumeration. jpayne@69: * @param vector Data to send; must have two iovecs before start for internal use. jpayne@69: * @param request Information about the request to be sent. jpayne@69: * @param num_fds Number of additional file descriptors to send to the server jpayne@69: * @param fds Additional file descriptors that should be send to the server. jpayne@69: * @return The request's sequence number on success, 0 otherwise. jpayne@69: * jpayne@69: * This function sends a new request to the X server. The data of the request is jpayne@69: * given as an array of @c iovecs in the @p vector argument. The length of that jpayne@69: * array and the necessary management information are given in the @p request jpayne@69: * argument. jpayne@69: * jpayne@69: * If @p num_fds is non-zero, @p fds points to an array of file descriptors that jpayne@69: * will be sent to the X server along with this request. After this function jpayne@69: * returns, all file descriptors sent are owned by xcb and will be closed jpayne@69: * eventually. jpayne@69: * jpayne@69: * When this function returns, the request might or might not be sent already. jpayne@69: * Use xcb_flush() to make sure that it really was sent. jpayne@69: * jpayne@69: * Please note that this function is not the preferred way for sending requests. jpayne@69: * jpayne@69: * Please note that xcb might use index -1 and -2 of the @p vector array internally, jpayne@69: * so they must be valid! jpayne@69: */ jpayne@69: unsigned int xcb_send_request_with_fds(xcb_connection_t *c, int flags, struct iovec *vector, jpayne@69: const xcb_protocol_request_t *request, unsigned int num_fds, int *fds); jpayne@69: jpayne@69: /** jpayne@69: * @brief Send a request to the server, with 64-bit sequence number returned. jpayne@69: * @param c The connection to the X server. jpayne@69: * @param flags A combination of flags from the xcb_send_request_flags_t enumeration. jpayne@69: * @param vector Data to send; must have two iovecs before start for internal use. jpayne@69: * @param request Information about the request to be sent. jpayne@69: * @return The request's sequence number on success, 0 otherwise. jpayne@69: * jpayne@69: * This function sends a new request to the X server. The data of the request is jpayne@69: * given as an array of @c iovecs in the @p vector argument. The length of that jpayne@69: * array and the necessary management information are given in the @p request jpayne@69: * argument. jpayne@69: * jpayne@69: * When this function returns, the request might or might not be sent already. jpayne@69: * Use xcb_flush() to make sure that it really was sent. jpayne@69: * jpayne@69: * Please note that this function is not the preferred way for sending requests. jpayne@69: * It's better to use the generated wrapper functions. jpayne@69: * jpayne@69: * Please note that xcb might use index -1 and -2 of the @p vector array internally, jpayne@69: * so they must be valid! jpayne@69: */ jpayne@69: uint64_t xcb_send_request64(xcb_connection_t *c, int flags, struct iovec *vector, const xcb_protocol_request_t *request); jpayne@69: jpayne@69: /** jpayne@69: * @brief Send a request to the server, with 64-bit sequence number returned. jpayne@69: * @param c The connection to the X server. jpayne@69: * @param flags A combination of flags from the xcb_send_request_flags_t enumeration. jpayne@69: * @param vector Data to send; must have two iovecs before start for internal use. jpayne@69: * @param request Information about the request to be sent. jpayne@69: * @param num_fds Number of additional file descriptors to send to the server jpayne@69: * @param fds Additional file descriptors that should be send to the server. jpayne@69: * @return The request's sequence number on success, 0 otherwise. jpayne@69: * jpayne@69: * This function sends a new request to the X server. The data of the request is jpayne@69: * given as an array of @c iovecs in the @p vector argument. The length of that jpayne@69: * array and the necessary management information are given in the @p request jpayne@69: * argument. jpayne@69: * jpayne@69: * If @p num_fds is non-zero, @p fds points to an array of file descriptors that jpayne@69: * will be sent to the X server along with this request. After this function jpayne@69: * returns, all file descriptors sent are owned by xcb and will be closed jpayne@69: * eventually. jpayne@69: * jpayne@69: * When this function returns, the request might or might not be sent already. jpayne@69: * Use xcb_flush() to make sure that it really was sent. jpayne@69: * jpayne@69: * Please note that this function is not the preferred way for sending requests. jpayne@69: * It's better to use the generated wrapper functions. jpayne@69: * jpayne@69: * Please note that xcb might use index -1 and -2 of the @p vector array internally, jpayne@69: * so they must be valid! jpayne@69: */ jpayne@69: uint64_t xcb_send_request_with_fds64(xcb_connection_t *c, int flags, struct iovec *vector, jpayne@69: const xcb_protocol_request_t *request, unsigned int num_fds, int *fds); jpayne@69: jpayne@69: /** jpayne@69: * @brief Send a file descriptor to the server in the next call to xcb_send_request. jpayne@69: * @param c The connection to the X server. jpayne@69: * @param fd The file descriptor to send. jpayne@69: * jpayne@69: * After this function returns, the file descriptor given is owned by xcb and jpayne@69: * will be closed eventually. jpayne@69: * jpayne@69: * @deprecated This function cannot be used in a thread-safe way. Two threads jpayne@69: * that run xcb_send_fd(); xcb_send_request(); could mix up their file jpayne@69: * descriptors. Instead, xcb_send_request_with_fds() should be used. jpayne@69: */ jpayne@69: void xcb_send_fd(xcb_connection_t *c, int fd); jpayne@69: jpayne@69: /** jpayne@69: * @brief Take over the write side of the socket jpayne@69: * @param c The connection to the X server. jpayne@69: * @param return_socket Callback function that will be called when xcb wants jpayne@69: * to use the socket again. jpayne@69: * @param closure Argument to the callback function. jpayne@69: * @param flags A combination of flags from the xcb_send_request_flags_t enumeration. jpayne@69: * @param sent Location to the sequence number of the last sequence request. jpayne@69: * Must not be NULL. jpayne@69: * @return 1 on success, else 0. jpayne@69: * jpayne@69: * xcb_take_socket allows external code to ask XCB for permission to jpayne@69: * take over the write side of the socket and send raw data with jpayne@69: * xcb_writev. xcb_take_socket provides the sequence number of the last jpayne@69: * request XCB sent. The caller of xcb_take_socket must supply a jpayne@69: * callback which XCB can call when it wants the write side of the jpayne@69: * socket back to make a request. This callback synchronizes with the jpayne@69: * external socket owner and flushes any output queues if appropriate. jpayne@69: * If you are sending requests which won't cause a reply, please note the jpayne@69: * comment for xcb_writev which explains some sequence number wrap issues. jpayne@69: * jpayne@69: * All replies that are generated while the socket is owned externally have jpayne@69: * @p flags applied to them. For example, use XCB_REQUEST_CHECK if you don't jpayne@69: * want errors to go to xcb's normal error handling, but instead having to be jpayne@69: * picked up via xcb_wait_for_reply(), xcb_poll_for_reply() or jpayne@69: * xcb_request_check(). jpayne@69: */ jpayne@69: int xcb_take_socket(xcb_connection_t *c, void (*return_socket)(void *closure), void *closure, int flags, uint64_t *sent); jpayne@69: jpayne@69: /** jpayne@69: * @brief Send raw data to the X server. jpayne@69: * @param c The connection to the X server. jpayne@69: * @param vector Array of data to be sent. jpayne@69: * @param count Number of entries in @p vector. jpayne@69: * @param requests Number of requests that are being sent. jpayne@69: * @return 1 on success, else 0. jpayne@69: * jpayne@69: * You must own the write-side of the socket (you've called jpayne@69: * xcb_take_socket, and haven't returned from return_socket yet) to call jpayne@69: * xcb_writev. Also, the iovec must have at least 1 byte of data in it. jpayne@69: * You have to make sure that xcb can detect sequence number wraps correctly. jpayne@69: * This means that the first request you send after xcb_take_socket must cause a jpayne@69: * reply (e.g. just insert a GetInputFocus request). After every (1 << 16) - 1 jpayne@69: * requests without a reply, you have to insert a request which will cause a jpayne@69: * reply. You can again use GetInputFocus for this. You do not have to wait for jpayne@69: * any of the GetInputFocus replies, but can instead handle them via jpayne@69: * xcb_discard_reply(). jpayne@69: */ jpayne@69: int xcb_writev(xcb_connection_t *c, struct iovec *vector, int count, uint64_t requests); jpayne@69: jpayne@69: jpayne@69: /* xcb_in.c */ jpayne@69: jpayne@69: /** jpayne@69: * @brief Wait for the reply of a given request. jpayne@69: * @param c The connection to the X server. jpayne@69: * @param request Sequence number of the request as returned by xcb_send_request(). jpayne@69: * @param e Location to store errors in, or NULL. Ignored for unchecked requests. jpayne@69: * jpayne@69: * Returns the reply to the given request or returns null in the event of jpayne@69: * errors. Blocks until the reply or error for the request arrives, or an I/O jpayne@69: * error occurs. jpayne@69: */ jpayne@69: void *xcb_wait_for_reply(xcb_connection_t *c, unsigned int request, xcb_generic_error_t **e); jpayne@69: jpayne@69: /** jpayne@69: * @brief Wait for the reply of a given request, with 64-bit sequence number jpayne@69: * @param c The connection to the X server. jpayne@69: * @param request 64-bit sequence number of the request as returned by xcb_send_request64(). jpayne@69: * @param e Location to store errors in, or NULL. Ignored for unchecked requests. jpayne@69: * jpayne@69: * Returns the reply to the given request or returns null in the event of jpayne@69: * errors. Blocks until the reply or error for the request arrives, or an I/O jpayne@69: * error occurs. jpayne@69: * jpayne@69: * Unlike its xcb_wait_for_reply() counterpart, the given sequence number is not jpayne@69: * automatically "widened" to 64-bit. jpayne@69: */ jpayne@69: void *xcb_wait_for_reply64(xcb_connection_t *c, uint64_t request, xcb_generic_error_t **e); jpayne@69: jpayne@69: /** jpayne@69: * @brief Poll for the reply of a given request. jpayne@69: * @param c The connection to the X server. jpayne@69: * @param request Sequence number of the request as returned by xcb_send_request(). jpayne@69: * @param reply Location to store the reply in, must not be NULL. jpayne@69: * @param error Location to store errors in, or NULL. Ignored for unchecked requests. jpayne@69: * @return 1 when the reply to the request was returned, else 0. jpayne@69: * jpayne@69: * Checks if the reply to the given request already received. Does not block. jpayne@69: */ jpayne@69: int xcb_poll_for_reply(xcb_connection_t *c, unsigned int request, void **reply, xcb_generic_error_t **error); jpayne@69: jpayne@69: /** jpayne@69: * @brief Poll for the reply of a given request, with 64-bit sequence number. jpayne@69: * @param c The connection to the X server. jpayne@69: * @param request 64-bit sequence number of the request as returned by xcb_send_request(). jpayne@69: * @param reply Location to store the reply in, must not be NULL. jpayne@69: * @param error Location to store errors in, or NULL. Ignored for unchecked requests. jpayne@69: * @return 1 when the reply to the request was returned, else 0. jpayne@69: * jpayne@69: * Checks if the reply to the given request already received. Does not block. jpayne@69: * jpayne@69: * Unlike its xcb_poll_for_reply() counterpart, the given sequence number is not jpayne@69: * automatically "widened" to 64-bit. jpayne@69: */ jpayne@69: int xcb_poll_for_reply64(xcb_connection_t *c, uint64_t request, void **reply, xcb_generic_error_t **error); jpayne@69: jpayne@69: /** jpayne@69: * @brief Don't use this, only needed by the generated code. jpayne@69: * @param c The connection to the X server. jpayne@69: * @param reply A reply that was received from the server jpayne@69: * @param replylen The size of the reply. jpayne@69: * @return Pointer to the location where received file descriptors are stored. jpayne@69: */ jpayne@69: int *xcb_get_reply_fds(xcb_connection_t *c, void *reply, size_t replylen); jpayne@69: jpayne@69: jpayne@69: /* xcb_util.c */ jpayne@69: jpayne@69: /** jpayne@69: * @param mask The mask to check jpayne@69: * @return The number of set bits in the mask jpayne@69: */ jpayne@69: int xcb_popcount(uint32_t mask); jpayne@69: jpayne@69: /** jpayne@69: * @param list The base of an array jpayne@69: * @param len The length of the array jpayne@69: * @return The sum of all entries in the array. jpayne@69: */ jpayne@69: int xcb_sumof(uint8_t *list, int len); jpayne@69: jpayne@69: #ifdef __cplusplus jpayne@69: } jpayne@69: #endif jpayne@69: jpayne@69: #endif