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_OFFSCREEN, /* no rendering, no frame events */
266 WESTON_COMPOSITOR_SLEEPING /* same as offscreen, but also set dmps
270 struct weston_layer {
271 struct wl_list surface_list;
275 struct weston_plane {
276 pixman_region32_t damage;
277 pixman_region32_t clip;
282 struct weston_renderer {
283 int (*read_pixels)(struct weston_output *output,
284 pixman_format_code_t format, void *pixels,
285 uint32_t x, uint32_t y,
286 uint32_t width, uint32_t height);
287 void (*repaint_output)(struct weston_output *output,
288 pixman_region32_t *output_damage);
289 void (*flush_damage)(struct weston_surface *surface);
290 void (*attach)(struct weston_surface *es, struct wl_buffer *buffer);
291 int (*create_surface)(struct weston_surface *surface);
292 void (*surface_set_color)(struct weston_surface *surface,
293 float red, float green,
294 float blue, float alpha);
295 void (*destroy_surface)(struct weston_surface *surface);
296 void (*destroy)(struct weston_compositor *ec);
299 struct weston_compositor {
300 struct wl_signal destroy_signal;
302 struct wl_display *wl_display;
303 struct weston_shell_interface shell_interface;
305 struct wl_signal activate_signal;
306 struct wl_signal kill_signal;
307 struct wl_signal idle_signal;
308 struct wl_signal wake_signal;
310 struct wl_signal show_input_panel_signal;
311 struct wl_signal hide_input_panel_signal;
313 struct wl_signal seat_created_signal;
315 struct wl_event_loop *input_loop;
316 struct wl_event_source *input_loop_source;
318 struct weston_layer fade_layer;
319 struct weston_layer cursor_layer;
321 struct wl_list output_list;
322 struct wl_list seat_list;
323 struct wl_list layer_list;
324 struct wl_list surface_list;
325 struct wl_list plane_list;
326 struct wl_list key_binding_list;
327 struct wl_list button_binding_list;
328 struct wl_list axis_binding_list;
329 struct wl_list debug_binding_list;
332 struct wl_event_source *idle_source;
333 uint32_t idle_inhibit;
334 int idle_time; /* timeout, s */
337 struct wl_array vertices;
338 struct wl_array indices; /* only used in compositor-wayland */
339 struct wl_array vtxcnt;
340 struct weston_plane primary_plane;
345 struct weston_renderer *renderer;
347 pixman_format_code_t read_format;
349 void (*destroy)(struct weston_compositor *ec);
350 void (*restore)(struct weston_compositor *ec);
351 int (*authenticate)(struct weston_compositor *c, uint32_t id);
353 void (*ping_handler)(struct weston_surface *surface, uint32_t serial);
357 uint32_t output_id_pool;
359 struct xkb_rule_names xkb_names;
360 struct xkb_context *xkb_context;
361 struct weston_xkb_info xkb_info;
364 struct weston_buffer_reference {
365 struct wl_buffer *buffer;
366 struct wl_listener destroy_listener;
369 struct weston_region {
370 struct wl_resource resource;
371 pixman_region32_t region;
374 /* Using weston_surface transformations
376 * To add a transformation to a surface, create a struct weston_transform, and
377 * add it to the list surface->geometry.transformation_list. Whenever you
378 * change the list, anything under surface->geometry, or anything in the
379 * weston_transforms linked into the list, you must call
380 * weston_surface_geometry_dirty().
382 * The order in the list defines the order of transformations. Let the list
383 * contain the transformation matrices M1, ..., Mn as head to tail. The
384 * transformation is applied to surface-local coordinate vector p as
385 * P = Mn * ... * M2 * M1 * p
386 * to produce the global coordinate vector P. The total transform
388 * is cached in surface->transform.matrix, and the inverse of it in
389 * surface->transform.inverse.
391 * The list always contains surface->transform.position transformation, which
392 * is the translation by surface->geometry.x and y.
394 * If you want to apply a transformation in local coordinates, add your
395 * weston_transform to the head of the list. If you want to apply a
396 * transformation in global coordinates, add it to the tail of the list.
398 * If surface->geometry.parent is set, the total transformation of this
399 * surface will be the parent's total transformation and this transformation
401 * Mparent * Mn * ... * M2 * M1
404 struct weston_surface {
405 struct wl_surface surface;
406 struct weston_compositor *compositor;
407 pixman_region32_t clip;
408 pixman_region32_t damage;
409 pixman_region32_t opaque; /* part of geometry, see below */
410 pixman_region32_t input;
412 struct wl_list layer_link;
413 float alpha; /* part of geometry, see below */
414 struct weston_plane *plane;
416 void *renderer_state;
418 /* Surface geometry state, mutable.
419 * If you change anything, call weston_surface_geometry_dirty().
420 * That includes the transformations referenced from the list.
423 float x, y; /* surface translation on display */
424 int32_t width, height;
426 /* struct weston_transform */
427 struct wl_list transformation_list;
429 /* managed by weston_surface_set_transform_parent() */
430 struct weston_surface *parent;
431 struct wl_listener parent_destroy_listener;
432 struct wl_list child_list; /* geometry.parent_link */
433 struct wl_list parent_link;
436 /* State derived from geometry state, read-only.
437 * This is updated by weston_surface_update_transform().
442 pixman_region32_t boundingbox;
443 pixman_region32_t opaque;
445 /* matrix and inverse are used only if enabled = 1.
446 * If enabled = 0, use x, y, width, height directly.
449 struct weston_matrix matrix;
450 struct weston_matrix inverse;
452 struct weston_transform position; /* matrix from x, y */
456 * Which output to vsync this surface to.
457 * Used to determine, whether to send or queue frame events.
458 * Must be NULL, if 'link' is not in weston_compositor::surface_list.
460 struct weston_output *output;
463 * A more complete representation of all outputs this surface is
466 uint32_t output_mask;
468 struct wl_list frame_callback_list;
470 struct weston_buffer_reference buffer_ref;
471 uint32_t buffer_transform;
472 int keep_buffer; /* bool for backends to prevent early release */
474 /* All the pending state, that wl_surface.commit will apply. */
476 /* wl_surface.attach */
478 struct wl_buffer *buffer;
479 struct wl_listener buffer_destroy_listener;
483 /* wl_surface.damage */
484 pixman_region32_t damage;
486 /* wl_surface.set_opaque_region */
487 pixman_region32_t opaque;
489 /* wl_surface.set_input_region */
490 pixman_region32_t input;
492 /* wl_surface.frame */
493 struct wl_list frame_callback_list;
495 /* wl_surface.set_buffer_transform */
496 uint32_t buffer_transform;
500 * If non-NULL, this function will be called on surface::attach after
501 * a new buffer has been set up for this surface. The integer params
502 * are the sx and sy paramerters supplied to surface::attach .
504 void (*configure)(struct weston_surface *es, int32_t sx, int32_t sy, int32_t width, int32_t height);
505 void *configure_private;
508 enum weston_key_state_update {
509 STATE_UPDATE_AUTOMATIC,
514 weston_version(int *major, int *minor, int *micro);
517 weston_surface_update_transform(struct weston_surface *surface);
520 weston_surface_geometry_dirty(struct weston_surface *surface);
523 weston_surface_to_global_fixed(struct weston_surface *surface,
524 wl_fixed_t sx, wl_fixed_t sy,
525 wl_fixed_t *x, wl_fixed_t *y);
527 weston_surface_to_global_float(struct weston_surface *surface,
528 float sx, float sy, float *x, float *y);
531 weston_surface_from_global_float(struct weston_surface *surface,
532 float x, float y, float *sx, float *sy);
534 weston_surface_from_global(struct weston_surface *surface,
535 int32_t x, int32_t y, int32_t *sx, int32_t *sy);
537 weston_surface_from_global_fixed(struct weston_surface *surface,
538 wl_fixed_t x, wl_fixed_t y,
539 wl_fixed_t *sx, wl_fixed_t *sy);
541 weston_surface_buffer_width(struct weston_surface *surface);
543 weston_surface_buffer_height(struct weston_surface *surface);
546 weston_surface_to_buffer_float(struct weston_surface *surface,
547 float x, float y, float *bx, float *by);
549 weston_surface_to_buffer_rect(struct weston_surface *surface,
550 pixman_box32_t rect);
553 weston_spring_init(struct weston_spring *spring,
554 double k, double current, double target);
556 weston_spring_update(struct weston_spring *spring, uint32_t msec);
558 weston_spring_done(struct weston_spring *spring);
561 weston_surface_activate(struct weston_surface *surface,
562 struct weston_seat *seat);
564 notify_motion(struct weston_seat *seat, uint32_t time,
565 wl_fixed_t dx, wl_fixed_t dy);
567 notify_motion_absolute(struct weston_seat *seat, uint32_t time,
568 wl_fixed_t x, wl_fixed_t y);
570 notify_button(struct weston_seat *seat, uint32_t time, int32_t button,
571 enum wl_pointer_button_state state);
573 notify_axis(struct weston_seat *seat, uint32_t time, uint32_t axis,
576 notify_key(struct weston_seat *seat, uint32_t time, uint32_t key,
577 enum wl_keyboard_key_state state,
578 enum weston_key_state_update update_state);
580 notify_modifiers(struct weston_seat *seat, uint32_t serial);
583 notify_pointer_focus(struct weston_seat *seat, struct weston_output *output,
584 wl_fixed_t x, wl_fixed_t y);
587 notify_keyboard_focus_in(struct weston_seat *seat, struct wl_array *keys,
588 enum weston_key_state_update update_state);
590 notify_keyboard_focus_out(struct weston_seat *seat);
593 notify_touch(struct weston_seat *seat, uint32_t time, int touch_id,
594 wl_fixed_t x, wl_fixed_t y, int touch_type);
597 weston_layer_init(struct weston_layer *layer, struct wl_list *below);
600 weston_plane_init(struct weston_plane *plane, int32_t x, int32_t y);
602 weston_plane_release(struct weston_plane *plane);
605 weston_compositor_stack_plane(struct weston_compositor *ec,
606 struct weston_plane *plane,
607 struct weston_plane *above);
610 weston_output_finish_frame(struct weston_output *output, uint32_t msecs);
612 weston_output_schedule_repaint(struct weston_output *output);
614 weston_output_damage(struct weston_output *output);
616 weston_compositor_schedule_repaint(struct weston_compositor *compositor);
618 weston_compositor_fade(struct weston_compositor *compositor, float tint);
620 weston_compositor_damage_all(struct weston_compositor *compositor);
622 weston_compositor_unlock(struct weston_compositor *compositor);
624 weston_compositor_wake(struct weston_compositor *compositor);
626 weston_compositor_offscreen(struct weston_compositor *compositor);
628 weston_compositor_sleep(struct weston_compositor *compositor);
630 weston_compositor_update_drag_surfaces(struct weston_compositor *compositor);
633 struct weston_binding;
634 typedef void (*weston_key_binding_handler_t)(struct wl_seat *seat,
635 uint32_t time, uint32_t key,
637 struct weston_binding *
638 weston_compositor_add_key_binding(struct weston_compositor *compositor,
640 enum weston_keyboard_modifier modifier,
641 weston_key_binding_handler_t binding,
644 typedef void (*weston_button_binding_handler_t)(struct wl_seat *seat,
645 uint32_t time, uint32_t button,
647 struct weston_binding *
648 weston_compositor_add_button_binding(struct weston_compositor *compositor,
650 enum weston_keyboard_modifier modifier,
651 weston_button_binding_handler_t binding,
654 typedef void (*weston_axis_binding_handler_t)(struct wl_seat *seat,
655 uint32_t time, uint32_t axis,
656 wl_fixed_t value, void *data);
657 struct weston_binding *
658 weston_compositor_add_axis_binding(struct weston_compositor *compositor,
660 enum weston_keyboard_modifier modifier,
661 weston_axis_binding_handler_t binding,
663 struct weston_binding *
664 weston_compositor_add_debug_binding(struct weston_compositor *compositor,
666 weston_key_binding_handler_t binding,
669 weston_binding_destroy(struct weston_binding *binding);
672 weston_binding_list_destroy_all(struct wl_list *list);
675 weston_compositor_run_key_binding(struct weston_compositor *compositor,
676 struct weston_seat *seat, uint32_t time,
678 enum wl_keyboard_key_state state);
680 weston_compositor_run_button_binding(struct weston_compositor *compositor,
681 struct weston_seat *seat, uint32_t time,
683 enum wl_pointer_button_state value);
685 weston_compositor_run_axis_binding(struct weston_compositor *compositor,
686 struct weston_seat *seat, uint32_t time,
687 uint32_t axis, int32_t value);
689 weston_compositor_run_debug_binding(struct weston_compositor *compositor,
690 struct weston_seat *seat, uint32_t time,
692 enum wl_keyboard_key_state state);
695 weston_environment_get_fd(const char *env);
698 weston_compositor_top(struct weston_compositor *compositor);
700 struct weston_surface *
701 weston_surface_create(struct weston_compositor *compositor);
704 weston_surface_configure(struct weston_surface *surface,
705 float x, float y, int width, int height);
708 weston_surface_restack(struct weston_surface *surface, struct wl_list *below);
711 weston_surface_set_position(struct weston_surface *surface,
715 weston_surface_set_transform_parent(struct weston_surface *surface,
716 struct weston_surface *parent);
719 weston_surface_is_mapped(struct weston_surface *surface);
722 weston_surface_schedule_repaint(struct weston_surface *surface);
725 weston_surface_damage(struct weston_surface *surface);
728 weston_surface_damage_below(struct weston_surface *surface);
731 weston_surface_move_to_plane(struct weston_surface *surface,
732 struct weston_plane *plane);
734 weston_surface_unmap(struct weston_surface *surface);
737 weston_buffer_reference(struct weston_buffer_reference *ref,
738 struct wl_buffer *buffer);
741 weston_compositor_get_time(void);
744 weston_compositor_init(struct weston_compositor *ec, struct wl_display *display,
745 int *argc, char *argv[], const char *config_file);
747 weston_compositor_shutdown(struct weston_compositor *ec);
749 weston_text_cursor_position_notify(struct weston_surface *surface,
750 wl_fixed_t x, wl_fixed_t y);
752 weston_output_init_zoom(struct weston_output *output);
754 weston_output_update_zoom(struct weston_output *output, uint32_t type);
756 weston_output_update_matrix(struct weston_output *output);
758 weston_output_move(struct weston_output *output, int x, int y);
760 weston_output_init(struct weston_output *output, struct weston_compositor *c,
761 int x, int y, int width, int height, uint32_t transform);
763 weston_output_destroy(struct weston_output *output);
766 weston_seat_init(struct weston_seat *seat, struct weston_compositor *ec);
768 weston_seat_init_pointer(struct weston_seat *seat);
770 weston_seat_init_keyboard(struct weston_seat *seat, struct xkb_keymap *keymap);
772 weston_seat_init_touch(struct weston_seat *seat);
775 weston_seat_release(struct weston_seat *seat);
777 /* String literal of spaces, the same width as the timestamp. */
778 #define STAMP_SPACE " "
781 weston_log_file_open(const char *filename);
783 weston_log_file_close(void);
785 weston_log(const char *fmt, ...)
786 __attribute__ ((format (printf, 1, 2)));
788 weston_log_continue(const char *fmt, ...)
789 __attribute__ ((format (printf, 1, 2)));
796 typedef void (*tty_vt_func_t)(struct weston_compositor *compositor, int event);
799 tty_create(struct weston_compositor *compositor,
800 tty_vt_func_t vt_func, int tty_nr);
803 tty_destroy(struct tty *tty);
806 tty_reset(struct tty *tty);
809 tty_activate_vt(struct tty *tty, int vt);
812 screenshooter_create(struct weston_compositor *ec);
815 clipboard_create(struct weston_seat *seat);
818 text_cursor_position_notifier_create(struct weston_compositor *ec);
821 text_backend_init(struct weston_compositor *ec);
823 struct weston_process;
824 typedef void (*weston_process_cleanup_func_t)(struct weston_process *process,
827 struct weston_process {
829 weston_process_cleanup_func_t cleanup;
834 weston_client_launch(struct weston_compositor *compositor,
835 struct weston_process *proc,
837 weston_process_cleanup_func_t cleanup);
840 weston_watch_process(struct weston_process *process);
842 struct weston_surface_animation;
843 typedef void (*weston_surface_animation_done_func_t)(struct weston_surface_animation *animation, void *data);
845 struct weston_surface_animation *
846 weston_zoom_run(struct weston_surface *surface, float start, float stop,
847 weston_surface_animation_done_func_t done, void *data);
849 struct weston_surface_animation *
850 weston_fade_run(struct weston_surface *surface,
851 float start, float end, float k,
852 weston_surface_animation_done_func_t done, void *data);
854 weston_fade_update(struct weston_surface_animation *fade,
855 float start, float end, float k);
857 struct weston_surface_animation *
858 weston_slide_run(struct weston_surface *surface, float start, float stop,
859 weston_surface_animation_done_func_t done, void *data);
862 weston_surface_set_color(struct weston_surface *surface,
863 float red, float green, float blue, float alpha);
866 weston_surface_destroy(struct weston_surface *surface);
869 weston_output_switch_mode(struct weston_output *output, struct weston_mode *mode);
872 noop_renderer_init(struct weston_compositor *ec);
874 struct weston_compositor *
875 backend_init(struct wl_display *display, int *argc, char *argv[],
876 const char *config_file);
879 module_init(struct weston_compositor *compositor,
880 int *argc, char *argv[], const char *config_file);
883 weston_transformed_coord(int width, int height,
884 enum wl_output_transform transform,
885 float sx, float sy, float *bx, float *by);
887 weston_transformed_rect(int width, int height,
888 enum wl_output_transform transform,
889 pixman_box32_t rect);