server: wl_display and wl_input_device are no longer resources
[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, void *data,
89                                       uint32_t version, uint32_t id);
90
91 struct wl_global *wl_display_add_global(struct wl_display *display,
92                                         const struct wl_interface *interface,
93                                         void *data,
94                                         wl_global_bind_func_t bind);
95
96 void wl_display_remove_global(struct wl_display *display,
97                               struct wl_global *global);
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_flush(struct wl_client *client);
105
106 struct wl_resource *
107 wl_client_add_object(struct wl_client *client,
108                      const struct wl_interface *interface,
109                      const void *implementation, uint32_t id, void *data);
110
111 struct wl_resource {
112         struct wl_object object;
113         void (*destroy)(struct wl_resource *resource);
114         struct wl_list link;
115         struct wl_list destroy_listener_list;
116         struct wl_client *client;
117         void *data;
118 };
119
120 struct wl_visual {
121         struct wl_object object;
122         uint32_t name;
123 };
124
125 struct wl_shm_callbacks {
126         void (*buffer_created)(struct wl_buffer *buffer);
127
128         void (*buffer_damaged)(struct wl_buffer *buffer,
129                               int32_t x, int32_t y,
130                               int32_t width, int32_t height);
131
132         void (*buffer_destroyed)(struct wl_buffer *buffer);
133 };
134
135 struct wl_compositor {
136         const struct wl_compositor_interface *interface;
137         struct wl_visual argb_visual;
138         struct wl_visual premultiplied_argb_visual;
139         struct wl_visual rgb_visual;
140 };
141
142 struct wl_buffer {
143         struct wl_resource resource;
144         struct wl_visual *visual;
145         int32_t width, height;
146         uint32_t busy_count;
147         void *user_data;
148 };
149
150 struct wl_listener {
151         struct wl_list link;
152         void (*func)(struct wl_listener *listener,
153                      struct wl_resource *resource, uint32_t time);
154 };
155
156 struct wl_surface {
157         struct wl_resource resource;
158 };
159
160 struct wl_grab;
161 struct wl_grab_interface {
162         void (*motion)(struct wl_grab *grab,
163                        uint32_t time, int32_t x, int32_t y);
164         void (*button)(struct wl_grab *grab,
165                        uint32_t time, int32_t button, int32_t state);
166         void (*end)(struct wl_grab *grab, uint32_t time);
167 };
168
169 struct wl_grab {
170         const struct wl_grab_interface *interface;
171         struct wl_input_device *input_device;
172 };
173
174 struct wl_input_device {
175         struct wl_list resource_list;
176         struct wl_compositor *compositor;
177         struct wl_resource *pointer_focus_resource;
178         struct wl_surface *pointer_focus;
179         struct wl_resource *keyboard_focus_resource;
180         struct wl_surface *keyboard_focus;
181         struct wl_array keys;
182         uint32_t pointer_focus_time;
183         uint32_t keyboard_focus_time;
184         struct wl_listener pointer_focus_listener;
185         struct wl_listener keyboard_focus_listener;
186
187         int32_t x, y;
188         struct wl_grab *grab;
189         struct wl_grab motion_grab;
190         uint32_t grab_time;
191         int32_t grab_x, grab_y;
192         uint32_t grab_button;
193         struct wl_listener grab_listener;
194 };
195
196 struct wl_drag_offer {
197         struct wl_resource resource;
198 };
199
200 struct wl_drag {
201         struct wl_resource resource;
202         struct wl_grab grab;
203         struct wl_drag_offer drag_offer;
204         struct wl_surface *source;
205         struct wl_surface *drag_focus;
206         struct wl_client *target;
207         int32_t x, y, sx, sy;
208         struct wl_array types;
209         const char *type;
210         uint32_t pointer_focus_time;
211         struct wl_listener drag_focus_listener;
212 };
213
214 struct wl_selection_offer {
215         struct wl_resource resource;
216 };
217
218 struct wl_selection {
219         struct wl_resource resource;
220         struct wl_client *client;
221         struct wl_input_device *input_device;
222         struct wl_selection_offer selection_offer;
223         struct wl_surface *selection_focus;
224         struct wl_client *target;
225         struct wl_array types;
226         struct wl_listener selection_focus_listener;
227 };
228
229 void
230 wl_resource_post_event(struct wl_resource *resource, uint32_t opcode, ...);
231
232 int
233 wl_display_set_compositor(struct wl_display *display,
234                           struct wl_compositor *compositor,
235                           const struct wl_compositor_interface *implementation);
236
237 void
238 wl_display_post_frame(struct wl_display *display, struct wl_surface *surface,
239                       uint32_t msecs);
240
241 void
242 wl_client_add_resource(struct wl_client *client,
243                        struct wl_resource *resource);
244
245 struct wl_display *
246 wl_client_get_display(struct wl_client *client);
247
248 void
249 wl_resource_destroy(struct wl_resource *resource, uint32_t time);
250
251 void
252 wl_input_device_init(struct wl_input_device *device,
253                      struct wl_compositor *compositor);
254
255 void
256 wl_input_device_set_pointer_focus(struct wl_input_device *device,
257                                   struct wl_surface *surface,
258                                   uint32_t time,
259                                   int32_t x, int32_t y,
260                                   int32_t sx, int32_t sy);
261
262 void
263 wl_input_device_set_keyboard_focus(struct wl_input_device *device,
264                                    struct wl_surface *surface,
265                                    uint32_t time);
266
267 void
268 wl_input_device_end_grab(struct wl_input_device *device, uint32_t time);
269 void
270 wl_input_device_start_grab(struct wl_input_device *device,
271                            struct wl_grab *grab,
272                            uint32_t button, uint32_t time);
273 int
274 wl_input_device_update_grab(struct wl_input_device *device,
275                             struct wl_grab *grab,
276                             struct wl_surface *surface, uint32_t time);
277
278 struct wl_shm;
279
280 void *
281 wl_shm_buffer_get_data(struct wl_buffer *buffer);
282
283 int32_t
284 wl_shm_buffer_get_stride(struct wl_buffer *buffer);
285
286 struct wl_buffer *
287 wl_shm_buffer_create(struct wl_shm *shm, int width, int height,
288                      int stride, struct wl_visual *visual,
289                      void *data);
290
291 int
292 wl_buffer_is_shm(struct wl_buffer *buffer);
293
294 struct wl_shm *
295 wl_shm_init(struct wl_display *display,
296             const struct wl_shm_callbacks *callbacks);
297
298 void
299 wl_shm_finish(struct wl_shm *shm);
300
301 int
302 wl_compositor_init(struct wl_compositor *compositor,
303                    const struct wl_compositor_interface *interface,
304                    struct wl_display *display);
305
306 #ifdef  __cplusplus
307 }
308 #endif
309
310 #endif