Switch to global output repaint timer
[platform/upstream/weston.git] / libweston / compositor.h
1 /*
2  * Copyright © 2008-2011 Kristian Høgsberg
3  * Copyright © 2012 Collabora, Ltd.
4  *
5  * Permission is hereby granted, free of charge, to any person obtaining
6  * a copy of this software and associated documentation files (the
7  * "Software"), to deal in the Software without restriction, including
8  * without limitation the rights to use, copy, modify, merge, publish,
9  * distribute, sublicense, and/or sell copies of the Software, and to
10  * permit persons to whom the Software is furnished to do so, subject to
11  * the following conditions:
12  *
13  * The above copyright notice and this permission notice (including the
14  * next paragraph) shall be included in all copies or substantial
15  * portions of the Software.
16  *
17  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20  * NONINFRINGEMENT.  IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
21  * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
22  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
23  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24  * SOFTWARE.
25  */
26
27 #ifndef _WAYLAND_SYSTEM_COMPOSITOR_H_
28 #define _WAYLAND_SYSTEM_COMPOSITOR_H_
29
30 #ifdef  __cplusplus
31 extern "C" {
32 #endif
33
34 #include <stdbool.h>
35 #include <stdint.h>
36 #include <time.h>
37 #include <pixman.h>
38 #include <xkbcommon/xkbcommon.h>
39
40 #define WL_HIDE_DEPRECATED
41 #include <wayland-server.h>
42
43 #include "matrix.h"
44 #include "config-parser.h"
45 #include "zalloc.h"
46 #include "timeline-object.h"
47
48 struct weston_geometry {
49         int32_t x, y;
50         int32_t width, height;
51 };
52
53 struct weston_position {
54         int32_t x, y;
55 };
56
57 struct weston_size {
58         int32_t width, height;
59 };
60
61 struct weston_transform {
62         struct weston_matrix matrix;
63         struct wl_list link;
64 };
65
66 struct weston_surface;
67 struct weston_buffer;
68 struct shell_surface;
69 struct weston_seat;
70 struct weston_output;
71 struct input_method;
72 struct weston_pointer;
73 struct linux_dmabuf_buffer;
74 struct weston_recorder;
75 struct weston_pointer_constraint;
76
77 enum weston_keyboard_modifier {
78         MODIFIER_CTRL = (1 << 0),
79         MODIFIER_ALT = (1 << 1),
80         MODIFIER_SUPER = (1 << 2),
81         MODIFIER_SHIFT = (1 << 3),
82 };
83
84 enum weston_keyboard_locks {
85         WESTON_NUM_LOCK = (1 << 0),
86         WESTON_CAPS_LOCK = (1 << 1),
87 };
88
89 enum weston_led {
90         LED_NUM_LOCK = (1 << 0),
91         LED_CAPS_LOCK = (1 << 1),
92         LED_SCROLL_LOCK = (1 << 2),
93 };
94
95 struct weston_mode {
96         uint32_t flags;
97         int32_t width, height;
98         uint32_t refresh;
99         struct wl_list link;
100 };
101
102 struct weston_animation {
103         void (*frame)(struct weston_animation *animation,
104                       struct weston_output *output, uint32_t msecs);
105         int frame_counter;
106         struct wl_list link;
107 };
108
109 enum {
110         WESTON_SPRING_OVERSHOOT,
111         WESTON_SPRING_CLAMP,
112         WESTON_SPRING_BOUNCE
113 };
114
115 struct weston_spring {
116         double k;
117         double friction;
118         double current;
119         double target;
120         double previous;
121         double min, max;
122         uint32_t timestamp;
123         uint32_t clip;
124 };
125
126 struct weston_output_zoom {
127         bool active;
128         float increment;
129         float level;
130         float max_level;
131         float trans_x, trans_y;
132         struct {
133                 double x, y;
134         } current;
135         struct weston_seat *seat;
136         struct weston_animation animation_z;
137         struct weston_spring spring_z;
138         struct wl_listener motion_listener;
139 };
140
141 /* bit compatible with drm definitions. */
142 enum dpms_enum {
143         WESTON_DPMS_ON,
144         WESTON_DPMS_STANDBY,
145         WESTON_DPMS_SUSPEND,
146         WESTON_DPMS_OFF
147 };
148
149 struct weston_output {
150         uint32_t id;
151         char *name;
152
153         void *renderer_state;
154
155         struct wl_list link;
156         struct wl_list resource_list;
157         struct wl_global *global;
158         struct weston_compositor *compositor;
159
160         /** From global to output buffer coordinates. */
161         struct weston_matrix matrix;
162         /** From output buffer to global coordinates. */
163         struct weston_matrix inverse_matrix;
164
165         struct wl_list animation_list;
166         int32_t x, y, width, height;
167         int32_t mm_width, mm_height;
168
169         /** Output area in global coordinates, simple rect */
170         pixman_region32_t region;
171
172         pixman_region32_t previous_damage;
173
174         /** True if damage has occurred since the last repaint for this output;
175          *  if set, a repaint will eventually occur. */
176         bool repaint_needed;
177
178         /** State of the repaint loop */
179         enum {
180                 REPAINT_NOT_SCHEDULED = 0, /**< idle; no repaint will occur */
181                 REPAINT_BEGIN_FROM_IDLE, /**< start_repaint_loop scheduled */
182                 REPAINT_SCHEDULED, /**< repaint is scheduled to occur */
183                 REPAINT_AWAITING_COMPLETION, /**< last repaint not yet finished */
184         } repaint_status;
185
186         /** If repaint_status is REPAINT_SCHEDULED, contains the time the
187          *  next repaint should be run */
188         struct timespec next_repaint;
189
190         struct weston_output_zoom zoom;
191         int dirty;
192         struct wl_signal frame_signal;
193         struct wl_signal destroy_signal;
194         int move_x, move_y;
195         uint32_t frame_time; /* presentation timestamp in milliseconds */
196         uint64_t msc;        /* media stream counter */
197         int disable_planes;
198         int destroying;
199         struct wl_list feedback_list;
200
201         char *make, *model, *serial_number;
202         uint32_t subpixel;
203         uint32_t transform;
204         int32_t native_scale;
205         int32_t current_scale;
206         int32_t original_scale;
207
208         struct weston_mode *native_mode;
209         struct weston_mode *current_mode;
210         struct weston_mode *original_mode;
211         struct wl_list mode_list;
212
213         void (*start_repaint_loop)(struct weston_output *output);
214         int (*repaint)(struct weston_output *output,
215                         pixman_region32_t *damage);
216         void (*destroy)(struct weston_output *output);
217         void (*assign_planes)(struct weston_output *output);
218         int (*switch_mode)(struct weston_output *output, struct weston_mode *mode);
219
220         /* backlight values are on 0-255 range, where higher is brighter */
221         int32_t backlight_current;
222         void (*set_backlight)(struct weston_output *output, uint32_t value);
223         void (*set_dpms)(struct weston_output *output, enum dpms_enum level);
224
225         int connection_internal;
226         uint16_t gamma_size;
227         void (*set_gamma)(struct weston_output *output,
228                           uint16_t size,
229                           uint16_t *r,
230                           uint16_t *g,
231                           uint16_t *b);
232
233         struct weston_timeline_object timeline;
234
235         bool enabled;
236         int scale;
237
238         int (*enable)(struct weston_output *output);
239         int (*disable)(struct weston_output *output);
240 };
241
242 enum weston_pointer_motion_mask {
243         WESTON_POINTER_MOTION_ABS = 1 << 0,
244         WESTON_POINTER_MOTION_REL = 1 << 1,
245         WESTON_POINTER_MOTION_REL_UNACCEL = 1 << 2,
246 };
247
248 struct weston_pointer_motion_event {
249         uint32_t mask;
250         uint64_t time_usec;
251         double x;
252         double y;
253         double dx;
254         double dy;
255         double dx_unaccel;
256         double dy_unaccel;
257 };
258
259 struct weston_pointer_axis_event {
260         uint32_t axis;
261         double value;
262         bool has_discrete;
263         int32_t discrete;
264 };
265
266 struct weston_pointer_grab;
267 struct weston_pointer_grab_interface {
268         void (*focus)(struct weston_pointer_grab *grab);
269         void (*motion)(struct weston_pointer_grab *grab, uint32_t time,
270                        struct weston_pointer_motion_event *event);
271         void (*button)(struct weston_pointer_grab *grab,
272                        uint32_t time, uint32_t button, uint32_t state);
273         void (*axis)(struct weston_pointer_grab *grab,
274                      uint32_t time,
275                      struct weston_pointer_axis_event *event);
276         void (*axis_source)(struct weston_pointer_grab *grab, uint32_t source);
277         void (*frame)(struct weston_pointer_grab *grab);
278         void (*cancel)(struct weston_pointer_grab *grab);
279 };
280
281 struct weston_pointer_grab {
282         const struct weston_pointer_grab_interface *interface;
283         struct weston_pointer *pointer;
284 };
285
286 struct weston_keyboard_grab;
287 struct weston_keyboard_grab_interface {
288         void (*key)(struct weston_keyboard_grab *grab, uint32_t time,
289                     uint32_t key, uint32_t state);
290         void (*modifiers)(struct weston_keyboard_grab *grab, uint32_t serial,
291                           uint32_t mods_depressed, uint32_t mods_latched,
292                           uint32_t mods_locked, uint32_t group);
293         void (*cancel)(struct weston_keyboard_grab *grab);
294 };
295
296 struct weston_keyboard_grab {
297         const struct weston_keyboard_grab_interface *interface;
298         struct weston_keyboard *keyboard;
299 };
300
301 struct weston_touch_grab;
302 struct weston_touch_grab_interface {
303         void (*down)(struct weston_touch_grab *grab,
304                         uint32_t time,
305                         int touch_id,
306                         wl_fixed_t sx,
307                         wl_fixed_t sy);
308         void (*up)(struct weston_touch_grab *grab,
309                         uint32_t time,
310                         int touch_id);
311         void (*motion)(struct weston_touch_grab *grab,
312                         uint32_t time,
313                         int touch_id,
314                         wl_fixed_t sx,
315                         wl_fixed_t sy);
316         void (*frame)(struct weston_touch_grab *grab);
317         void (*cancel)(struct weston_touch_grab *grab);
318 };
319
320 struct weston_touch_grab {
321         const struct weston_touch_grab_interface *interface;
322         struct weston_touch *touch;
323 };
324
325 struct weston_data_offer {
326         struct wl_resource *resource;
327         struct weston_data_source *source;
328         struct wl_listener source_destroy_listener;
329         uint32_t dnd_actions;
330         enum wl_data_device_manager_dnd_action preferred_dnd_action;
331         bool in_ask;
332 };
333
334 struct weston_data_source {
335         struct wl_resource *resource;
336         struct wl_signal destroy_signal;
337         struct wl_array mime_types;
338         struct weston_data_offer *offer;
339         struct weston_seat *seat;
340         bool accepted;
341         bool actions_set;
342         uint32_t dnd_actions;
343         enum wl_data_device_manager_dnd_action current_dnd_action;
344         enum wl_data_device_manager_dnd_action compositor_action;
345
346         void (*accept)(struct weston_data_source *source,
347                        uint32_t serial, const char *mime_type);
348         void (*send)(struct weston_data_source *source,
349                      const char *mime_type, int32_t fd);
350         void (*cancel)(struct weston_data_source *source);
351 };
352
353 struct weston_pointer_client {
354         struct wl_list link;
355         struct wl_client *client;
356         struct wl_list pointer_resources;
357         struct wl_list relative_pointer_resources;
358 };
359
360 struct weston_pointer {
361         struct weston_seat *seat;
362
363         struct wl_list pointer_clients;
364
365         struct weston_view *focus;
366         struct weston_pointer_client *focus_client;
367         uint32_t focus_serial;
368         struct wl_listener focus_view_listener;
369         struct wl_listener focus_resource_listener;
370         struct wl_signal focus_signal;
371         struct wl_signal motion_signal;
372         struct wl_signal destroy_signal;
373
374         struct weston_view *sprite;
375         struct wl_listener sprite_destroy_listener;
376         int32_t hotspot_x, hotspot_y;
377
378         struct weston_pointer_grab *grab;
379         struct weston_pointer_grab default_grab;
380         wl_fixed_t grab_x, grab_y;
381         uint32_t grab_button;
382         uint32_t grab_serial;
383         uint32_t grab_time;
384
385         wl_fixed_t x, y;
386         wl_fixed_t sx, sy;
387         uint32_t button_count;
388
389         struct wl_listener output_destroy_listener;
390 };
391
392
393 struct weston_touch {
394         struct weston_seat *seat;
395
396         struct wl_list resource_list;
397         struct wl_list focus_resource_list;
398         struct weston_view *focus;
399         struct wl_listener focus_view_listener;
400         struct wl_listener focus_resource_listener;
401         uint32_t focus_serial;
402         struct wl_signal focus_signal;
403
404         uint32_t num_tp;
405
406         struct weston_touch_grab *grab;
407         struct weston_touch_grab default_grab;
408         int grab_touch_id;
409         wl_fixed_t grab_x, grab_y;
410         uint32_t grab_serial;
411         uint32_t grab_time;
412 };
413
414 void
415 weston_pointer_motion_to_abs(struct weston_pointer *pointer,
416                              struct weston_pointer_motion_event *event,
417                              wl_fixed_t *x, wl_fixed_t *y);
418
419 struct weston_pointer *
420 weston_pointer_create(struct weston_seat *seat);
421 void
422 weston_pointer_destroy(struct weston_pointer *pointer);
423 void
424 weston_pointer_send_motion(struct weston_pointer *pointer, uint32_t time,
425                            struct weston_pointer_motion_event *event);
426 bool
427 weston_pointer_has_focus_resource(struct weston_pointer *pointer);
428 void
429 weston_pointer_send_button(struct weston_pointer *pointer,
430                            uint32_t time, uint32_t button, uint32_t state_w);
431 void
432 weston_pointer_send_axis(struct weston_pointer *pointer,
433                          uint32_t time,
434                          struct weston_pointer_axis_event *event);
435 void
436 weston_pointer_send_axis_source(struct weston_pointer *pointer,
437                                 uint32_t source);
438 void
439 weston_pointer_send_frame(struct weston_pointer *pointer);
440
441 void
442 weston_pointer_set_focus(struct weston_pointer *pointer,
443                          struct weston_view *view,
444                          wl_fixed_t sx, wl_fixed_t sy);
445 void
446 weston_pointer_clear_focus(struct weston_pointer *pointer);
447 void
448 weston_pointer_start_grab(struct weston_pointer *pointer,
449                           struct weston_pointer_grab *grab);
450 void
451 weston_pointer_end_grab(struct weston_pointer *pointer);
452 void
453 weston_pointer_clamp(struct weston_pointer *pointer,
454                             wl_fixed_t *fx, wl_fixed_t *fy);
455 void
456 weston_pointer_move(struct weston_pointer *pointer,
457                     struct weston_pointer_motion_event *event);
458 void
459 weston_pointer_set_default_grab(struct weston_pointer *pointer,
460                 const struct weston_pointer_grab_interface *interface);
461
462 void
463 weston_pointer_constraint_destroy(struct weston_pointer_constraint *constraint);
464
465 struct weston_keyboard *
466 weston_keyboard_create(void);
467 void
468 weston_keyboard_destroy(struct weston_keyboard *keyboard);
469 void
470 weston_keyboard_set_focus(struct weston_keyboard *keyboard,
471                           struct weston_surface *surface);
472 void
473 weston_keyboard_start_grab(struct weston_keyboard *device,
474                            struct weston_keyboard_grab *grab);
475 void
476 weston_keyboard_end_grab(struct weston_keyboard *keyboard);
477 int
478 /*
479  * 'mask' and 'value' should be a bitwise mask of one or more
480  * valued of the weston_keyboard_locks enum.
481  */
482 weston_keyboard_set_locks(struct weston_keyboard *keyboard,
483                           uint32_t mask, uint32_t value);
484
485 bool
486 weston_keyboard_has_focus_resource(struct weston_keyboard *keyboard);
487 void
488 weston_keyboard_send_key(struct weston_keyboard *keyboard,
489                          uint32_t time, uint32_t key,
490                          enum wl_keyboard_key_state state);
491 void
492 weston_keyboard_send_modifiers(struct weston_keyboard *keyboard,
493                                uint32_t serial, uint32_t mods_depressed,
494                                uint32_t mods_latched,
495                                uint32_t mods_locked, uint32_t group);
496
497 struct weston_touch *
498 weston_touch_create(void);
499 void
500 weston_touch_destroy(struct weston_touch *touch);
501 void
502 weston_touch_set_focus(struct weston_touch *touch,
503                        struct weston_view *view);
504 void
505 weston_touch_start_grab(struct weston_touch *device,
506                         struct weston_touch_grab *grab);
507 void
508 weston_touch_end_grab(struct weston_touch *touch);
509
510 bool
511 weston_touch_has_focus_resource(struct weston_touch *touch);
512 void
513 weston_touch_send_down(struct weston_touch *touch, uint32_t time,
514                        int touch_id, wl_fixed_t x, wl_fixed_t y);
515 void
516 weston_touch_send_up(struct weston_touch *touch, uint32_t time, int touch_id);
517 void
518 weston_touch_send_motion(struct weston_touch *touch, uint32_t time,
519                          int touch_id, wl_fixed_t x, wl_fixed_t y);
520 void
521 weston_touch_send_frame(struct weston_touch *touch);
522
523 void
524 wl_data_device_set_keyboard_focus(struct weston_seat *seat);
525
526 int
527 wl_data_device_manager_init(struct wl_display *display);
528
529
530 void
531 weston_seat_set_selection(struct weston_seat *seat,
532                           struct weston_data_source *source, uint32_t serial);
533 void
534 weston_seat_send_selection(struct weston_seat *seat, struct wl_client *client);
535
536 int
537 weston_pointer_start_drag(struct weston_pointer *pointer,
538                        struct weston_data_source *source,
539                        struct weston_surface *icon,
540                        struct wl_client *client);
541 int
542 weston_touch_start_drag(struct weston_touch *touch,
543                         struct weston_data_source *source,
544                         struct weston_surface *icon,
545                         struct wl_client *client);
546
547 struct weston_xkb_info {
548         struct xkb_keymap *keymap;
549         int keymap_fd;
550         size_t keymap_size;
551         char *keymap_area;
552         int32_t ref_count;
553         xkb_mod_index_t shift_mod;
554         xkb_mod_index_t caps_mod;
555         xkb_mod_index_t ctrl_mod;
556         xkb_mod_index_t alt_mod;
557         xkb_mod_index_t mod2_mod;
558         xkb_mod_index_t mod3_mod;
559         xkb_mod_index_t super_mod;
560         xkb_mod_index_t mod5_mod;
561         xkb_led_index_t num_led;
562         xkb_led_index_t caps_led;
563         xkb_led_index_t scroll_led;
564 };
565
566 struct weston_keyboard {
567         struct weston_seat *seat;
568
569         struct wl_list resource_list;
570         struct wl_list focus_resource_list;
571         struct weston_surface *focus;
572         struct wl_listener focus_resource_listener;
573         uint32_t focus_serial;
574         struct wl_signal focus_signal;
575
576         struct weston_keyboard_grab *grab;
577         struct weston_keyboard_grab default_grab;
578         uint32_t grab_key;
579         uint32_t grab_serial;
580         uint32_t grab_time;
581
582         struct wl_array keys;
583
584         struct {
585                 uint32_t mods_depressed;
586                 uint32_t mods_latched;
587                 uint32_t mods_locked;
588                 uint32_t group;
589         } modifiers;
590
591         struct weston_keyboard_grab input_method_grab;
592         struct wl_resource *input_method_resource;
593
594         struct weston_xkb_info *xkb_info;
595         struct {
596                 struct xkb_state *state;
597                 enum weston_led leds;
598         } xkb_state;
599         struct xkb_keymap *pending_keymap;
600 };
601
602 struct weston_seat {
603         struct wl_list base_resource_list;
604
605         struct wl_global *global;
606         struct weston_pointer *pointer_state;
607         struct weston_keyboard *keyboard_state;
608         struct weston_touch *touch_state;
609         int pointer_device_count;
610         int keyboard_device_count;
611         int touch_device_count;
612
613         struct weston_output *output; /* constraint */
614
615         struct wl_signal destroy_signal;
616         struct wl_signal updated_caps_signal;
617
618         struct weston_compositor *compositor;
619         struct wl_list link;
620         enum weston_keyboard_modifier modifier_state;
621         struct weston_surface *saved_kbd_focus;
622         struct wl_listener saved_kbd_focus_listener;
623         struct wl_list drag_resource_list;
624
625         uint32_t selection_serial;
626         struct weston_data_source *selection_data_source;
627         struct wl_listener selection_data_source_listener;
628         struct wl_signal selection_signal;
629
630         void (*led_update)(struct weston_seat *ws, enum weston_led leds);
631
632         struct input_method *input_method;
633         char *seat_name;
634 };
635
636 enum {
637         WESTON_COMPOSITOR_ACTIVE,       /* normal rendering and events */
638         WESTON_COMPOSITOR_IDLE,         /* shell->unlock called on activity */
639         WESTON_COMPOSITOR_OFFSCREEN,    /* no rendering, no frame events */
640         WESTON_COMPOSITOR_SLEEPING      /* same as offscreen, but also set dpms
641                                          * to off */
642 };
643
644 struct weston_layer_entry {
645         struct wl_list link;
646         struct weston_layer *layer;
647 };
648
649 /**
650  * Higher value means higher in the stack.
651  *
652  * These values are based on well-known concepts in a classic desktop
653  * environment. Third-party modules based on libweston are encouraged to use
654  * them to integrate better with other projects.
655  *
656  * A fully integrated environment can use any value, based on these or not,
657  * at their discretion.
658  */
659 enum weston_layer_position {
660         /*
661          * Special value to make the layer invisible and still rendered.
662          * This is used by compositors wanting e.g. minimized surfaces to still
663          * receive frame callbacks.
664          */
665         WESTON_LAYER_POSITION_HIDDEN     = 0x00000000,
666
667         /*
668          * There should always be a background layer with a surface covering
669          * the visible area.
670          *
671          * If the compositor handles the background itself, it should use
672          * BACKGROUND.
673          *
674          * If the compositor supports runtime-loadable modules to set the
675          * background, it should put a solid color surface at (BACKGROUND - 1)
676          * and modules must use BACKGROUND.
677          */
678         WESTON_LAYER_POSITION_BACKGROUND = 0x00000002,
679
680         /* For "desktop widgets" and applications like conky. */
681         WESTON_LAYER_POSITION_BOTTOM_UI  = 0x30000000,
682
683         /* For regular applications, only one layer should have this value
684          * to ensure proper stacking control. */
685         WESTON_LAYER_POSITION_NORMAL     = 0x50000000,
686
687         /* For desktop UI, like panels. */
688         WESTON_LAYER_POSITION_UI         = 0x80000000,
689
690         /* For fullscreen applications that should cover UI. */
691         WESTON_LAYER_POSITION_FULLSCREEN = 0xb0000000,
692
693         /* For special UI like on-screen keyboard that fullscreen applications
694          * will need. */
695         WESTON_LAYER_POSITION_TOP_UI     = 0xe0000000,
696
697         /* For the lock surface. */
698         WESTON_LAYER_POSITION_LOCK       = 0xffff0000,
699
700         /* Values reserved for libweston internal usage */
701         WESTON_LAYER_POSITION_CURSOR     = 0xfffffffe,
702         WESTON_LAYER_POSITION_FADE       = 0xffffffff,
703 };
704
705 struct weston_layer {
706         struct weston_compositor *compositor;
707         struct wl_list link; /* weston_compositor::layer_list */
708         enum weston_layer_position position;
709         pixman_box32_t mask;
710         struct weston_layer_entry view_list;
711 };
712
713 struct weston_plane {
714         struct weston_compositor *compositor;
715         pixman_region32_t damage; /**< in global coords */
716         pixman_region32_t clip;
717         int32_t x, y;
718         struct wl_list link;
719 };
720
721 struct weston_renderer {
722         int (*read_pixels)(struct weston_output *output,
723                                pixman_format_code_t format, void *pixels,
724                                uint32_t x, uint32_t y,
725                                uint32_t width, uint32_t height);
726         void (*repaint_output)(struct weston_output *output,
727                                pixman_region32_t *output_damage);
728         void (*flush_damage)(struct weston_surface *surface);
729         void (*attach)(struct weston_surface *es, struct weston_buffer *buffer);
730         void (*surface_set_color)(struct weston_surface *surface,
731                                float red, float green,
732                                float blue, float alpha);
733         void (*destroy)(struct weston_compositor *ec);
734
735
736         /** See weston_surface_get_content_size() */
737         void (*surface_get_content_size)(struct weston_surface *surface,
738                                          int *width, int *height);
739
740         /** See weston_surface_copy_content() */
741         int (*surface_copy_content)(struct weston_surface *surface,
742                                     void *target, size_t size,
743                                     int src_x, int src_y,
744                                     int width, int height);
745
746         /** See weston_compositor_import_dmabuf() */
747         bool (*import_dmabuf)(struct weston_compositor *ec,
748                               struct linux_dmabuf_buffer *buffer);
749 };
750
751 enum weston_capability {
752         /* backend/renderer supports arbitrary rotation */
753         WESTON_CAP_ROTATION_ANY                 = 0x0001,
754
755         /* screencaptures need to be y-flipped */
756         WESTON_CAP_CAPTURE_YFLIP                = 0x0002,
757
758         /* backend/renderer has a separate cursor plane */
759         WESTON_CAP_CURSOR_PLANE                 = 0x0004,
760
761         /* backend supports setting arbitrary resolutions */
762         WESTON_CAP_ARBITRARY_MODES              = 0x0008,
763
764         /* renderer supports weston_view_set_mask() clipping */
765         WESTON_CAP_VIEW_CLIP_MASK               = 0x0010,
766 };
767
768 /* Configuration struct for a backend.
769  *
770  * This struct carries the configuration for a backend, and it's
771  * passed to the backend's init entry point. The backend will
772  * likely want to subclass this in order to handle backend specific
773  * data.
774  *
775  * NOTE: Alternate designs were proposed (Feb 2016) for using opaque
776  * structures[1] and for section+key/value getter/setters[2].  The rationale
777  * for selecting the transparent structure design is based on several
778  * assumptions[3] which may require re-evaluating the design choice if they
779  * fail to hold.
780  *
781  * 1: https://lists.freedesktop.org/archives/wayland-devel/2016-February/026989.html
782  * 2: https://lists.freedesktop.org/archives/wayland-devel/2016-February/026929.html
783  * 3: https://lists.freedesktop.org/archives/wayland-devel/2016-February/027228.html
784  */
785 struct weston_backend_config {
786    /** Major version for the backend-specific config struct
787     *
788     * This version must match exactly what the backend expects, otherwise
789     * the struct is incompatible.
790     */
791    uint32_t struct_version;
792
793    /** Minor version of the backend-specific config struct
794     *
795     * This must be set to sizeof(struct backend-specific config).
796     * If the value here is smaller than what the backend expects, the
797     * extra config members will assume their default values.
798     *
799     * A value greater than what the backend expects is incompatible.
800     */
801    size_t struct_size;
802 };
803
804 struct weston_backend {
805         void (*destroy)(struct weston_compositor *compositor);
806         void (*restore)(struct weston_compositor *compositor);
807 };
808
809 struct weston_desktop_xwayland;
810 struct weston_desktop_xwayland_interface;
811
812 struct weston_compositor {
813         struct wl_signal destroy_signal;
814
815         struct wl_display *wl_display;
816         struct weston_desktop_xwayland *xwayland;
817         const struct weston_desktop_xwayland_interface *xwayland_interface;
818
819         /* surface signals */
820         struct wl_signal create_surface_signal;
821         struct wl_signal activate_signal;
822         struct wl_signal transform_signal;
823
824         struct wl_signal kill_signal;
825         struct wl_signal idle_signal;
826         struct wl_signal wake_signal;
827
828         struct wl_signal show_input_panel_signal;
829         struct wl_signal hide_input_panel_signal;
830         struct wl_signal update_input_panel_signal;
831
832         struct wl_signal seat_created_signal;
833         struct wl_signal output_pending_signal;
834         struct wl_signal output_created_signal;
835         struct wl_signal output_destroyed_signal;
836         struct wl_signal output_moved_signal;
837         struct wl_signal output_resized_signal; /* callback argument: resized output */
838
839         struct wl_signal session_signal;
840         int session_active;
841
842         struct weston_layer fade_layer;
843         struct weston_layer cursor_layer;
844
845         struct wl_list pending_output_list;
846         struct wl_list output_list;
847         struct wl_list seat_list;
848         struct wl_list layer_list;      /* struct weston_layer::link */
849         struct wl_list view_list;       /* struct weston_view::link */
850         struct wl_list plane_list;
851         struct wl_list key_binding_list;
852         struct wl_list modifier_binding_list;
853         struct wl_list button_binding_list;
854         struct wl_list touch_binding_list;
855         struct wl_list axis_binding_list;
856         struct wl_list debug_binding_list;
857
858         uint32_t state;
859         struct wl_event_source *idle_source;
860         uint32_t idle_inhibit;
861         int idle_time;                  /* timeout, s */
862         struct wl_event_source *repaint_timer;
863
864         const struct weston_pointer_grab_interface *default_pointer_grab;
865
866         /* Repaint state. */
867         struct weston_plane primary_plane;
868         uint32_t capabilities; /* combination of enum weston_capability */
869
870         struct weston_renderer *renderer;
871
872         pixman_format_code_t read_format;
873
874         struct weston_backend *backend;
875
876         struct weston_launcher *launcher;
877
878         struct wl_list plugin_api_list; /* struct weston_plugin_api::link */
879
880         uint32_t output_id_pool;
881
882         struct xkb_rule_names xkb_names;
883         struct xkb_context *xkb_context;
884         struct weston_xkb_info *xkb_info;
885
886         /* Raw keyboard processing (no libxkbcommon initialization or handling) */
887         int use_xkbcommon;
888
889         int32_t kb_repeat_rate;
890         int32_t kb_repeat_delay;
891
892         bool vt_switching;
893
894         clockid_t presentation_clock;
895         int32_t repaint_msec;
896
897         unsigned int activate_serial;
898
899         struct wl_global *pointer_constraints;
900
901         int exit_code;
902
903         void *user_data;
904         void (*exit)(struct weston_compositor *c);
905
906         /* Whether to let the compositor run without any input device. */
907         bool require_input;
908
909 };
910
911 struct weston_buffer {
912         struct wl_resource *resource;
913         struct wl_signal destroy_signal;
914         struct wl_listener destroy_listener;
915
916         union {
917                 struct wl_shm_buffer *shm_buffer;
918                 void *legacy_buffer;
919         };
920         int32_t width, height;
921         uint32_t busy_count;
922         int y_inverted;
923 };
924
925 struct weston_buffer_reference {
926         struct weston_buffer *buffer;
927         struct wl_listener destroy_listener;
928 };
929
930 struct weston_buffer_viewport {
931         struct {
932                 /* wl_surface.set_buffer_transform */
933                 uint32_t transform;
934
935                 /* wl_surface.set_scaling_factor */
936                 int32_t scale;
937
938                 /*
939                  * If src_width != wl_fixed_from_int(-1),
940                  * then and only then src_* are used.
941                  */
942                 wl_fixed_t src_x, src_y;
943                 wl_fixed_t src_width, src_height;
944         } buffer;
945
946         struct {
947                 /*
948                  * If width == -1, the size is inferred from the buffer.
949                  */
950                 int32_t width, height;
951         } surface;
952
953         int changed;
954 };
955
956 struct weston_region {
957         struct wl_resource *resource;
958         pixman_region32_t region;
959 };
960
961 /* Using weston_view transformations
962  *
963  * To add a transformation to a view, create a struct weston_transform, and
964  * add it to the list view->geometry.transformation_list. Whenever you
965  * change the list, anything under view->geometry, or anything in the
966  * weston_transforms linked into the list, you must call
967  * weston_view_geometry_dirty().
968  *
969  * The order in the list defines the order of transformations. Let the list
970  * contain the transformation matrices M1, ..., Mn as head to tail. The
971  * transformation is applied to view-local coordinate vector p as
972  *    P = Mn * ... * M2 * M1 * p
973  * to produce the global coordinate vector P. The total transform
974  *    Mn * ... * M2 * M1
975  * is cached in view->transform.matrix, and the inverse of it in
976  * view->transform.inverse.
977  *
978  * The list always contains view->transform.position transformation, which
979  * is the translation by view->geometry.x and y.
980  *
981  * If you want to apply a transformation in local coordinates, add your
982  * weston_transform to the head of the list. If you want to apply a
983  * transformation in global coordinates, add it to the tail of the list.
984  *
985  * If view->geometry.parent is set, the total transformation of this
986  * view will be the parent's total transformation and this transformation
987  * combined:
988  *    Mparent * Mn * ... * M2 * M1
989  */
990
991 struct weston_view {
992         struct weston_surface *surface;
993         struct wl_list surface_link;
994         struct wl_signal destroy_signal;
995
996         struct wl_list link;             /* weston_compositor::view_list */
997         struct weston_layer_entry layer_link; /* part of geometry */
998         struct weston_plane *plane;
999
1000         /* For weston_layer inheritance from another view */
1001         struct weston_view *parent_view;
1002
1003         unsigned int click_to_activate_serial;
1004
1005         pixman_region32_t clip;          /* See weston_view_damage_below() */
1006         float alpha;                     /* part of geometry, see below */
1007
1008         void *renderer_state;
1009
1010         /* Surface geometry state, mutable.
1011          * If you change anything, call weston_surface_geometry_dirty().
1012          * That includes the transformations referenced from the list.
1013          */
1014         struct {
1015                 float x, y; /* surface translation on display */
1016
1017                 /* struct weston_transform */
1018                 struct wl_list transformation_list;
1019
1020                 /* managed by weston_surface_set_transform_parent() */
1021                 struct weston_view *parent;
1022                 struct wl_listener parent_destroy_listener;
1023                 struct wl_list child_list; /* geometry.parent_link */
1024                 struct wl_list parent_link;
1025
1026                 /* managed by weston_view_set_mask() */
1027                 bool scissor_enabled;
1028                 pixman_region32_t scissor; /* always a simple rect */
1029         } geometry;
1030
1031         /* State derived from geometry state, read-only.
1032          * This is updated by weston_view_update_transform().
1033          */
1034         struct {
1035                 int dirty;
1036
1037                 /* Approximations in global coordinates:
1038                  * - boundingbox is guaranteed to include the whole view in
1039                  *   the smallest possible single rectangle.
1040                  * - opaque is guaranteed to be fully opaque, though not
1041                  *   necessarily include all opaque areas.
1042                  */
1043                 pixman_region32_t boundingbox;
1044                 pixman_region32_t opaque;
1045
1046                 /* matrix and inverse are used only if enabled = 1.
1047                  * If enabled = 0, use x, y, width, height directly.
1048                  */
1049                 int enabled;
1050                 struct weston_matrix matrix;
1051                 struct weston_matrix inverse;
1052
1053                 struct weston_transform position; /* matrix from x, y */
1054         } transform;
1055
1056         /*
1057          * The primary output for this view.
1058          * Used for picking the output for driving internal animations on the
1059          * view, inheriting the primary output for related views in shells, etc.
1060          */
1061         struct weston_output *output;
1062
1063         /*
1064          * A more complete representation of all outputs this surface is
1065          * displayed on.
1066          */
1067         uint32_t output_mask;
1068
1069         /* Per-surface Presentation feedback flags, controlled by backend. */
1070         uint32_t psf_flags;
1071
1072         bool is_mapped;
1073 };
1074
1075 struct weston_surface_state {
1076         /* wl_surface.attach */
1077         int newly_attached;
1078         struct weston_buffer *buffer;
1079         struct wl_listener buffer_destroy_listener;
1080         int32_t sx;
1081         int32_t sy;
1082
1083         /* wl_surface.damage */
1084         pixman_region32_t damage_surface;
1085         /* wl_surface.damage_buffer */
1086         pixman_region32_t damage_buffer;
1087
1088         /* wl_surface.set_opaque_region */
1089         pixman_region32_t opaque;
1090
1091         /* wl_surface.set_input_region */
1092         pixman_region32_t input;
1093
1094         /* wl_surface.frame */
1095         struct wl_list frame_callback_list;
1096
1097         /* presentation.feedback */
1098         struct wl_list feedback_list;
1099
1100         /* wl_surface.set_buffer_transform */
1101         /* wl_surface.set_scaling_factor */
1102         /* wp_viewport.set_source */
1103         /* wp_viewport.set_destination */
1104         struct weston_buffer_viewport buffer_viewport;
1105 };
1106
1107 struct weston_surface_activation_data {
1108         struct weston_surface *surface;
1109         struct weston_seat *seat;
1110 };
1111
1112 struct weston_pointer_constraint {
1113         struct wl_list link;
1114
1115         struct weston_surface *surface;
1116         struct weston_view *view;
1117         struct wl_resource *resource;
1118         struct weston_pointer_grab grab;
1119         struct weston_pointer *pointer;
1120         uint32_t lifetime;
1121
1122         pixman_region32_t region;
1123         pixman_region32_t region_pending;
1124         bool region_is_pending;
1125
1126         wl_fixed_t hint_x;
1127         wl_fixed_t hint_y;
1128         wl_fixed_t hint_x_pending;
1129         wl_fixed_t hint_y_pending;
1130         bool hint_is_pending;
1131
1132         struct wl_listener pointer_destroy_listener;
1133         struct wl_listener surface_destroy_listener;
1134         struct wl_listener surface_commit_listener;
1135         struct wl_listener surface_activate_listener;
1136 };
1137
1138 struct weston_surface {
1139         struct wl_resource *resource;
1140         struct wl_signal destroy_signal; /* callback argument: this surface */
1141         struct weston_compositor *compositor;
1142         struct wl_signal commit_signal;
1143
1144         /** Damage in local coordinates from the client, for tex upload. */
1145         pixman_region32_t damage;
1146
1147         pixman_region32_t opaque;        /* part of geometry, see below */
1148         pixman_region32_t input;
1149         int32_t width, height;
1150         int32_t ref_count;
1151
1152         /* Not for long-term storage.  This exists for book-keeping while
1153          * iterating over surfaces and views
1154          */
1155         bool touched;
1156
1157         void *renderer_state;
1158
1159         struct wl_list views;
1160
1161         /*
1162          * Which output to vsync this surface to.
1163          * Used to determine whether to send or queue frame events, and for
1164          * other client-visible syncing/throttling tied to the output
1165          * repaint cycle.
1166          */
1167         struct weston_output *output;
1168
1169         /*
1170          * A more complete representation of all outputs this surface is
1171          * displayed on.
1172          */
1173         uint32_t output_mask;
1174
1175         struct wl_list frame_callback_list;
1176         struct wl_list feedback_list;
1177
1178         struct weston_buffer_reference buffer_ref;
1179         struct weston_buffer_viewport buffer_viewport;
1180         int32_t width_from_buffer; /* before applying viewport */
1181         int32_t height_from_buffer;
1182         bool keep_buffer; /* for backends to prevent early release */
1183
1184         /* wp_viewport resource for this surface */
1185         struct wl_resource *viewport_resource;
1186
1187         /* All the pending state, that wl_surface.commit will apply. */
1188         struct weston_surface_state pending;
1189
1190         /* Matrices representating of the full transformation between
1191          * buffer and surface coordinates.  These matrices are updated
1192          * using the weston_surface_build_buffer_matrix function. */
1193         struct weston_matrix buffer_to_surface_matrix;
1194         struct weston_matrix surface_to_buffer_matrix;
1195
1196         /*
1197          * If non-NULL, this function will be called on
1198          * wl_surface::commit after a new buffer has been set up for
1199          * this surface. The integer params are the sx and sy
1200          * parameters supplied to wl_surface::attach.
1201          */
1202         void (*committed)(struct weston_surface *es, int32_t sx, int32_t sy);
1203         void *committed_private;
1204         int (*get_label)(struct weston_surface *surface, char *buf, size_t len);
1205
1206         /* Parent's list of its sub-surfaces, weston_subsurface:parent_link.
1207          * Contains also the parent itself as a dummy weston_subsurface,
1208          * if the list is not empty.
1209          */
1210         struct wl_list subsurface_list; /* weston_subsurface::parent_link */
1211         struct wl_list subsurface_list_pending; /* ...::parent_link_pending */
1212
1213         /*
1214          * For tracking protocol role assignments. Different roles may
1215          * have the same configure hook, e.g. in shell.c. Configure hook
1216          * may get reset, this will not.
1217          * XXX: map configure functions 1:1 to roles, and never reset it,
1218          * and replace role_name with configure.
1219          */
1220         const char *role_name;
1221
1222         struct weston_timeline_object timeline;
1223
1224         bool is_mapped;
1225
1226         /* An list of per seat pointer constraints. */
1227         struct wl_list pointer_constraints;
1228 };
1229
1230 struct weston_subsurface {
1231         struct wl_resource *resource;
1232
1233         /* guaranteed to be valid and non-NULL */
1234         struct weston_surface *surface;
1235         struct wl_listener surface_destroy_listener;
1236
1237         /* can be NULL */
1238         struct weston_surface *parent;
1239         struct wl_listener parent_destroy_listener;
1240         struct wl_list parent_link;
1241         struct wl_list parent_link_pending;
1242
1243         struct {
1244                 int32_t x;
1245                 int32_t y;
1246                 int set;
1247         } position;
1248
1249         int has_cached_data;
1250         struct weston_surface_state cached;
1251         struct weston_buffer_reference cached_buffer_ref;
1252
1253         /* Sub-surface has been reordered; need to apply damage. */
1254         bool reordered;
1255
1256         int synchronized;
1257
1258         /* Used for constructing the view tree */
1259         struct wl_list unused_views;
1260 };
1261
1262 enum weston_key_state_update {
1263         STATE_UPDATE_AUTOMATIC,
1264         STATE_UPDATE_NONE,
1265 };
1266
1267 enum weston_activate_flag {
1268         WESTON_ACTIVATE_FLAG_NONE = 0,
1269         WESTON_ACTIVATE_FLAG_CONFIGURE = 1 << 0,
1270         WESTON_ACTIVATE_FLAG_CLICKED = 1 << 1,
1271 };
1272
1273 void
1274 weston_version(int *major, int *minor, int *micro);
1275
1276 void
1277 weston_view_update_transform(struct weston_view *view);
1278
1279 void
1280 weston_view_geometry_dirty(struct weston_view *view);
1281
1282 void
1283 weston_view_to_global_fixed(struct weston_view *view,
1284                             wl_fixed_t sx, wl_fixed_t sy,
1285                             wl_fixed_t *x, wl_fixed_t *y);
1286 void
1287 weston_view_to_global_float(struct weston_view *view,
1288                             float sx, float sy, float *x, float *y);
1289
1290 void
1291 weston_view_from_global_float(struct weston_view *view,
1292                               float x, float y, float *vx, float *vy);
1293 void
1294 weston_view_from_global(struct weston_view *view,
1295                         int32_t x, int32_t y, int32_t *vx, int32_t *vy);
1296 void
1297 weston_view_from_global_fixed(struct weston_view *view,
1298                               wl_fixed_t x, wl_fixed_t y,
1299                               wl_fixed_t *vx, wl_fixed_t *vy);
1300
1301 void
1302 weston_surface_to_buffer_float(struct weston_surface *surface,
1303                                float x, float y, float *bx, float *by);
1304 pixman_box32_t
1305 weston_surface_to_buffer_rect(struct weston_surface *surface,
1306                               pixman_box32_t rect);
1307
1308 void
1309 weston_surface_to_buffer_region(struct weston_surface *surface,
1310                                 pixman_region32_t *surface_region,
1311                                 pixman_region32_t *buffer_region);
1312
1313 void
1314 weston_spring_init(struct weston_spring *spring,
1315                    double k, double current, double target);
1316 void
1317 weston_spring_update(struct weston_spring *spring, uint32_t msec);
1318 int
1319 weston_spring_done(struct weston_spring *spring);
1320
1321 void
1322 weston_view_activate(struct weston_view *view,
1323                      struct weston_seat *seat,
1324                      uint32_t flags);
1325
1326 void
1327 notify_motion(struct weston_seat *seat, uint32_t time,
1328               struct weston_pointer_motion_event *event);
1329 void
1330 notify_motion_absolute(struct weston_seat *seat, uint32_t time,
1331                        double x, double y);
1332 void
1333 notify_button(struct weston_seat *seat, uint32_t time, int32_t button,
1334               enum wl_pointer_button_state state);
1335 void
1336 notify_axis(struct weston_seat *seat, uint32_t time,
1337             struct weston_pointer_axis_event *event);
1338 void
1339 notify_axis_source(struct weston_seat *seat, uint32_t source);
1340
1341 void
1342 notify_pointer_frame(struct weston_seat *seat);
1343
1344 void
1345 notify_key(struct weston_seat *seat, uint32_t time, uint32_t key,
1346            enum wl_keyboard_key_state state,
1347            enum weston_key_state_update update_state);
1348 void
1349 notify_modifiers(struct weston_seat *seat, uint32_t serial);
1350
1351 void
1352 notify_pointer_focus(struct weston_seat *seat, struct weston_output *output,
1353                      double x, double y);
1354
1355 void
1356 notify_keyboard_focus_in(struct weston_seat *seat, struct wl_array *keys,
1357                          enum weston_key_state_update update_state);
1358 void
1359 notify_keyboard_focus_out(struct weston_seat *seat);
1360
1361 void
1362 notify_touch(struct weston_seat *seat, uint32_t time, int touch_id,
1363              double x, double y, int touch_type);
1364 void
1365 notify_touch_frame(struct weston_seat *seat);
1366
1367 void
1368 notify_touch_cancel(struct weston_seat *seat);
1369
1370 void
1371 weston_layer_entry_insert(struct weston_layer_entry *list,
1372                           struct weston_layer_entry *entry);
1373 void
1374 weston_layer_entry_remove(struct weston_layer_entry *entry);
1375 void
1376 weston_layer_init(struct weston_layer *layer,
1377                   struct weston_compositor *compositor);
1378 void
1379 weston_layer_set_position(struct weston_layer *layer,
1380                           enum weston_layer_position position);
1381 void
1382 weston_layer_unset_position(struct weston_layer *layer);
1383
1384 void
1385 weston_layer_set_mask(struct weston_layer *layer, int x, int y, int width, int height);
1386
1387 void
1388 weston_layer_set_mask_infinite(struct weston_layer *layer);
1389
1390 void
1391 weston_plane_init(struct weston_plane *plane,
1392                         struct weston_compositor *ec,
1393                         int32_t x, int32_t y);
1394 void
1395 weston_plane_release(struct weston_plane *plane);
1396
1397 void
1398 weston_compositor_stack_plane(struct weston_compositor *ec,
1399                               struct weston_plane *plane,
1400                               struct weston_plane *above);
1401
1402 /* An invalid flag in presented_flags to catch logic errors. */
1403 #define WP_PRESENTATION_FEEDBACK_INVALID (1U << 31)
1404
1405 void
1406 weston_output_finish_frame(struct weston_output *output,
1407                            const struct timespec *stamp,
1408                            uint32_t presented_flags);
1409 void
1410 weston_output_schedule_repaint(struct weston_output *output);
1411 void
1412 weston_output_damage(struct weston_output *output);
1413 void
1414 weston_compositor_schedule_repaint(struct weston_compositor *compositor);
1415 void
1416 weston_compositor_fade(struct weston_compositor *compositor, float tint);
1417 void
1418 weston_compositor_damage_all(struct weston_compositor *compositor);
1419 void
1420 weston_compositor_unlock(struct weston_compositor *compositor);
1421 void
1422 weston_compositor_wake(struct weston_compositor *compositor);
1423 void
1424 weston_compositor_offscreen(struct weston_compositor *compositor);
1425 void
1426 weston_compositor_sleep(struct weston_compositor *compositor);
1427 struct weston_view *
1428 weston_compositor_pick_view(struct weston_compositor *compositor,
1429                             wl_fixed_t x, wl_fixed_t y,
1430                             wl_fixed_t *sx, wl_fixed_t *sy);
1431
1432
1433 struct weston_binding;
1434 typedef void (*weston_key_binding_handler_t)(struct weston_keyboard *keyboard,
1435                                              uint32_t time, uint32_t key,
1436                                              void *data);
1437 struct weston_binding *
1438 weston_compositor_add_key_binding(struct weston_compositor *compositor,
1439                                   uint32_t key,
1440                                   enum weston_keyboard_modifier modifier,
1441                                   weston_key_binding_handler_t binding,
1442                                   void *data);
1443
1444 typedef void (*weston_modifier_binding_handler_t)(struct weston_keyboard *keyboard,
1445                                                   enum weston_keyboard_modifier modifier,
1446                                                   void *data);
1447 struct weston_binding *
1448 weston_compositor_add_modifier_binding(struct weston_compositor *compositor,
1449                                        enum weston_keyboard_modifier modifier,
1450                                        weston_modifier_binding_handler_t binding,
1451                                        void *data);
1452
1453 typedef void (*weston_button_binding_handler_t)(struct weston_pointer *pointer,
1454                                                 uint32_t time, uint32_t button,
1455                                                 void *data);
1456 struct weston_binding *
1457 weston_compositor_add_button_binding(struct weston_compositor *compositor,
1458                                      uint32_t button,
1459                                      enum weston_keyboard_modifier modifier,
1460                                      weston_button_binding_handler_t binding,
1461                                      void *data);
1462
1463 typedef void (*weston_touch_binding_handler_t)(struct weston_touch *touch,
1464                                                uint32_t time,
1465                                                void *data);
1466 struct weston_binding *
1467 weston_compositor_add_touch_binding(struct weston_compositor *compositor,
1468                                     enum weston_keyboard_modifier modifier,
1469                                     weston_touch_binding_handler_t binding,
1470                                     void *data);
1471
1472 typedef void (*weston_axis_binding_handler_t)(struct weston_pointer *pointer,
1473                                               uint32_t time,
1474                                               struct weston_pointer_axis_event *event,
1475                                               void *data);
1476 struct weston_binding *
1477 weston_compositor_add_axis_binding(struct weston_compositor *compositor,
1478                                    uint32_t axis,
1479                                    enum weston_keyboard_modifier modifier,
1480                                    weston_axis_binding_handler_t binding,
1481                                    void *data);
1482 struct weston_binding *
1483 weston_compositor_add_debug_binding(struct weston_compositor *compositor,
1484                                     uint32_t key,
1485                                     weston_key_binding_handler_t binding,
1486                                     void *data);
1487 void
1488 weston_binding_destroy(struct weston_binding *binding);
1489
1490 void
1491 weston_install_debug_key_binding(struct weston_compositor *compositor,
1492                                  uint32_t mod);
1493
1494 void
1495 weston_binding_list_destroy_all(struct wl_list *list);
1496
1497 void
1498 weston_compositor_run_key_binding(struct weston_compositor *compositor,
1499                                   struct weston_keyboard *keyboard,
1500                                   uint32_t time,
1501                                   uint32_t key,
1502                                   enum wl_keyboard_key_state state);
1503
1504 void
1505 weston_compositor_run_modifier_binding(struct weston_compositor *compositor,
1506                                        struct weston_keyboard *keyboard,
1507                                        enum weston_keyboard_modifier modifier,
1508                                        enum wl_keyboard_key_state state);
1509 void
1510 weston_compositor_run_button_binding(struct weston_compositor *compositor,
1511                                      struct weston_pointer *pointer, uint32_t time,
1512                                      uint32_t button,
1513                                      enum wl_pointer_button_state value);
1514 void
1515 weston_compositor_run_touch_binding(struct weston_compositor *compositor,
1516                                     struct weston_touch *touch, uint32_t time,
1517                                     int touch_type);
1518 int
1519 weston_compositor_run_axis_binding(struct weston_compositor *compositor,
1520                                    struct weston_pointer *pointer, uint32_t time,
1521                                    struct weston_pointer_axis_event *event);
1522 int
1523 weston_compositor_run_debug_binding(struct weston_compositor *compositor,
1524                                     struct weston_keyboard *keyboard, uint32_t time,
1525                                     uint32_t key,
1526                                     enum wl_keyboard_key_state state);
1527
1528 void
1529 weston_compositor_set_default_pointer_grab(struct weston_compositor *compositor,
1530                         const struct weston_pointer_grab_interface *interface);
1531
1532 int
1533 weston_environment_get_fd(const char *env);
1534
1535 struct weston_surface *
1536 weston_surface_create(struct weston_compositor *compositor);
1537
1538 struct weston_view *
1539 weston_view_create(struct weston_surface *surface);
1540
1541 void
1542 weston_view_destroy(struct weston_view *view);
1543
1544 void
1545 weston_view_set_position(struct weston_view *view,
1546                          float x, float y);
1547
1548 void
1549 weston_view_set_transform_parent(struct weston_view *view,
1550                                  struct weston_view *parent);
1551
1552 void
1553 weston_view_set_mask(struct weston_view *view,
1554                      int x, int y, int width, int height);
1555
1556 void
1557 weston_view_set_mask_infinite(struct weston_view *view);
1558
1559 bool
1560 weston_view_is_mapped(struct weston_view *view);
1561
1562 void
1563 weston_view_schedule_repaint(struct weston_view *view);
1564
1565 bool
1566 weston_surface_is_mapped(struct weston_surface *surface);
1567
1568 void
1569 weston_surface_set_size(struct weston_surface *surface,
1570                         int32_t width, int32_t height);
1571
1572 void
1573 weston_surface_schedule_repaint(struct weston_surface *surface);
1574
1575 void
1576 weston_surface_damage(struct weston_surface *surface);
1577
1578 void
1579 weston_view_damage_below(struct weston_view *view);
1580
1581 void
1582 weston_view_move_to_plane(struct weston_view *view,
1583                           struct weston_plane *plane);
1584 void
1585 weston_view_unmap(struct weston_view *view);
1586
1587 void
1588 weston_surface_unmap(struct weston_surface *surface);
1589
1590 struct weston_surface *
1591 weston_surface_get_main_surface(struct weston_surface *surface);
1592
1593 int
1594 weston_surface_set_role(struct weston_surface *surface,
1595                         const char *role_name,
1596                         struct wl_resource *error_resource,
1597                         uint32_t error_code);
1598 const char *
1599 weston_surface_get_role(struct weston_surface *surface);
1600
1601 void
1602 weston_surface_set_label_func(struct weston_surface *surface,
1603                               int (*desc)(struct weston_surface *,
1604                                           char *, size_t));
1605
1606 void
1607 weston_surface_get_content_size(struct weston_surface *surface,
1608                                 int *width, int *height);
1609
1610 struct weston_geometry
1611 weston_surface_get_bounding_box(struct weston_surface *surface);
1612
1613 int
1614 weston_surface_copy_content(struct weston_surface *surface,
1615                             void *target, size_t size,
1616                             int src_x, int src_y,
1617                             int width, int height);
1618
1619 struct weston_buffer *
1620 weston_buffer_from_resource(struct wl_resource *resource);
1621
1622 void
1623 weston_buffer_reference(struct weston_buffer_reference *ref,
1624                         struct weston_buffer *buffer);
1625
1626 uint32_t
1627 weston_compositor_get_time(void);
1628
1629 void
1630 weston_compositor_destroy(struct weston_compositor *ec);
1631 struct weston_compositor *
1632 weston_compositor_create(struct wl_display *display, void *user_data);
1633
1634 enum weston_compositor_backend {
1635         WESTON_BACKEND_DRM,
1636         WESTON_BACKEND_FBDEV,
1637         WESTON_BACKEND_HEADLESS,
1638         WESTON_BACKEND_RDP,
1639         WESTON_BACKEND_WAYLAND,
1640         WESTON_BACKEND_X11,
1641 };
1642
1643 int
1644 weston_compositor_load_backend(struct weston_compositor *compositor,
1645                                enum weston_compositor_backend backend,
1646                                struct weston_backend_config *config_base);
1647 void
1648 weston_compositor_exit(struct weston_compositor *ec);
1649 void *
1650 weston_compositor_get_user_data(struct weston_compositor *compositor);
1651 int
1652 weston_compositor_set_presentation_clock(struct weston_compositor *compositor,
1653                                          clockid_t clk_id);
1654 int
1655 weston_compositor_set_presentation_clock_software(
1656                                         struct weston_compositor *compositor);
1657 void
1658 weston_compositor_read_presentation_clock(
1659                         const struct weston_compositor *compositor,
1660                         struct timespec *ts);
1661
1662 bool
1663 weston_compositor_import_dmabuf(struct weston_compositor *compositor,
1664                                 struct linux_dmabuf_buffer *buffer);
1665
1666 void
1667 weston_compositor_shutdown(struct weston_compositor *ec);
1668 void
1669 weston_compositor_exit_with_code(struct weston_compositor *compositor,
1670                                  int exit_code);
1671 void
1672 weston_output_init_zoom(struct weston_output *output);
1673 void
1674 weston_output_update_zoom(struct weston_output *output);
1675 void
1676 weston_output_activate_zoom(struct weston_output *output,
1677                             struct weston_seat *seat);
1678 void
1679 weston_output_update_matrix(struct weston_output *output);
1680 void
1681 weston_output_move(struct weston_output *output, int x, int y);
1682
1683 void
1684 weston_compositor_add_output(struct weston_compositor *compositor,
1685                              struct weston_output *output);
1686 void
1687 weston_output_destroy(struct weston_output *output);
1688 void
1689 weston_output_transform_coordinate(struct weston_output *output,
1690                                    double device_x, double device_y,
1691                                    double *x, double *y);
1692
1693 void
1694 weston_seat_init(struct weston_seat *seat, struct weston_compositor *ec,
1695                  const char *seat_name);
1696 void
1697 weston_seat_init_pointer(struct weston_seat *seat);
1698 void
1699 weston_seat_release_pointer(struct weston_seat *seat);
1700 int
1701 weston_seat_init_keyboard(struct weston_seat *seat, struct xkb_keymap *keymap);
1702 void
1703 weston_seat_release_keyboard(struct weston_seat *seat);
1704 void
1705 weston_seat_init_touch(struct weston_seat *seat);
1706 void
1707 weston_seat_release_touch(struct weston_seat *seat);
1708 void
1709 weston_seat_repick(struct weston_seat *seat);
1710 void
1711 weston_seat_update_keymap(struct weston_seat *seat, struct xkb_keymap *keymap);
1712
1713 void
1714 weston_seat_release(struct weston_seat *seat);
1715 int
1716 weston_compositor_set_xkb_rule_names(struct weston_compositor *ec,
1717                                      struct xkb_rule_names *names);
1718 void
1719 weston_compositor_xkb_destroy(struct weston_compositor *ec);
1720
1721 /* String literal of spaces, the same width as the timestamp. */
1722 #define STAMP_SPACE "               "
1723
1724 typedef int (*log_func_t)(const char *fmt, va_list ap);
1725 void
1726 weston_log_set_handler(log_func_t log, log_func_t cont);
1727 int
1728 weston_vlog(const char *fmt, va_list ap);
1729 int
1730 weston_vlog_continue(const char *fmt, va_list ap);
1731 int
1732 weston_log(const char *fmt, ...)
1733         __attribute__ ((format (printf, 1, 2)));
1734 int
1735 weston_log_continue(const char *fmt, ...)
1736         __attribute__ ((format (printf, 1, 2)));
1737
1738 enum {
1739         TTY_ENTER_VT,
1740         TTY_LEAVE_VT
1741 };
1742
1743 struct tty *
1744 tty_create(struct weston_compositor *compositor, int tty_nr);
1745
1746 void
1747 tty_destroy(struct tty *tty);
1748
1749 void
1750 tty_reset(struct tty *tty);
1751
1752 int
1753 tty_activate_vt(struct tty *tty, int vt);
1754
1755 enum weston_screenshooter_outcome {
1756         WESTON_SCREENSHOOTER_SUCCESS,
1757         WESTON_SCREENSHOOTER_NO_MEMORY,
1758         WESTON_SCREENSHOOTER_BAD_BUFFER
1759 };
1760
1761 typedef void (*weston_screenshooter_done_func_t)(void *data,
1762                                 enum weston_screenshooter_outcome outcome);
1763 int
1764 weston_screenshooter_shoot(struct weston_output *output, struct weston_buffer *buffer,
1765                            weston_screenshooter_done_func_t done, void *data);
1766 struct weston_recorder *
1767 weston_recorder_start(struct weston_output *output, const char *filename);
1768 void
1769 weston_recorder_stop(struct weston_recorder *recorder);
1770
1771 struct clipboard *
1772 clipboard_create(struct weston_seat *seat);
1773
1774 struct weston_view_animation;
1775 typedef void (*weston_view_animation_done_func_t)(struct weston_view_animation *animation, void *data);
1776
1777 void
1778 weston_view_animation_destroy(struct weston_view_animation *animation);
1779
1780 struct weston_view_animation *
1781 weston_zoom_run(struct weston_view *view, float start, float stop,
1782                 weston_view_animation_done_func_t done, void *data);
1783
1784 struct weston_view_animation *
1785 weston_fade_run(struct weston_view *view,
1786                 float start, float end, float k,
1787                 weston_view_animation_done_func_t done, void *data);
1788
1789 struct weston_view_animation *
1790 weston_move_scale_run(struct weston_view *view, int dx, int dy,
1791                       float start, float end, bool reverse,
1792                       weston_view_animation_done_func_t done, void *data);
1793
1794 struct weston_view_animation *
1795 weston_move_run(struct weston_view *view, int dx, int dy,
1796                 float start, float end, bool reverse,
1797                 weston_view_animation_done_func_t done, void *data);
1798
1799 void
1800 weston_fade_update(struct weston_view_animation *fade, float target);
1801
1802 struct weston_view_animation *
1803 weston_stable_fade_run(struct weston_view *front_view, float start,
1804                        struct weston_view *back_view, float end,
1805                        weston_view_animation_done_func_t done, void *data);
1806
1807 struct weston_view_animation *
1808 weston_slide_run(struct weston_view *view, float start, float stop,
1809                  weston_view_animation_done_func_t done, void *data);
1810
1811 void
1812 weston_surface_set_color(struct weston_surface *surface,
1813                          float red, float green, float blue, float alpha);
1814
1815 void
1816 weston_surface_destroy(struct weston_surface *surface);
1817
1818 int
1819 weston_output_mode_set_native(struct weston_output *output,
1820                               struct weston_mode *mode,
1821                               int32_t scale);
1822 int
1823 weston_output_mode_switch_to_temporary(struct weston_output *output,
1824                                        struct weston_mode *mode,
1825                                        int32_t scale);
1826 int
1827 weston_output_mode_switch_to_native(struct weston_output *output);
1828
1829 int
1830 noop_renderer_init(struct weston_compositor *ec);
1831
1832 int
1833 weston_input_init(struct weston_compositor *compositor);
1834
1835 int
1836 weston_backend_init(struct weston_compositor *c,
1837                     struct weston_backend_config *config_base);
1838 int
1839 weston_module_init(struct weston_compositor *compositor);
1840
1841 void
1842 weston_transformed_coord(int width, int height,
1843                          enum wl_output_transform transform,
1844                          int32_t scale,
1845                          float sx, float sy, float *bx, float *by);
1846 pixman_box32_t
1847 weston_transformed_rect(int width, int height,
1848                         enum wl_output_transform transform,
1849                         int32_t scale,
1850                         pixman_box32_t rect);
1851 void
1852 weston_matrix_transform_region(pixman_region32_t *dest,
1853                                struct weston_matrix *matrix,
1854                                pixman_region32_t *src);
1855 void
1856 weston_transformed_region(int width, int height,
1857                           enum wl_output_transform transform,
1858                           int32_t scale,
1859                           pixman_region32_t *src, pixman_region32_t *dest);
1860
1861 void *
1862 weston_load_module(const char *name, const char *entrypoint);
1863
1864 int
1865 weston_parse_transform(const char *transform, uint32_t *out);
1866
1867 const char *
1868 weston_transform_to_string(uint32_t output_transform);
1869
1870 struct weston_keyboard *
1871 weston_seat_get_keyboard(struct weston_seat *seat);
1872
1873 struct weston_pointer *
1874 weston_seat_get_pointer(struct weston_seat *seat);
1875
1876 struct weston_touch *
1877 weston_seat_get_touch(struct weston_seat *seat);
1878
1879 void
1880 weston_seat_set_keyboard_focus(struct weston_seat *seat,
1881                                struct weston_surface *surface);
1882
1883 int
1884 weston_compositor_load_xwayland(struct weston_compositor *compositor);
1885
1886 void
1887 weston_output_set_scale(struct weston_output *output,
1888                         int32_t scale);
1889
1890 void
1891 weston_output_set_transform(struct weston_output *output,
1892                             uint32_t transform);
1893
1894 void
1895 weston_output_init(struct weston_output *output,
1896                    struct weston_compositor *compositor);
1897
1898 void
1899 weston_compositor_add_pending_output(struct weston_output *output,
1900                                      struct weston_compositor *compositor);
1901
1902 int
1903 weston_output_enable(struct weston_output *output);
1904
1905 void
1906 weston_output_disable(struct weston_output *output);
1907
1908 void
1909 weston_pending_output_coldplug(struct weston_compositor *compositor);
1910
1911 #ifdef  __cplusplus
1912 }
1913 #endif
1914
1915 #endif