2 * Copyright © 2008-2011 Kristian Høgsberg
3 * Copyright © 2012 Collabora, Ltd.
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.
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.
24 #ifndef _WAYLAND_SYSTEM_COMPOSITOR_H_
25 #define _WAYLAND_SYSTEM_COMPOSITOR_H_
32 #include <xkbcommon/xkbcommon.h>
33 #include <wayland-server.h>
37 #include "config-parser.h"
39 #define ARRAY_LENGTH(a) (sizeof (a) / sizeof (a)[0])
41 #define container_of(ptr, type, member) ({ \
42 const __typeof__( ((type *)0)->member ) *__mptr = (ptr); \
43 (type *)( (char *)__mptr - offsetof(type,member) );})
45 struct weston_transform {
46 struct weston_matrix matrix;
50 struct weston_surface;
56 enum weston_keyboard_modifier {
57 MODIFIER_CTRL = (1 << 0),
58 MODIFIER_ALT = (1 << 1),
59 MODIFIER_SUPER = (1 << 2),
60 MODIFIER_SHIFT = (1 << 3),
64 LED_NUM_LOCK = (1 << 0),
65 LED_CAPS_LOCK = (1 << 1),
66 LED_SCROLL_LOCK = (1 << 2),
71 int32_t width, height;
76 struct weston_shell_client {
77 void (*send_configure)(struct weston_surface *surface,
78 uint32_t edges, int32_t width, int32_t height);
81 struct weston_shell_interface {
82 void *shell; /* either desktop or tablet */
84 struct shell_surface *(*create_shell_surface)(void *shell,
85 struct weston_surface *surface,
86 const struct weston_shell_client *client);
88 void (*set_toplevel)(struct shell_surface *shsurf);
90 void (*set_transient)(struct shell_surface *shsurf,
91 struct weston_surface *parent,
92 int x, int y, uint32_t flags);
93 void (*set_fullscreen)(struct shell_surface *shsurf,
96 struct weston_output *output);
97 int (*move)(struct shell_surface *shsurf, struct weston_seat *ws);
98 int (*resize)(struct shell_surface *shsurf,
99 struct weston_seat *ws, uint32_t edges);
103 struct weston_border {
104 int32_t left, right, top, bottom;
107 struct weston_animation {
108 void (*frame)(struct weston_animation *animation,
109 struct weston_output *output, uint32_t msecs);
114 struct weston_spring {
128 struct weston_fixed_point {
132 struct weston_output_zoom {
138 float trans_x, trans_y;
139 struct weston_animation animation_z;
140 struct weston_spring spring_z;
141 struct weston_animation animation_xy;
142 struct weston_spring spring_xy;
143 struct weston_fixed_point from;
144 struct weston_fixed_point to;
145 struct weston_fixed_point current;
146 struct weston_fixed_point text_cursor;
149 /* bit compatible with drm definitions. */
157 struct weston_output {
160 void *renderer_state;
163 struct wl_list resource_list;
164 struct wl_global *global;
165 struct weston_compositor *compositor;
166 struct weston_matrix matrix;
167 struct wl_list animation_list;
168 int32_t x, y, width, height;
169 int32_t mm_width, mm_height;
170 struct weston_border border;
171 pixman_region32_t region;
172 pixman_region32_t previous_damage;
174 int repaint_scheduled;
175 struct weston_output_zoom zoom;
177 struct wl_signal frame_signal;
185 struct weston_mode *current;
186 struct weston_mode *origin;
187 struct wl_list mode_list;
189 void (*repaint)(struct weston_output *output,
190 pixman_region32_t *damage);
191 void (*destroy)(struct weston_output *output);
192 void (*assign_planes)(struct weston_output *output);
193 int (*switch_mode)(struct weston_output *output, struct weston_mode *mode);
195 /* backlight values are on 0-255 range, where higher is brighter */
196 uint32_t backlight_current;
197 void (*set_backlight)(struct weston_output *output, uint32_t value);
198 void (*set_dpms)(struct weston_output *output, enum dpms_enum level);
201 struct weston_xkb_info {
202 struct xkb_keymap *keymap;
206 xkb_mod_index_t shift_mod;
207 xkb_mod_index_t caps_mod;
208 xkb_mod_index_t ctrl_mod;
209 xkb_mod_index_t alt_mod;
210 xkb_mod_index_t mod2_mod;
211 xkb_mod_index_t mod3_mod;
212 xkb_mod_index_t super_mod;
213 xkb_mod_index_t mod5_mod;
214 xkb_led_index_t num_led;
215 xkb_led_index_t caps_led;
216 xkb_led_index_t scroll_led;
219 struct weston_keyboard {
220 struct wl_keyboard keyboard;
222 struct wl_keyboard_grab input_method_grab;
223 struct wl_resource *input_method_resource;
228 struct wl_pointer pointer;
230 struct weston_keyboard keyboard;
232 struct wl_touch touch;
234 struct wl_signal destroy_signal;
236 struct weston_compositor *compositor;
237 struct weston_surface *sprite;
238 struct wl_listener sprite_destroy_listener;
239 struct weston_surface *drag_surface;
240 struct wl_listener drag_surface_destroy_listener;
241 int32_t hotspot_x, hotspot_y;
243 enum weston_keyboard_modifier modifier_state;
244 struct wl_surface *saved_kbd_focus;
245 struct wl_listener saved_kbd_focus_listener;
249 struct wl_listener new_drag_icon_listener;
251 void (*led_update)(struct weston_seat *ws, enum weston_led leds);
253 struct weston_xkb_info xkb_info;
255 struct xkb_state *state;
256 enum weston_led leds;
259 struct input_method *input_method;
263 WESTON_COMPOSITOR_ACTIVE,
264 WESTON_COMPOSITOR_IDLE, /* shell->unlock called on activity */
265 WESTON_COMPOSITOR_SLEEPING /* no rendering, no frame events */
268 struct weston_layer {
269 struct wl_list surface_list;
273 struct weston_plane {
274 pixman_region32_t damage;
275 pixman_region32_t clip;
280 struct weston_renderer {
281 int (*read_pixels)(struct weston_output *output,
282 pixman_format_code_t format, void *pixels,
283 uint32_t x, uint32_t y,
284 uint32_t width, uint32_t height);
285 void (*repaint_output)(struct weston_output *output,
286 pixman_region32_t *output_damage);
287 void (*flush_damage)(struct weston_surface *surface);
288 void (*attach)(struct weston_surface *es, struct wl_buffer *buffer);
289 int (*create_surface)(struct weston_surface *surface);
290 void (*surface_set_color)(struct weston_surface *surface,
291 float red, float green,
292 float blue, float alpha);
293 void (*destroy_surface)(struct weston_surface *surface);
294 void (*destroy)(struct weston_compositor *ec);
297 struct weston_compositor {
298 struct wl_signal destroy_signal;
300 struct wl_display *wl_display;
301 struct weston_shell_interface shell_interface;
303 struct wl_signal activate_signal;
304 struct wl_signal kill_signal;
305 struct wl_signal idle_signal;
306 struct wl_signal wake_signal;
308 struct wl_signal show_input_panel_signal;
309 struct wl_signal hide_input_panel_signal;
311 struct wl_signal seat_created_signal;
313 struct wl_event_loop *input_loop;
314 struct wl_event_source *input_loop_source;
316 struct weston_layer fade_layer;
317 struct weston_layer cursor_layer;
319 struct wl_list output_list;
320 struct wl_list seat_list;
321 struct wl_list layer_list;
322 struct wl_list surface_list;
323 struct wl_list plane_list;
324 struct wl_list key_binding_list;
325 struct wl_list button_binding_list;
326 struct wl_list axis_binding_list;
327 struct wl_list debug_binding_list;
330 struct wl_event_source *idle_source;
331 uint32_t idle_inhibit;
332 int idle_time; /* timeout, s */
335 struct wl_array vertices;
336 struct wl_array indices; /* only used in compositor-wayland */
337 struct wl_array vtxcnt;
338 struct weston_plane primary_plane;
343 struct weston_renderer *renderer;
345 pixman_format_code_t read_format;
347 void (*destroy)(struct weston_compositor *ec);
348 void (*restore)(struct weston_compositor *ec);
349 int (*authenticate)(struct weston_compositor *c, uint32_t id);
351 void (*ping_handler)(struct weston_surface *surface, uint32_t serial);
355 uint32_t output_id_pool;
357 struct xkb_rule_names xkb_names;
358 struct xkb_context *xkb_context;
359 struct weston_xkb_info xkb_info;
362 struct weston_buffer_reference {
363 struct wl_buffer *buffer;
364 struct wl_listener destroy_listener;
367 struct weston_region {
368 struct wl_resource resource;
369 pixman_region32_t region;
372 /* Using weston_surface transformations
374 * To add a transformation to a surface, create a struct weston_transform, and
375 * add it to the list surface->geometry.transformation_list. Whenever you
376 * change the list, anything under surface->geometry, or anything in the
377 * weston_transforms linked into the list, you must call
378 * weston_surface_geometry_dirty().
380 * The order in the list defines the order of transformations. Let the list
381 * contain the transformation matrices M1, ..., Mn as head to tail. The
382 * transformation is applied to surface-local coordinate vector p as
383 * P = Mn * ... * M2 * M1 * p
384 * to produce the global coordinate vector P. The total transform
386 * is cached in surface->transform.matrix, and the inverse of it in
387 * surface->transform.inverse.
389 * The list always contains surface->transform.position transformation, which
390 * is the translation by surface->geometry.x and y.
392 * If you want to apply a transformation in local coordinates, add your
393 * weston_transform to the head of the list. If you want to apply a
394 * transformation in global coordinates, add it to the tail of the list.
396 * If surface->geometry.parent is set, the total transformation of this
397 * surface will be the parent's total transformation and this transformation
399 * Mparent * Mn * ... * M2 * M1
402 struct weston_surface {
403 struct wl_surface surface;
404 struct weston_compositor *compositor;
405 pixman_region32_t clip;
406 pixman_region32_t damage;
407 pixman_region32_t opaque; /* part of geometry, see below */
408 pixman_region32_t input;
410 struct wl_list layer_link;
411 float alpha; /* part of geometry, see below */
412 struct weston_plane *plane;
414 void *renderer_state;
416 /* Surface geometry state, mutable.
417 * If you change anything, call weston_surface_geometry_dirty().
418 * That includes the transformations referenced from the list.
421 float x, y; /* surface translation on display */
422 int32_t width, height;
424 /* struct weston_transform */
425 struct wl_list transformation_list;
427 /* managed by weston_surface_set_transform_parent() */
428 struct weston_surface *parent;
429 struct wl_listener parent_destroy_listener;
430 struct wl_list child_list; /* geometry.parent_link */
431 struct wl_list parent_link;
434 /* State derived from geometry state, read-only.
435 * This is updated by weston_surface_update_transform().
440 pixman_region32_t boundingbox;
441 pixman_region32_t opaque;
443 /* matrix and inverse are used only if enabled = 1.
444 * If enabled = 0, use x, y, width, height directly.
447 struct weston_matrix matrix;
448 struct weston_matrix inverse;
450 struct weston_transform position; /* matrix from x, y */
454 * Which output to vsync this surface to.
455 * Used to determine, whether to send or queue frame events.
456 * Must be NULL, if 'link' is not in weston_compositor::surface_list.
458 struct weston_output *output;
461 * A more complete representation of all outputs this surface is
464 uint32_t output_mask;
466 struct wl_list frame_callback_list;
468 struct weston_buffer_reference buffer_ref;
469 uint32_t buffer_transform;
470 int keep_buffer; /* bool for backends to prevent early release */
472 /* All the pending state, that wl_surface.commit will apply. */
474 /* wl_surface.attach */
476 struct wl_buffer *buffer;
477 struct wl_listener buffer_destroy_listener;
481 /* wl_surface.damage */
482 pixman_region32_t damage;
484 /* wl_surface.set_opaque_region */
485 pixman_region32_t opaque;
487 /* wl_surface.set_input_region */
488 pixman_region32_t input;
490 /* wl_surface.frame */
491 struct wl_list frame_callback_list;
493 /* wl_surface.set_buffer_transform */
494 uint32_t buffer_transform;
498 * If non-NULL, this function will be called on surface::attach after
499 * a new buffer has been set up for this surface. The integer params
500 * are the sx and sy paramerters supplied to surface::attach .
502 void (*configure)(struct weston_surface *es, int32_t sx, int32_t sy, int32_t width, int32_t height);
503 void *configure_private;
506 enum weston_key_state_update {
507 STATE_UPDATE_AUTOMATIC,
512 weston_version(int *major, int *minor, int *micro);
515 weston_surface_update_transform(struct weston_surface *surface);
518 weston_surface_geometry_dirty(struct weston_surface *surface);
521 weston_surface_to_global_fixed(struct weston_surface *surface,
522 wl_fixed_t sx, wl_fixed_t sy,
523 wl_fixed_t *x, wl_fixed_t *y);
525 weston_surface_to_global_float(struct weston_surface *surface,
526 float sx, float sy, float *x, float *y);
529 weston_surface_from_global_float(struct weston_surface *surface,
530 float x, float y, float *sx, float *sy);
532 weston_surface_from_global(struct weston_surface *surface,
533 int32_t x, int32_t y, int32_t *sx, int32_t *sy);
535 weston_surface_from_global_fixed(struct weston_surface *surface,
536 wl_fixed_t x, wl_fixed_t y,
537 wl_fixed_t *sx, wl_fixed_t *sy);
539 weston_surface_buffer_width(struct weston_surface *surface);
541 weston_surface_buffer_height(struct weston_surface *surface);
544 weston_surface_to_buffer_float(struct weston_surface *surface,
545 float x, float y, float *bx, float *by);
547 weston_surface_to_buffer_rect(struct weston_surface *surface,
548 pixman_box32_t rect);
551 weston_spring_init(struct weston_spring *spring,
552 double k, double current, double target);
554 weston_spring_update(struct weston_spring *spring, uint32_t msec);
556 weston_spring_done(struct weston_spring *spring);
559 weston_surface_activate(struct weston_surface *surface,
560 struct weston_seat *seat);
562 notify_motion(struct weston_seat *seat, uint32_t time,
563 wl_fixed_t dx, wl_fixed_t dy);
565 notify_motion_absolute(struct weston_seat *seat, uint32_t time,
566 wl_fixed_t x, wl_fixed_t y);
568 notify_button(struct weston_seat *seat, uint32_t time, int32_t button,
569 enum wl_pointer_button_state state);
571 notify_axis(struct weston_seat *seat, uint32_t time, uint32_t axis,
574 notify_key(struct weston_seat *seat, uint32_t time, uint32_t key,
575 enum wl_keyboard_key_state state,
576 enum weston_key_state_update update_state);
578 notify_modifiers(struct weston_seat *seat, uint32_t serial);
581 notify_pointer_focus(struct weston_seat *seat, struct weston_output *output,
582 wl_fixed_t x, wl_fixed_t y);
585 notify_keyboard_focus_in(struct weston_seat *seat, struct wl_array *keys,
586 enum weston_key_state_update update_state);
588 notify_keyboard_focus_out(struct weston_seat *seat);
591 notify_touch(struct weston_seat *seat, uint32_t time, int touch_id,
592 wl_fixed_t x, wl_fixed_t y, int touch_type);
595 weston_layer_init(struct weston_layer *layer, struct wl_list *below);
598 weston_plane_init(struct weston_plane *plane, int32_t x, int32_t y);
600 weston_plane_release(struct weston_plane *plane);
603 weston_compositor_stack_plane(struct weston_compositor *ec,
604 struct weston_plane *plane,
605 struct weston_plane *above);
608 weston_output_finish_frame(struct weston_output *output, uint32_t msecs);
610 weston_output_schedule_repaint(struct weston_output *output);
612 weston_output_damage(struct weston_output *output);
614 weston_compositor_schedule_repaint(struct weston_compositor *compositor);
616 weston_compositor_fade(struct weston_compositor *compositor, float tint);
618 weston_compositor_damage_all(struct weston_compositor *compositor);
620 weston_compositor_unlock(struct weston_compositor *compositor);
622 weston_compositor_wake(struct weston_compositor *compositor);
624 weston_compositor_sleep(struct weston_compositor *compositor);
626 weston_compositor_update_drag_surfaces(struct weston_compositor *compositor);
629 struct weston_binding;
630 typedef void (*weston_key_binding_handler_t)(struct wl_seat *seat,
631 uint32_t time, uint32_t key,
633 struct weston_binding *
634 weston_compositor_add_key_binding(struct weston_compositor *compositor,
636 enum weston_keyboard_modifier modifier,
637 weston_key_binding_handler_t binding,
640 typedef void (*weston_button_binding_handler_t)(struct wl_seat *seat,
641 uint32_t time, uint32_t button,
643 struct weston_binding *
644 weston_compositor_add_button_binding(struct weston_compositor *compositor,
646 enum weston_keyboard_modifier modifier,
647 weston_button_binding_handler_t binding,
650 typedef void (*weston_axis_binding_handler_t)(struct wl_seat *seat,
651 uint32_t time, uint32_t axis,
652 wl_fixed_t value, void *data);
653 struct weston_binding *
654 weston_compositor_add_axis_binding(struct weston_compositor *compositor,
656 enum weston_keyboard_modifier modifier,
657 weston_axis_binding_handler_t binding,
659 struct weston_binding *
660 weston_compositor_add_debug_binding(struct weston_compositor *compositor,
662 weston_key_binding_handler_t binding,
665 weston_binding_destroy(struct weston_binding *binding);
668 weston_binding_list_destroy_all(struct wl_list *list);
671 weston_compositor_run_key_binding(struct weston_compositor *compositor,
672 struct weston_seat *seat, uint32_t time,
674 enum wl_keyboard_key_state state);
676 weston_compositor_run_button_binding(struct weston_compositor *compositor,
677 struct weston_seat *seat, uint32_t time,
679 enum wl_pointer_button_state value);
681 weston_compositor_run_axis_binding(struct weston_compositor *compositor,
682 struct weston_seat *seat, uint32_t time,
683 uint32_t axis, int32_t value);
685 weston_compositor_run_debug_binding(struct weston_compositor *compositor,
686 struct weston_seat *seat, uint32_t time,
688 enum wl_keyboard_key_state state);
691 weston_environment_get_fd(const char *env);
694 weston_compositor_top(struct weston_compositor *compositor);
696 struct weston_surface *
697 weston_surface_create(struct weston_compositor *compositor);
700 weston_surface_configure(struct weston_surface *surface,
701 float x, float y, int width, int height);
704 weston_surface_restack(struct weston_surface *surface, struct wl_list *below);
707 weston_surface_set_position(struct weston_surface *surface,
711 weston_surface_set_transform_parent(struct weston_surface *surface,
712 struct weston_surface *parent);
715 weston_surface_is_mapped(struct weston_surface *surface);
718 weston_surface_schedule_repaint(struct weston_surface *surface);
721 weston_surface_damage(struct weston_surface *surface);
724 weston_surface_damage_below(struct weston_surface *surface);
727 weston_surface_move_to_plane(struct weston_surface *surface,
728 struct weston_plane *plane);
730 weston_surface_unmap(struct weston_surface *surface);
733 weston_buffer_reference(struct weston_buffer_reference *ref,
734 struct wl_buffer *buffer);
737 weston_compositor_get_time(void);
740 weston_compositor_init(struct weston_compositor *ec, struct wl_display *display,
741 int *argc, char *argv[], const char *config_file);
743 weston_compositor_shutdown(struct weston_compositor *ec);
745 weston_text_cursor_position_notify(struct weston_surface *surface,
746 wl_fixed_t x, wl_fixed_t y);
748 weston_output_init_zoom(struct weston_output *output);
750 weston_output_update_zoom(struct weston_output *output, uint32_t type);
752 weston_output_update_matrix(struct weston_output *output);
754 weston_output_move(struct weston_output *output, int x, int y);
756 weston_output_init(struct weston_output *output, struct weston_compositor *c,
757 int x, int y, int width, int height, uint32_t transform);
759 weston_output_destroy(struct weston_output *output);
762 weston_seat_init(struct weston_seat *seat, struct weston_compositor *ec);
764 weston_seat_init_pointer(struct weston_seat *seat);
766 weston_seat_init_keyboard(struct weston_seat *seat, struct xkb_keymap *keymap);
768 weston_seat_init_touch(struct weston_seat *seat);
771 weston_seat_release(struct weston_seat *seat);
773 /* String literal of spaces, the same width as the timestamp. */
774 #define STAMP_SPACE " "
777 weston_log_file_open(const char *filename);
779 weston_log_file_close(void);
781 weston_log(const char *fmt, ...)
782 __attribute__ ((format (printf, 1, 2)));
784 weston_log_continue(const char *fmt, ...)
785 __attribute__ ((format (printf, 1, 2)));
792 typedef void (*tty_vt_func_t)(struct weston_compositor *compositor, int event);
795 tty_create(struct weston_compositor *compositor,
796 tty_vt_func_t vt_func, int tty_nr);
799 tty_destroy(struct tty *tty);
802 tty_reset(struct tty *tty);
805 tty_activate_vt(struct tty *tty, int vt);
808 screenshooter_create(struct weston_compositor *ec);
811 clipboard_create(struct weston_seat *seat);
814 text_cursor_position_notifier_create(struct weston_compositor *ec);
817 text_backend_init(struct weston_compositor *ec);
819 struct weston_process;
820 typedef void (*weston_process_cleanup_func_t)(struct weston_process *process,
823 struct weston_process {
825 weston_process_cleanup_func_t cleanup;
830 weston_client_launch(struct weston_compositor *compositor,
831 struct weston_process *proc,
833 weston_process_cleanup_func_t cleanup);
836 weston_watch_process(struct weston_process *process);
838 struct weston_surface_animation;
839 typedef void (*weston_surface_animation_done_func_t)(struct weston_surface_animation *animation, void *data);
841 struct weston_surface_animation *
842 weston_zoom_run(struct weston_surface *surface, float start, float stop,
843 weston_surface_animation_done_func_t done, void *data);
845 struct weston_surface_animation *
846 weston_fade_run(struct weston_surface *surface,
847 float start, float end, float k,
848 weston_surface_animation_done_func_t done, void *data);
850 weston_fade_update(struct weston_surface_animation *fade,
851 float start, float end, float k);
853 struct weston_surface_animation *
854 weston_slide_run(struct weston_surface *surface, float start, float stop,
855 weston_surface_animation_done_func_t done, void *data);
858 weston_surface_set_color(struct weston_surface *surface,
859 float red, float green, float blue, float alpha);
862 weston_surface_destroy(struct weston_surface *surface);
865 weston_output_switch_mode(struct weston_output *output, struct weston_mode *mode);
868 noop_renderer_init(struct weston_compositor *ec);
870 struct weston_compositor *
871 backend_init(struct wl_display *display, int *argc, char *argv[],
872 const char *config_file);
875 module_init(struct weston_compositor *compositor,
876 int *argc, char *argv[], const char *config_file);
879 weston_transformed_coord(int width, int height,
880 enum wl_output_transform transform,
881 float sx, float sy, float *bx, float *by);
883 weston_transformed_rect(int width, int height,
884 enum wl_output_transform transform,
885 pixman_box32_t rect);