window: create sub-surfaces
[platform/upstream/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 #include "subsurface-client-protocol.h"
31
32 #define ARRAY_LENGTH(a) (sizeof (a) / sizeof (a)[0])
33
34 #define container_of(ptr, type, member) ({                              \
35         const __typeof__( ((type *)0)->member ) *__mptr = (ptr);        \
36         (type *)( (char *)__mptr - offsetof(type,member) );})
37
38 struct window;
39 struct widget;
40 struct display;
41 struct input;
42 struct output;
43
44 struct task {
45         void (*run)(struct task *task, uint32_t events);
46         struct wl_list link;
47 };
48
49 struct rectangle {
50         int32_t x;
51         int32_t y;
52         int32_t width;
53         int32_t height;
54 };
55
56 struct display *
57 display_create(int *argc, char *argv[]);
58
59 void
60 display_destroy(struct display *display);
61
62 void
63 display_set_user_data(struct display *display, void *data);
64
65 void *
66 display_get_user_data(struct display *display);
67
68 struct wl_display *
69 display_get_display(struct display *display);
70
71 struct wl_compositor *
72 display_get_compositor(struct display *display);
73
74 struct wl_shell *
75 display_get_shell(struct display *display);
76
77 struct output *
78 display_get_output(struct display *display);
79
80 uint32_t
81 display_get_serial(struct display *display);
82
83 typedef void (*display_global_handler_t)(struct display *display,
84                                          uint32_t name,
85                                          const char *interface,
86                                          uint32_t version, void *data);
87
88 void
89 display_set_global_handler(struct display *display,
90                            display_global_handler_t handler);
91 void *
92 display_bind(struct display *display, uint32_t name,
93              const struct wl_interface *interface, uint32_t version);
94
95 typedef void (*display_output_handler_t)(struct output *output, void *data);
96
97 /*
98  * The output configure handler is called, when a new output is connected
99  * and we know its current mode, or when the current mode changes.
100  * Test and set the output user data in your handler to know, if the
101  * output is new. Note: 'data' in the configure handler is the display
102  * user data.
103  */
104 void
105 display_set_output_configure_handler(struct display *display,
106                                      display_output_handler_t handler);
107
108 struct wl_data_source *
109 display_create_data_source(struct display *display);
110
111 #ifdef EGL_NO_DISPLAY
112 EGLDisplay
113 display_get_egl_display(struct display *d);
114
115 EGLConfig
116 display_get_argb_egl_config(struct display *d);
117
118 int
119 display_acquire_window_surface(struct display *display,
120                                struct window *window,
121                                EGLContext ctx);
122 void
123 display_release_window_surface(struct display *display,
124                                struct window *window);
125 #endif
126
127 #define SURFACE_OPAQUE 0x01
128 #define SURFACE_SHM    0x02
129
130 #define SURFACE_HINT_RESIZE 0x10
131
132 cairo_surface_t *
133 display_create_surface(struct display *display,
134                        struct wl_surface *surface,
135                        struct rectangle *rectangle,
136                        uint32_t flags);
137
138 struct wl_buffer *
139 display_get_buffer_for_surface(struct display *display,
140                                cairo_surface_t *surface);
141
142 struct wl_cursor_image *
143 display_get_pointer_image(struct display *display, int pointer);
144
145 void
146 display_defer(struct display *display, struct task *task);
147
148 void
149 display_watch_fd(struct display *display,
150                  int fd, uint32_t events, struct task *task);
151
152 void
153 display_unwatch_fd(struct display *display, int fd);
154
155 void
156 display_run(struct display *d);
157
158 void
159 display_exit(struct display *d);
160
161 enum cursor_type {
162         CURSOR_BOTTOM_LEFT,
163         CURSOR_BOTTOM_RIGHT,
164         CURSOR_BOTTOM,
165         CURSOR_DRAGGING,
166         CURSOR_LEFT_PTR,
167         CURSOR_LEFT,
168         CURSOR_RIGHT,
169         CURSOR_TOP_LEFT,
170         CURSOR_TOP_RIGHT,
171         CURSOR_TOP,
172         CURSOR_IBEAM,
173         CURSOR_HAND1,
174         CURSOR_WATCH,
175
176         CURSOR_BLANK
177 };
178
179 typedef void (*window_key_handler_t)(struct window *window, struct input *input,
180                                      uint32_t time, uint32_t key, uint32_t unicode,
181                                      enum wl_keyboard_key_state state, void *data);
182
183 typedef void (*window_keyboard_focus_handler_t)(struct window *window,
184                                                 struct input *device, void *data);
185
186 typedef void (*window_data_handler_t)(struct window *window,
187                                       struct input *input,
188                                       float x, float y,
189                                       const char **types,
190                                       void *data);
191
192 typedef void (*window_drop_handler_t)(struct window *window,
193                                       struct input *input,
194                                       int32_t x, int32_t y, void *data);
195
196 typedef void (*window_close_handler_t)(struct window *window, void *data);
197 typedef void (*window_fullscreen_handler_t)(struct window *window, void *data);
198
199 typedef void (*window_output_handler_t)(struct window *window, struct output *output,
200                                         int enter, void *data);
201
202 typedef void (*widget_resize_handler_t)(struct widget *widget,
203                                         int32_t width, int32_t height,
204                                         void *data);
205 typedef void (*widget_redraw_handler_t)(struct widget *widget, void *data);
206
207 typedef int (*widget_enter_handler_t)(struct widget *widget,
208                                       struct input *input,
209                                       float x, float y, void *data);
210 typedef void (*widget_leave_handler_t)(struct widget *widget,
211                                        struct input *input, void *data);
212 typedef int (*widget_motion_handler_t)(struct widget *widget,
213                                        struct input *input, uint32_t time,
214                                        float x, float y, void *data);
215 typedef void (*widget_button_handler_t)(struct widget *widget,
216                                         struct input *input, uint32_t time,
217                                         uint32_t button,
218                                         enum wl_pointer_button_state state,
219                                         void *data);
220 typedef void (*widget_axis_handler_t)(struct widget *widget,
221                                       struct input *input, uint32_t time,
222                                       uint32_t axis,
223                                       wl_fixed_t value,
224                                       void *data);
225
226 struct window *
227 window_create(struct display *display);
228 struct window *
229 window_create_transient(struct display *display, struct window *parent,
230                         int32_t x, int32_t y, uint32_t flags);
231 struct window *
232 window_create_custom(struct display *display);
233
234 int
235 window_has_focus(struct window *window);
236
237 typedef void (*menu_func_t)(struct window *window, int index, void *data);
238
239 void
240 window_show_menu(struct display *display,
241                  struct input *input, uint32_t time, struct window *parent,
242                  int32_t x, int32_t y,
243                  menu_func_t func, const char **entries, int count);
244
245 void
246 window_show_frame_menu(struct window *window,
247                        struct input *input, uint32_t time);
248
249 int
250 window_get_buffer_transform(struct window *window);
251
252 void
253 window_set_buffer_transform(struct window *window,
254                             enum wl_output_transform transform);
255
256 void
257 window_destroy(struct window *window);
258
259 struct widget *
260 window_add_widget(struct window *window, void *data);
261
262 enum subsurface_mode {
263         SUBSURFACE_SYNCHRONIZED,
264         SUBSURFACE_DESYNCHRONIZED
265 };
266
267 struct widget *
268 window_add_subsurface(struct window *window, void *data,
269                       enum subsurface_mode default_mode);
270
271 typedef void (*data_func_t)(void *data, size_t len,
272                             int32_t x, int32_t y, void *user_data);
273
274 struct display *
275 window_get_display(struct window *window);
276 void
277 window_move(struct window *window, struct input *input, uint32_t time);
278 void
279 window_get_allocation(struct window *window, struct rectangle *allocation);
280 void
281 window_schedule_redraw(struct window *window);
282 void
283 window_schedule_resize(struct window *window, int width, int height);
284
285 void
286 window_damage(struct window *window, int32_t x, int32_t y,
287               int32_t width, int32_t height);
288
289 cairo_surface_t *
290 window_get_surface(struct window *window);
291
292 struct wl_surface *
293 window_get_wl_surface(struct window *window);
294
295 struct wl_shell_surface *
296 window_get_wl_shell_surface(struct window *window);
297
298 enum window_buffer_type {
299         WINDOW_BUFFER_TYPE_EGL_WINDOW,
300         WINDOW_BUFFER_TYPE_SHM,
301 };
302
303 void
304 display_surface_damage(struct display *display, cairo_surface_t *cairo_surface,
305                        int32_t x, int32_t y, int32_t width, int32_t height);
306
307 void
308 window_set_buffer_type(struct window *window, enum window_buffer_type type);
309
310 int
311 window_is_fullscreen(struct window *window);
312
313 void
314 window_set_fullscreen(struct window *window, int fullscreen);
315
316 void
317 window_set_fullscreen_method(struct window *window,
318                              enum wl_shell_surface_fullscreen_method method);
319 int
320 window_is_maximized(struct window *window);
321
322 void
323 window_set_maximized(struct window *window, int maximized);
324
325 void
326 window_set_user_data(struct window *window, void *data);
327
328 void *
329 window_get_user_data(struct window *window);
330
331 void
332 window_set_key_handler(struct window *window,
333                        window_key_handler_t handler);
334
335 void
336 window_set_keyboard_focus_handler(struct window *window,
337                                   window_keyboard_focus_handler_t handler);
338
339 void
340 window_set_data_handler(struct window *window,
341                         window_data_handler_t handler);
342
343 void
344 window_set_drop_handler(struct window *window,
345                         window_drop_handler_t handler);
346
347 void
348 window_set_close_handler(struct window *window,
349                          window_close_handler_t handler);
350 void
351 window_set_fullscreen_handler(struct window *window,
352                               window_fullscreen_handler_t handler);
353 void
354 window_set_output_handler(struct window *window,
355                           window_output_handler_t handler);
356
357 void
358 window_set_title(struct window *window, const char *title);
359
360 const char *
361 window_get_title(struct window *window);
362
363 void
364 window_set_text_cursor_position(struct window *window, int32_t x, int32_t y);
365
366 int
367 widget_set_tooltip(struct widget *parent, char *entry, float x, float y);
368
369 void
370 widget_destroy_tooltip(struct widget *parent);
371
372 struct widget *
373 widget_add_widget(struct widget *parent, void *data);
374
375 void
376 widget_destroy(struct widget *widget);
377 void
378 widget_set_default_cursor(struct widget *widget, int cursor);
379 void
380 widget_get_allocation(struct widget *widget, struct rectangle *allocation);
381
382 void
383 widget_set_allocation(struct widget *widget,
384                       int32_t x, int32_t y, int32_t width, int32_t height);
385 void
386 widget_set_size(struct widget *widget, int32_t width, int32_t height);
387 void
388 widget_set_transparent(struct widget *widget, int transparent);
389 void
390 widget_schedule_resize(struct widget *widget, int32_t width, int32_t height);
391
392 void *
393 widget_get_user_data(struct widget *widget);
394
395 cairo_t *
396 widget_cairo_create(struct widget *widget);
397
398 void
399 widget_set_redraw_handler(struct widget *widget,
400                           widget_redraw_handler_t handler);
401 void
402 widget_set_resize_handler(struct widget *widget,
403                           widget_resize_handler_t handler);
404 void
405 widget_set_enter_handler(struct widget *widget,
406                          widget_enter_handler_t handler);
407 void
408 widget_set_leave_handler(struct widget *widget,
409                          widget_leave_handler_t handler);
410 void
411 widget_set_motion_handler(struct widget *widget,
412                           widget_motion_handler_t handler);
413 void
414 widget_set_button_handler(struct widget *widget,
415                           widget_button_handler_t handler);
416 void
417 widget_set_axis_handler(struct widget *widget,
418                         widget_axis_handler_t handler);
419
420 void
421 widget_schedule_redraw(struct widget *widget);
422
423 struct widget *
424 frame_create(struct window *window, void *data);
425
426 void
427 frame_set_child_size(struct widget *widget, int child_width, int child_height);
428
429 void
430 input_set_pointer_image(struct input *input, int pointer);
431
432 void
433 input_get_position(struct input *input, int32_t *x, int32_t *y);
434
435 #define MOD_SHIFT_MASK          0x01
436 #define MOD_ALT_MASK            0x02
437 #define MOD_CONTROL_MASK        0x04
438
439 uint32_t
440 input_get_modifiers(struct input *input);
441
442 void
443 input_grab(struct input *input, struct widget *widget, uint32_t button);
444
445 void
446 input_ungrab(struct input *input);
447
448 struct widget *
449 input_get_focus_widget(struct input *input);
450
451 struct display *
452 input_get_display(struct input *input);
453
454 struct wl_seat *
455 input_get_seat(struct input *input);
456
457 struct wl_data_device *
458 input_get_data_device(struct input *input);
459
460 void
461 input_set_selection(struct input *input,
462                     struct wl_data_source *source, uint32_t time);
463
464 void
465 input_accept(struct input *input, const char *type);
466
467
468 void
469 input_receive_drag_data(struct input *input, const char *mime_type,
470                         data_func_t func, void *user_data);
471
472 int
473 input_receive_selection_data(struct input *input, const char *mime_type,
474                              data_func_t func, void *data);
475 int
476 input_receive_selection_data_to_fd(struct input *input,
477                                    const char *mime_type, int fd);
478
479 void
480 output_set_user_data(struct output *output, void *data);
481
482 void *
483 output_get_user_data(struct output *output);
484
485 void
486 output_set_destroy_handler(struct output *output,
487                            display_output_handler_t handler);
488
489 void
490 output_get_allocation(struct output *output, struct rectangle *allocation);
491
492 struct wl_output *
493 output_get_wl_output(struct output *output);
494
495 enum wl_output_transform
496 output_get_transform(struct output *output);
497
498 void
499 keysym_modifiers_add(struct wl_array *modifiers_map,
500                      const char *name);
501
502 xkb_mod_mask_t
503 keysym_modifiers_get_mask(struct wl_array *modifiers_map,
504                           const char *name);
505
506 #endif