blob: bde49874c1ce4f21a4cf032d8161fa4b2193c9a4 [file] [log] [blame]
Kristian Høgsberg698c0582011-12-04 15:20:19 -05001/*
2 * Copyright © 2011 Intel Corporation
3 *
4 * Permission to use, copy, modify, distribute, and sell this software and
5 * its documentation for any purpose is hereby granted without fee, provided
6 * that the above copyright notice appear in all copies and that both that
7 * copyright notice and this permission notice appear in supporting
8 * documentation, and that the name of the copyright holders not be used in
9 * advertising or publicity pertaining to distribution of the software
10 * without specific, written prior permission. The copyright holders make
11 * no representations about the suitability of this software for any
12 * purpose. It is provided "as is" without express or implied warranty.
13 *
14 * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
15 * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
16 * FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY
17 * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
18 * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
19 * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
20 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
21 */
22
23#include <stdlib.h>
Kristian Høgsberg4bfb82a2011-12-04 15:47:16 -050024#include <string.h>
Kristian Høgsberg698c0582011-12-04 15:20:19 -050025#include <stdio.h>
Kristian Høgsberg4bfb82a2011-12-04 15:47:16 -050026#include <math.h>
Kristian Høgsberg698c0582011-12-04 15:20:19 -050027
Benjamin Franzkebfeda132012-01-30 14:04:04 +010028#include <unistd.h>
29#include <fcntl.h>
30
Kristian Høgsberg698c0582011-12-04 15:20:19 -050031#include "compositor.h"
32
Kristian Høgsberg4bfb82a2011-12-04 15:47:16 -050033WL_EXPORT void
Kristian Høgsberg8334bc12012-01-03 10:29:47 -050034weston_spring_init(struct weston_spring *spring,
Kristian Høgsberg4bfb82a2011-12-04 15:47:16 -050035 double k, double current, double target)
36{
37 spring->k = k;
38 spring->friction = 400.0;
39 spring->current = current;
40 spring->previous = current;
41 spring->target = target;
42}
43
44WL_EXPORT void
Kristian Høgsberg8334bc12012-01-03 10:29:47 -050045weston_spring_update(struct weston_spring *spring, uint32_t msec)
Kristian Høgsberg4bfb82a2011-12-04 15:47:16 -050046{
47 double force, v, current, step;
48
49 step = 0.01;
50 while (4 < msec - spring->timestamp) {
51 current = spring->current;
52 v = current - spring->previous;
53 force = spring->k * (spring->target - current) / 10.0 +
54 (spring->previous - current) - v * spring->friction;
55
56 spring->current =
57 current + (current - spring->previous) +
58 force * step * step;
59 spring->previous = current;
60
61#if 0
62 if (spring->current >= 1.0) {
63#ifdef TWEENER_BOUNCE
64 spring->current = 2.0 - spring->current;
65 spring->previous = 2.0 - spring->previous;
66#else
67 spring->current = 1.0;
68 spring->previous = 1.0;
69#endif
70 }
71
72 if (spring->current <= 0.0) {
73 spring->current = 0.0;
74 spring->previous = 0.0;
75 }
76#endif
77 spring->timestamp += 4;
78 }
79}
80
81WL_EXPORT int
Kristian Høgsberg8334bc12012-01-03 10:29:47 -050082weston_spring_done(struct weston_spring *spring)
Kristian Høgsberg4bfb82a2011-12-04 15:47:16 -050083{
84 return fabs(spring->previous - spring->target) < 0.0002 &&
85 fabs(spring->current - spring->target) < 0.0002;
86}
87
Kristian Høgsberg8334bc12012-01-03 10:29:47 -050088struct weston_zoom {
89 struct weston_surface *surface;
90 struct weston_animation animation;
91 struct weston_spring spring;
92 struct weston_transform transform;
Kristian Høgsberg698c0582011-12-04 15:20:19 -050093 struct wl_listener listener;
Kristian Høgsbergef458242011-12-15 11:24:25 -050094 GLfloat start, stop;
Kristian Høgsberg8334bc12012-01-03 10:29:47 -050095 void (*done)(struct weston_zoom *zoom, void *data);
Kristian Høgsberg698c0582011-12-04 15:20:19 -050096 void *data;
97};
98
Juan Zhao2abd07b2012-04-25 19:09:51 +080099struct weston_fade {
100 struct weston_surface *surface;
101 struct weston_animation animation;
102 struct weston_spring spring;
103 struct wl_listener listener;
104 void (*done)(struct weston_fade *fade, void *data);
105 void *data;
106};
107
Kristian Høgsberg698c0582011-12-04 15:20:19 -0500108static void
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500109weston_zoom_destroy(struct weston_zoom *zoom)
Kristian Høgsberg698c0582011-12-04 15:20:19 -0500110{
111 wl_list_remove(&zoom->animation.link);
112 wl_list_remove(&zoom->listener.link);
Pekka Paalanenc61eca62012-01-06 14:10:06 +0200113 wl_list_remove(&zoom->transform.link);
Pekka Paalanenbc0b7e72012-01-24 09:53:37 +0200114 zoom->surface->geometry.dirty = 1;
Kristian Høgsberg698c0582011-12-04 15:20:19 -0500115 if (zoom->done)
116 zoom->done(zoom, zoom->data);
117 free(zoom);
118}
119
120static void
Kristian Høgsberg27e30522012-04-11 23:18:23 -0400121handle_zoom_surface_destroy(struct wl_listener *listener, void *data)
Kristian Høgsberg698c0582011-12-04 15:20:19 -0500122{
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500123 struct weston_zoom *zoom =
124 container_of(listener, struct weston_zoom, listener);
Kristian Høgsberg698c0582011-12-04 15:20:19 -0500125
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500126 weston_zoom_destroy(zoom);
Kristian Høgsberg698c0582011-12-04 15:20:19 -0500127}
128
129static void
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500130weston_zoom_frame(struct weston_animation *animation,
131 struct weston_output *output, uint32_t msecs)
Kristian Høgsberg698c0582011-12-04 15:20:19 -0500132{
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500133 struct weston_zoom *zoom =
134 container_of(animation, struct weston_zoom, animation);
135 struct weston_surface *es = zoom->surface;
Kristian Høgsberg698c0582011-12-04 15:20:19 -0500136 GLfloat scale;
137
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500138 weston_spring_update(&zoom->spring, msecs);
Kristian Høgsberg698c0582011-12-04 15:20:19 -0500139
Kristian Høgsberg3466bc82012-01-03 11:29:15 -0500140 if (weston_spring_done(&zoom->spring)) {
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500141 weston_zoom_destroy(zoom);
Pekka Paalanen2da6d5f2012-01-03 13:27:41 +0200142 return;
143 }
Kristian Høgsberg698c0582011-12-04 15:20:19 -0500144
Kristian Høgsbergef458242011-12-15 11:24:25 -0500145 scale = zoom->start +
146 (zoom->stop - zoom->start) * zoom->spring.current;
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500147 weston_matrix_init(&zoom->transform.matrix);
148 weston_matrix_translate(&zoom->transform.matrix,
Pekka Paalanen60921e52012-01-25 15:55:43 +0200149 -0.5f * es->geometry.width,
150 -0.5f * es->geometry.height, 0);
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500151 weston_matrix_scale(&zoom->transform.matrix, scale, scale, scale);
152 weston_matrix_translate(&zoom->transform.matrix,
Pekka Paalanen60921e52012-01-25 15:55:43 +0200153 0.5f * es->geometry.width,
154 0.5f * es->geometry.height, 0);
Kristian Høgsberg698c0582011-12-04 15:20:19 -0500155
Kristian Høgsberga416fa12012-05-21 14:06:52 -0400156 es->alpha = zoom->spring.current;
157 if (es->alpha > 1.0)
158 es->alpha = 1.0;
Kristian Høgsberg698c0582011-12-04 15:20:19 -0500159
Pekka Paalanenbc0b7e72012-01-24 09:53:37 +0200160 zoom->surface->geometry.dirty = 1;
Kristian Høgsberg2ea09442012-02-28 23:12:52 -0500161 weston_compositor_schedule_repaint(es->compositor);
Kristian Høgsberg698c0582011-12-04 15:20:19 -0500162}
163
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500164WL_EXPORT struct weston_zoom *
165weston_zoom_run(struct weston_surface *surface, GLfloat start, GLfloat stop,
166 weston_zoom_done_func_t done, void *data)
Kristian Høgsberg698c0582011-12-04 15:20:19 -0500167{
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500168 struct weston_zoom *zoom;
Kristian Høgsberg698c0582011-12-04 15:20:19 -0500169
170 zoom = malloc(sizeof *zoom);
171 if (!zoom)
172 return NULL;
173
174 zoom->surface = surface;
175 zoom->done = done;
176 zoom->data = data;
Kristian Høgsbergef458242011-12-15 11:24:25 -0500177 zoom->start = start;
178 zoom->stop = stop;
Pekka Paalanenbc0b7e72012-01-24 09:53:37 +0200179 wl_list_insert(&surface->geometry.transformation_list,
180 &zoom->transform.link);
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500181 weston_spring_init(&zoom->spring, 200.0, 0.0, 1.0);
Kristian Høgsbergef458242011-12-15 11:24:25 -0500182 zoom->spring.friction = 700;
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500183 zoom->spring.timestamp = weston_compositor_get_time();
184 zoom->animation.frame = weston_zoom_frame;
185 weston_zoom_frame(&zoom->animation, NULL, zoom->spring.timestamp);
Kristian Høgsberg698c0582011-12-04 15:20:19 -0500186
Kristian Høgsberg27e30522012-04-11 23:18:23 -0400187 zoom->listener.notify = handle_zoom_surface_destroy;
188 wl_signal_add(&surface->surface.resource.destroy_signal,
189 &zoom->listener);
Kristian Høgsberg698c0582011-12-04 15:20:19 -0500190
Pekka Paalanen73772042012-01-25 14:45:18 +0200191 wl_list_insert(&surface->compositor->animation_list,
Kristian Høgsberg698c0582011-12-04 15:20:19 -0500192 &zoom->animation.link);
193
194 return zoom;
195}
Kristian Høgsbergf47d8fe2011-12-19 15:16:06 -0500196
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500197struct weston_binding {
Kristian Høgsbergf47d8fe2011-12-19 15:16:06 -0500198 uint32_t key;
199 uint32_t button;
Scott Moreau6a3633d2012-03-20 08:47:59 -0600200 uint32_t axis;
Kristian Høgsbergf47d8fe2011-12-19 15:16:06 -0500201 uint32_t modifier;
Daniel Stone325fc2d2012-05-30 16:31:58 +0100202 void *handler;
Kristian Høgsbergf47d8fe2011-12-19 15:16:06 -0500203 void *data;
204 struct wl_list link;
205};
206
Daniel Stone325fc2d2012-05-30 16:31:58 +0100207static struct weston_binding *
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500208weston_compositor_add_binding(struct weston_compositor *compositor,
Daniel Stone325fc2d2012-05-30 16:31:58 +0100209 uint32_t key, uint32_t button, uint32_t axis,
210 uint32_t modifier, void *handler, void *data)
Kristian Høgsbergf47d8fe2011-12-19 15:16:06 -0500211{
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500212 struct weston_binding *binding;
Kristian Høgsbergf47d8fe2011-12-19 15:16:06 -0500213
214 binding = malloc(sizeof *binding);
215 if (binding == NULL)
216 return NULL;
217
218 binding->key = key;
219 binding->button = button;
Scott Moreau6a3633d2012-03-20 08:47:59 -0600220 binding->axis = axis;
Kristian Høgsbergf47d8fe2011-12-19 15:16:06 -0500221 binding->modifier = modifier;
222 binding->handler = handler;
223 binding->data = data;
Daniel Stone325fc2d2012-05-30 16:31:58 +0100224
225 return binding;
226}
227
228WL_EXPORT struct weston_binding *
229weston_compositor_add_key_binding(struct weston_compositor *compositor,
230 uint32_t key, uint32_t modifier,
231 weston_key_binding_handler_t handler,
232 void *data)
233{
234 struct weston_binding *binding;
235
236 binding = weston_compositor_add_binding(compositor, key, 0, 0,
237 modifier, handler, data);
238 if (binding == NULL)
239 return NULL;
240
241 wl_list_insert(compositor->key_binding_list.prev, &binding->link);
242
243 return binding;
244}
245
246WL_EXPORT struct weston_binding *
247weston_compositor_add_button_binding(struct weston_compositor *compositor,
248 uint32_t button, uint32_t modifier,
249 weston_button_binding_handler_t handler,
250 void *data)
251{
252 struct weston_binding *binding;
253
254 binding = weston_compositor_add_binding(compositor, 0, button, 0,
255 modifier, handler, data);
256 if (binding == NULL)
257 return NULL;
258
259 wl_list_insert(compositor->button_binding_list.prev, &binding->link);
260
261 return binding;
262}
263
264WL_EXPORT struct weston_binding *
265weston_compositor_add_axis_binding(struct weston_compositor *compositor,
266 uint32_t axis, uint32_t modifier,
267 weston_axis_binding_handler_t handler,
268 void *data)
269{
270 struct weston_binding *binding;
271
272 binding = weston_compositor_add_binding(compositor, 0, 0, axis,
273 modifier, handler, data);
274 if (binding == NULL)
275 return NULL;
276
277 wl_list_insert(compositor->axis_binding_list.prev, &binding->link);
Kristian Høgsbergf47d8fe2011-12-19 15:16:06 -0500278
279 return binding;
280}
281
282WL_EXPORT void
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500283weston_binding_destroy(struct weston_binding *binding)
Kristian Høgsbergf47d8fe2011-12-19 15:16:06 -0500284{
285 wl_list_remove(&binding->link);
286 free(binding);
287}
288
289WL_EXPORT void
Kristian Høgsberg3466bc82012-01-03 11:29:15 -0500290weston_binding_list_destroy_all(struct wl_list *list)
Pekka Paalanen4738f3b2012-01-02 15:47:07 +0200291{
Kristian Høgsberg3466bc82012-01-03 11:29:15 -0500292 struct weston_binding *binding, *tmp;
Pekka Paalanen4738f3b2012-01-02 15:47:07 +0200293
294 wl_list_for_each_safe(binding, tmp, list, link)
Kristian Høgsberg3466bc82012-01-03 11:29:15 -0500295 weston_binding_destroy(binding);
Pekka Paalanen4738f3b2012-01-02 15:47:07 +0200296}
297
Kristian Høgsbergabcef3c2012-03-05 17:47:15 -0500298struct binding_keyboard_grab {
299 uint32_t key;
300 struct wl_keyboard_grab grab;
301};
302
303static void
304binding_key(struct wl_keyboard_grab *grab,
Daniel Stonec9785ea2012-05-30 16:31:52 +0100305 uint32_t time, uint32_t key, uint32_t state_w)
Kristian Høgsbergabcef3c2012-03-05 17:47:15 -0500306{
307 struct binding_keyboard_grab *b =
308 container_of(grab, struct binding_keyboard_grab, grab);
309 struct wl_resource *resource;
Kristian Høgsbergeae5de72012-04-11 22:42:15 -0400310 struct wl_display *display;
Daniel Stonec9785ea2012-05-30 16:31:52 +0100311 enum wl_keyboard_key_state state = state_w;
Kristian Høgsbergeae5de72012-04-11 22:42:15 -0400312 uint32_t serial;
Kristian Høgsbergabcef3c2012-03-05 17:47:15 -0500313
Daniel Stone37816df2012-05-16 18:45:18 +0100314 resource = grab->keyboard->focus_resource;
Kristian Høgsbergabcef3c2012-03-05 17:47:15 -0500315 if (key == b->key) {
Daniel Stonec9785ea2012-05-30 16:31:52 +0100316 if (state == WL_KEYBOARD_KEY_STATE_RELEASED) {
Daniel Stone37816df2012-05-16 18:45:18 +0100317 wl_keyboard_end_grab(grab->keyboard);
Kristian Høgsbergabcef3c2012-03-05 17:47:15 -0500318 free(b);
319 }
Kristian Høgsbergeae5de72012-04-11 22:42:15 -0400320 } else if (resource) {
321 display = wl_client_get_display(resource->client);
322 serial = wl_display_next_serial(display);
Daniel Stone37816df2012-05-16 18:45:18 +0100323 wl_keyboard_send_key(resource, serial, time, key, state);
Kristian Høgsbergeae5de72012-04-11 22:42:15 -0400324 }
Kristian Høgsbergabcef3c2012-03-05 17:47:15 -0500325}
326
Daniel Stone351eb612012-05-31 15:27:47 -0400327static void
328binding_modifiers(struct wl_keyboard_grab *grab, uint32_t serial,
329 uint32_t mods_depressed, uint32_t mods_latched,
330 uint32_t mods_locked, uint32_t group)
331{
332 struct wl_resource *resource;
333
334 resource = grab->keyboard->focus_resource;
335 if (!resource)
336 return;
337
338 wl_keyboard_send_modifiers(resource, serial, mods_depressed,
339 mods_latched, mods_locked, group);
340}
341
Kristian Høgsbergabcef3c2012-03-05 17:47:15 -0500342static const struct wl_keyboard_grab_interface binding_grab = {
Daniel Stone351eb612012-05-31 15:27:47 -0400343 binding_key,
344 binding_modifiers,
Kristian Høgsbergabcef3c2012-03-05 17:47:15 -0500345};
346
347static void
Daniel Stone37816df2012-05-16 18:45:18 +0100348install_binding_grab(struct wl_seat *seat,
Kristian Høgsbergabcef3c2012-03-05 17:47:15 -0500349 uint32_t time, uint32_t key)
350{
351 struct binding_keyboard_grab *grab;
352
353 grab = malloc(sizeof *grab);
354 grab->key = key;
355 grab->grab.interface = &binding_grab;
Daniel Stone37816df2012-05-16 18:45:18 +0100356 wl_keyboard_start_grab(seat->keyboard, &grab->grab);
Kristian Høgsbergabcef3c2012-03-05 17:47:15 -0500357}
358
Pekka Paalanen4738f3b2012-01-02 15:47:07 +0200359WL_EXPORT void
Daniel Stone325fc2d2012-05-30 16:31:58 +0100360weston_compositor_run_key_binding(struct weston_compositor *compositor,
361 struct weston_seat *seat,
362 uint32_t time, uint32_t key,
363 enum wl_keyboard_key_state state)
Kristian Høgsbergf47d8fe2011-12-19 15:16:06 -0500364{
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500365 struct weston_binding *b;
Kristian Høgsbergf47d8fe2011-12-19 15:16:06 -0500366
Daniel Stone325fc2d2012-05-30 16:31:58 +0100367 if (state == WL_KEYBOARD_KEY_STATE_RELEASED)
368 return;
369
370 wl_list_for_each(b, &compositor->key_binding_list, link) {
371 if (b->key == key && b->modifier == seat->modifier_state) {
372 weston_key_binding_handler_t handler = b->handler;
373 handler(&seat->seat, time, key, b->data);
Kristian Høgsbergabcef3c2012-03-05 17:47:15 -0500374
375 /* If this was a key binding and it didn't
376 * install a keyboard grab, install one now to
377 * swallow the key release. */
Daniel Stone325fc2d2012-05-30 16:31:58 +0100378 if (seat->seat.keyboard->grab ==
Daniel Stone37816df2012-05-16 18:45:18 +0100379 &seat->seat.keyboard->default_grab)
380 install_binding_grab(&seat->seat, time, key);
Kristian Høgsbergf47d8fe2011-12-19 15:16:06 -0500381 }
382 }
383}
Benjamin Franzkebfeda132012-01-30 14:04:04 +0100384
Daniel Stone325fc2d2012-05-30 16:31:58 +0100385WL_EXPORT void
386weston_compositor_run_button_binding(struct weston_compositor *compositor,
387 struct weston_seat *seat,
388 uint32_t time, uint32_t button,
389 enum wl_pointer_button_state state)
390{
391 struct weston_binding *b;
392
393 if (state == WL_POINTER_BUTTON_STATE_RELEASED)
394 return;
395
396 wl_list_for_each(b, &compositor->button_binding_list, link) {
397 if (b->button == button && b->modifier == seat->modifier_state) {
398 weston_button_binding_handler_t handler = b->handler;
399 handler(&seat->seat, time, button, b->data);
400 }
401 }
402}
403
404WL_EXPORT void
405weston_compositor_run_axis_binding(struct weston_compositor *compositor,
406 struct weston_seat *seat,
407 uint32_t time, uint32_t axis,
408 int32_t value)
409{
410 struct weston_binding *b;
411
412 wl_list_for_each(b, &compositor->axis_binding_list, link) {
413 if (b->axis == axis && b->modifier == seat->modifier_state) {
414 weston_axis_binding_handler_t handler = b->handler;
415 handler(&seat->seat, time, axis, value, b->data);
416 }
417 }
418}
419
Benjamin Franzkebfeda132012-01-30 14:04:04 +0100420WL_EXPORT int
421weston_environment_get_fd(const char *env)
422{
423 char *e, *end;
424 int fd, flags;
425
426 e = getenv(env);
427 if (!e)
428 return -1;
429 fd = strtol(e, &end, 0);
430 if (*end != '\0')
431 return -1;
432
433 flags = fcntl(fd, F_GETFD);
434 if (flags == -1)
435 return -1;
436
437 fcntl(fd, F_SETFD, flags | FD_CLOEXEC);
438 unsetenv(env);
439
440 return fd;
441}
Juan Zhao2abd07b2012-04-25 19:09:51 +0800442/*fade in and fade out animation*/
443static void
444weston_fade_destroy(struct weston_fade *fade)
445{
446 wl_list_remove(&fade->animation.link);
447 wl_list_remove(&fade->listener.link);
448 fade->surface->geometry.dirty = 1;
449 if (fade->done)
450 fade->done(fade, fade->data);
451 free(fade);
452}
453
454static void
455handle_fade_surface_destroy(struct wl_listener *listener, void *data)
456{
457 struct weston_fade *fade =
458 container_of(listener, struct weston_fade, listener);
459
460 weston_fade_destroy(fade);
461}
462
463static void
464weston_fade_frame(struct weston_animation *animation,
465 struct weston_output *output, uint32_t msecs)
466{
467 struct weston_fade *fade =
468 container_of(animation, struct weston_fade, animation);
469 struct weston_surface *es = fade->surface;
470 float fade_factor;
471
472 weston_spring_update(&fade->spring, msecs);
473
474 if (weston_spring_done(&fade->spring)) {
475 weston_fade_destroy(fade);
476 return;
477 }
478 if (fade->spring.current > 1)
479 fade_factor = 1;
480 else if (fade->spring.current < 0 )
481 fade_factor = 0;
482 else
483 fade_factor = fade->spring.current;
Kristian Høgsberga416fa12012-05-21 14:06:52 -0400484 es->alpha = fade_factor;
Juan Zhao2abd07b2012-04-25 19:09:51 +0800485
486 fade->surface->geometry.dirty = 1;
487 weston_compositor_schedule_repaint(es->compositor);
488}
489
490WL_EXPORT struct weston_fade *
491weston_fade_run(struct weston_surface *surface,
492 weston_fade_done_func_t done, void *data)
493{
494 struct weston_fade *fade;
495
496 fade = malloc(sizeof *fade);
497 if (!fade)
498 return NULL;
499
500 fade->surface = surface;
501 fade->done = done;
502 fade->data = data;
503 weston_spring_init(&fade->spring, 200.0, 0, 1.0);
504 fade->spring.friction = 700;
505 fade->spring.timestamp = weston_compositor_get_time();
506 fade->animation.frame = weston_fade_frame;
507 weston_fade_frame(&fade->animation, NULL, fade->spring.timestamp);
508
509 fade->listener.notify = handle_fade_surface_destroy;
510 wl_signal_add(&surface->surface.resource.destroy_signal,
511 &fade->listener);
512
513 wl_list_insert(&surface->compositor->animation_list,
514 &fade->animation.link);
515
516 return fade;
517}