AtlatestRepositorysigil-ui

sigil-ui / tree / native / wayland / includewayland-client-core.h

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 */
26#ifndef WAYLAND_CLIENT_CORE_H
27#define WAYLAND_CLIENT_CORE_H
29#include <stdint.h>
30#include "wayland-util.h"
31#include "wayland-version.h"
33#ifdef __cplusplus
34extern "C" {
35#endif
37struct timespec;
39/** \class wl_proxy
40 *
41 * \brief Represents a protocol object on the client side.
42 *
43 * A wl_proxy acts as a client side proxy to an object existing in the
44 * compositor. The proxy is responsible for converting requests made by the
45 * clients with \ref wl_proxy_marshal() into Wayland's wire format. Events
46 * coming from the compositor are also handled by the proxy, which will in
47 * turn call the handler set with \ref wl_proxy_add_listener().
48 *
49 * \note With the exception of function \ref wl_proxy_set_queue(), functions
50 * accessing a wl_proxy are not normally used by client code. Clients
51 * should normally use the higher level interface generated by the scanner to
52 * interact with compositor objects.
53 *
54 */
55struct wl_proxy;
57/** \class wl_display
58 *
59 * \brief Represents a connection to the compositor and acts as a proxy to
60 * the wl_display singleton object.
61 *
62 * A wl_display object represents a client connection to a Wayland
63 * compositor. It is created with either \ref wl_display_connect() or
64 * \ref wl_display_connect_to_fd(). A connection is terminated using
65 * \ref wl_display_disconnect().
66 *
67 * A wl_display is also used as the \ref wl_proxy for the wl_display
68 * singleton object on the compositor side.
69 *
70 * A wl_display object handles all the data sent from and to the
71 * compositor. When a \ref wl_proxy marshals a request, it will write its wire
72 * representation to the display's write buffer. The data is sent to the
73 * compositor when the client calls \ref wl_display_flush().
74 *
75 * Incoming data is handled in two steps: queueing and dispatching. In the
76 * queue step, the data coming from the display fd is interpreted and
77 * added to a queue. On the dispatch step, the handler for the incoming
78 * event set by the client on the corresponding \ref wl_proxy is called.
79 *
80 * A wl_display has at least one event queue, called the <em>default
81 * queue</em>. Clients can create additional event queues with \ref
82 * wl_display_create_queue() and assign \ref wl_proxy's to it. Events
83 * occurring in a particular proxy are always queued in its assigned queue.
84 * A client can ensure that a certain assumption, such as holding a lock
85 * or running from a given thread, is true when a proxy event handler is
86 * called by assigning that proxy to an event queue and making sure that
87 * this queue is only dispatched when the assumption holds.
88 *
89 * The default queue is dispatched by calling \ref wl_display_dispatch().
90 * This will dispatch any events queued on the default queue and attempt
91 * to read from the display fd if it's empty. Events read are then queued
92 * on the appropriate queues according to the proxy assignment.
93 *
94 * A user created queue is dispatched with \ref wl_display_dispatch_queue().
95 * This function behaves exactly the same as wl_display_dispatch()
96 * but it dispatches given queue instead of the default queue.
97 *
98 * A real world example of event queue usage is Mesa's implementation of
99 * eglSwapBuffers() for the Wayland platform. This function might need
100 * to block until a frame callback is received, but dispatching the default
101 * queue could cause an event handler on the client to start drawing
102 * again. This problem is solved using another event queue, so that only
103 * the events handled by the EGL code are dispatched during the block.
104 *
105 * This creates a problem where a thread dispatches a non-default
106 * queue, reading all the data from the display fd. If the application
107 * would call \em poll(2) after that it would block, even though there
108 * might be events queued on the default queue. Those events should be
109 * dispatched with \ref wl_display_dispatch_pending() or \ref
110 * wl_display_dispatch_queue_pending() before flushing and blocking.
111 */
112struct wl_display;
114/** \class wl_event_queue
115 *
116 * \brief A queue for \ref wl_proxy object events.
117 *
118 * Event queues allows the events on a display to be handled in a thread-safe
119 * manner. See \ref wl_display for details.
120 *
121 */
122struct wl_event_queue;
124/** Destroy proxy after marshalling
125 * \relates wl_proxy
126 */
127#define WL_MARSHAL_FLAG_DESTROY (1 << 0)
129void
130wl_event_queue_destroy(struct wl_event_queue *queue);
132struct wl_proxy *
133wl_proxy_marshal_flags(struct wl_proxy *proxy, uint32_t opcode,
134 const struct wl_interface *interface,
135 uint32_t version,
136 uint32_t flags, ...);
138struct wl_proxy *
139wl_proxy_marshal_array_flags(struct wl_proxy *proxy, uint32_t opcode,
140 const struct wl_interface *interface,
141 uint32_t version,
142 uint32_t flags,
143 union wl_argument *args);
145void
146wl_proxy_marshal(struct wl_proxy *p, uint32_t opcode, ...);
148void
149wl_proxy_marshal_array(struct wl_proxy *p, uint32_t opcode,
150 union wl_argument *args);
152struct wl_proxy *
153wl_proxy_create(struct wl_proxy *factory,
154 const struct wl_interface *interface);
156void *
157wl_proxy_create_wrapper(void *proxy);
159void
160wl_proxy_wrapper_destroy(void *proxy_wrapper);
162struct wl_proxy *
163wl_proxy_marshal_constructor(struct wl_proxy *proxy,
164 uint32_t opcode,
165 const struct wl_interface *interface,
166 ...);
168struct wl_proxy *
169wl_proxy_marshal_constructor_versioned(struct wl_proxy *proxy,
170 uint32_t opcode,
171 const struct wl_interface *interface,
172 uint32_t version,
173 ...);
175struct wl_proxy *
176wl_proxy_marshal_array_constructor(struct wl_proxy *proxy,
177 uint32_t opcode, union wl_argument *args,
178 const struct wl_interface *interface);
180struct wl_proxy *
181wl_proxy_marshal_array_constructor_versioned(struct wl_proxy *proxy,
182 uint32_t opcode,
183 union wl_argument *args,
184 const struct wl_interface *interface,
185 uint32_t version);
187void
188wl_proxy_destroy(struct wl_proxy *proxy);
190int
191wl_proxy_add_listener(struct wl_proxy *proxy,
192 void (**implementation)(void), void *data);
194const void *
195wl_proxy_get_listener(struct wl_proxy *proxy);
197int
198wl_proxy_add_dispatcher(struct wl_proxy *proxy,
199 wl_dispatcher_func_t dispatcher_func,
200 const void * dispatcher_data, void *data);
202void
203wl_proxy_set_user_data(struct wl_proxy *proxy, void *user_data);
205void *
206wl_proxy_get_user_data(struct wl_proxy *proxy);
208uint32_t
209wl_proxy_get_version(struct wl_proxy *proxy);
211uint32_t
212wl_proxy_get_id(struct wl_proxy *proxy);
214void
215wl_proxy_set_tag(struct wl_proxy *proxy,
216 const char * const *tag);
218const char * const *
219wl_proxy_get_tag(struct wl_proxy *proxy);
221const char *
222wl_proxy_get_class(struct wl_proxy *proxy);
224const struct wl_interface *
225wl_proxy_get_interface(struct wl_proxy *proxy);
227struct wl_display *
228wl_proxy_get_display(struct wl_proxy *proxy);
230void
231wl_proxy_set_queue(struct wl_proxy *proxy, struct wl_event_queue *queue);
233struct wl_event_queue *
234wl_proxy_get_queue(const struct wl_proxy *proxy);
236const char *
237wl_event_queue_get_name(const struct wl_event_queue *queue);
239struct wl_display *
240wl_display_connect(const char *name);
242struct wl_display *
243wl_display_connect_to_fd(int fd);
245void
246wl_display_disconnect(struct wl_display *display);
248int
249wl_display_get_fd(struct wl_display *display);
251int
252wl_display_dispatch(struct wl_display *display);
254int
255wl_display_dispatch_queue(struct wl_display *display,
256 struct wl_event_queue *queue);
258int
259wl_display_dispatch_timeout(struct wl_display *display,
260 const struct timespec *timeout);
262int
263wl_display_dispatch_queue_timeout(struct wl_display *display,
264 struct wl_event_queue *queue,
265 const struct timespec *timeout);
267int
268wl_display_dispatch_queue_pending(struct wl_display *display,
269 struct wl_event_queue *queue);
271int
272wl_display_dispatch_pending(struct wl_display *display);
274int
275wl_display_get_error(struct wl_display *display);
277uint32_t
278wl_display_get_protocol_error(struct wl_display *display,
279 const struct wl_interface **interface,
280 uint32_t *id);
282int
283wl_display_flush(struct wl_display *display);
285int
286wl_display_roundtrip_queue(struct wl_display *display,
287 struct wl_event_queue *queue);
289int
290wl_display_roundtrip(struct wl_display *display);
292struct wl_event_queue *
293wl_display_create_queue(struct wl_display *display);
295struct wl_event_queue *
296wl_display_create_queue_with_name(struct wl_display *display,
297 const char *name);
299int
300wl_display_prepare_read_queue(struct wl_display *display,
301 struct wl_event_queue *queue);
303int
304wl_display_prepare_read(struct wl_display *display);
306void
307wl_display_cancel_read(struct wl_display *display);
309int
310wl_display_read_events(struct wl_display *display);
312void
313wl_log_set_handler_client(wl_log_func_t handler);
315void
316wl_display_set_max_buffer_size(struct wl_display *display,
317 size_t max_buffer_size);
319#ifdef __cplusplus
321#endif
323#endif