blob: 306c7971519cfe5d570ab55577d204f203bd9197 [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
Rob Bradford84cf5412012-08-09 15:35:49 +010049 /* Limit the number of executions of the loop below by ensuring that
50 * the timestamp for last update of the spring is no more than 1s ago.
51 * This handles the case where time moves backwards or forwards in
52 * large jumps.
53 */
54 if (msec - spring->timestamp > 1000) {
55 weston_log("unexpectedly large timestamp jump (from %u to %u)\n",
56 spring->timestamp, msec);
57 spring->timestamp = msec - 1000;
Rob Bradfordc4f33382012-08-03 17:02:04 +010058 }
59
Kristian Høgsberg4bfb82a2011-12-04 15:47:16 -050060 step = 0.01;
61 while (4 < msec - spring->timestamp) {
62 current = spring->current;
63 v = current - spring->previous;
64 force = spring->k * (spring->target - current) / 10.0 +
65 (spring->previous - current) - v * spring->friction;
66
67 spring->current =
68 current + (current - spring->previous) +
69 force * step * step;
70 spring->previous = current;
71
72#if 0
73 if (spring->current >= 1.0) {
74#ifdef TWEENER_BOUNCE
75 spring->current = 2.0 - spring->current;
76 spring->previous = 2.0 - spring->previous;
77#else
78 spring->current = 1.0;
79 spring->previous = 1.0;
80#endif
81 }
82
83 if (spring->current <= 0.0) {
84 spring->current = 0.0;
85 spring->previous = 0.0;
86 }
87#endif
88 spring->timestamp += 4;
89 }
90}
91
92WL_EXPORT int
Kristian Høgsberg8334bc12012-01-03 10:29:47 -050093weston_spring_done(struct weston_spring *spring)
Kristian Høgsberg4bfb82a2011-12-04 15:47:16 -050094{
95 return fabs(spring->previous - spring->target) < 0.0002 &&
96 fabs(spring->current - spring->target) < 0.0002;
97}
98
Kristian Høgsberg414bd422012-06-21 22:07:30 -040099typedef void (*weston_surface_animation_frame_func_t)(struct weston_surface_animation *animation);
100
101struct weston_surface_animation {
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500102 struct weston_surface *surface;
103 struct weston_animation animation;
104 struct weston_spring spring;
105 struct weston_transform transform;
Kristian Høgsberg698c0582011-12-04 15:20:19 -0500106 struct wl_listener listener;
John Kåre Alsaker490d02a2012-09-30 02:57:21 +0200107 float start, stop;
Kristian Høgsberg414bd422012-06-21 22:07:30 -0400108 weston_surface_animation_frame_func_t frame;
109 weston_surface_animation_done_func_t done;
Juan Zhao2abd07b2012-04-25 19:09:51 +0800110 void *data;
111};
112
Kristian Høgsberg698c0582011-12-04 15:20:19 -0500113static void
Kristian Høgsberg414bd422012-06-21 22:07:30 -0400114weston_surface_animation_destroy(struct weston_surface_animation *animation)
Kristian Høgsberg698c0582011-12-04 15:20:19 -0500115{
Kristian Høgsberg414bd422012-06-21 22:07:30 -0400116 wl_list_remove(&animation->animation.link);
117 wl_list_remove(&animation->listener.link);
118 wl_list_remove(&animation->transform.link);
119 animation->surface->geometry.dirty = 1;
120 if (animation->done)
121 animation->done(animation, animation->data);
122 free(animation);
Kristian Høgsberg698c0582011-12-04 15:20:19 -0500123}
124
125static void
Kristian Høgsberg414bd422012-06-21 22:07:30 -0400126handle_animation_surface_destroy(struct wl_listener *listener, void *data)
Kristian Høgsberg698c0582011-12-04 15:20:19 -0500127{
Kristian Høgsberg414bd422012-06-21 22:07:30 -0400128 struct weston_surface_animation *animation =
129 container_of(listener,
130 struct weston_surface_animation, listener);
Kristian Høgsberg698c0582011-12-04 15:20:19 -0500131
Kristian Høgsberg414bd422012-06-21 22:07:30 -0400132 weston_surface_animation_destroy(animation);
Kristian Høgsberg698c0582011-12-04 15:20:19 -0500133}
134
135static void
Kristian Høgsberg414bd422012-06-21 22:07:30 -0400136weston_surface_animation_frame(struct weston_animation *base,
137 struct weston_output *output, uint32_t msecs)
Kristian Høgsberg698c0582011-12-04 15:20:19 -0500138{
Kristian Høgsberg414bd422012-06-21 22:07:30 -0400139 struct weston_surface_animation *animation =
140 container_of(base,
141 struct weston_surface_animation, animation);
Kristian Høgsberg698c0582011-12-04 15:20:19 -0500142
Kristian Høgsberg414bd422012-06-21 22:07:30 -0400143 if (base->frame_counter <= 1)
144 animation->spring.timestamp = msecs;
Scott Moreaue2949db2012-06-11 13:09:23 -0600145
Kristian Høgsberg414bd422012-06-21 22:07:30 -0400146 weston_spring_update(&animation->spring, msecs);
Kristian Høgsberg698c0582011-12-04 15:20:19 -0500147
Kristian Høgsberg414bd422012-06-21 22:07:30 -0400148 if (weston_spring_done(&animation->spring)) {
149 weston_surface_animation_destroy(animation);
Pekka Paalanen2da6d5f2012-01-03 13:27:41 +0200150 return;
151 }
Kristian Høgsberg698c0582011-12-04 15:20:19 -0500152
Kristian Høgsberg414bd422012-06-21 22:07:30 -0400153 if (animation->frame)
154 animation->frame(animation);
155
156 animation->surface->geometry.dirty = 1;
157 weston_compositor_schedule_repaint(animation->surface->compositor);
158}
159
160static struct weston_surface_animation *
161weston_surface_animation_run(struct weston_surface *surface,
John Kåre Alsaker490d02a2012-09-30 02:57:21 +0200162 float start, float stop,
Kristian Høgsberg414bd422012-06-21 22:07:30 -0400163 weston_surface_animation_frame_func_t frame,
164 weston_surface_animation_done_func_t done,
165 void *data)
166{
167 struct weston_surface_animation *animation;
168
169 animation = malloc(sizeof *animation);
170 if (!animation)
171 return NULL;
172
173 animation->surface = surface;
174 animation->frame = frame;
175 animation->done = done;
176 animation->data = data;
177 animation->start = start;
178 animation->stop = stop;
179 weston_matrix_init(&animation->transform.matrix);
180 wl_list_insert(&surface->geometry.transformation_list,
181 &animation->transform.link);
182 weston_spring_init(&animation->spring, 200.0, 0.0, 1.0);
183 animation->spring.friction = 700;
184 animation->animation.frame_counter = 0;
185 animation->animation.frame = weston_surface_animation_frame;
186 weston_surface_animation_frame(&animation->animation, NULL, 0);
187
188 animation->listener.notify = handle_animation_surface_destroy;
189 wl_signal_add(&surface->surface.resource.destroy_signal,
190 &animation->listener);
191
192 wl_list_insert(&surface->output->animation_list,
193 &animation->animation.link);
194
195 return animation;
196}
197
198static void
199zoom_frame(struct weston_surface_animation *animation)
200{
201 struct weston_surface *es = animation->surface;
John Kåre Alsaker490d02a2012-09-30 02:57:21 +0200202 float scale;
Kristian Høgsberg414bd422012-06-21 22:07:30 -0400203
204 scale = animation->start +
205 (animation->stop - animation->start) *
206 animation->spring.current;
207 weston_matrix_init(&animation->transform.matrix);
208 weston_matrix_translate(&animation->transform.matrix,
Pekka Paalanen60921e52012-01-25 15:55:43 +0200209 -0.5f * es->geometry.width,
210 -0.5f * es->geometry.height, 0);
Kristian Høgsberg414bd422012-06-21 22:07:30 -0400211 weston_matrix_scale(&animation->transform.matrix, scale, scale, scale);
212 weston_matrix_translate(&animation->transform.matrix,
Pekka Paalanen60921e52012-01-25 15:55:43 +0200213 0.5f * es->geometry.width,
214 0.5f * es->geometry.height, 0);
Kristian Høgsberg698c0582011-12-04 15:20:19 -0500215
Kristian Høgsberg414bd422012-06-21 22:07:30 -0400216 es->alpha = animation->spring.current;
Kristian Høgsberga416fa12012-05-21 14:06:52 -0400217 if (es->alpha > 1.0)
218 es->alpha = 1.0;
Kristian Høgsberg698c0582011-12-04 15:20:19 -0500219}
220
Kristian Høgsberg414bd422012-06-21 22:07:30 -0400221WL_EXPORT struct weston_surface_animation *
John Kåre Alsaker490d02a2012-09-30 02:57:21 +0200222weston_zoom_run(struct weston_surface *surface, float start, float stop,
Kristian Høgsberg414bd422012-06-21 22:07:30 -0400223 weston_surface_animation_done_func_t done, void *data)
Kristian Høgsberg698c0582011-12-04 15:20:19 -0500224{
Kristian Høgsberg414bd422012-06-21 22:07:30 -0400225 return weston_surface_animation_run(surface, start, stop,
226 zoom_frame, done, data);
227}
Kristian Høgsberg698c0582011-12-04 15:20:19 -0500228
Kristian Høgsberg414bd422012-06-21 22:07:30 -0400229static void
230fade_frame(struct weston_surface_animation *animation)
231{
232 if (animation->spring.current > 1)
233 animation->surface->alpha = 1;
234 else if (animation->spring.current < 0 )
235 animation->surface->alpha = 0;
236 else
237 animation->surface->alpha = animation->spring.current;
238}
Kristian Høgsberg698c0582011-12-04 15:20:19 -0500239
Kristian Høgsberg414bd422012-06-21 22:07:30 -0400240WL_EXPORT struct weston_surface_animation *
241weston_fade_run(struct weston_surface *surface,
242 weston_surface_animation_done_func_t done, void *data)
243{
244 return weston_surface_animation_run(surface, 0, 0,
245 fade_frame, done, data);
Kristian Høgsberg698c0582011-12-04 15:20:19 -0500246}
Kristian Høgsbergf47d8fe2011-12-19 15:16:06 -0500247
Kristian Høgsberg1ce6a2a2012-06-21 22:34:39 -0400248static void
249slide_frame(struct weston_surface_animation *animation)
250{
John Kåre Alsaker490d02a2012-09-30 02:57:21 +0200251 float scale;
Kristian Høgsberg1ce6a2a2012-06-21 22:34:39 -0400252
253 scale = animation->start +
254 (animation->stop - animation->start) *
255 animation->spring.current;
256 weston_matrix_init(&animation->transform.matrix);
257 weston_matrix_translate(&animation->transform.matrix, 0, scale, 0);
258}
259
260WL_EXPORT struct weston_surface_animation *
John Kåre Alsaker490d02a2012-09-30 02:57:21 +0200261weston_slide_run(struct weston_surface *surface, float start, float stop,
Kristian Høgsberg1ce6a2a2012-06-21 22:34:39 -0400262 weston_surface_animation_done_func_t done, void *data)
263{
264 struct weston_surface_animation *animation;
265
266 animation = weston_surface_animation_run(surface, start, stop,
267 slide_frame, done, data);
John Kåre Alsaker7a92ea42012-10-12 12:32:03 +0200268 if (!animation)
269 return NULL;
270
Kristian Høgsberg1ce6a2a2012-06-21 22:34:39 -0400271 animation->spring.friction = 900;
272 animation->spring.k = 300;
273
274 return animation;
275}
276
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500277struct weston_binding {
Kristian Høgsbergf47d8fe2011-12-19 15:16:06 -0500278 uint32_t key;
279 uint32_t button;
Scott Moreau6a3633d2012-03-20 08:47:59 -0600280 uint32_t axis;
Kristian Høgsbergf47d8fe2011-12-19 15:16:06 -0500281 uint32_t modifier;
Daniel Stone325fc2d2012-05-30 16:31:58 +0100282 void *handler;
Kristian Høgsbergf47d8fe2011-12-19 15:16:06 -0500283 void *data;
284 struct wl_list link;
285};
286
Daniel Stone325fc2d2012-05-30 16:31:58 +0100287static struct weston_binding *
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500288weston_compositor_add_binding(struct weston_compositor *compositor,
Daniel Stone325fc2d2012-05-30 16:31:58 +0100289 uint32_t key, uint32_t button, uint32_t axis,
290 uint32_t modifier, void *handler, void *data)
Kristian Høgsbergf47d8fe2011-12-19 15:16:06 -0500291{
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500292 struct weston_binding *binding;
Kristian Høgsbergf47d8fe2011-12-19 15:16:06 -0500293
294 binding = malloc(sizeof *binding);
295 if (binding == NULL)
296 return NULL;
297
298 binding->key = key;
299 binding->button = button;
Scott Moreau6a3633d2012-03-20 08:47:59 -0600300 binding->axis = axis;
Kristian Høgsbergf47d8fe2011-12-19 15:16:06 -0500301 binding->modifier = modifier;
302 binding->handler = handler;
303 binding->data = data;
Daniel Stone325fc2d2012-05-30 16:31:58 +0100304
305 return binding;
306}
307
308WL_EXPORT struct weston_binding *
309weston_compositor_add_key_binding(struct weston_compositor *compositor,
310 uint32_t key, uint32_t modifier,
311 weston_key_binding_handler_t handler,
312 void *data)
313{
314 struct weston_binding *binding;
315
316 binding = weston_compositor_add_binding(compositor, key, 0, 0,
317 modifier, handler, data);
318 if (binding == NULL)
319 return NULL;
320
321 wl_list_insert(compositor->key_binding_list.prev, &binding->link);
322
323 return binding;
324}
325
326WL_EXPORT struct weston_binding *
327weston_compositor_add_button_binding(struct weston_compositor *compositor,
328 uint32_t button, uint32_t modifier,
329 weston_button_binding_handler_t handler,
330 void *data)
331{
332 struct weston_binding *binding;
333
334 binding = weston_compositor_add_binding(compositor, 0, button, 0,
335 modifier, handler, data);
336 if (binding == NULL)
337 return NULL;
338
339 wl_list_insert(compositor->button_binding_list.prev, &binding->link);
340
341 return binding;
342}
343
344WL_EXPORT struct weston_binding *
345weston_compositor_add_axis_binding(struct weston_compositor *compositor,
346 uint32_t axis, uint32_t modifier,
347 weston_axis_binding_handler_t handler,
348 void *data)
349{
350 struct weston_binding *binding;
351
352 binding = weston_compositor_add_binding(compositor, 0, 0, axis,
353 modifier, handler, data);
354 if (binding == NULL)
355 return NULL;
356
357 wl_list_insert(compositor->axis_binding_list.prev, &binding->link);
Kristian Høgsbergf47d8fe2011-12-19 15:16:06 -0500358
359 return binding;
360}
361
362WL_EXPORT void
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500363weston_binding_destroy(struct weston_binding *binding)
Kristian Høgsbergf47d8fe2011-12-19 15:16:06 -0500364{
365 wl_list_remove(&binding->link);
366 free(binding);
367}
368
369WL_EXPORT void
Kristian Høgsberg3466bc82012-01-03 11:29:15 -0500370weston_binding_list_destroy_all(struct wl_list *list)
Pekka Paalanen4738f3b2012-01-02 15:47:07 +0200371{
Kristian Høgsberg3466bc82012-01-03 11:29:15 -0500372 struct weston_binding *binding, *tmp;
Pekka Paalanen4738f3b2012-01-02 15:47:07 +0200373
374 wl_list_for_each_safe(binding, tmp, list, link)
Kristian Høgsberg3466bc82012-01-03 11:29:15 -0500375 weston_binding_destroy(binding);
Pekka Paalanen4738f3b2012-01-02 15:47:07 +0200376}
377
Kristian Høgsbergabcef3c2012-03-05 17:47:15 -0500378struct binding_keyboard_grab {
379 uint32_t key;
380 struct wl_keyboard_grab grab;
381};
382
383static void
384binding_key(struct wl_keyboard_grab *grab,
Daniel Stonec9785ea2012-05-30 16:31:52 +0100385 uint32_t time, uint32_t key, uint32_t state_w)
Kristian Høgsbergabcef3c2012-03-05 17:47:15 -0500386{
387 struct binding_keyboard_grab *b =
388 container_of(grab, struct binding_keyboard_grab, grab);
389 struct wl_resource *resource;
Kristian Høgsbergeae5de72012-04-11 22:42:15 -0400390 struct wl_display *display;
Daniel Stonec9785ea2012-05-30 16:31:52 +0100391 enum wl_keyboard_key_state state = state_w;
Kristian Høgsbergeae5de72012-04-11 22:42:15 -0400392 uint32_t serial;
Kristian Høgsbergabcef3c2012-03-05 17:47:15 -0500393
Daniel Stone37816df2012-05-16 18:45:18 +0100394 resource = grab->keyboard->focus_resource;
Kristian Høgsbergabcef3c2012-03-05 17:47:15 -0500395 if (key == b->key) {
Daniel Stonec9785ea2012-05-30 16:31:52 +0100396 if (state == WL_KEYBOARD_KEY_STATE_RELEASED) {
Daniel Stone37816df2012-05-16 18:45:18 +0100397 wl_keyboard_end_grab(grab->keyboard);
Kristian Høgsbergabcef3c2012-03-05 17:47:15 -0500398 free(b);
399 }
Kristian Høgsbergeae5de72012-04-11 22:42:15 -0400400 } else if (resource) {
401 display = wl_client_get_display(resource->client);
402 serial = wl_display_next_serial(display);
Daniel Stone37816df2012-05-16 18:45:18 +0100403 wl_keyboard_send_key(resource, serial, time, key, state);
Kristian Høgsbergeae5de72012-04-11 22:42:15 -0400404 }
Kristian Høgsbergabcef3c2012-03-05 17:47:15 -0500405}
406
Daniel Stone351eb612012-05-31 15:27:47 -0400407static void
408binding_modifiers(struct wl_keyboard_grab *grab, uint32_t serial,
409 uint32_t mods_depressed, uint32_t mods_latched,
410 uint32_t mods_locked, uint32_t group)
411{
412 struct wl_resource *resource;
413
414 resource = grab->keyboard->focus_resource;
415 if (!resource)
416 return;
417
418 wl_keyboard_send_modifiers(resource, serial, mods_depressed,
419 mods_latched, mods_locked, group);
420}
421
Kristian Høgsbergabcef3c2012-03-05 17:47:15 -0500422static const struct wl_keyboard_grab_interface binding_grab = {
Daniel Stone351eb612012-05-31 15:27:47 -0400423 binding_key,
424 binding_modifiers,
Kristian Høgsbergabcef3c2012-03-05 17:47:15 -0500425};
426
427static void
Daniel Stone37816df2012-05-16 18:45:18 +0100428install_binding_grab(struct wl_seat *seat,
Kristian Høgsbergabcef3c2012-03-05 17:47:15 -0500429 uint32_t time, uint32_t key)
430{
431 struct binding_keyboard_grab *grab;
432
433 grab = malloc(sizeof *grab);
434 grab->key = key;
435 grab->grab.interface = &binding_grab;
Daniel Stone37816df2012-05-16 18:45:18 +0100436 wl_keyboard_start_grab(seat->keyboard, &grab->grab);
Kristian Høgsbergabcef3c2012-03-05 17:47:15 -0500437}
438
Pekka Paalanen4738f3b2012-01-02 15:47:07 +0200439WL_EXPORT void
Daniel Stone325fc2d2012-05-30 16:31:58 +0100440weston_compositor_run_key_binding(struct weston_compositor *compositor,
441 struct weston_seat *seat,
442 uint32_t time, uint32_t key,
443 enum wl_keyboard_key_state state)
Kristian Høgsbergf47d8fe2011-12-19 15:16:06 -0500444{
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500445 struct weston_binding *b;
Kristian Høgsbergf47d8fe2011-12-19 15:16:06 -0500446
Daniel Stone325fc2d2012-05-30 16:31:58 +0100447 if (state == WL_KEYBOARD_KEY_STATE_RELEASED)
448 return;
449
450 wl_list_for_each(b, &compositor->key_binding_list, link) {
451 if (b->key == key && b->modifier == seat->modifier_state) {
452 weston_key_binding_handler_t handler = b->handler;
453 handler(&seat->seat, time, key, b->data);
Kristian Høgsbergabcef3c2012-03-05 17:47:15 -0500454
455 /* If this was a key binding and it didn't
456 * install a keyboard grab, install one now to
457 * swallow the key release. */
Daniel Stone325fc2d2012-05-30 16:31:58 +0100458 if (seat->seat.keyboard->grab ==
Daniel Stone37816df2012-05-16 18:45:18 +0100459 &seat->seat.keyboard->default_grab)
460 install_binding_grab(&seat->seat, time, key);
Kristian Høgsbergf47d8fe2011-12-19 15:16:06 -0500461 }
462 }
463}
Benjamin Franzkebfeda132012-01-30 14:04:04 +0100464
Daniel Stone325fc2d2012-05-30 16:31:58 +0100465WL_EXPORT void
466weston_compositor_run_button_binding(struct weston_compositor *compositor,
467 struct weston_seat *seat,
468 uint32_t time, uint32_t button,
469 enum wl_pointer_button_state state)
470{
471 struct weston_binding *b;
472
473 if (state == WL_POINTER_BUTTON_STATE_RELEASED)
474 return;
475
476 wl_list_for_each(b, &compositor->button_binding_list, link) {
477 if (b->button == button && b->modifier == seat->modifier_state) {
478 weston_button_binding_handler_t handler = b->handler;
479 handler(&seat->seat, time, button, b->data);
480 }
481 }
482}
483
484WL_EXPORT void
485weston_compositor_run_axis_binding(struct weston_compositor *compositor,
486 struct weston_seat *seat,
487 uint32_t time, uint32_t axis,
Daniel Stone0c1e46e2012-05-30 16:31:59 +0100488 wl_fixed_t value)
Daniel Stone325fc2d2012-05-30 16:31:58 +0100489{
490 struct weston_binding *b;
491
492 wl_list_for_each(b, &compositor->axis_binding_list, link) {
493 if (b->axis == axis && b->modifier == seat->modifier_state) {
494 weston_axis_binding_handler_t handler = b->handler;
495 handler(&seat->seat, time, axis, value, b->data);
496 }
497 }
498}
499
Benjamin Franzkebfeda132012-01-30 14:04:04 +0100500WL_EXPORT int
501weston_environment_get_fd(const char *env)
502{
503 char *e, *end;
504 int fd, flags;
505
506 e = getenv(env);
507 if (!e)
508 return -1;
509 fd = strtol(e, &end, 0);
510 if (*end != '\0')
511 return -1;
512
513 flags = fcntl(fd, F_GETFD);
514 if (flags == -1)
515 return -1;
516
517 fcntl(fd, F_SETFD, flags | FD_CLOEXEC);
518 unsetenv(env);
519
520 return fd;
521}