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