e445dc325bc3d826aca0337ac5b339d215d4651b
[platform/upstream/weston.git] / src / compositor.h
1 /*
2  * Copyright © 2008-2011 Kristian Høgsberg
3  * Copyright © 2012 Collabora, Ltd.
4  *
5  * Permission to use, copy, modify, distribute, and sell this software and
6  * its documentation for any purpose is hereby granted without fee, provided
7  * that the above copyright notice appear in all copies and that both that
8  * copyright notice and this permission notice appear in supporting
9  * documentation, and that the name of the copyright holders not be used in
10  * advertising or publicity pertaining to distribution of the software
11  * without specific, written prior permission.  The copyright holders make
12  * no representations about the suitability of this software for any
13  * purpose.  It is provided "as is" without express or implied warranty.
14  *
15  * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
16  * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
17  * FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY
18  * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
19  * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
20  * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
21  * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
22  */
23
24 #ifndef _WAYLAND_SYSTEM_COMPOSITOR_H_
25 #define _WAYLAND_SYSTEM_COMPOSITOR_H_
26
27 #ifdef  __cplusplus
28 extern "C" {
29 #endif
30
31 #include <pixman.h>
32 #include <xkbcommon/xkbcommon.h>
33
34 #define WL_HIDE_DEPRECATED
35 #include <wayland-server.h>
36
37 #include "version.h"
38 #include "matrix.h"
39 #include "config-parser.h"
40 #include "zalloc.h"
41
42 #ifndef MIN
43 #define MIN(x,y) (((x) < (y)) ? (x) : (y))
44 #endif
45
46 #define ARRAY_LENGTH(a) (sizeof (a) / sizeof (a)[0])
47
48 #define container_of(ptr, type, member) ({                              \
49         const __typeof__( ((type *)0)->member ) *__mptr = (ptr);        \
50         (type *)( (char *)__mptr - offsetof(type,member) );})
51
52 struct weston_transform {
53         struct weston_matrix matrix;
54         struct wl_list link;
55 };
56
57 struct weston_surface;
58 struct weston_buffer;
59 struct shell_surface;
60 struct weston_seat;
61 struct weston_output;
62 struct input_method;
63
64 enum weston_keyboard_modifier {
65         MODIFIER_CTRL = (1 << 0),
66         MODIFIER_ALT = (1 << 1),
67         MODIFIER_SUPER = (1 << 2),
68         MODIFIER_SHIFT = (1 << 3),
69 };
70
71 enum weston_led {
72         LED_NUM_LOCK = (1 << 0),
73         LED_CAPS_LOCK = (1 << 1),
74         LED_SCROLL_LOCK = (1 << 2),
75 };
76
77 struct weston_mode {
78         uint32_t flags;
79         int32_t width, height;
80         uint32_t refresh;
81         struct wl_list link;
82 };
83
84 struct weston_shell_client {
85         void (*send_configure)(struct weston_surface *surface,
86                                uint32_t edges, int32_t width, int32_t height);
87 };
88
89 struct weston_shell_interface {
90         void *shell;                    /* either desktop or tablet */
91
92         struct shell_surface *(*create_shell_surface)(void *shell,
93                                                       struct weston_surface *surface,
94                                                       const struct weston_shell_client *client);
95         struct weston_view *(*get_primary_view)(void *shell,
96                                                 struct shell_surface *shsurf);
97
98         void (*set_toplevel)(struct shell_surface *shsurf);
99
100         void (*set_transient)(struct shell_surface *shsurf,
101                               struct weston_surface *parent,
102                               int x, int y, uint32_t flags);
103         void (*set_fullscreen)(struct shell_surface *shsurf,
104                                uint32_t method,
105                                uint32_t framerate,
106                                struct weston_output *output);
107         void (*set_xwayland)(struct shell_surface *shsurf,
108                                int x, int y, uint32_t flags);
109         int (*move)(struct shell_surface *shsurf, struct weston_seat *ws);
110         int (*resize)(struct shell_surface *shsurf,
111                       struct weston_seat *ws, uint32_t edges);
112         void (*set_title)(struct shell_surface *shsurf,
113                           const char *title);
114
115 };
116
117 struct weston_animation {
118         void (*frame)(struct weston_animation *animation,
119                       struct weston_output *output, uint32_t msecs);
120         int frame_counter;
121         struct wl_list link;
122 };
123
124 enum {
125         WESTON_SPRING_OVERSHOOT,
126         WESTON_SPRING_CLAMP,
127         WESTON_SPRING_BOUNCE
128 };
129
130 struct weston_spring {
131         double k;
132         double friction;
133         double current;
134         double target;
135         double previous;
136         double min, max;
137         uint32_t timestamp;
138         uint32_t clip;
139 };
140
141 struct weston_fixed_point {
142         wl_fixed_t x, y;
143 };
144
145 struct weston_output_zoom {
146         int active;
147         float increment;
148         float level;
149         float max_level;
150         float trans_x, trans_y;
151         struct weston_animation animation_z;
152         struct weston_spring spring_z;
153         struct weston_animation animation_xy;
154         struct weston_spring spring_xy;
155         struct weston_fixed_point from;
156         struct weston_fixed_point to;
157         struct weston_fixed_point current;
158         struct wl_listener motion_listener;
159 };
160
161 /* bit compatible with drm definitions. */
162 enum dpms_enum {
163         WESTON_DPMS_ON,
164         WESTON_DPMS_STANDBY,
165         WESTON_DPMS_SUSPEND,
166         WESTON_DPMS_OFF
167 };
168
169 enum weston_mode_switch_op {
170         WESTON_MODE_SWITCH_SET_NATIVE,
171         WESTON_MODE_SWITCH_SET_TEMPORARY,
172         WESTON_MODE_SWITCH_RESTORE_NATIVE
173 };
174
175 struct weston_output {
176         uint32_t id;
177         char *name;
178
179         void *renderer_state;
180
181         struct wl_list link;
182         struct wl_list resource_list;
183         struct wl_global *global;
184         struct weston_compositor *compositor;
185         struct weston_matrix matrix;
186         struct wl_list animation_list;
187         int32_t x, y, width, height;
188         int32_t mm_width, mm_height;
189         pixman_region32_t region;
190         pixman_region32_t previous_damage;
191         int repaint_needed;
192         int repaint_scheduled;
193         struct weston_output_zoom zoom;
194         int dirty;
195         struct wl_signal frame_signal;
196         struct wl_signal destroy_signal;
197         uint32_t frame_time;
198         int disable_planes;
199
200         char *make, *model, *serial_number;
201         uint32_t subpixel;
202         uint32_t transform;
203         int32_t native_scale;
204         int32_t current_scale;
205         int32_t original_scale;
206
207         struct weston_mode *native_mode;
208         struct weston_mode *current_mode;
209         struct weston_mode *original_mode;
210         struct wl_list mode_list;
211
212         void (*start_repaint_loop)(struct weston_output *output);
213         int (*repaint)(struct weston_output *output,
214                         pixman_region32_t *damage);
215         void (*destroy)(struct weston_output *output);
216         void (*assign_planes)(struct weston_output *output);
217         int (*switch_mode)(struct weston_output *output, struct weston_mode *mode);
218
219         /* backlight values are on 0-255 range, where higher is brighter */
220         int32_t backlight_current;
221         void (*set_backlight)(struct weston_output *output, uint32_t value);
222         void (*set_dpms)(struct weston_output *output, enum dpms_enum level);
223
224         int connection_internal;
225         uint16_t gamma_size;
226         void (*set_gamma)(struct weston_output *output,
227                           uint16_t size,
228                           uint16_t *r,
229                           uint16_t *g,
230                           uint16_t *b);
231 };
232
233 struct weston_pointer_grab;
234 struct weston_pointer_grab_interface {
235         void (*focus)(struct weston_pointer_grab *grab);
236         void (*motion)(struct weston_pointer_grab *grab, uint32_t time,
237                        wl_fixed_t x, wl_fixed_t y);
238         void (*button)(struct weston_pointer_grab *grab,
239                        uint32_t time, uint32_t button, uint32_t state);
240         void (*cancel)(struct weston_pointer_grab *grab);
241 };
242
243 struct weston_pointer_grab {
244         const struct weston_pointer_grab_interface *interface;
245         struct weston_pointer *pointer;
246 };
247
248 struct weston_keyboard_grab;
249 struct weston_keyboard_grab_interface {
250         void (*key)(struct weston_keyboard_grab *grab, uint32_t time,
251                     uint32_t key, uint32_t state);
252         void (*modifiers)(struct weston_keyboard_grab *grab, uint32_t serial,
253                           uint32_t mods_depressed, uint32_t mods_latched,
254                           uint32_t mods_locked, uint32_t group);
255         void (*cancel)(struct weston_keyboard_grab *grab);
256 };
257
258 struct weston_keyboard_grab {
259         const struct weston_keyboard_grab_interface *interface;
260         struct weston_keyboard *keyboard;
261 };
262
263 struct weston_touch_grab;
264 struct weston_touch_grab_interface {
265         void (*down)(struct weston_touch_grab *grab,
266                         uint32_t time,
267                         int touch_id,
268                         wl_fixed_t sx,
269                         wl_fixed_t sy);
270         void (*up)(struct weston_touch_grab *grab,
271                         uint32_t time,
272                         int touch_id);
273         void (*motion)(struct weston_touch_grab *grab,
274                         uint32_t time,
275                         int touch_id,
276                         wl_fixed_t sx,
277                         wl_fixed_t sy);
278         void (*cancel)(struct weston_touch_grab *grab);
279 };
280
281 struct weston_touch_grab {
282         const struct weston_touch_grab_interface *interface;
283         struct weston_touch *touch;
284 };
285
286 struct weston_data_offer {
287         struct wl_resource *resource;
288         struct weston_data_source *source;
289         struct wl_listener source_destroy_listener;
290 };
291
292 struct weston_data_source {
293         struct wl_resource *resource;
294         struct wl_signal destroy_signal;
295         struct wl_array mime_types;
296
297         void (*accept)(struct weston_data_source *source,
298                        uint32_t serial, const char *mime_type);
299         void (*send)(struct weston_data_source *source,
300                      const char *mime_type, int32_t fd);
301         void (*cancel)(struct weston_data_source *source);
302 };
303
304 struct weston_pointer {
305         struct weston_seat *seat;
306
307         struct wl_list resource_list;
308         struct wl_list focus_resource_list;
309         struct weston_view *focus;
310         uint32_t focus_serial;
311         struct wl_listener focus_view_listener;
312         struct wl_listener focus_resource_listener;
313         struct wl_signal focus_signal;
314         struct wl_signal motion_signal;
315
316         struct weston_view *sprite;
317         struct wl_listener sprite_destroy_listener;
318         int32_t hotspot_x, hotspot_y;
319
320         struct weston_pointer_grab *grab;
321         struct weston_pointer_grab default_grab;
322         wl_fixed_t grab_x, grab_y;
323         uint32_t grab_button;
324         uint32_t grab_serial;
325         uint32_t grab_time;
326
327         wl_fixed_t x, y;
328         uint32_t button_count;
329 };
330
331
332 struct weston_touch {
333         struct weston_seat *seat;
334
335         struct wl_list resource_list;
336         struct wl_list focus_resource_list;
337         struct weston_view *focus;
338         struct wl_listener focus_view_listener;
339         struct wl_listener focus_resource_listener;
340         uint32_t focus_serial;
341         struct wl_signal focus_signal;
342
343         struct weston_touch_grab *grab;
344         struct weston_touch_grab default_grab;
345         int grab_touch_id;
346         wl_fixed_t grab_x, grab_y;
347         uint32_t grab_serial;
348         uint32_t grab_time;
349 };
350
351 struct weston_pointer *
352 weston_pointer_create(struct weston_seat *seat);
353 void
354 weston_pointer_destroy(struct weston_pointer *pointer);
355 void
356 weston_pointer_set_focus(struct weston_pointer *pointer,
357                          struct weston_view *view,
358                          wl_fixed_t sx, wl_fixed_t sy);
359 void
360 weston_pointer_start_grab(struct weston_pointer *pointer,
361                           struct weston_pointer_grab *grab);
362 void
363 weston_pointer_end_grab(struct weston_pointer *pointer);
364 void
365 weston_pointer_clamp(struct weston_pointer *pointer,
366                             wl_fixed_t *fx, wl_fixed_t *fy);
367 void
368 weston_pointer_move(struct weston_pointer *pointer,
369                     wl_fixed_t x, wl_fixed_t y);
370 void
371 weston_pointer_set_default_grab(struct weston_pointer *pointer,
372                 const struct weston_pointer_grab_interface *interface);
373
374 struct weston_keyboard *
375 weston_keyboard_create(void);
376 void
377 weston_keyboard_destroy(struct weston_keyboard *keyboard);
378 void
379 weston_keyboard_set_focus(struct weston_keyboard *keyboard,
380                           struct weston_surface *surface);
381 void
382 weston_keyboard_start_grab(struct weston_keyboard *device,
383                            struct weston_keyboard_grab *grab);
384 void
385 weston_keyboard_end_grab(struct weston_keyboard *keyboard);
386
387 struct weston_touch *
388 weston_touch_create(void);
389 void
390 weston_touch_destroy(struct weston_touch *touch);
391 void
392 weston_touch_set_focus(struct weston_seat *seat,
393                        struct weston_view *view);
394 void
395 weston_touch_start_grab(struct weston_touch *device,
396                         struct weston_touch_grab *grab);
397 void
398 weston_touch_end_grab(struct weston_touch *touch);
399
400 void
401 wl_data_device_set_keyboard_focus(struct weston_seat *seat);
402
403 int
404 wl_data_device_manager_init(struct wl_display *display);
405
406
407 void
408 weston_seat_set_selection(struct weston_seat *seat,
409                           struct weston_data_source *source, uint32_t serial);
410 int
411 weston_pointer_start_drag(struct weston_pointer *pointer,
412                        struct weston_data_source *source,
413                        struct weston_surface *icon,
414                        struct wl_client *client);
415 int
416 weston_touch_start_drag(struct weston_touch *touch,
417                         struct weston_data_source *source,
418                         struct weston_surface *icon,
419                         struct wl_client *client);
420
421 struct weston_xkb_info {
422         struct xkb_keymap *keymap;
423         int keymap_fd;
424         size_t keymap_size;
425         char *keymap_area;
426         int32_t ref_count;
427         xkb_mod_index_t shift_mod;
428         xkb_mod_index_t caps_mod;
429         xkb_mod_index_t ctrl_mod;
430         xkb_mod_index_t alt_mod;
431         xkb_mod_index_t mod2_mod;
432         xkb_mod_index_t mod3_mod;
433         xkb_mod_index_t super_mod;
434         xkb_mod_index_t mod5_mod;
435         xkb_led_index_t num_led;
436         xkb_led_index_t caps_led;
437         xkb_led_index_t scroll_led;
438 };
439
440 struct weston_keyboard {
441         struct weston_seat *seat;
442
443         struct wl_list resource_list;
444         struct wl_list focus_resource_list;
445         struct weston_surface *focus;
446         struct wl_listener focus_resource_listener;
447         uint32_t focus_serial;
448         struct wl_signal focus_signal;
449
450         struct weston_keyboard_grab *grab;
451         struct weston_keyboard_grab default_grab;
452         uint32_t grab_key;
453         uint32_t grab_serial;
454         uint32_t grab_time;
455
456         struct wl_array keys;
457
458         struct {
459                 uint32_t mods_depressed;
460                 uint32_t mods_latched;
461                 uint32_t mods_locked;
462                 uint32_t group;
463         } modifiers;
464
465         struct weston_keyboard_grab input_method_grab;
466         struct wl_resource *input_method_resource;
467 };
468
469 struct weston_seat {
470         struct wl_list base_resource_list;
471
472         struct wl_global *global;
473         struct weston_pointer *pointer;
474         struct weston_keyboard *keyboard;
475         struct weston_touch *touch;
476         int pointer_device_count;
477         int keyboard_device_count;
478         int touch_device_count;
479
480         struct weston_output *output; /* constraint */
481
482         struct wl_signal destroy_signal;
483
484         struct weston_compositor *compositor;
485         struct wl_list link;
486         enum weston_keyboard_modifier modifier_state;
487         struct weston_surface *saved_kbd_focus;
488         struct wl_listener saved_kbd_focus_listener;
489         struct wl_list drag_resource_list;
490
491         uint32_t selection_serial;
492         struct weston_data_source *selection_data_source;
493         struct wl_listener selection_data_source_listener;
494         struct wl_signal selection_signal;
495
496         uint32_t num_tp;
497
498         void (*led_update)(struct weston_seat *ws, enum weston_led leds);
499
500         struct weston_xkb_info *xkb_info;
501         struct {
502                 struct xkb_state *state;
503                 enum weston_led leds;
504         } xkb_state;
505         struct xkb_keymap *pending_keymap;
506
507         struct input_method *input_method;
508         char *seat_name;
509 };
510
511 enum {
512         WESTON_COMPOSITOR_ACTIVE,
513         WESTON_COMPOSITOR_IDLE,         /* shell->unlock called on activity */
514         WESTON_COMPOSITOR_OFFSCREEN,    /* no rendering, no frame events */
515         WESTON_COMPOSITOR_SLEEPING      /* same as offscreen, but also set dmps
516                                          * to off */
517 };
518
519 struct weston_layer {
520         struct wl_list view_list;
521         struct wl_list link;
522 };
523
524 struct weston_plane {
525         struct weston_compositor *compositor;
526         pixman_region32_t damage;
527         pixman_region32_t clip;
528         int32_t x, y;
529         struct wl_list link;
530 };
531
532 struct weston_renderer {
533         int (*read_pixels)(struct weston_output *output,
534                                pixman_format_code_t format, void *pixels,
535                                uint32_t x, uint32_t y,
536                                uint32_t width, uint32_t height);
537         void (*repaint_output)(struct weston_output *output,
538                                pixman_region32_t *output_damage);
539         void (*flush_damage)(struct weston_surface *surface);
540         void (*attach)(struct weston_surface *es, struct weston_buffer *buffer);
541         void (*surface_set_color)(struct weston_surface *surface,
542                                float red, float green,
543                                float blue, float alpha);
544         void (*destroy)(struct weston_compositor *ec);
545 };
546
547 enum weston_capability {
548         /* backend/renderer supports arbitrary rotation */
549         WESTON_CAP_ROTATION_ANY                 = 0x0001,
550
551         /* screencaptures need to be y-flipped */
552         WESTON_CAP_CAPTURE_YFLIP                = 0x0002,
553 };
554
555 struct weston_compositor {
556         struct wl_signal destroy_signal;
557
558         struct wl_display *wl_display;
559         struct weston_shell_interface shell_interface;
560         struct weston_config *config;
561
562         /* surface signals */
563         struct wl_signal activate_signal;
564         struct wl_signal transform_signal;
565
566         struct wl_signal kill_signal;
567         struct wl_signal idle_signal;
568         struct wl_signal wake_signal;
569
570         struct wl_signal show_input_panel_signal;
571         struct wl_signal hide_input_panel_signal;
572         struct wl_signal update_input_panel_signal;
573
574         struct wl_signal seat_created_signal;
575         struct wl_signal output_created_signal;
576
577         struct wl_event_loop *input_loop;
578         struct wl_event_source *input_loop_source;
579
580         struct wl_signal session_signal;
581         int session_active;
582
583         struct weston_layer fade_layer;
584         struct weston_layer cursor_layer;
585
586         struct wl_list output_list;
587         struct wl_list seat_list;
588         struct wl_list layer_list;
589         struct wl_list view_list;
590         struct wl_list plane_list;
591         struct wl_list key_binding_list;
592         struct wl_list modifier_binding_list;
593         struct wl_list button_binding_list;
594         struct wl_list touch_binding_list;
595         struct wl_list axis_binding_list;
596         struct wl_list debug_binding_list;
597
598         uint32_t state;
599         struct wl_event_source *idle_source;
600         uint32_t idle_inhibit;
601         int idle_time;                  /* timeout, s */
602
603         const struct weston_pointer_grab_interface *default_pointer_grab;
604
605         /* Repaint state. */
606         struct weston_plane primary_plane;
607         uint32_t capabilities; /* combination of enum weston_capability */
608
609         struct weston_renderer *renderer;
610
611         pixman_format_code_t read_format;
612
613         void (*destroy)(struct weston_compositor *ec);
614         void (*restore)(struct weston_compositor *ec);
615         int (*authenticate)(struct weston_compositor *c, uint32_t id);
616
617         void (*ping_handler)(struct weston_surface *surface, uint32_t serial);
618
619         struct weston_launcher *launcher;
620
621         uint32_t output_id_pool;
622
623         struct xkb_rule_names xkb_names;
624         struct xkb_context *xkb_context;
625         struct weston_xkb_info *xkb_info;
626
627         /* Raw keyboard processing (no libxkbcommon initialization or handling) */
628         int use_xkbcommon;
629 };
630
631 struct weston_buffer {
632         struct wl_resource *resource;
633         struct wl_signal destroy_signal;
634         struct wl_listener destroy_listener;
635
636         union {
637                 struct wl_shm_buffer *shm_buffer;
638                 void *legacy_buffer;
639         };
640         int32_t width, height;
641         uint32_t busy_count;
642         int y_inverted;
643 };
644
645 struct weston_buffer_reference {
646         struct weston_buffer *buffer;
647         struct wl_listener destroy_listener;
648 };
649
650 struct weston_buffer_viewport {
651         /* wl_surface.set_buffer_transform */
652         uint32_t transform;
653
654         /* wl_surface.set_scaling_factor */
655         int32_t scale;
656 };
657
658 struct weston_region {
659         struct wl_resource *resource;
660         pixman_region32_t region;
661 };
662
663 struct weston_subsurface {
664         struct wl_resource *resource;
665
666         /* guaranteed to be valid and non-NULL */
667         struct weston_surface *surface;
668         struct wl_listener surface_destroy_listener;
669
670         /* can be NULL */
671         struct weston_surface *parent;
672         struct wl_listener parent_destroy_listener;
673         struct wl_list parent_link;
674         struct wl_list parent_link_pending;
675
676         struct {
677                 int32_t x;
678                 int32_t y;
679                 int set;
680         } position;
681
682         struct {
683                 int has_data;
684
685                 /* wl_surface.attach */
686                 int newly_attached;
687                 struct weston_buffer_reference buffer_ref;
688                 int32_t sx;
689                 int32_t sy;
690
691                 /* wl_surface.damage */
692                 pixman_region32_t damage;
693
694                 /* wl_surface.set_opaque_region */
695                 pixman_region32_t opaque;
696
697                 /* wl_surface.set_input_region */
698                 pixman_region32_t input;
699
700                 /* wl_surface.frame */
701                 struct wl_list frame_callback_list;
702
703                 /* wl_surface.set_buffer_transform */
704                 /* wl_surface.set_buffer_scale */
705                 struct weston_buffer_viewport buffer_viewport;
706         } cached;
707
708         int synchronized;
709
710         /* Used for constructing the view tree */
711         struct wl_list unused_views;
712 };
713
714 /* Using weston_view transformations
715  *
716  * To add a transformation to a view, create a struct weston_transform, and
717  * add it to the list view->geometry.transformation_list. Whenever you
718  * change the list, anything under view->geometry, or anything in the
719  * weston_transforms linked into the list, you must call
720  * weston_view_geometry_dirty().
721  *
722  * The order in the list defines the order of transformations. Let the list
723  * contain the transformation matrices M1, ..., Mn as head to tail. The
724  * transformation is applied to view-local coordinate vector p as
725  *    P = Mn * ... * M2 * M1 * p
726  * to produce the global coordinate vector P. The total transform
727  *    Mn * ... * M2 * M1
728  * is cached in view->transform.matrix, and the inverse of it in
729  * view->transform.inverse.
730  *
731  * The list always contains view->transform.position transformation, which
732  * is the translation by view->geometry.x and y.
733  *
734  * If you want to apply a transformation in local coordinates, add your
735  * weston_transform to the head of the list. If you want to apply a
736  * transformation in global coordinates, add it to the tail of the list.
737  *
738  * If view->geometry.parent is set, the total transformation of this
739  * view will be the parent's total transformation and this transformation
740  * combined:
741  *    Mparent * Mn * ... * M2 * M1
742  */
743
744 struct weston_view {
745         struct weston_surface *surface;
746         struct wl_list surface_link;
747         struct wl_signal destroy_signal;
748
749         struct wl_list link;
750         struct wl_list layer_link;
751         struct weston_plane *plane;
752
753         pixman_region32_t clip;
754         float alpha;                     /* part of geometry, see below */
755
756         void *renderer_state;
757
758         /* Surface geometry state, mutable.
759          * If you change anything, call weston_surface_geometry_dirty().
760          * That includes the transformations referenced from the list.
761          */
762         struct {
763                 float x, y; /* surface translation on display */
764                 int32_t width, height;
765
766                 /* struct weston_transform */
767                 struct wl_list transformation_list;
768
769                 /* managed by weston_surface_set_transform_parent() */
770                 struct weston_view *parent;
771                 struct wl_listener parent_destroy_listener;
772                 struct wl_list child_list; /* geometry.parent_link */
773                 struct wl_list parent_link;
774         } geometry;
775
776         /* State derived from geometry state, read-only.
777          * This is updated by weston_view_update_transform().
778          */
779         struct {
780                 int dirty;
781
782                 pixman_region32_t boundingbox;
783                 pixman_region32_t opaque;
784
785                 /* matrix and inverse are used only if enabled = 1.
786                  * If enabled = 0, use x, y, width, height directly.
787                  */
788                 int enabled;
789                 struct weston_matrix matrix;
790                 struct weston_matrix inverse;
791
792                 struct weston_transform position; /* matrix from x, y */
793         } transform;
794
795         /*
796          * Which output to vsync this surface to.
797          * Used to determine, whether to send or queue frame events.
798          * Must be NULL, if 'link' is not in weston_compositor::surface_list.
799          */
800         struct weston_output *output;
801
802         /*
803          * A more complete representation of all outputs this surface is
804          * displayed on.
805          */
806         uint32_t output_mask;
807 };
808
809 struct weston_surface {
810         struct wl_resource *resource;
811         struct wl_signal destroy_signal;
812         struct weston_compositor *compositor;
813         pixman_region32_t damage;
814         pixman_region32_t opaque;        /* part of geometry, see below */
815         pixman_region32_t input;
816         int32_t width, height;
817         int32_t ref_count;
818
819         /* Not for long-term storage.  This exists for book-keeping while
820          * iterating over surfaces and views
821          */
822         int32_t touched;
823
824         void *renderer_state;
825
826         struct wl_list views;
827
828         /*
829          * Which output to vsync this surface to.
830          * Used to determine, whether to send or queue frame events.
831          * Must be NULL, if 'link' is not in weston_compositor::surface_list.
832          */
833         struct weston_output *output;
834
835         /*
836          * A more complete representation of all outputs this surface is
837          * displayed on.
838          */
839         uint32_t output_mask;
840
841         struct wl_list frame_callback_list;
842
843         struct weston_buffer_reference buffer_ref;
844         struct weston_buffer_viewport buffer_viewport;
845         int keep_buffer; /* bool for backends to prevent early release */
846
847         /* All the pending state, that wl_surface.commit will apply. */
848         struct {
849                 /* wl_surface.attach */
850                 int newly_attached;
851                 struct weston_buffer *buffer;
852                 struct wl_listener buffer_destroy_listener;
853                 int32_t sx;
854                 int32_t sy;
855
856                 /* wl_surface.damage */
857                 pixman_region32_t damage;
858
859                 /* wl_surface.set_opaque_region */
860                 pixman_region32_t opaque;
861
862                 /* wl_surface.set_input_region */
863                 pixman_region32_t input;
864
865                 /* wl_surface.frame */
866                 struct wl_list frame_callback_list;
867
868                 /* wl_surface.set_buffer_transform */
869                 /* wl_surface.set_scaling_factor */
870                 struct weston_buffer_viewport buffer_viewport;
871         } pending;
872
873         /*
874          * If non-NULL, this function will be called on surface::attach after
875          * a new buffer has been set up for this surface. The integer params
876          * are the sx and sy paramerters supplied to surface::attach .
877          */
878         void (*configure)(struct weston_surface *es, int32_t sx, int32_t sy, int32_t width, int32_t height);
879         void *configure_private;
880
881         /* Parent's list of its sub-surfaces, weston_subsurface:parent_link.
882          * Contains also the parent itself as a dummy weston_subsurface,
883          * if the list is not empty.
884          */
885         struct wl_list subsurface_list; /* weston_subsurface::parent_link */
886         struct wl_list subsurface_list_pending; /* ...::parent_link_pending */
887 };
888
889 enum weston_key_state_update {
890         STATE_UPDATE_AUTOMATIC,
891         STATE_UPDATE_NONE,
892 };
893
894 void
895 weston_version(int *major, int *minor, int *micro);
896
897 void
898 weston_view_update_transform(struct weston_view *view);
899
900 void
901 weston_view_geometry_dirty(struct weston_view *view);
902
903 void
904 weston_view_to_global_fixed(struct weston_view *view,
905                             wl_fixed_t sx, wl_fixed_t sy,
906                             wl_fixed_t *x, wl_fixed_t *y);
907 void
908 weston_view_to_global_float(struct weston_view *view,
909                             float sx, float sy, float *x, float *y);
910
911 void
912 weston_view_from_global_float(struct weston_view *view,
913                               float x, float y, float *vx, float *vy);
914 void
915 weston_view_from_global(struct weston_view *view,
916                         int32_t x, int32_t y, int32_t *vx, int32_t *vy);
917 void
918 weston_view_from_global_fixed(struct weston_view *view,
919                               wl_fixed_t x, wl_fixed_t y,
920                               wl_fixed_t *vx, wl_fixed_t *vy);
921 int32_t
922 weston_surface_buffer_width(struct weston_surface *surface);
923 int32_t
924 weston_surface_buffer_height(struct weston_surface *surface);
925
926 WL_EXPORT void
927 weston_surface_to_buffer_float(struct weston_surface *surface,
928                                float x, float y, float *bx, float *by);
929 WL_EXPORT void
930 weston_surface_to_buffer(struct weston_surface *surface,
931                          int sx, int sy, int *bx, int *by);
932 pixman_box32_t
933 weston_surface_to_buffer_rect(struct weston_surface *surface,
934                               pixman_box32_t rect);
935
936 void
937 weston_spring_init(struct weston_spring *spring,
938                    double k, double current, double target);
939 void
940 weston_spring_update(struct weston_spring *spring, uint32_t msec);
941 int
942 weston_spring_done(struct weston_spring *spring);
943
944 void
945 weston_surface_activate(struct weston_surface *surface,
946                         struct weston_seat *seat);
947 void
948 notify_motion(struct weston_seat *seat, uint32_t time,
949               wl_fixed_t dx, wl_fixed_t dy);
950 void
951 notify_motion_absolute(struct weston_seat *seat, uint32_t time,
952                        wl_fixed_t x, wl_fixed_t y);
953 void
954 notify_button(struct weston_seat *seat, uint32_t time, int32_t button,
955               enum wl_pointer_button_state state);
956 void
957 notify_axis(struct weston_seat *seat, uint32_t time, uint32_t axis,
958             wl_fixed_t value);
959 void
960 notify_key(struct weston_seat *seat, uint32_t time, uint32_t key,
961            enum wl_keyboard_key_state state,
962            enum weston_key_state_update update_state);
963 void
964 notify_modifiers(struct weston_seat *seat, uint32_t serial);
965
966 void
967 notify_pointer_focus(struct weston_seat *seat, struct weston_output *output,
968                      wl_fixed_t x, wl_fixed_t y);
969
970 void
971 notify_keyboard_focus_in(struct weston_seat *seat, struct wl_array *keys,
972                          enum weston_key_state_update update_state);
973 void
974 notify_keyboard_focus_out(struct weston_seat *seat);
975
976 void
977 notify_touch(struct weston_seat *seat, uint32_t time, int touch_id,
978              wl_fixed_t x, wl_fixed_t y, int touch_type);
979
980 void
981 weston_layer_init(struct weston_layer *layer, struct wl_list *below);
982
983 void
984 weston_plane_init(struct weston_plane *plane,
985                         struct weston_compositor *ec,
986                         int32_t x, int32_t y);
987 void
988 weston_plane_release(struct weston_plane *plane);
989
990 void
991 weston_compositor_stack_plane(struct weston_compositor *ec,
992                               struct weston_plane *plane,
993                               struct weston_plane *above);
994
995 void
996 weston_output_finish_frame(struct weston_output *output, uint32_t msecs);
997 void
998 weston_output_schedule_repaint(struct weston_output *output);
999 void
1000 weston_output_damage(struct weston_output *output);
1001 void
1002 weston_compositor_schedule_repaint(struct weston_compositor *compositor);
1003 void
1004 weston_compositor_fade(struct weston_compositor *compositor, float tint);
1005 void
1006 weston_compositor_damage_all(struct weston_compositor *compositor);
1007 void
1008 weston_compositor_unlock(struct weston_compositor *compositor);
1009 void
1010 weston_compositor_wake(struct weston_compositor *compositor);
1011 void
1012 weston_compositor_offscreen(struct weston_compositor *compositor);
1013 void
1014 weston_compositor_sleep(struct weston_compositor *compositor);
1015 struct weston_view *
1016 weston_compositor_pick_view(struct weston_compositor *compositor,
1017                             wl_fixed_t x, wl_fixed_t y,
1018                             wl_fixed_t *sx, wl_fixed_t *sy);
1019
1020
1021 struct weston_binding;
1022 typedef void (*weston_key_binding_handler_t)(struct weston_seat *seat,
1023                                              uint32_t time, uint32_t key,
1024                                              void *data);
1025 struct weston_binding *
1026 weston_compositor_add_key_binding(struct weston_compositor *compositor,
1027                                   uint32_t key,
1028                                   enum weston_keyboard_modifier modifier,
1029                                   weston_key_binding_handler_t binding,
1030                                   void *data);
1031
1032 typedef void (*weston_modifier_binding_handler_t)(struct weston_seat *seat,
1033                                                   enum weston_keyboard_modifier modifier,
1034                                                   void *data);
1035 struct weston_binding *
1036 weston_compositor_add_modifier_binding(struct weston_compositor *compositor,
1037                                        enum weston_keyboard_modifier modifier,
1038                                        weston_modifier_binding_handler_t binding,
1039                                        void *data);
1040
1041 typedef void (*weston_button_binding_handler_t)(struct weston_seat *seat,
1042                                                 uint32_t time, uint32_t button,
1043                                                 void *data);
1044 struct weston_binding *
1045 weston_compositor_add_button_binding(struct weston_compositor *compositor,
1046                                      uint32_t button,
1047                                      enum weston_keyboard_modifier modifier,
1048                                      weston_button_binding_handler_t binding,
1049                                      void *data);
1050
1051 typedef void (*weston_touch_binding_handler_t)(struct weston_seat *seat,
1052                                                uint32_t time,
1053                                                void *data);
1054 struct weston_binding *
1055 weston_compositor_add_touch_binding(struct weston_compositor *compositor,
1056                                     enum weston_keyboard_modifier modifier,
1057                                     weston_touch_binding_handler_t binding,
1058                                     void *data);
1059
1060 typedef void (*weston_axis_binding_handler_t)(struct weston_seat *seat,
1061                                               uint32_t time, uint32_t axis,
1062                                               wl_fixed_t value, void *data);
1063 struct weston_binding *
1064 weston_compositor_add_axis_binding(struct weston_compositor *compositor,
1065                                    uint32_t axis,
1066                                    enum weston_keyboard_modifier modifier,
1067                                    weston_axis_binding_handler_t binding,
1068                                    void *data);
1069 struct weston_binding *
1070 weston_compositor_add_debug_binding(struct weston_compositor *compositor,
1071                                     uint32_t key,
1072                                     weston_key_binding_handler_t binding,
1073                                     void *data);
1074 void
1075 weston_binding_destroy(struct weston_binding *binding);
1076
1077 void
1078 weston_binding_list_destroy_all(struct wl_list *list);
1079
1080 void
1081 weston_compositor_run_key_binding(struct weston_compositor *compositor,
1082                                   struct weston_seat *seat, uint32_t time,
1083                                   uint32_t key,
1084                                   enum wl_keyboard_key_state state);
1085
1086 void
1087 weston_compositor_run_modifier_binding(struct weston_compositor *compositor,
1088                                        struct weston_seat *seat,
1089                                        enum weston_keyboard_modifier modifier,
1090                                        enum wl_keyboard_key_state state);
1091 void
1092 weston_compositor_run_button_binding(struct weston_compositor *compositor,
1093                                      struct weston_seat *seat, uint32_t time,
1094                                      uint32_t button,
1095                                      enum wl_pointer_button_state value);
1096 void
1097 weston_compositor_run_touch_binding(struct weston_compositor *compositor,
1098                                     struct weston_seat *seat, uint32_t time,
1099                                     int touch_type);
1100 int
1101 weston_compositor_run_axis_binding(struct weston_compositor *compositor,
1102                                    struct weston_seat *seat, uint32_t time,
1103                                    uint32_t axis, int32_t value);
1104 int
1105 weston_compositor_run_debug_binding(struct weston_compositor *compositor,
1106                                     struct weston_seat *seat, uint32_t time,
1107                                     uint32_t key,
1108                                     enum wl_keyboard_key_state state);
1109
1110 void
1111 weston_compositor_set_default_pointer_grab(struct weston_compositor *compositor,
1112                         const struct weston_pointer_grab_interface *interface);
1113
1114 int
1115 weston_environment_get_fd(const char *env);
1116
1117 struct wl_list *
1118 weston_compositor_top(struct weston_compositor *compositor);
1119
1120 struct weston_surface *
1121 weston_surface_create(struct weston_compositor *compositor);
1122
1123 struct weston_view *
1124 weston_view_create(struct weston_surface *surface);
1125
1126 void
1127 weston_view_destroy(struct weston_view *view);
1128
1129 void
1130 weston_view_configure(struct weston_view *view,
1131                       float x, float y, int width, int height);
1132
1133 void
1134 weston_view_restack(struct weston_view *surface, struct wl_list *below);
1135
1136 void
1137 weston_view_set_position(struct weston_view *view,
1138                          float x, float y);
1139
1140 void
1141 weston_view_set_transform_parent(struct weston_view *view,
1142                                  struct weston_view *parent);
1143
1144 int
1145 weston_view_is_mapped(struct weston_view *view);
1146
1147 void
1148 weston_view_schedule_repaint(struct weston_view *view);
1149
1150 int
1151 weston_surface_is_mapped(struct weston_surface *surface);
1152
1153 void
1154 weston_surface_schedule_repaint(struct weston_surface *surface);
1155
1156 void
1157 weston_surface_damage(struct weston_surface *surface);
1158
1159 void
1160 weston_view_damage_below(struct weston_view *view);
1161
1162 void
1163 weston_view_move_to_plane(struct weston_view *view,
1164                           struct weston_plane *plane);
1165 void
1166 weston_view_unmap(struct weston_view *view);
1167
1168 void
1169 weston_surface_unmap(struct weston_surface *surface);
1170
1171 struct weston_surface *
1172 weston_surface_get_main_surface(struct weston_surface *surface);
1173
1174 struct weston_buffer *
1175 weston_buffer_from_resource(struct wl_resource *resource);
1176
1177 void
1178 weston_buffer_reference(struct weston_buffer_reference *ref,
1179                         struct weston_buffer *buffer);
1180
1181 uint32_t
1182 weston_compositor_get_time(void);
1183
1184 int
1185 weston_compositor_init(struct weston_compositor *ec, struct wl_display *display,
1186                        int *argc, char *argv[], struct weston_config *config);
1187 void
1188 weston_compositor_shutdown(struct weston_compositor *ec);
1189 void
1190 weston_output_init_zoom(struct weston_output *output);
1191 void
1192 weston_output_update_zoom(struct weston_output *output);
1193 void
1194 weston_output_activate_zoom(struct weston_output *output);
1195 void
1196 weston_output_update_matrix(struct weston_output *output);
1197 void
1198 weston_output_move(struct weston_output *output, int x, int y);
1199 void
1200 weston_output_init(struct weston_output *output, struct weston_compositor *c,
1201                    int x, int y, int width, int height, uint32_t transform, int32_t scale);
1202 void
1203 weston_output_destroy(struct weston_output *output);
1204 void
1205 weston_output_transform_coordinate(struct weston_output *output,
1206                                    wl_fixed_t device_x, wl_fixed_t device_y,
1207                                    wl_fixed_t *x, wl_fixed_t *y);
1208
1209 void
1210 weston_seat_init(struct weston_seat *seat, struct weston_compositor *ec,
1211                  const char *seat_name);
1212 void
1213 weston_seat_init_pointer(struct weston_seat *seat);
1214 void
1215 weston_seat_release_pointer(struct weston_seat *seat);
1216 int
1217 weston_seat_init_keyboard(struct weston_seat *seat, struct xkb_keymap *keymap);
1218 void
1219 weston_seat_release_keyboard(struct weston_seat *seat);
1220 void
1221 weston_seat_init_touch(struct weston_seat *seat);
1222 void
1223 weston_seat_release_touch(struct weston_seat *seat);
1224 void
1225 weston_seat_repick(struct weston_seat *seat);
1226 void
1227 weston_seat_update_keymap(struct weston_seat *seat, struct xkb_keymap *keymap);
1228
1229 void
1230 weston_seat_release(struct weston_seat *seat);
1231 int
1232 weston_compositor_xkb_init(struct weston_compositor *ec,
1233                            struct xkb_rule_names *names);
1234 void
1235 weston_compositor_xkb_destroy(struct weston_compositor *ec);
1236
1237 /* String literal of spaces, the same width as the timestamp. */
1238 #define STAMP_SPACE "               "
1239
1240 void
1241 weston_log_file_open(const char *filename);
1242 void
1243 weston_log_file_close(void);
1244 int
1245 weston_vlog(const char *fmt, va_list ap);
1246 int
1247 weston_vlog_continue(const char *fmt, va_list ap);
1248 int
1249 weston_log(const char *fmt, ...)
1250         __attribute__ ((format (printf, 1, 2)));
1251 int
1252 weston_log_continue(const char *fmt, ...)
1253         __attribute__ ((format (printf, 1, 2)));
1254
1255 enum {
1256         TTY_ENTER_VT,
1257         TTY_LEAVE_VT
1258 };
1259
1260 struct tty *
1261 tty_create(struct weston_compositor *compositor, int tty_nr);
1262
1263 void
1264 tty_destroy(struct tty *tty);
1265
1266 void
1267 tty_reset(struct tty *tty);
1268
1269 int
1270 tty_activate_vt(struct tty *tty, int vt);
1271
1272 void
1273 screenshooter_create(struct weston_compositor *ec);
1274
1275 struct clipboard *
1276 clipboard_create(struct weston_seat *seat);
1277
1278 int
1279 text_backend_init(struct weston_compositor *ec);
1280
1281 struct weston_process;
1282 typedef void (*weston_process_cleanup_func_t)(struct weston_process *process,
1283                                             int status);
1284
1285 struct weston_process {
1286         pid_t pid;
1287         weston_process_cleanup_func_t cleanup;
1288         struct wl_list link;
1289 };
1290
1291 struct wl_client *
1292 weston_client_launch(struct weston_compositor *compositor,
1293                      struct weston_process *proc,
1294                      const char *path,
1295                      weston_process_cleanup_func_t cleanup);
1296
1297 void
1298 weston_watch_process(struct weston_process *process);
1299
1300 struct weston_view_animation;
1301 typedef void (*weston_view_animation_done_func_t)(struct weston_view_animation *animation, void *data);
1302
1303 void
1304 weston_view_animation_destroy(struct weston_view_animation *animation);
1305
1306 struct weston_view_animation *
1307 weston_zoom_run(struct weston_view *view, float start, float stop,
1308                 weston_view_animation_done_func_t done, void *data);
1309
1310 struct weston_view_animation *
1311 weston_fade_run(struct weston_view *view,
1312                 float start, float end, float k,
1313                 weston_view_animation_done_func_t done, void *data);
1314
1315 struct weston_view_animation *
1316 weston_move_scale_run(struct weston_view *view, int dx, int dy,
1317                       float start, float end, int reverse,
1318                       weston_view_animation_done_func_t done, void *data);
1319
1320 void
1321 weston_fade_update(struct weston_view_animation *fade, float target);
1322
1323 struct weston_view_animation *
1324 weston_stable_fade_run(struct weston_view *front_view, float start,
1325                        struct weston_view *back_view, float end,
1326                        weston_view_animation_done_func_t done, void *data);
1327
1328 struct weston_view_animation *
1329 weston_slide_run(struct weston_view *view, float start, float stop,
1330                  weston_view_animation_done_func_t done, void *data);
1331
1332 void
1333 weston_surface_set_color(struct weston_surface *surface,
1334                          float red, float green, float blue, float alpha);
1335
1336 void
1337 weston_surface_destroy(struct weston_surface *surface);
1338
1339 int
1340 weston_output_switch_mode(struct weston_output *output, struct weston_mode *mode,
1341                         int32_t scale, enum weston_mode_switch_op op);
1342
1343 int
1344 noop_renderer_init(struct weston_compositor *ec);
1345
1346 struct weston_compositor *
1347 backend_init(struct wl_display *display, int *argc, char *argv[],
1348              struct weston_config *config);
1349
1350 int
1351 module_init(struct weston_compositor *compositor,
1352             int *argc, char *argv[]);
1353
1354 void
1355 weston_transformed_coord(int width, int height,
1356                          enum wl_output_transform transform,
1357                          int32_t scale,
1358                          float sx, float sy, float *bx, float *by);
1359 pixman_box32_t
1360 weston_transformed_rect(int width, int height,
1361                         enum wl_output_transform transform,
1362                         int32_t scale,
1363                         pixman_box32_t rect);
1364 void
1365 weston_transformed_region(int width, int height,
1366                           enum wl_output_transform transform,
1367                           int32_t scale,
1368                           pixman_region32_t *src, pixman_region32_t *dest);
1369
1370 void *
1371 weston_load_module(const char *name, const char *entrypoint);
1372
1373 #ifdef  __cplusplus
1374 }
1375 #endif
1376
1377 #endif