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