xcbext.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322
  1. /*
  2. * Copyright (C) 2001-2004 Bart Massey and Jamey Sharp.
  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. #ifndef __XCBEXT_H
  28. #define __XCBEXT_H
  29. #include "xcb.h"
  30. #ifdef __cplusplus
  31. extern "C" {
  32. #endif
  33. /* xcb_ext.c */
  34. struct xcb_extension_t {
  35. const char *name;
  36. int global_id;
  37. };
  38. /* xcb_out.c */
  39. typedef struct {
  40. size_t count;
  41. xcb_extension_t *ext;
  42. uint8_t opcode;
  43. uint8_t isvoid;
  44. } xcb_protocol_request_t;
  45. enum xcb_send_request_flags_t {
  46. XCB_REQUEST_CHECKED = 1 << 0,
  47. XCB_REQUEST_RAW = 1 << 1,
  48. XCB_REQUEST_DISCARD_REPLY = 1 << 2,
  49. XCB_REQUEST_REPLY_FDS = 1 << 3
  50. };
  51. /**
  52. * @brief Send a request to the server.
  53. * @param c The connection to the X server.
  54. * @param flags A combination of flags from the xcb_send_request_flags_t enumeration.
  55. * @param vector Data to send; must have two iovecs before start for internal use.
  56. * @param request Information about the request to be sent.
  57. * @return The request's sequence number on success, 0 otherwise.
  58. *
  59. * This function sends a new request to the X server. The data of the request is
  60. * given as an array of @c iovecs in the @p vector argument. The length of that
  61. * array and the necessary management information are given in the @p request
  62. * argument.
  63. *
  64. * When this function returns, the request might or might not be sent already.
  65. * Use xcb_flush() to make sure that it really was sent.
  66. *
  67. * Please note that this function is not the preferred way for sending requests.
  68. * It's better to use the generated wrapper functions.
  69. *
  70. * Please note that xcb might use index -1 and -2 of the @p vector array internally,
  71. * so they must be valid!
  72. */
  73. unsigned int xcb_send_request(xcb_connection_t *c, int flags, struct iovec *vector, const xcb_protocol_request_t *request);
  74. /**
  75. * @brief Send a request to the server.
  76. * @param c The connection to the X server.
  77. * @param flags A combination of flags from the xcb_send_request_flags_t enumeration.
  78. * @param vector Data to send; must have two iovecs before start for internal use.
  79. * @param request Information about the request to be sent.
  80. * @param num_fds Number of additional file descriptors to send to the server
  81. * @param fds Additional file descriptors that should be send to the server.
  82. * @return The request's sequence number on success, 0 otherwise.
  83. *
  84. * This function sends a new request to the X server. The data of the request is
  85. * given as an array of @c iovecs in the @p vector argument. The length of that
  86. * array and the necessary management information are given in the @p request
  87. * argument.
  88. *
  89. * If @p num_fds is non-zero, @p fds points to an array of file descriptors that
  90. * will be sent to the X server along with this request. After this function
  91. * returns, all file descriptors sent are owned by xcb and will be closed
  92. * eventually.
  93. *
  94. * When this function returns, the request might or might not be sent already.
  95. * Use xcb_flush() to make sure that it really was sent.
  96. *
  97. * Please note that this function is not the preferred way for sending requests.
  98. *
  99. * Please note that xcb might use index -1 and -2 of the @p vector array internally,
  100. * so they must be valid!
  101. */
  102. unsigned int xcb_send_request_with_fds(xcb_connection_t *c, int flags, struct iovec *vector,
  103. const xcb_protocol_request_t *request, unsigned int num_fds, int *fds);
  104. /**
  105. * @brief Send a request to the server, with 64-bit sequence number returned.
  106. * @param c The connection to the X server.
  107. * @param flags A combination of flags from the xcb_send_request_flags_t enumeration.
  108. * @param vector Data to send; must have two iovecs before start for internal use.
  109. * @param request Information about the request to be sent.
  110. * @return The request's sequence number on success, 0 otherwise.
  111. *
  112. * This function sends a new request to the X server. The data of the request is
  113. * given as an array of @c iovecs in the @p vector argument. The length of that
  114. * array and the necessary management information are given in the @p request
  115. * argument.
  116. *
  117. * When this function returns, the request might or might not be sent already.
  118. * Use xcb_flush() to make sure that it really was sent.
  119. *
  120. * Please note that this function is not the preferred way for sending requests.
  121. * It's better to use the generated wrapper functions.
  122. *
  123. * Please note that xcb might use index -1 and -2 of the @p vector array internally,
  124. * so they must be valid!
  125. */
  126. uint64_t xcb_send_request64(xcb_connection_t *c, int flags, struct iovec *vector, const xcb_protocol_request_t *request);
  127. /**
  128. * @brief Send a request to the server, with 64-bit sequence number returned.
  129. * @param c The connection to the X server.
  130. * @param flags A combination of flags from the xcb_send_request_flags_t enumeration.
  131. * @param vector Data to send; must have two iovecs before start for internal use.
  132. * @param request Information about the request to be sent.
  133. * @param num_fds Number of additional file descriptors to send to the server
  134. * @param fds Additional file descriptors that should be send to the server.
  135. * @return The request's sequence number on success, 0 otherwise.
  136. *
  137. * This function sends a new request to the X server. The data of the request is
  138. * given as an array of @c iovecs in the @p vector argument. The length of that
  139. * array and the necessary management information are given in the @p request
  140. * argument.
  141. *
  142. * If @p num_fds is non-zero, @p fds points to an array of file descriptors that
  143. * will be sent to the X server along with this request. After this function
  144. * returns, all file descriptors sent are owned by xcb and will be closed
  145. * eventually.
  146. *
  147. * When this function returns, the request might or might not be sent already.
  148. * Use xcb_flush() to make sure that it really was sent.
  149. *
  150. * Please note that this function is not the preferred way for sending requests.
  151. * It's better to use the generated wrapper functions.
  152. *
  153. * Please note that xcb might use index -1 and -2 of the @p vector array internally,
  154. * so they must be valid!
  155. */
  156. uint64_t xcb_send_request_with_fds64(xcb_connection_t *c, int flags, struct iovec *vector,
  157. const xcb_protocol_request_t *request, unsigned int num_fds, int *fds);
  158. /**
  159. * @brief Send a file descriptor to the server in the next call to xcb_send_request.
  160. * @param c The connection to the X server.
  161. * @param fd The file descriptor to send.
  162. *
  163. * After this function returns, the file descriptor given is owned by xcb and
  164. * will be closed eventually.
  165. *
  166. * @deprecated This function cannot be used in a thread-safe way. Two threads
  167. * that run xcb_send_fd(); xcb_send_request(); could mix up their file
  168. * descriptors. Instead, xcb_send_request_with_fds() should be used.
  169. */
  170. void xcb_send_fd(xcb_connection_t *c, int fd);
  171. /**
  172. * @brief Take over the write side of the socket
  173. * @param c The connection to the X server.
  174. * @param return_socket Callback function that will be called when xcb wants
  175. * to use the socket again.
  176. * @param closure Argument to the callback function.
  177. * @param flags A combination of flags from the xcb_send_request_flags_t enumeration.
  178. * @param sent Location to the sequence number of the last sequence request.
  179. * Must not be NULL.
  180. * @return 1 on success, else 0.
  181. *
  182. * xcb_take_socket allows external code to ask XCB for permission to
  183. * take over the write side of the socket and send raw data with
  184. * xcb_writev. xcb_take_socket provides the sequence number of the last
  185. * request XCB sent. The caller of xcb_take_socket must supply a
  186. * callback which XCB can call when it wants the write side of the
  187. * socket back to make a request. This callback synchronizes with the
  188. * external socket owner and flushes any output queues if appropriate.
  189. * If you are sending requests which won't cause a reply, please note the
  190. * comment for xcb_writev which explains some sequence number wrap issues.
  191. *
  192. * All replies that are generated while the socket is owned externally have
  193. * @p flags applied to them. For example, use XCB_REQUEST_CHECK if you don't
  194. * want errors to go to xcb's normal error handling, but instead having to be
  195. * picked up via xcb_wait_for_reply(), xcb_poll_for_reply() or
  196. * xcb_request_check().
  197. */
  198. int xcb_take_socket(xcb_connection_t *c, void (*return_socket)(void *closure), void *closure, int flags, uint64_t *sent);
  199. /**
  200. * @brief Send raw data to the X server.
  201. * @param c The connection to the X server.
  202. * @param vector Array of data to be sent.
  203. * @param count Number of entries in @p vector.
  204. * @param requests Number of requests that are being sent.
  205. * @return 1 on success, else 0.
  206. *
  207. * You must own the write-side of the socket (you've called
  208. * xcb_take_socket, and haven't returned from return_socket yet) to call
  209. * xcb_writev. Also, the iovec must have at least 1 byte of data in it.
  210. * You have to make sure that xcb can detect sequence number wraps correctly.
  211. * This means that the first request you send after xcb_take_socket must cause a
  212. * reply (e.g. just insert a GetInputFocus request). After every (1 << 16) - 1
  213. * requests without a reply, you have to insert a request which will cause a
  214. * reply. You can again use GetInputFocus for this. You do not have to wait for
  215. * any of the GetInputFocus replies, but can instead handle them via
  216. * xcb_discard_reply().
  217. */
  218. int xcb_writev(xcb_connection_t *c, struct iovec *vector, int count, uint64_t requests);
  219. /* xcb_in.c */
  220. /**
  221. * @brief Wait for the reply of a given request.
  222. * @param c The connection to the X server.
  223. * @param request Sequence number of the request as returned by xcb_send_request().
  224. * @param e Location to store errors in, or NULL. Ignored for unchecked requests.
  225. *
  226. * Returns the reply to the given request or returns null in the event of
  227. * errors. Blocks until the reply or error for the request arrives, or an I/O
  228. * error occurs.
  229. */
  230. void *xcb_wait_for_reply(xcb_connection_t *c, unsigned int request, xcb_generic_error_t **e);
  231. /**
  232. * @brief Wait for the reply of a given request, with 64-bit sequence number
  233. * @param c The connection to the X server.
  234. * @param request 64-bit sequence number of the request as returned by xcb_send_request64().
  235. * @param e Location to store errors in, or NULL. Ignored for unchecked requests.
  236. *
  237. * Returns the reply to the given request or returns null in the event of
  238. * errors. Blocks until the reply or error for the request arrives, or an I/O
  239. * error occurs.
  240. *
  241. * Unlike its xcb_wait_for_reply() counterpart, the given sequence number is not
  242. * automatically "widened" to 64-bit.
  243. */
  244. void *xcb_wait_for_reply64(xcb_connection_t *c, uint64_t request, xcb_generic_error_t **e);
  245. /**
  246. * @brief Poll for the reply of a given request.
  247. * @param c The connection to the X server.
  248. * @param request Sequence number of the request as returned by xcb_send_request().
  249. * @param reply Location to store the reply in, must not be NULL.
  250. * @param error Location to store errors in, or NULL. Ignored for unchecked requests.
  251. * @return 1 when the reply to the request was returned, else 0.
  252. *
  253. * Checks if the reply to the given request already received. Does not block.
  254. */
  255. int xcb_poll_for_reply(xcb_connection_t *c, unsigned int request, void **reply, xcb_generic_error_t **error);
  256. /**
  257. * @brief Poll for the reply of a given request, with 64-bit sequence number.
  258. * @param c The connection to the X server.
  259. * @param request 64-bit sequence number of the request as returned by xcb_send_request().
  260. * @param reply Location to store the reply in, must not be NULL.
  261. * @param error Location to store errors in, or NULL. Ignored for unchecked requests.
  262. * @return 1 when the reply to the request was returned, else 0.
  263. *
  264. * Checks if the reply to the given request already received. Does not block.
  265. *
  266. * Unlike its xcb_poll_for_reply() counterpart, the given sequence number is not
  267. * automatically "widened" to 64-bit.
  268. */
  269. int xcb_poll_for_reply64(xcb_connection_t *c, uint64_t request, void **reply, xcb_generic_error_t **error);
  270. /**
  271. * @brief Don't use this, only needed by the generated code.
  272. * @param c The connection to the X server.
  273. * @param reply A reply that was received from the server
  274. * @param replylen The size of the reply.
  275. * @return Pointer to the location where received file descriptors are stored.
  276. */
  277. int *xcb_get_reply_fds(xcb_connection_t *c, void *reply, size_t replylen);
  278. /* xcb_util.c */
  279. /**
  280. * @param mask The mask to check
  281. * @return The number of set bits in the mask
  282. */
  283. int xcb_popcount(uint32_t mask);
  284. /**
  285. * @param list The base of an array
  286. * @param len The length of the array
  287. * @return The sum of all entries in the array.
  288. */
  289. int xcb_sumof(uint8_t *list, int len);
  290. #ifdef __cplusplus
  291. }
  292. #endif
  293. #endif