815b3f1cea7615a010ad9133befc2f9e3348b7bf
[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 typedef void (*data_func_t)(void *data, size_t len,
263                             int32_t x, int32_t y, void *user_data);
264
265 struct display *
266 window_get_display(struct window *window);
267 void
268 window_move(struct window *window, struct input *input, uint32_t time);
269 void
270 window_get_allocation(struct window *window, struct rectangle *allocation);
271 void
272 window_schedule_redraw(struct window *window);
273 void
274 window_schedule_resize(struct window *window, int width, int height);
275
276 void
277 window_damage(struct window *window, int32_t x, int32_t y,
278               int32_t width, int32_t height);
279
280 cairo_surface_t *
281 window_get_surface(struct window *window);
282
283 struct wl_surface *
284 window_get_wl_surface(struct window *window);
285
286 struct wl_shell_surface *
287 window_get_wl_shell_surface(struct window *window);
288
289 enum window_buffer_type {
290         WINDOW_BUFFER_TYPE_EGL_WINDOW,
291         WINDOW_BUFFER_TYPE_SHM,
292 };
293
294 void
295 display_surface_damage(struct display *display, cairo_surface_t *cairo_surface,
296                        int32_t x, int32_t y, int32_t width, int32_t height);
297
298 void
299 window_set_buffer_type(struct window *window, enum window_buffer_type type);
300
301 int
302 window_is_fullscreen(struct window *window);
303
304 void
305 window_set_fullscreen(struct window *window, int fullscreen);
306
307 void
308 window_set_fullscreen_method(struct window *window,
309                              enum wl_shell_surface_fullscreen_method method);
310 int
311 window_is_maximized(struct window *window);
312
313 void
314 window_set_maximized(struct window *window, int maximized);
315
316 void
317 window_set_user_data(struct window *window, void *data);
318
319 void *
320 window_get_user_data(struct window *window);
321
322 void
323 window_set_key_handler(struct window *window,
324                        window_key_handler_t handler);
325
326 void
327 window_set_keyboard_focus_handler(struct window *window,
328                                   window_keyboard_focus_handler_t handler);
329
330 void
331 window_set_data_handler(struct window *window,
332                         window_data_handler_t handler);
333
334 void
335 window_set_drop_handler(struct window *window,
336                         window_drop_handler_t handler);
337
338 void
339 window_set_close_handler(struct window *window,
340                          window_close_handler_t handler);
341 void
342 window_set_fullscreen_handler(struct window *window,
343                               window_fullscreen_handler_t handler);
344 void
345 window_set_output_handler(struct window *window,
346                           window_output_handler_t handler);
347
348 void
349 window_set_title(struct window *window, const char *title);
350
351 const char *
352 window_get_title(struct window *window);
353
354 void
355 window_set_text_cursor_position(struct window *window, int32_t x, int32_t y);
356
357 int
358 widget_set_tooltip(struct widget *parent, char *entry, float x, float y);
359
360 void
361 widget_destroy_tooltip(struct widget *parent);
362
363 struct widget *
364 widget_add_widget(struct widget *parent, void *data);
365
366 void
367 widget_destroy(struct widget *widget);
368 void
369 widget_set_default_cursor(struct widget *widget, int cursor);
370 void
371 widget_get_allocation(struct widget *widget, struct rectangle *allocation);
372
373 void
374 widget_set_allocation(struct widget *widget,
375                       int32_t x, int32_t y, int32_t width, int32_t height);
376 void
377 widget_set_size(struct widget *widget, int32_t width, int32_t height);
378 void
379 widget_set_transparent(struct widget *widget, int transparent);
380 void
381 widget_schedule_resize(struct widget *widget, int32_t width, int32_t height);
382
383 void *
384 widget_get_user_data(struct widget *widget);
385
386 cairo_t *
387 widget_cairo_create(struct widget *widget);
388
389 void
390 widget_set_redraw_handler(struct widget *widget,
391                           widget_redraw_handler_t handler);
392 void
393 widget_set_resize_handler(struct widget *widget,
394                           widget_resize_handler_t handler);
395 void
396 widget_set_enter_handler(struct widget *widget,
397                          widget_enter_handler_t handler);
398 void
399 widget_set_leave_handler(struct widget *widget,
400                          widget_leave_handler_t handler);
401 void
402 widget_set_motion_handler(struct widget *widget,
403                           widget_motion_handler_t handler);
404 void
405 widget_set_button_handler(struct widget *widget,
406                           widget_button_handler_t handler);
407 void
408 widget_set_axis_handler(struct widget *widget,
409                         widget_axis_handler_t handler);
410
411 void
412 widget_schedule_redraw(struct widget *widget);
413
414 struct widget *
415 frame_create(struct window *window, void *data);
416
417 void
418 frame_set_child_size(struct widget *widget, int child_width, int child_height);
419
420 void
421 input_set_pointer_image(struct input *input, int pointer);
422
423 void
424 input_get_position(struct input *input, int32_t *x, int32_t *y);
425
426 #define MOD_SHIFT_MASK          0x01
427 #define MOD_ALT_MASK            0x02
428 #define MOD_CONTROL_MASK        0x04
429
430 uint32_t
431 input_get_modifiers(struct input *input);
432
433 void
434 input_grab(struct input *input, struct widget *widget, uint32_t button);
435
436 void
437 input_ungrab(struct input *input);
438
439 struct widget *
440 input_get_focus_widget(struct input *input);
441
442 struct display *
443 input_get_display(struct input *input);
444
445 struct wl_seat *
446 input_get_seat(struct input *input);
447
448 struct wl_data_device *
449 input_get_data_device(struct input *input);
450
451 void
452 input_set_selection(struct input *input,
453                     struct wl_data_source *source, uint32_t time);
454
455 void
456 input_accept(struct input *input, const char *type);
457
458
459 void
460 input_receive_drag_data(struct input *input, const char *mime_type,
461                         data_func_t func, void *user_data);
462
463 int
464 input_receive_selection_data(struct input *input, const char *mime_type,
465                              data_func_t func, void *data);
466 int
467 input_receive_selection_data_to_fd(struct input *input,
468                                    const char *mime_type, int fd);
469
470 void
471 output_set_user_data(struct output *output, void *data);
472
473 void *
474 output_get_user_data(struct output *output);
475
476 void
477 output_set_destroy_handler(struct output *output,
478                            display_output_handler_t handler);
479
480 void
481 output_get_allocation(struct output *output, struct rectangle *allocation);
482
483 struct wl_output *
484 output_get_wl_output(struct output *output);
485
486 enum wl_output_transform
487 output_get_transform(struct output *output);
488
489 void
490 keysym_modifiers_add(struct wl_array *modifiers_map,
491                      const char *name);
492
493 xkb_mod_mask_t
494 keysym_modifiers_get_mask(struct wl_array *modifiers_map,
495                           const char *name);
496
497 #endif