blob: bac9c5b6e197e3e4d4a997c8e1930df2440224ca [file] [log] [blame]
Kristian Høgsbergffd710e2008-12-02 15:15:01 -05001/*
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
Kristian Høgsberg97f1ebe2008-09-30 09:46:10 -040023#ifndef WAYLAND_H
24#define WAYLAND_H
25
26#include <stdint.h>
Kristian Høgsberg1e4b86a2008-11-23 23:41:08 -050027#include "wayland-util.h"
Kristian Høgsbergb7a01922008-11-08 15:39:41 -050028
Kristian Høgsberg97f1ebe2008-09-30 09:46:10 -040029enum {
30 WL_EVENT_READABLE = 0x01,
31 WL_EVENT_WRITEABLE = 0x02
32};
33
34struct wl_event_loop;
35struct wl_event_source;
Kristian Høgsberg5ebb3172008-10-11 19:21:35 -040036typedef void (*wl_event_loop_fd_func_t)(int fd, uint32_t mask, void *data);
Kristian Høgsberg4a298902008-11-28 18:35:25 -050037typedef void (*wl_event_loop_timer_func_t)(void *data);
Kristian Høgsberg5ebb3172008-10-11 19:21:35 -040038typedef void (*wl_event_loop_idle_func_t)(void *data);
Kristian Høgsberg97f1ebe2008-09-30 09:46:10 -040039
40struct wl_event_loop *wl_event_loop_create(void);
41void wl_event_loop_destroy(struct wl_event_loop *loop);
42struct wl_event_source *wl_event_loop_add_fd(struct wl_event_loop *loop,
43 int fd, uint32_t mask,
Kristian Høgsberg5ebb3172008-10-11 19:21:35 -040044 wl_event_loop_fd_func_t func,
Kristian Høgsberg97f1ebe2008-09-30 09:46:10 -040045 void *data);
Kristian Høgsberg4a298902008-11-28 18:35:25 -050046int wl_event_source_fd_update(struct wl_event_source *source, uint32_t mask);
47struct wl_event_source *wl_event_loop_add_timer(struct wl_event_loop *loop,
48 wl_event_loop_timer_func_t func,
49 void *data);
50int wl_event_source_timer_update(struct wl_event_source *source,
51 int ms_delay);
52int wl_event_source_remove(struct wl_event_source *source);
Kristian Høgsberga67a71a2008-10-07 10:10:36 -040053
Kristian Høgsberg4a298902008-11-28 18:35:25 -050054
Kristian Høgsberg97f1ebe2008-09-30 09:46:10 -040055int wl_event_loop_wait(struct wl_event_loop *loop);
Kristian Høgsberg5ebb3172008-10-11 19:21:35 -040056struct wl_event_source *wl_event_loop_add_idle(struct wl_event_loop *loop,
57 wl_event_loop_idle_func_t func,
58 void *data);
Kristian Høgsberg97f1ebe2008-09-30 09:46:10 -040059
Kristian Høgsberg97f1ebe2008-09-30 09:46:10 -040060struct wl_client;
61
62enum {
63 WL_ARGUMENT_UINT32,
64 WL_ARGUMENT_STRING,
65 WL_ARGUMENT_OBJECT,
66 WL_ARGUMENT_NEW_ID
67};
68
69struct wl_argument {
70 uint32_t type;
71 void *data;
72};
73
74struct wl_method {
75 const char *name;
Kristian Høgsberg87e0a382008-12-05 10:38:42 -050076 const char *signature;
77 const void **types;
Kristian Høgsberg97f1ebe2008-09-30 09:46:10 -040078};
79
Kristian Høgsberga67a71a2008-10-07 10:10:36 -040080struct wl_event {
81 const char *name;
Kristian Høgsberg87e0a382008-12-05 10:38:42 -050082 const char *signature;
Kristian Høgsberga67a71a2008-10-07 10:10:36 -040083};
84
Kristian Høgsberg97f1ebe2008-09-30 09:46:10 -040085struct wl_interface {
86 const char *name;
87 int version;
88 int method_count;
89 const struct wl_method *methods;
Kristian Høgsberga67a71a2008-10-07 10:10:36 -040090 int event_count;
91 const struct wl_event *events;
Kristian Høgsberg97f1ebe2008-09-30 09:46:10 -040092};
93
94struct wl_object {
95 const struct wl_interface *interface;
Kristian Høgsbergd2412e22008-12-15 20:35:24 -050096 void (**implementation)(void);
Kristian Høgsberg97f1ebe2008-09-30 09:46:10 -040097 uint32_t id;
98};
99
Kristian Høgsberga67a71a2008-10-07 10:10:36 -0400100struct wl_display;
Kristian Høgsberg5ee1a602008-12-11 23:18:45 -0500101struct wl_input_device;
Kristian Høgsberga67a71a2008-10-07 10:10:36 -0400102
Kristian Høgsberg05eff512008-10-07 10:10:36 -0400103struct wl_map {
104 int32_t x, y, width, height;
105};
106
Kristian Høgsberg122912c2008-12-05 11:13:50 -0500107struct wl_display *wl_display_create(void);
108struct wl_event_loop *wl_display_get_event_loop(struct wl_display *display);
Kristian Høgsbergdc0f3552008-12-07 15:22:22 -0500109int wl_display_add_socket(struct wl_display *display, const char *name, size_t name_size);
Kristian Høgsberg122912c2008-12-05 11:13:50 -0500110void wl_display_run(struct wl_display *display);
111
Kristian Høgsberg1e4b86a2008-11-23 23:41:08 -0500112void
113wl_display_add_object(struct wl_display *display, struct wl_object *object);
Kristian Høgsberg14fcff72008-11-23 19:10:23 -0500114int
115wl_display_add_global(struct wl_display *display, struct wl_object *object);
Kristian Høgsberg1e4b86a2008-11-23 23:41:08 -0500116
Kristian Høgsberg5ee1a602008-12-11 23:18:45 -0500117const struct wl_interface *
118wl_input_device_get_interface(void);
119
Kristian Høgsberg5a75c902008-12-10 13:16:50 -0500120#define WL_INPUT_MOTION 0
121#define WL_INPUT_BUTTON 1
122#define WL_INPUT_KEY 2
123
Kristian Høgsbergd2412e22008-12-15 20:35:24 -0500124struct wl_compositor {
125 struct wl_object base;
126};
127
128struct wl_surface {
129 struct wl_object base;
130 struct wl_client *client;
131};
132
133struct wl_compositor_interface {
134 void (*create_surface)(struct wl_client *client,
135 struct wl_compositor *compositor, uint32_t id);
136 void (*commit)(struct wl_client *client,
137 struct wl_compositor *compositor, uint32_t key);
138};
139
140struct wl_surface_interface {
141 void (*destroy)(struct wl_client *client,
142 struct wl_surface *surface);
143 void (*attach)(struct wl_client *client,
144 struct wl_surface *surface, uint32_t name,
Kristian Høgsbergde31d5c2008-12-18 17:55:33 -0500145 uint32_t width, uint32_t height, uint32_t stride,
146 struct wl_object *visual);
Kristian Høgsbergd2412e22008-12-15 20:35:24 -0500147 void (*map)(struct wl_client *client,
148 struct wl_surface *surface,
149 int32_t x, int32_t y, int32_t width, int32_t height);
150 void (*copy)(struct wl_client *client, struct wl_surface *surface,
151 int32_t dst_x, int32_t dst_y, uint32_t name, uint32_t stride,
152 int32_t x, int32_t y, int32_t width, int32_t height);
153 void (*damage)(struct wl_client *client, struct wl_surface *surface,
154 int32_t x, int32_t y, int32_t width, int32_t height);
155};
156
Kristian Høgsberg715a0812008-12-10 10:42:04 -0500157void
Kristian Høgsberg5a75c902008-12-10 13:16:50 -0500158wl_surface_post_event(struct wl_surface *surface,
159 struct wl_object *sender,
160 uint32_t event, ...);
Kristian Høgsbergf9bc7952008-11-02 10:12:29 -0500161
Kristian Høgsbergd2412e22008-12-15 20:35:24 -0500162int
163wl_display_set_compositor(struct wl_display *display,
164 struct wl_compositor *compositor,
165 const struct wl_compositor_interface *implementation);
Kristian Høgsberga67a71a2008-10-07 10:10:36 -0400166
Kristian Høgsbergd2412e22008-12-15 20:35:24 -0500167int
168wl_client_add_surface(struct wl_client *client,
169 struct wl_surface *surface,
170 const struct wl_surface_interface *implementation,
171 uint32_t id);
Kristian Høgsberga67a71a2008-10-07 10:10:36 -0400172
Kristian Høgsbergd2412e22008-12-15 20:35:24 -0500173void
174wl_client_send_acknowledge(struct wl_client *client,
175 struct wl_compositor *compositor,
176 uint32_t key, uint32_t frame);
177
178void
179wl_display_post_frame(struct wl_display *display,
180 struct wl_compositor *compositor,
181 uint32_t frame, uint32_t msecs);
Kristian Høgsberga67a71a2008-10-07 10:10:36 -0400182
Kristian Høgsberg97f1ebe2008-09-30 09:46:10 -0400183#endif