xwm: Implement resizing by frame borders
[profile/ivi/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 #include <pixman.h>
28 #include <xkbcommon/xkbcommon.h>
29 #include <wayland-server.h>
30
31 #include <GLES2/gl2.h>
32 #include <GLES2/gl2ext.h>
33 #include <EGL/egl.h>
34 #include <EGL/eglext.h>
35
36 #include "matrix.h"
37 #include "../shared/config-parser.h"
38 #include "weston-egl-ext.h"
39
40
41 struct weston_transform {
42         struct weston_matrix matrix;
43         struct wl_list link;
44 };
45
46 struct weston_surface;
47 struct shell_surface;
48 struct weston_seat;
49 struct weston_output;
50
51 struct weston_mode {
52         uint32_t flags;
53         int32_t width, height;
54         uint32_t refresh;
55         struct wl_list link;
56 };
57
58 struct weston_shell_client {
59         void (*send_configure)(struct weston_surface *surface,
60                                uint32_t edges, int32_t width, int32_t height);
61 };
62
63 struct weston_shell_interface {
64         void *shell;                    /* either desktop or tablet */
65
66         struct shell_surface *(*create_shell_surface)(void *shell,
67                                                       struct weston_surface *surface,
68                                                       const struct weston_shell_client *client);
69
70         void (*set_toplevel)(struct shell_surface *shsurf);
71
72         void (*set_transient)(struct shell_surface *shsurf,
73                               struct shell_surface *pshsurf,
74                               int x, int y, uint32_t flags);
75         int (*move)(struct shell_surface *shsurf, struct weston_seat *ws);
76         int (*resize)(struct shell_surface *shsurf,
77                       struct weston_seat *ws, uint32_t edges);
78
79 };
80
81 struct weston_border {
82         int32_t left, right, top, bottom;
83 };
84
85 struct weston_output_zoom {
86         int active;
87         float increment;
88         float level;
89         float trans_x, trans_y;
90 };
91
92 /* bit compatible with drm definitions. */
93 enum dpms_enum {
94         WESTON_DPMS_ON,
95         WESTON_DPMS_STANDBY,
96         WESTON_DPMS_SUSPEND,
97         WESTON_DPMS_OFF
98 };
99
100 struct weston_read_pixels {
101         void *data;
102         int x, y, width, height;
103         void (*done)(struct weston_read_pixels *read_pixels,
104                      struct weston_output *output);
105         struct wl_list link;
106 };
107
108 struct weston_output {
109         uint32_t id;
110
111         struct wl_list link;
112         struct wl_list resource_list;
113         struct wl_global *global;
114         struct weston_compositor *compositor;
115         struct weston_matrix matrix;
116         struct wl_list frame_callback_list;
117         int32_t x, y, mm_width, mm_height;
118         struct weston_border border;
119         pixman_region32_t region;
120         pixman_region32_t previous_damage;
121         uint32_t flags;
122         int repaint_needed;
123         int repaint_scheduled;
124         struct weston_output_zoom zoom;
125         int dirty;
126         struct wl_list read_pixels_list;
127
128         char *make, *model;
129         uint32_t subpixel;
130         
131         struct weston_mode *current;
132         struct weston_mode *origin;
133         struct wl_list mode_list;
134
135         void (*repaint)(struct weston_output *output,
136                         pixman_region32_t *damage);
137         void (*destroy)(struct weston_output *output);
138         void (*assign_planes)(struct weston_output *output);
139         int (*switch_mode)(struct weston_output *output, struct weston_mode *mode);
140
141         /* backlight values are on 0-255 range, where higher is brighter */
142         uint32_t backlight_current;
143         void (*set_backlight)(struct weston_output *output, uint32_t value);
144         void (*set_dpms)(struct weston_output *output, enum dpms_enum level);
145 };
146
147 struct weston_seat {
148         struct wl_seat seat;
149         struct wl_pointer pointer;
150         struct wl_keyboard keyboard;
151         struct wl_touch touch;
152         struct weston_compositor *compositor;
153         struct weston_surface *sprite;
154         struct weston_surface *drag_surface;
155         struct wl_listener drag_surface_destroy_listener;
156         int32_t hotspot_x, hotspot_y;
157         struct wl_list link;
158         uint32_t modifier_state;
159         int hw_cursor;
160         struct wl_surface *saved_kbd_focus;
161         struct wl_listener saved_kbd_focus_listener;
162
163         uint32_t num_tp;
164         struct wl_surface *touch_focus;
165         struct wl_listener touch_focus_listener;
166         struct wl_resource *touch_focus_resource;
167         struct wl_listener touch_focus_resource_listener;
168
169         struct wl_listener new_drag_icon_listener;
170 };
171
172 struct weston_shader {
173         GLuint program;
174         GLuint vertex_shader, fragment_shader;
175         GLint proj_uniform;
176         GLint tex_uniform;
177         GLint alpha_uniform;
178         GLint brightness_uniform;
179         GLint saturation_uniform;
180         GLint color_uniform;
181         GLint texwidth_uniform;
182         GLint opaque_uniform;
183 };
184
185 struct weston_animation {
186         void (*frame)(struct weston_animation *animation,
187                       struct weston_output *output, uint32_t msecs);
188         struct wl_list link;
189 };
190
191 struct weston_spring {
192         double k;
193         double friction;
194         double current;
195         double target;
196         double previous;
197         uint32_t timestamp;
198 };
199
200 enum {
201         WESTON_COMPOSITOR_ACTIVE,
202         WESTON_COMPOSITOR_IDLE,         /* shell->unlock called on activity */
203         WESTON_COMPOSITOR_SLEEPING      /* no rendering, no frame events */
204 };
205
206 struct weston_layer {
207         struct wl_list surface_list;
208         struct wl_list link;
209 };
210
211 struct weston_compositor {
212         struct wl_shm *shm;
213         struct wl_signal destroy_signal;
214
215         EGLDisplay display;
216         EGLContext context;
217         EGLConfig config;
218         GLuint fbo;
219         struct weston_shader texture_shader;
220         struct weston_shader solid_shader;
221         struct weston_shader *current_shader;
222         struct wl_display *wl_display;
223         struct weston_shell_interface shell_interface;
224
225         struct wl_signal activate_signal;
226         struct wl_signal lock_signal;
227         struct wl_signal unlock_signal;
228
229         struct wl_event_loop *input_loop;
230         struct wl_event_source *input_loop_source;
231
232         /* There can be more than one, but not right now... */
233         struct weston_seat *seat;
234
235         struct weston_layer fade_layer;
236         struct weston_layer cursor_layer;
237
238         struct wl_list output_list;
239         struct wl_list seat_list;
240         struct wl_list layer_list;
241         struct wl_list surface_list;
242         struct wl_list binding_list;
243         struct wl_list animation_list;
244         struct {
245                 struct weston_spring spring;
246                 struct weston_animation animation;
247                 struct weston_surface *surface;
248         } fade;
249
250         uint32_t state;
251         struct wl_event_source *idle_source;
252         uint32_t idle_inhibit;
253         int option_idle_time;           /* default timeout, s */
254         int idle_time;                  /* effective timeout, s */
255
256         /* Repaint state. */
257         struct wl_array vertices, indices;
258         pixman_region32_t damage;
259
260         uint32_t focus;
261
262         PFNGLEGLIMAGETARGETRENDERBUFFERSTORAGEOESPROC
263                 image_target_renderbuffer_storage;
264         PFNGLEGLIMAGETARGETTEXTURE2DOESPROC image_target_texture_2d;
265         PFNEGLCREATEIMAGEKHRPROC create_image;
266         PFNEGLDESTROYIMAGEKHRPROC destroy_image;
267
268         int has_unpack_subimage;
269         GLenum read_format;
270
271         PFNEGLBINDWAYLANDDISPLAYWL bind_display;
272         PFNEGLUNBINDWAYLANDDISPLAYWL unbind_display;
273         int has_bind_display;
274
275         void (*destroy)(struct weston_compositor *ec);
276         int (*authenticate)(struct weston_compositor *c, uint32_t id);
277
278         void (*ping_handler)(struct weston_surface *surface, uint32_t serial);
279
280         int launcher_sock;
281
282         uint32_t output_id_pool;
283
284         struct {
285                 struct xkb_rule_names names;
286                 struct xkb_context *context;
287                 struct xkb_keymap *keymap;
288                 struct xkb_state *state;
289         } xkb_info;
290 };
291
292 #define MODIFIER_CTRL   (1 << 8)
293 #define MODIFIER_ALT    (1 << 9)
294 #define MODIFIER_SUPER  (1 << 10)
295
296 enum weston_output_flags {
297         WL_OUTPUT_FLIPPED = 0x01
298 };
299
300 struct weston_region {
301         struct wl_resource resource;
302         pixman_region32_t region;
303 };
304
305 /* Using weston_surface transformations
306  *
307  * To add a transformation to a surface, create a struct weston_transform, and
308  * add it to the list surface->geometry.transformation_list. Whenever you
309  * change the list, anything under surface->geometry, or anything in the
310  * weston_transforms linked into the list, you must set
311  * surface->geometry.dirty = 1.
312  *
313  * The order in the list defines the order of transformations. Let the list
314  * contain the transformation matrices M1, ..., Mn as head to tail. The
315  * transformation is applied to surface-local coordinate vector p as
316  *    P = Mn * ... * M2 * M1 * p
317  * to produce the global coordinate vector P. The total transform
318  *    Mn * ... * M2 * M1
319  * is cached in surface->transform.matrix, and the inverse of it in
320  * surface->transform.inverse.
321  *
322  * The list always contains surface->transform.position transformation, which
323  * is the translation by surface->geometry.x and y.
324  *
325  * If you want to apply a transformation in local coordinates, add your
326  * weston_transform to the head of the list. If you want to apply a
327  * transformation in global coordinates, add it to the tail of the list.
328  */
329
330 struct weston_surface {
331         struct wl_surface surface;
332         struct weston_compositor *compositor;
333         GLuint texture;
334         pixman_region32_t clip;
335         pixman_region32_t damage;
336         pixman_region32_t opaque;
337         pixman_region32_t input;
338         int32_t pitch;
339         struct wl_list link;
340         struct wl_list layer_link;
341         struct weston_shader *shader;
342         GLfloat color[4];
343         GLfloat opaque_rect[4];
344         GLfloat alpha;
345         GLfloat brightness;
346         GLfloat saturation;
347         int blend;
348
349         /* Surface geometry state, mutable.
350          * If you change anything, set dirty = 1.
351          * That includes the transformations referenced from the list.
352          */
353         struct {
354                 GLfloat x, y; /* surface translation on display */
355                 int32_t width, height;
356
357                 /* struct weston_transform */
358                 struct wl_list transformation_list;
359
360                 int dirty;
361         } geometry;
362
363         /* State derived from geometry state, read-only.
364          * This is updated by weston_surface_update_transform().
365          */
366         struct {
367                 pixman_region32_t boundingbox;
368                 pixman_region32_t opaque;
369
370                 /* matrix and inverse are used only if enabled = 1.
371                  * If enabled = 0, use x, y, width, height directly.
372                  */
373                 int enabled;
374                 struct weston_matrix matrix;
375                 struct weston_matrix inverse;
376
377                 struct weston_transform position; /* matrix from x, y */
378         } transform;
379
380         /*
381          * Which output to vsync this surface to.
382          * Used to determine, whether to send or queue frame events.
383          * Must be NULL, if 'link' is not in weston_compositor::surface_list.
384          */
385         struct weston_output *output;
386
387         /*
388          * A more complete representation of all outputs this surface is
389          * displayed on.
390          */
391         uint32_t output_mask;
392
393         struct wl_list frame_callback_list;
394
395         EGLImageKHR image;
396
397         struct wl_buffer *buffer;
398         struct wl_listener buffer_destroy_listener;
399
400         /*
401          * If non-NULL, this function will be called on surface::attach after
402          * a new buffer has been set up for this surface. The integer params
403          * are the sx and sy paramerters supplied to surface::attach .
404          */
405         void (*configure)(struct weston_surface *es, int32_t sx, int32_t sy);
406         void *private;
407 };
408
409 void
410 weston_surface_update_transform(struct weston_surface *surface);
411
412 void
413 weston_surface_to_global(struct weston_surface *surface,
414                          int32_t sx, int32_t sy, int32_t *x, int32_t *y);
415 void
416 weston_surface_to_global_fixed(struct weston_surface *surface,
417                                wl_fixed_t sx, wl_fixed_t sy,
418                                wl_fixed_t *x, wl_fixed_t *y);
419 void
420 weston_surface_to_global_float(struct weston_surface *surface,
421                                GLfloat sx, GLfloat sy, GLfloat *x, GLfloat *y);
422
423 void
424 weston_surface_from_global(struct weston_surface *surface,
425                            int32_t x, int32_t y, int32_t *sx, int32_t *sy);
426 void
427 weston_surface_from_global_fixed(struct weston_surface *surface,
428                                  wl_fixed_t x, wl_fixed_t y,
429                                  wl_fixed_t *sx, wl_fixed_t *sy);
430
431 void
432 weston_spring_init(struct weston_spring *spring,
433                    double k, double current, double target);
434 void
435 weston_spring_update(struct weston_spring *spring, uint32_t msec);
436 int
437 weston_spring_done(struct weston_spring *spring);
438
439 void
440 weston_surface_activate(struct weston_surface *surface,
441                         struct weston_seat *seat);
442 void
443 weston_surface_draw(struct weston_surface *es,
444                     struct weston_output *output, pixman_region32_t *damage);
445
446 void
447 notify_motion(struct wl_seat *seat, uint32_t time,
448               wl_fixed_t x, wl_fixed_t y);
449 void
450 notify_button(struct wl_seat *seat, uint32_t time, int32_t button,
451               uint32_t state);
452 void
453 notify_axis(struct wl_seat *seat, uint32_t time, uint32_t axis,
454             int32_t value);
455 void
456 notify_key(struct wl_seat *seat, uint32_t time, uint32_t key,
457            uint32_t state);
458
459 void
460 notify_pointer_focus(struct wl_seat *seat, struct weston_output *output,
461                      wl_fixed_t x, wl_fixed_t y);
462
463 void
464 notify_keyboard_focus(struct wl_seat *seat, struct wl_array *keys);
465
466 void
467 notify_touch(struct wl_seat *seat, uint32_t time, int touch_id,
468              wl_fixed_t x, wl_fixed_t y, int touch_type);
469
470 void
471 weston_layer_init(struct weston_layer *layer, struct wl_list *below);
472
473 void
474 weston_output_finish_frame(struct weston_output *output, int msecs);
475 void
476 weston_output_damage(struct weston_output *output);
477 void
478 weston_output_do_read_pixels(struct weston_output *output);
479 void
480 weston_compositor_repick(struct weston_compositor *compositor);
481 void
482 weston_compositor_schedule_repaint(struct weston_compositor *compositor);
483 void
484 weston_compositor_fade(struct weston_compositor *compositor, float tint);
485 void
486 weston_compositor_damage_all(struct weston_compositor *compositor);
487 void
488 weston_compositor_unlock(struct weston_compositor *compositor);
489 void
490 weston_compositor_wake(struct weston_compositor *compositor);
491 void
492 weston_compositor_activity(struct weston_compositor *compositor);
493 void
494 weston_compositor_update_drag_surfaces(struct weston_compositor *compositor);
495
496
497 struct weston_binding;
498 typedef void (*weston_binding_handler_t)(struct wl_seat *seat,
499                                          uint32_t time, uint32_t key,
500                                          uint32_t button,
501                                          uint32_t axis,
502                                          int32_t value, void *data);
503 struct weston_binding *
504 weston_compositor_add_binding(struct weston_compositor *compositor,
505                               uint32_t key, uint32_t button, uint32_t axis,
506                               uint32_t modifier,
507                               weston_binding_handler_t binding, void *data);
508 void
509 weston_binding_destroy(struct weston_binding *binding);
510
511 void
512 weston_binding_list_destroy_all(struct wl_list *list);
513
514 void
515 weston_compositor_run_binding(struct weston_compositor *compositor,
516                               struct weston_seat *seat,
517                               uint32_t time,
518                               uint32_t key, uint32_t button, uint32_t axis,
519                               int32_t value);
520 int
521 weston_environment_get_fd(const char *env);
522
523 struct wl_list *
524 weston_compositor_top(struct weston_compositor *compositor);
525
526 struct weston_surface *
527 weston_surface_create(struct weston_compositor *compositor);
528
529 void
530 weston_surface_configure(struct weston_surface *surface,
531                          GLfloat x, GLfloat y, int width, int height);
532
533 void
534 weston_surface_restack(struct weston_surface *surface, struct wl_list *below);
535
536 void
537 weston_surface_set_position(struct weston_surface *surface,
538                             GLfloat x, GLfloat y);
539
540 int
541 weston_surface_is_mapped(struct weston_surface *surface);
542
543 void
544 weston_surface_assign_output(struct weston_surface *surface);
545
546 void
547 weston_surface_damage(struct weston_surface *surface);
548
549 void
550 weston_surface_damage_below(struct weston_surface *surface);
551
552 void
553 weston_buffer_post_release(struct wl_buffer *buffer);
554
555 uint32_t
556 weston_compositor_get_time(void);
557
558 int
559 weston_compositor_init(struct weston_compositor *ec, struct wl_display *display);
560 void
561 weston_compositor_shutdown(struct weston_compositor *ec);
562 void
563 weston_output_update_zoom(struct weston_output *output, int x, int y);
564 void
565 weston_output_update_matrix(struct weston_output *output);
566 void
567 weston_output_move(struct weston_output *output, int x, int y);
568 void
569 weston_output_init(struct weston_output *output, struct weston_compositor *c,
570                    int x, int y, int width, int height, uint32_t flags);
571 void
572 weston_output_destroy(struct weston_output *output);
573
574 void
575 weston_seat_init(struct weston_seat *seat, struct weston_compositor *ec);
576
577 void
578 weston_seat_release(struct weston_seat *seat);
579
580 enum {
581         TTY_ENTER_VT,
582         TTY_LEAVE_VT
583 };
584
585 typedef void (*tty_vt_func_t)(struct weston_compositor *compositor, int event);
586
587 struct tty *
588 tty_create(struct weston_compositor *compositor,
589            tty_vt_func_t vt_func, int tty_nr);
590
591 void
592 tty_destroy(struct tty *tty);
593
594 int
595 tty_activate_vt(struct tty *tty, int vt);
596
597 void
598 screenshooter_create(struct weston_compositor *ec);
599
600 struct weston_process;
601 typedef void (*weston_process_cleanup_func_t)(struct weston_process *process,
602                                             int status);
603
604 struct weston_process {
605         pid_t pid;
606         weston_process_cleanup_func_t cleanup;
607         struct wl_list link;
608 };
609
610 struct wl_client *
611 weston_client_launch(struct weston_compositor *compositor,
612                      struct weston_process *proc,
613                      const char *path,
614                      weston_process_cleanup_func_t cleanup);
615
616 void
617 weston_watch_process(struct weston_process *process);
618
619 int
620 weston_xserver_init(struct weston_compositor *compositor);
621
622 struct weston_zoom;
623 typedef void (*weston_zoom_done_func_t)(struct weston_zoom *zoom, void *data);
624
625 struct weston_zoom *
626 weston_zoom_run(struct weston_surface *surface, GLfloat start, GLfloat stop,
627                 weston_zoom_done_func_t done, void *data);
628
629 struct weston_fade;
630 typedef void (*weston_fade_done_func_t)(struct weston_fade *fade, void *data);
631
632 struct weston_fade *
633 weston_fade_run(struct weston_surface *surface,
634                 weston_fade_done_func_t done, void *data);
635
636
637 void
638 weston_surface_set_color(struct weston_surface *surface,
639                          GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha);
640
641 void
642 weston_surface_destroy(struct weston_surface *surface);
643
644 struct weston_compositor *
645 backend_init(struct wl_display *display, int argc, char *argv[]);
646
647 int
648 weston_output_switch_mode(struct weston_output *output, struct weston_mode *mode);
649
650 #endif