Rename source subdir from wayland to src
[profile/ivi/wayland.git] / src / wayland-server.h
1 /*
2  * Copyright © 2008 Kristian Høgsberg
3  *
4  * Permission to use, copy, modify, distribute, and sell this software and its
5  * documentation for any purpose is hereby granted without fee, provided that
6  * the above copyright notice appear in all copies and that both that copyright
7  * notice and this permission notice appear in supporting documentation, and
8  * that the name of the copyright holders not be used in advertising or
9  * publicity pertaining to distribution of the software without specific,
10  * written prior permission.  The copyright holders make no representations
11  * about the suitability of this software for any purpose.  It is provided "as
12  * is" without express or implied warranty.
13  *
14  * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
15  * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
16  * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
17  * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
18  * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
19  * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
20  * OF THIS SOFTWARE.
21  */
22
23 #ifndef WAYLAND_H
24 #define WAYLAND_H
25
26 #ifdef  __cplusplus
27 extern "C" {
28 #endif
29
30 #include <stdint.h>
31 #include "wayland-util.h"
32 #include "wayland-server-protocol.h"
33
34 enum {
35         WL_EVENT_READABLE = 0x01,
36         WL_EVENT_WRITEABLE = 0x02
37 };
38
39 struct wl_event_loop;
40 struct wl_event_source;
41 typedef int (*wl_event_loop_fd_func_t)(int fd, uint32_t mask, void *data);
42 typedef int (*wl_event_loop_timer_func_t)(void *data);
43 typedef int (*wl_event_loop_signal_func_t)(int signal_number, void *data);
44 typedef void (*wl_event_loop_idle_func_t)(void *data);
45
46 struct wl_event_loop *wl_event_loop_create(void);
47 void wl_event_loop_destroy(struct wl_event_loop *loop);
48 struct wl_event_source *wl_event_loop_add_fd(struct wl_event_loop *loop,
49                                              int fd, uint32_t mask,
50                                              wl_event_loop_fd_func_t func,
51                                              void *data);
52 int wl_event_source_fd_update(struct wl_event_source *source, uint32_t mask);
53 struct wl_event_source *wl_event_loop_add_timer(struct wl_event_loop *loop,
54                                                 wl_event_loop_timer_func_t func,
55                                                 void *data);
56 struct wl_event_source *
57 wl_event_loop_add_signal(struct wl_event_loop *loop,
58                         int signal_number,
59                         wl_event_loop_signal_func_t func,
60                         void *data);
61
62 int wl_event_source_timer_update(struct wl_event_source *source,
63                                  int ms_delay);
64 int wl_event_source_remove(struct wl_event_source *source);
65 void wl_event_source_check(struct wl_event_source *source);
66
67
68 int wl_event_loop_dispatch(struct wl_event_loop *loop, int timeout);
69 struct wl_event_source *wl_event_loop_add_idle(struct wl_event_loop *loop,
70                                                wl_event_loop_idle_func_t func,
71                                                void *data);
72 int wl_event_loop_get_fd(struct wl_event_loop *loop);
73
74 struct wl_client;
75 struct wl_display;
76 struct wl_input_device;
77
78 struct wl_display *wl_display_create(void);
79 void wl_display_destroy(struct wl_display *display);
80 struct wl_event_loop *wl_display_get_event_loop(struct wl_display *display);
81 int wl_display_add_socket(struct wl_display *display, const char *name);
82 void wl_display_terminate(struct wl_display *display);
83 void wl_display_run(struct wl_display *display);
84
85 void wl_display_add_object(struct wl_display *display,
86                            struct wl_object *object);
87
88 typedef void (*wl_global_bind_func_t)(struct wl_client *client,
89                                       struct wl_object *global,
90                                       uint32_t version);
91
92 int wl_display_add_global(struct wl_display *display,
93                           struct wl_object *object,
94                           wl_global_bind_func_t func);
95
96 int wl_display_remove_global(struct wl_display *display,
97                              struct wl_object *object);
98
99 struct wl_client *wl_client_create(struct wl_display *display, int fd);
100 void wl_client_destroy(struct wl_client *client);
101 void wl_client_post_error(struct wl_client *client, struct wl_object *object,
102                           uint32_t code, const char *msg, ...);
103 void wl_client_post_no_memory(struct wl_client *client);
104 void wl_client_post_global(struct wl_client *client, struct wl_object *object);
105 void wl_client_flush(struct wl_client *client);
106
107 struct wl_visual {
108         struct wl_object object;
109 };
110
111 struct wl_shm_callbacks {
112         void (*buffer_created)(struct wl_buffer *buffer);
113
114         void (*buffer_damaged)(struct wl_buffer *buffer,
115                               int32_t x, int32_t y,
116                               int32_t width, int32_t height);
117
118         void (*buffer_destroyed)(struct wl_buffer *buffer);
119 };
120
121 struct wl_compositor {
122         struct wl_object object;
123         struct wl_visual argb_visual;
124         struct wl_visual premultiplied_argb_visual;
125         struct wl_visual rgb_visual;
126 };
127
128 struct wl_resource {
129         struct wl_object object;
130         void (*destroy)(struct wl_resource *resource,
131                         struct wl_client *client);
132         struct wl_list link;
133         struct wl_list destroy_listener_list;
134 };
135
136 struct wl_buffer {
137         struct wl_resource resource;
138         struct wl_client *client;
139         struct wl_visual *visual;
140         int32_t width, height;
141         uint32_t busy_count;
142         void *user_data;
143 };
144
145 struct wl_listener {
146         struct wl_list link;
147         void (*func)(struct wl_listener *listener,
148                      struct wl_resource *resource, uint32_t time);
149 };
150
151 struct wl_surface {
152         struct wl_resource resource;
153         struct wl_client *client;
154 };
155
156 struct wl_grab;
157 struct wl_grab_interface {
158         void (*motion)(struct wl_grab *grab,
159                        uint32_t time, int32_t x, int32_t y);
160         void (*button)(struct wl_grab *grab,
161                        uint32_t time, int32_t button, int32_t state);
162         void (*end)(struct wl_grab *grab, uint32_t time);
163 };
164
165 struct wl_grab {
166         const struct wl_grab_interface *interface;
167         struct wl_input_device *input_device;
168 };
169
170 struct wl_input_device {
171         struct wl_object object;
172         struct wl_compositor *compositor;
173         struct wl_surface *pointer_focus;
174         struct wl_surface *keyboard_focus;
175         struct wl_array keys;
176         uint32_t pointer_focus_time;
177         uint32_t keyboard_focus_time;
178         struct wl_listener pointer_focus_listener;
179         struct wl_listener keyboard_focus_listener;
180
181         int32_t x, y;
182         struct wl_grab *grab;
183         struct wl_grab motion_grab;
184         uint32_t grab_time;
185         int32_t grab_x, grab_y;
186         uint32_t grab_button;
187         struct wl_listener grab_listener;
188 };
189
190 struct wl_drag_offer {
191         struct wl_object object;
192 };
193
194 struct wl_drag {
195         struct wl_resource resource;
196         struct wl_grab grab;
197         struct wl_drag_offer drag_offer;
198         struct wl_surface *source;
199         struct wl_surface *drag_focus;
200         struct wl_client *target;
201         int32_t x, y, sx, sy;
202         struct wl_array types;
203         const char *type;
204         uint32_t pointer_focus_time;
205         struct wl_listener drag_focus_listener;
206 };
207
208 struct wl_selection_offer {
209         struct wl_object object;
210 };
211
212 struct wl_selection {
213         struct wl_resource resource;
214         struct wl_client *client;
215         struct wl_input_device *input_device;
216         struct wl_selection_offer selection_offer;
217         struct wl_surface *selection_focus;
218         struct wl_client *target;
219         struct wl_array types;
220         struct wl_listener selection_focus_listener;
221 };
222
223 void
224 wl_client_post_event(struct wl_client *client,
225                       struct wl_object *sender,
226                       uint32_t event, ...);
227
228 int
229 wl_display_set_compositor(struct wl_display *display,
230                           struct wl_compositor *compositor,
231                           const struct wl_compositor_interface *implementation);
232
233 void
234 wl_display_post_frame(struct wl_display *display, struct wl_surface *surface,
235                       uint32_t msecs);
236
237 void
238 wl_client_add_resource(struct wl_client *client,
239                        struct wl_resource *resource);
240
241 struct wl_display *
242 wl_client_get_display(struct wl_client *client);
243
244 void
245 wl_resource_destroy(struct wl_resource *resource,
246                     struct wl_client *client, uint32_t time);
247
248 void
249 wl_input_device_init(struct wl_input_device *device,
250                      struct wl_compositor *compositor);
251
252 void
253 wl_input_device_set_pointer_focus(struct wl_input_device *device,
254                                   struct wl_surface *surface,
255                                   uint32_t time,
256                                   int32_t x, int32_t y,
257                                   int32_t sx, int32_t sy);
258
259 void
260 wl_input_device_set_keyboard_focus(struct wl_input_device *device,
261                                    struct wl_surface *surface,
262                                    uint32_t time);
263
264 void
265 wl_input_device_end_grab(struct wl_input_device *device, uint32_t time);
266 void
267 wl_input_device_start_grab(struct wl_input_device *device,
268                            struct wl_grab *grab,
269                            uint32_t button, uint32_t time);
270 int
271 wl_input_device_update_grab(struct wl_input_device *device,
272                             struct wl_grab *grab,
273                             struct wl_surface *surface, uint32_t time);
274
275 struct wl_shm;
276
277 void *
278 wl_shm_buffer_get_data(struct wl_buffer *buffer);
279
280 int32_t
281 wl_shm_buffer_get_stride(struct wl_buffer *buffer);
282
283 struct wl_buffer *
284 wl_shm_buffer_create(struct wl_shm *shm, int width, int height,
285                      int stride, struct wl_visual *visual,
286                      void *data);
287
288 int
289 wl_buffer_is_shm(struct wl_buffer *buffer);
290
291 struct wl_shm *
292 wl_shm_init(struct wl_display *display,
293             const struct wl_shm_callbacks *callbacks);
294
295 void
296 wl_shm_finish(struct wl_shm *shm);
297
298 int
299 wl_compositor_init(struct wl_compositor *compositor,
300                    const struct wl_compositor_interface *interface,
301                    struct wl_display *display);
302
303 #ifdef  __cplusplus
304 }
305 #endif
306
307 #endif