2 * Copyright © 2008 Kristian Høgsberg
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.
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
30 #include <sys/types.h>
32 #include "wayland-util.h"
33 #include "wayland-version.h"
36 WL_EVENT_READABLE = 0x01,
37 WL_EVENT_WRITABLE = 0x02,
38 WL_EVENT_HANGUP = 0x04,
43 struct wl_event_source;
44 typedef int (*wl_event_loop_fd_func_t)(int fd, uint32_t mask, void *data);
45 typedef int (*wl_event_loop_timer_func_t)(void *data);
46 typedef int (*wl_event_loop_signal_func_t)(int signal_number, void *data);
47 typedef void (*wl_event_loop_idle_func_t)(void *data);
49 struct wl_event_loop *wl_event_loop_create(void);
50 void wl_event_loop_destroy(struct wl_event_loop *loop);
51 struct wl_event_source *wl_event_loop_add_fd(struct wl_event_loop *loop,
52 int fd, uint32_t mask,
53 wl_event_loop_fd_func_t func,
55 int wl_event_source_fd_update(struct wl_event_source *source, uint32_t mask);
56 struct wl_event_source *wl_event_loop_add_timer(struct wl_event_loop *loop,
57 wl_event_loop_timer_func_t func,
59 struct wl_event_source *
60 wl_event_loop_add_signal(struct wl_event_loop *loop,
62 wl_event_loop_signal_func_t func,
65 int wl_event_source_timer_update(struct wl_event_source *source,
67 int wl_event_source_remove(struct wl_event_source *source);
68 void wl_event_source_check(struct wl_event_source *source);
71 int wl_event_loop_dispatch(struct wl_event_loop *loop, int timeout);
72 void wl_event_loop_dispatch_idle(struct wl_event_loop *loop);
73 struct wl_event_source *wl_event_loop_add_idle(struct wl_event_loop *loop,
74 wl_event_loop_idle_func_t func,
76 int wl_event_loop_get_fd(struct wl_event_loop *loop);
85 typedef void (*wl_notify_func_t)(struct wl_listener *listener, void *data);
87 struct wl_display *wl_display_create(void);
88 void wl_display_destroy(struct wl_display *display);
89 struct wl_event_loop *wl_display_get_event_loop(struct wl_display *display);
90 int wl_display_add_socket(struct wl_display *display, const char *name);
91 void wl_display_terminate(struct wl_display *display);
92 void wl_display_run(struct wl_display *display);
93 void wl_display_flush_clients(struct wl_display *display);
95 typedef void (*wl_global_bind_func_t)(struct wl_client *client, void *data,
96 uint32_t version, uint32_t id);
98 struct wl_global *wl_display_add_global(struct wl_display *display,
99 const struct wl_interface *interface,
101 wl_global_bind_func_t bind);
103 void wl_display_remove_global(struct wl_display *display,
104 struct wl_global *global);
106 uint32_t wl_display_get_serial(struct wl_display *display);
107 uint32_t wl_display_next_serial(struct wl_display *display);
109 struct wl_client *wl_client_create(struct wl_display *display, int fd);
110 void wl_client_destroy(struct wl_client *client);
111 void wl_client_flush(struct wl_client *client);
112 void wl_client_get_credentials(struct wl_client *client,
113 pid_t *pid, uid_t *uid, gid_t *gid);
115 void wl_client_add_destroy_listener(struct wl_client *client,
116 struct wl_listener *listener);
117 struct wl_listener *wl_client_get_destroy_listener(struct wl_client *client,
118 wl_notify_func_t notify);
121 wl_client_add_object(struct wl_client *client,
122 const struct wl_interface *interface,
123 const void *implementation, uint32_t id, void *data);
125 wl_client_new_object(struct wl_client *client,
126 const struct wl_interface *interface,
127 const void *implementation, void *data);
129 wl_client_get_object(struct wl_client *client, uint32_t id);
133 wl_notify_func_t notify;
137 struct wl_list listener_list;
141 wl_signal_init(struct wl_signal *signal)
143 wl_list_init(&signal->listener_list);
147 wl_signal_add(struct wl_signal *signal, struct wl_listener *listener)
149 wl_list_insert(signal->listener_list.prev, &listener->link);
152 static inline struct wl_listener *
153 wl_signal_get(struct wl_signal *signal, void *notify)
155 struct wl_listener *l;
157 wl_list_for_each(l, &signal->listener_list, link)
158 if (l->notify == notify)
165 wl_signal_emit(struct wl_signal *signal, void *data)
167 struct wl_listener *l, *next;
169 wl_list_for_each_safe(l, next, &signal->listener_list, link)
174 struct wl_object object;
175 void (*destroy)(struct wl_resource *resource);
177 struct wl_signal destroy_signal;
178 struct wl_client *client;
183 struct wl_resource resource;
184 int32_t width, height;
189 struct wl_resource resource;
192 struct wl_pointer_grab;
193 struct wl_pointer_grab_interface {
194 void (*focus)(struct wl_pointer_grab *grab,
195 struct wl_surface *surface,
198 void (*motion)(struct wl_pointer_grab *grab,
202 void (*button)(struct wl_pointer_grab *grab,
203 uint32_t time, uint32_t button, uint32_t state);
206 struct wl_pointer_grab {
207 const struct wl_pointer_grab_interface *interface;
208 struct wl_pointer *pointer;
209 struct wl_surface *focus;
213 struct wl_keyboard_grab;
214 struct wl_keyboard_grab_interface {
215 void (*key)(struct wl_keyboard_grab *grab, uint32_t time,
216 uint32_t key, uint32_t state);
217 void (*modifiers)(struct wl_keyboard_grab *grab, uint32_t serial,
218 uint32_t mods_depressed, uint32_t mods_latched,
219 uint32_t mods_locked, uint32_t group);
222 struct wl_keyboard_grab {
223 const struct wl_keyboard_grab_interface *interface;
224 struct wl_keyboard *keyboard;
225 struct wl_surface *focus;
229 struct wl_data_offer {
230 struct wl_resource resource;
231 struct wl_data_source *source;
232 struct wl_listener source_destroy_listener;
235 struct wl_data_source {
236 struct wl_resource resource;
237 struct wl_array mime_types;
239 void (*accept)(struct wl_data_source *source,
240 uint32_t serial, const char *mime_type);
241 void (*send)(struct wl_data_source *source,
242 const char *mime_type, int32_t fd);
243 void (*cancel)(struct wl_data_source *source);
247 struct wl_seat *seat;
249 struct wl_list resource_list;
250 struct wl_surface *focus;
251 struct wl_resource *focus_resource;
252 struct wl_listener focus_listener;
253 uint32_t focus_serial;
254 struct wl_signal focus_signal;
256 struct wl_pointer_grab *grab;
257 struct wl_pointer_grab default_grab;
258 wl_fixed_t grab_x, grab_y;
259 uint32_t grab_button;
260 uint32_t grab_serial;
264 struct wl_surface *current;
265 wl_fixed_t current_x, current_y;
267 uint32_t button_count;
271 struct wl_seat *seat;
273 struct wl_list resource_list;
274 struct wl_surface *focus;
275 struct wl_resource *focus_resource;
276 struct wl_listener focus_listener;
277 uint32_t focus_serial;
278 struct wl_signal focus_signal;
280 struct wl_keyboard_grab *grab;
281 struct wl_keyboard_grab default_grab;
283 uint32_t grab_serial;
286 struct wl_array keys;
289 uint32_t mods_depressed;
290 uint32_t mods_latched;
291 uint32_t mods_locked;
297 struct wl_seat *seat;
299 struct wl_list resource_list;
300 struct wl_surface *focus;
301 struct wl_resource *focus_resource;
302 struct wl_listener focus_listener;
303 uint32_t focus_serial;
307 struct wl_list base_resource_list;
308 struct wl_signal destroy_signal;
310 struct wl_pointer *pointer;
311 struct wl_keyboard *keyboard;
312 struct wl_touch *touch;
314 uint32_t selection_serial;
315 struct wl_data_source *selection_data_source;
316 struct wl_listener selection_data_source_listener;
317 struct wl_signal selection_signal;
319 struct wl_list drag_resource_list;
320 struct wl_client *drag_client;
321 struct wl_data_source *drag_data_source;
322 struct wl_listener drag_data_source_listener;
323 struct wl_surface *drag_focus;
324 struct wl_resource *drag_focus_resource;
325 struct wl_listener drag_focus_listener;
326 struct wl_pointer_grab drag_grab;
327 struct wl_surface *drag_surface;
328 struct wl_listener drag_icon_listener;
329 struct wl_signal drag_icon_signal;
333 * Post an event to the client's object referred to by 'resource'.
334 * 'opcode' is the event number generated from the protocol XML
335 * description (the event name). The variable arguments are the event
336 * parameters, in the order they appear in the protocol XML specification.
338 * The variable arguments' types are:
339 * - type=uint: uint32_t
340 * - type=int: int32_t
341 * - type=fixed: wl_fixed_t
342 * - type=string: (const char *) to a nil-terminated string
343 * - type=array: (struct wl_array *)
344 * - type=fd: int, that is an open file descriptor
345 * - type=new_id: (struct wl_object *) or (struct wl_resource *)
346 * - type=object: (struct wl_object *) or (struct wl_resource *)
348 void wl_resource_post_event(struct wl_resource *resource,
349 uint32_t opcode, ...);
350 void wl_resource_queue_event(struct wl_resource *resource,
351 uint32_t opcode, ...);
353 /* msg is a printf format string, variable args are its args. */
354 void wl_resource_post_error(struct wl_resource *resource,
355 uint32_t code, const char *msg, ...)
356 __attribute__ ((format (printf, 3, 4)));
357 void wl_resource_post_no_memory(struct wl_resource *resource);
359 #include "wayland-server-protocol.h"
362 wl_client_add_resource(struct wl_client *client,
363 struct wl_resource *resource);
366 wl_client_get_display(struct wl_client *client);
369 wl_resource_destroy(struct wl_resource *resource);
372 wl_seat_init(struct wl_seat *seat);
375 wl_seat_release(struct wl_seat *seat);
378 wl_seat_set_pointer(struct wl_seat *seat, struct wl_pointer *pointer);
380 wl_seat_set_keyboard(struct wl_seat *seat, struct wl_keyboard *keyboard);
382 wl_seat_set_touch(struct wl_seat *seat, struct wl_touch *touch);
385 wl_pointer_init(struct wl_pointer *pointer);
387 wl_pointer_release(struct wl_pointer *pointer);
389 wl_pointer_set_focus(struct wl_pointer *pointer, struct wl_surface *surface,
390 wl_fixed_t sx, wl_fixed_t sy);
392 wl_pointer_start_grab(struct wl_pointer *pointer,
393 struct wl_pointer_grab *grab);
395 wl_pointer_end_grab(struct wl_pointer *pointer);
398 wl_keyboard_init(struct wl_keyboard *keyboard);
400 wl_keyboard_release(struct wl_keyboard *keyboard);
402 wl_keyboard_set_focus(struct wl_keyboard *keyboard, struct wl_surface *surface);
404 wl_keyboard_start_grab(struct wl_keyboard *device,
405 struct wl_keyboard_grab *grab);
407 wl_keyboard_end_grab(struct wl_keyboard *keyboard);
410 wl_touch_init(struct wl_touch *touch);
412 wl_touch_release(struct wl_touch *touch);
415 wl_data_device_set_keyboard_focus(struct wl_seat *seat);
418 wl_data_device_manager_init(struct wl_display *display);
422 wl_seat_set_selection(struct wl_seat *seat,
423 struct wl_data_source *source, uint32_t serial);
427 wl_shm_buffer_get_data(struct wl_buffer *buffer);
430 wl_shm_buffer_get_stride(struct wl_buffer *buffer);
433 wl_shm_buffer_get_format(struct wl_buffer *buffer);
436 wl_shm_buffer_get_width(struct wl_buffer *buffer);
439 wl_shm_buffer_get_height(struct wl_buffer *buffer);
442 wl_buffer_is_shm(struct wl_buffer *buffer);
445 wl_display_init_shm(struct wl_display *display);
448 wl_shm_buffer_create(struct wl_client *client,
449 uint32_t id, int32_t width, int32_t height,
450 int32_t stride, uint32_t format);
452 void wl_log_set_handler_server(wl_log_func_t handler);