window: Drop EGLImage surface type
[profile/ivi/weston.git] / clients / window.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 _WINDOW_H_
24 #define _WINDOW_H_
25
26 #include <xkbcommon/xkbcommon.h>
27 #include <wayland-client.h>
28 #include <cairo.h>
29 #include "../shared/config-parser.h"
30
31 struct window;
32 struct widget;
33 struct display;
34 struct input;
35 struct output;
36
37 struct task {
38         void (*run)(struct task *task, uint32_t events);
39         struct wl_list link;
40 };
41
42 struct rectangle {
43         int32_t x;
44         int32_t y;
45         int32_t width;
46         int32_t height;
47 };
48
49 struct display *
50 display_create(int argc, char *argv[]);
51
52 void
53 display_destroy(struct display *display);
54
55 void
56 display_set_user_data(struct display *display, void *data);
57
58 void *
59 display_get_user_data(struct display *display);
60
61 struct wl_display *
62 display_get_display(struct display *display);
63
64 struct wl_compositor *
65 display_get_compositor(struct display *display);
66
67 struct wl_shell *
68 display_get_shell(struct display *display);
69
70 struct output *
71 display_get_output(struct display *display);
72
73 typedef void (*display_output_handler_t)(struct output *output, void *data);
74
75 /*
76  * The output configure handler is called, when a new output is connected
77  * and we know its current mode, or when the current mode changes.
78  * Test and set the output user data in your handler to know, if the
79  * output is new. Note: 'data' in the configure handler is the display
80  * user data.
81  */
82 void
83 display_set_output_configure_handler(struct display *display,
84                                      display_output_handler_t handler);
85
86 struct wl_data_source *
87 display_create_data_source(struct display *display);
88
89 #ifdef EGL_NO_DISPLAY
90 EGLDisplay
91 display_get_egl_display(struct display *d);
92
93 EGLConfig
94 display_get_argb_egl_config(struct display *d);
95
96 int
97 display_acquire_window_surface(struct display *display,
98                                struct window *window,
99                                EGLContext ctx);
100 void
101 display_release_window_surface(struct display *display,
102                                struct window *window);
103
104 #ifdef HAVE_CAIRO_EGL
105 EGLImageKHR
106 display_get_image_for_egl_image_surface(struct display *display,
107                                         cairo_surface_t *surface);
108 #endif
109 #endif
110
111 #define SURFACE_OPAQUE 0x01
112
113 cairo_surface_t *
114 display_create_surface(struct display *display,
115                        struct wl_surface *surface,
116                        struct rectangle *rectangle,
117                        uint32_t flags);
118
119 struct wl_buffer *
120 display_get_buffer_for_surface(struct display *display,
121                                cairo_surface_t *surface);
122
123 cairo_surface_t *
124 display_get_pointer_surface(struct display *display, int pointer,
125                             int *width, int *height,
126                             int *hotspot_x, int *hotspot_y);
127
128 void
129 display_defer(struct display *display, struct task *task);
130
131 void
132 display_watch_fd(struct display *display,
133                  int fd, uint32_t events, struct task *task);
134
135 void
136 display_run(struct display *d);
137
138 void
139 display_exit(struct display *d);
140
141 enum pointer_type {
142         POINTER_BOTTOM_LEFT,
143         POINTER_BOTTOM_RIGHT,
144         POINTER_BOTTOM,
145         POINTER_DRAGGING,
146         POINTER_LEFT_PTR,
147         POINTER_LEFT,
148         POINTER_RIGHT,
149         POINTER_TOP_LEFT,
150         POINTER_TOP_RIGHT,
151         POINTER_TOP,
152         POINTER_IBEAM,
153         POINTER_HAND1,
154 };
155
156 typedef void (*window_key_handler_t)(struct window *window, struct input *input,
157                                      uint32_t time, uint32_t key, uint32_t unicode,
158                                      uint32_t state, void *data);
159
160 typedef void (*window_keyboard_focus_handler_t)(struct window *window,
161                                                 struct input *device, void *data);
162
163 typedef void (*window_data_handler_t)(struct window *window,
164                                       struct input *input, uint32_t time,
165                                       int32_t x, int32_t y,
166                                       const char **types,
167                                       void *data);
168
169 typedef void (*window_drop_handler_t)(struct window *window,
170                                       struct input *input,
171                                       int32_t x, int32_t y, void *data);
172
173 typedef void (*window_close_handler_t)(struct window *window, void *data);
174
175 typedef void (*widget_resize_handler_t)(struct widget *widget,
176                                         int32_t width, int32_t height,
177                                         void *data);
178 typedef void (*widget_redraw_handler_t)(struct widget *widget, void *data);
179
180 typedef int (*widget_enter_handler_t)(struct widget *widget,
181                                       struct input *input, uint32_t time,
182                                       int32_t x, int32_t y, void *data);
183 typedef void (*widget_leave_handler_t)(struct widget *widget,
184                                        struct input *input, void *data);
185 typedef int (*widget_motion_handler_t)(struct widget *widget,
186                                        struct input *input, uint32_t time,
187                                        int32_t x, int32_t y, void *data);
188 typedef void (*widget_button_handler_t)(struct widget *widget,
189                                         struct input *input, uint32_t time,
190                                         int button, int state, void *data);
191
192 struct window *
193 window_create(struct display *display);
194 struct window *
195 window_create_transient(struct display *display, struct window *parent,
196                         int32_t x, int32_t y);
197
198 typedef void (*menu_func_t)(struct window *window, int index, void *data);
199
200 void
201 window_show_menu(struct display *display,
202                  struct input *input, uint32_t time, struct window *parent,
203                  int32_t x, int32_t y,
204                  menu_func_t func, const char **entries, int count);
205
206 void
207 window_show_frame_menu(struct window *window,
208                        struct input *input, uint32_t time);
209
210 void
211 window_destroy(struct window *window);
212
213 struct widget *
214 window_add_widget(struct window *window, void *data);
215
216 typedef void (*data_func_t)(void *data, size_t len,
217                             int32_t x, int32_t y, void *user_data);
218
219 struct display *
220 window_get_display(struct window *window);
221 void
222 window_move(struct window *window, struct input *input, uint32_t time);
223 void
224 window_get_allocation(struct window *window, struct rectangle *allocation);
225 void
226 window_set_transparent(struct window *window, int transparent);
227 void
228 window_schedule_redraw(struct window *window);
229 void
230 window_schedule_resize(struct window *window, int width, int height);
231
232 void
233 window_damage(struct window *window, int32_t x, int32_t y,
234               int32_t width, int32_t height);
235
236 cairo_surface_t *
237 window_get_surface(struct window *window);
238
239 struct wl_surface *
240 window_get_wl_surface(struct window *window);
241
242 struct wl_shell_surface *
243 window_get_wl_shell_surface(struct window *window);
244
245 void
246 window_flush(struct window *window);
247
248 void
249 window_set_surface(struct window *window, cairo_surface_t *surface);
250
251 void
252 window_create_surface(struct window *window);
253
254 enum window_buffer_type {
255         WINDOW_BUFFER_TYPE_EGL_WINDOW,
256         WINDOW_BUFFER_TYPE_SHM,
257 };
258
259 void
260 display_surface_damage(struct display *display, cairo_surface_t *cairo_surface,
261                        int32_t x, int32_t y, int32_t width, int32_t height);
262
263 void
264 window_set_buffer_type(struct window *window, enum window_buffer_type type);
265
266 void
267 window_set_fullscreen(struct window *window, int fullscreen);
268
269 void
270 window_set_maximized(struct window *window, int maximized);
271
272 void
273 window_set_custom(struct window *window);
274
275 void
276 window_set_user_data(struct window *window, void *data);
277
278 void *
279 window_get_user_data(struct window *window);
280
281 void
282 window_set_key_handler(struct window *window,
283                        window_key_handler_t handler);
284
285 void
286 window_set_keyboard_focus_handler(struct window *window,
287                                   window_keyboard_focus_handler_t handler);
288
289 void
290 window_set_data_handler(struct window *window,
291                         window_data_handler_t handler);
292
293 void
294 window_set_drop_handler(struct window *window,
295                         window_drop_handler_t handler);
296
297 void
298 window_set_close_handler(struct window *window,
299                          window_close_handler_t handler);
300
301 void
302 window_set_title(struct window *window, const char *title);
303
304 const char *
305 window_get_title(struct window *window);
306
307 struct widget *
308 widget_add_widget(struct widget *parent, void *data);
309 void
310 widget_destroy(struct widget *widget);
311 void
312 widget_get_allocation(struct widget *widget, struct rectangle *allocation);
313
314 void
315 widget_set_allocation(struct widget *widget,
316                       int32_t x, int32_t y, int32_t width, int32_t height);
317 void
318 widget_set_size(struct widget *widget, int32_t width, int32_t height);
319 void
320 widget_set_transparent(struct widget *widget, int transparent);
321 void
322 widget_schedule_resize(struct widget *widget, int32_t width, int32_t height);
323
324 void *
325 widget_get_user_data(struct widget *widget);
326
327 void
328 widget_set_redraw_handler(struct widget *widget,
329                           widget_redraw_handler_t handler);
330 void
331 widget_set_resize_handler(struct widget *widget,
332                           widget_resize_handler_t handler);
333 void
334 widget_set_enter_handler(struct widget *widget,
335                          widget_enter_handler_t handler);
336 void
337 widget_set_leave_handler(struct widget *widget,
338                          widget_leave_handler_t handler);
339 void
340 widget_set_motion_handler(struct widget *widget,
341                           widget_motion_handler_t handler);
342 void
343 widget_set_button_handler(struct widget *widget,
344                           widget_button_handler_t handler);
345
346 void
347 widget_schedule_redraw(struct widget *widget);
348
349 struct widget *
350 frame_create(struct window *window, void *data);
351
352 void
353 input_set_pointer_image(struct input *input, uint32_t time, int pointer);
354
355 void
356 input_get_position(struct input *input, int32_t *x, int32_t *y);
357
358 uint32_t
359 input_get_modifiers(struct input *input);
360
361 void
362 input_grab(struct input *input, struct widget *widget, uint32_t button);
363
364 void
365 input_ungrab(struct input *input, uint32_t time);
366
367 struct widget *
368 input_get_focus_widget(struct input *input);
369
370 struct wl_input_device *
371 input_get_input_device(struct input *input);
372
373 struct wl_data_device *
374 input_get_data_device(struct input *input);
375
376 void
377 input_set_selection(struct input *input,
378                     struct wl_data_source *source, uint32_t time);
379
380 void
381 input_accept(struct input *input, uint32_t time, const char *type);
382
383
384 void
385 input_receive_drag_data(struct input *input, const char *mime_type,
386                         data_func_t func, void *user_data);
387
388 int
389 input_receive_selection_data(struct input *input, const char *mime_type,
390                              data_func_t func, void *data);
391 int
392 input_receive_selection_data_to_fd(struct input *input,
393                                    const char *mime_type, int fd);
394
395 void
396 output_set_user_data(struct output *output, void *data);
397
398 void *
399 output_get_user_data(struct output *output);
400
401 void
402 output_set_destroy_handler(struct output *output,
403                            display_output_handler_t handler);
404
405 void
406 output_get_allocation(struct output *output, struct rectangle *allocation);
407
408 struct wl_output *
409 output_get_wl_output(struct output *output);
410
411 #endif