wayland-client-core.h 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  1. /*
  2. * Copyright © 2008 Kristian Høgsberg
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining
  5. * a copy of this software and associated documentation files (the
  6. * "Software"), to deal in the Software without restriction, including
  7. * without limitation the rights to use, copy, modify, merge, publish,
  8. * distribute, sublicense, and/or sell copies of the Software, and to
  9. * permit persons to whom the Software is furnished to do so, subject to
  10. * the following conditions:
  11. *
  12. * The above copyright notice and this permission notice (including the
  13. * next paragraph) shall be included in all copies or substantial
  14. * portions of the Software.
  15. *
  16. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  17. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  18. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  19. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  20. * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  21. * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  22. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  23. * SOFTWARE.
  24. */
  25. #ifndef WAYLAND_CLIENT_CORE_H
  26. #define WAYLAND_CLIENT_CORE_H
  27. #include <stdint.h>
  28. #include "wayland-util.h"
  29. #include "wayland-version.h"
  30. #ifdef __cplusplus
  31. extern "C" {
  32. #endif
  33. /** \class wl_proxy
  34. *
  35. * \brief Represents a protocol object on the client side.
  36. *
  37. * A wl_proxy acts as a client side proxy to an object existing in the
  38. * compositor. The proxy is responsible for converting requests made by the
  39. * clients with \ref wl_proxy_marshal() into Wayland's wire format. Events
  40. * coming from the compositor are also handled by the proxy, which will in
  41. * turn call the handler set with \ref wl_proxy_add_listener().
  42. *
  43. * \note With the exception of function \ref wl_proxy_set_queue(), functions
  44. * accessing a wl_proxy are not normally used by client code. Clients
  45. * should normally use the higher level interface generated by the scanner to
  46. * interact with compositor objects.
  47. *
  48. */
  49. struct wl_proxy;
  50. /** \class wl_display
  51. *
  52. * \brief Represents a connection to the compositor and acts as a proxy to
  53. * the wl_display singleton object.
  54. *
  55. * A wl_display object represents a client connection to a Wayland
  56. * compositor. It is created with either \ref wl_display_connect() or
  57. * \ref wl_display_connect_to_fd(). A connection is terminated using
  58. * \ref wl_display_disconnect().
  59. *
  60. * A wl_display is also used as the \ref wl_proxy for the wl_display
  61. * singleton object on the compositor side.
  62. *
  63. * A wl_display object handles all the data sent from and to the
  64. * compositor. When a \ref wl_proxy marshals a request, it will write its wire
  65. * representation to the display's write buffer. The data is sent to the
  66. * compositor when the client calls \ref wl_display_flush().
  67. *
  68. * Incoming data is handled in two steps: queueing and dispatching. In the
  69. * queue step, the data coming from the display fd is interpreted and
  70. * added to a queue. On the dispatch step, the handler for the incoming
  71. * event set by the client on the corresponding \ref wl_proxy is called.
  72. *
  73. * A wl_display has at least one event queue, called the <em>default
  74. * queue</em>. Clients can create additional event queues with \ref
  75. * wl_display_create_queue() and assign \ref wl_proxy's to it. Events
  76. * occurring in a particular proxy are always queued in its assigned queue.
  77. * A client can ensure that a certain assumption, such as holding a lock
  78. * or running from a given thread, is true when a proxy event handler is
  79. * called by assigning that proxy to an event queue and making sure that
  80. * this queue is only dispatched when the assumption holds.
  81. *
  82. * The default queue is dispatched by calling \ref wl_display_dispatch().
  83. * This will dispatch any events queued on the default queue and attempt
  84. * to read from the display fd if it's empty. Events read are then queued
  85. * on the appropriate queues according to the proxy assignment.
  86. *
  87. * A user created queue is dispatched with \ref wl_display_dispatch_queue().
  88. * This function behaves exactly the same as wl_display_dispatch()
  89. * but it dispatches given queue instead of the default queue.
  90. *
  91. * A real world example of event queue usage is Mesa's implementation of
  92. * eglSwapBuffers() for the Wayland platform. This function might need
  93. * to block until a frame callback is received, but dispatching the default
  94. * queue could cause an event handler on the client to start drawing
  95. * again. This problem is solved using another event queue, so that only
  96. * the events handled by the EGL code are dispatched during the block.
  97. *
  98. * This creates a problem where a thread dispatches a non-default
  99. * queue, reading all the data from the display fd. If the application
  100. * would call \em poll(2) after that it would block, even though there
  101. * might be events queued on the default queue. Those events should be
  102. * dispatched with \ref wl_display_dispatch_pending() or \ref
  103. * wl_display_dispatch_queue_pending() before flushing and blocking.
  104. */
  105. struct wl_display;
  106. /** \class wl_event_queue
  107. *
  108. * \brief A queue for \ref wl_proxy object events.
  109. *
  110. * Event queues allows the events on a display to be handled in a thread-safe
  111. * manner. See \ref wl_display for details.
  112. *
  113. */
  114. struct wl_event_queue;
  115. /** Destroy proxy after marshalling
  116. * @ingroup wl_proxy
  117. */
  118. #define WL_MARSHAL_FLAG_DESTROY (1 << 0)
  119. void
  120. wl_event_queue_destroy(struct wl_event_queue *queue);
  121. struct wl_proxy *
  122. wl_proxy_marshal_flags(struct wl_proxy *proxy, uint32_t opcode,
  123. const struct wl_interface *interface,
  124. uint32_t version,
  125. uint32_t flags, ...);
  126. struct wl_proxy *
  127. wl_proxy_marshal_array_flags(struct wl_proxy *proxy, uint32_t opcode,
  128. const struct wl_interface *interface,
  129. uint32_t version,
  130. uint32_t flags,
  131. union wl_argument *args);
  132. void
  133. wl_proxy_marshal(struct wl_proxy *p, uint32_t opcode, ...);
  134. void
  135. wl_proxy_marshal_array(struct wl_proxy *p, uint32_t opcode,
  136. union wl_argument *args);
  137. struct wl_proxy *
  138. wl_proxy_create(struct wl_proxy *factory,
  139. const struct wl_interface *interface);
  140. void *
  141. wl_proxy_create_wrapper(void *proxy);
  142. void
  143. wl_proxy_wrapper_destroy(void *proxy_wrapper);
  144. struct wl_proxy *
  145. wl_proxy_marshal_constructor(struct wl_proxy *proxy,
  146. uint32_t opcode,
  147. const struct wl_interface *interface,
  148. ...);
  149. struct wl_proxy *
  150. wl_proxy_marshal_constructor_versioned(struct wl_proxy *proxy,
  151. uint32_t opcode,
  152. const struct wl_interface *interface,
  153. uint32_t version,
  154. ...);
  155. struct wl_proxy *
  156. wl_proxy_marshal_array_constructor(struct wl_proxy *proxy,
  157. uint32_t opcode, union wl_argument *args,
  158. const struct wl_interface *interface);
  159. struct wl_proxy *
  160. wl_proxy_marshal_array_constructor_versioned(struct wl_proxy *proxy,
  161. uint32_t opcode,
  162. union wl_argument *args,
  163. const struct wl_interface *interface,
  164. uint32_t version);
  165. void
  166. wl_proxy_destroy(struct wl_proxy *proxy);
  167. int
  168. wl_proxy_add_listener(struct wl_proxy *proxy,
  169. void (**implementation)(void), void *data);
  170. const void *
  171. wl_proxy_get_listener(struct wl_proxy *proxy);
  172. int
  173. wl_proxy_add_dispatcher(struct wl_proxy *proxy,
  174. wl_dispatcher_func_t dispatcher_func,
  175. const void * dispatcher_data, void *data);
  176. void
  177. wl_proxy_set_user_data(struct wl_proxy *proxy, void *user_data);
  178. void *
  179. wl_proxy_get_user_data(struct wl_proxy *proxy);
  180. uint32_t
  181. wl_proxy_get_version(struct wl_proxy *proxy);
  182. uint32_t
  183. wl_proxy_get_id(struct wl_proxy *proxy);
  184. void
  185. wl_proxy_set_tag(struct wl_proxy *proxy,
  186. const char * const *tag);
  187. const char * const *
  188. wl_proxy_get_tag(struct wl_proxy *proxy);
  189. const char *
  190. wl_proxy_get_class(struct wl_proxy *proxy);
  191. void
  192. wl_proxy_set_queue(struct wl_proxy *proxy, struct wl_event_queue *queue);
  193. struct wl_display *
  194. wl_display_connect(const char *name);
  195. struct wl_display *
  196. wl_display_connect_to_fd(int fd);
  197. void
  198. wl_display_disconnect(struct wl_display *display);
  199. int
  200. wl_display_get_fd(struct wl_display *display);
  201. int
  202. wl_display_dispatch(struct wl_display *display);
  203. int
  204. wl_display_dispatch_queue(struct wl_display *display,
  205. struct wl_event_queue *queue);
  206. int
  207. wl_display_dispatch_queue_pending(struct wl_display *display,
  208. struct wl_event_queue *queue);
  209. int
  210. wl_display_dispatch_pending(struct wl_display *display);
  211. int
  212. wl_display_get_error(struct wl_display *display);
  213. uint32_t
  214. wl_display_get_protocol_error(struct wl_display *display,
  215. const struct wl_interface **interface,
  216. uint32_t *id);
  217. int
  218. wl_display_flush(struct wl_display *display);
  219. int
  220. wl_display_roundtrip_queue(struct wl_display *display,
  221. struct wl_event_queue *queue);
  222. int
  223. wl_display_roundtrip(struct wl_display *display);
  224. struct wl_event_queue *
  225. wl_display_create_queue(struct wl_display *display);
  226. int
  227. wl_display_prepare_read_queue(struct wl_display *display,
  228. struct wl_event_queue *queue);
  229. int
  230. wl_display_prepare_read(struct wl_display *display);
  231. void
  232. wl_display_cancel_read(struct wl_display *display);
  233. int
  234. wl_display_read_events(struct wl_display *display);
  235. void
  236. wl_log_set_handler_client(wl_log_func_t handler);
  237. #ifdef __cplusplus
  238. }
  239. #endif
  240. #endif