Kristian Høgsberg | 698c058 | 2011-12-04 15:20:19 -0500 | [diff] [blame] | 1 | /* |
| 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øgsberg | 4bfb82a | 2011-12-04 15:47:16 -0500 | [diff] [blame] | 24 | #include <string.h> |
Kristian Høgsberg | 698c058 | 2011-12-04 15:20:19 -0500 | [diff] [blame] | 25 | #include <stdio.h> |
Kristian Høgsberg | 4bfb82a | 2011-12-04 15:47:16 -0500 | [diff] [blame] | 26 | #include <math.h> |
Kristian Høgsberg | 698c058 | 2011-12-04 15:20:19 -0500 | [diff] [blame] | 27 | |
Benjamin Franzke | bfeda13 | 2012-01-30 14:04:04 +0100 | [diff] [blame] | 28 | #include <unistd.h> |
| 29 | #include <fcntl.h> |
| 30 | |
Kristian Høgsberg | 698c058 | 2011-12-04 15:20:19 -0500 | [diff] [blame] | 31 | #include "compositor.h" |
| 32 | |
Kristian Høgsberg | 4bfb82a | 2011-12-04 15:47:16 -0500 | [diff] [blame] | 33 | WL_EXPORT void |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 34 | weston_spring_init(struct weston_spring *spring, |
Kristian Høgsberg | 4bfb82a | 2011-12-04 15:47:16 -0500 | [diff] [blame] | 35 | 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 | |
| 44 | WL_EXPORT void |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 45 | weston_spring_update(struct weston_spring *spring, uint32_t msec) |
Kristian Høgsberg | 4bfb82a | 2011-12-04 15:47:16 -0500 | [diff] [blame] | 46 | { |
| 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 | |
| 81 | WL_EXPORT int |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 82 | weston_spring_done(struct weston_spring *spring) |
Kristian Høgsberg | 4bfb82a | 2011-12-04 15:47:16 -0500 | [diff] [blame] | 83 | { |
| 84 | return fabs(spring->previous - spring->target) < 0.0002 && |
| 85 | fabs(spring->current - spring->target) < 0.0002; |
| 86 | } |
| 87 | |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 88 | struct weston_zoom { |
| 89 | struct weston_surface *surface; |
| 90 | struct weston_animation animation; |
| 91 | struct weston_spring spring; |
| 92 | struct weston_transform transform; |
Kristian Høgsberg | 698c058 | 2011-12-04 15:20:19 -0500 | [diff] [blame] | 93 | struct wl_listener listener; |
Kristian Høgsberg | ef45824 | 2011-12-15 11:24:25 -0500 | [diff] [blame] | 94 | GLfloat start, stop; |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 95 | void (*done)(struct weston_zoom *zoom, void *data); |
Kristian Høgsberg | 698c058 | 2011-12-04 15:20:19 -0500 | [diff] [blame] | 96 | void *data; |
| 97 | }; |
| 98 | |
Juan Zhao | 2abd07b | 2012-04-25 19:09:51 +0800 | [diff] [blame^] | 99 | struct 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øgsberg | 698c058 | 2011-12-04 15:20:19 -0500 | [diff] [blame] | 108 | static void |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 109 | weston_zoom_destroy(struct weston_zoom *zoom) |
Kristian Høgsberg | 698c058 | 2011-12-04 15:20:19 -0500 | [diff] [blame] | 110 | { |
| 111 | wl_list_remove(&zoom->animation.link); |
| 112 | wl_list_remove(&zoom->listener.link); |
Pekka Paalanen | c61eca6 | 2012-01-06 14:10:06 +0200 | [diff] [blame] | 113 | wl_list_remove(&zoom->transform.link); |
Pekka Paalanen | bc0b7e7 | 2012-01-24 09:53:37 +0200 | [diff] [blame] | 114 | zoom->surface->geometry.dirty = 1; |
Kristian Høgsberg | 698c058 | 2011-12-04 15:20:19 -0500 | [diff] [blame] | 115 | if (zoom->done) |
| 116 | zoom->done(zoom, zoom->data); |
| 117 | free(zoom); |
| 118 | } |
| 119 | |
| 120 | static void |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 121 | handle_zoom_surface_destroy(struct wl_listener *listener, void *data) |
Kristian Høgsberg | 698c058 | 2011-12-04 15:20:19 -0500 | [diff] [blame] | 122 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 123 | struct weston_zoom *zoom = |
| 124 | container_of(listener, struct weston_zoom, listener); |
Kristian Høgsberg | 698c058 | 2011-12-04 15:20:19 -0500 | [diff] [blame] | 125 | |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 126 | weston_zoom_destroy(zoom); |
Kristian Høgsberg | 698c058 | 2011-12-04 15:20:19 -0500 | [diff] [blame] | 127 | } |
| 128 | |
| 129 | static void |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 130 | weston_zoom_frame(struct weston_animation *animation, |
| 131 | struct weston_output *output, uint32_t msecs) |
Kristian Høgsberg | 698c058 | 2011-12-04 15:20:19 -0500 | [diff] [blame] | 132 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 133 | struct weston_zoom *zoom = |
| 134 | container_of(animation, struct weston_zoom, animation); |
| 135 | struct weston_surface *es = zoom->surface; |
Kristian Høgsberg | 698c058 | 2011-12-04 15:20:19 -0500 | [diff] [blame] | 136 | GLfloat scale; |
| 137 | |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 138 | weston_spring_update(&zoom->spring, msecs); |
Kristian Høgsberg | 698c058 | 2011-12-04 15:20:19 -0500 | [diff] [blame] | 139 | |
Kristian Høgsberg | 3466bc8 | 2012-01-03 11:29:15 -0500 | [diff] [blame] | 140 | if (weston_spring_done(&zoom->spring)) { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 141 | weston_zoom_destroy(zoom); |
Pekka Paalanen | 2da6d5f | 2012-01-03 13:27:41 +0200 | [diff] [blame] | 142 | return; |
| 143 | } |
Kristian Høgsberg | 698c058 | 2011-12-04 15:20:19 -0500 | [diff] [blame] | 144 | |
Kristian Høgsberg | ef45824 | 2011-12-15 11:24:25 -0500 | [diff] [blame] | 145 | scale = zoom->start + |
| 146 | (zoom->stop - zoom->start) * zoom->spring.current; |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 147 | weston_matrix_init(&zoom->transform.matrix); |
| 148 | weston_matrix_translate(&zoom->transform.matrix, |
Pekka Paalanen | 60921e5 | 2012-01-25 15:55:43 +0200 | [diff] [blame] | 149 | -0.5f * es->geometry.width, |
| 150 | -0.5f * es->geometry.height, 0); |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 151 | weston_matrix_scale(&zoom->transform.matrix, scale, scale, scale); |
| 152 | weston_matrix_translate(&zoom->transform.matrix, |
Pekka Paalanen | 60921e5 | 2012-01-25 15:55:43 +0200 | [diff] [blame] | 153 | 0.5f * es->geometry.width, |
| 154 | 0.5f * es->geometry.height, 0); |
Kristian Høgsberg | 698c058 | 2011-12-04 15:20:19 -0500 | [diff] [blame] | 155 | |
Kristian Høgsberg | ef45824 | 2011-12-15 11:24:25 -0500 | [diff] [blame] | 156 | es->alpha = zoom->spring.current * 255; |
| 157 | if (es->alpha > 255) |
| 158 | es->alpha = 255; |
Kristian Høgsberg | 698c058 | 2011-12-04 15:20:19 -0500 | [diff] [blame] | 159 | |
Pekka Paalanen | bc0b7e7 | 2012-01-24 09:53:37 +0200 | [diff] [blame] | 160 | zoom->surface->geometry.dirty = 1; |
Kristian Høgsberg | 2ea0944 | 2012-02-28 23:12:52 -0500 | [diff] [blame] | 161 | weston_compositor_schedule_repaint(es->compositor); |
Kristian Høgsberg | 698c058 | 2011-12-04 15:20:19 -0500 | [diff] [blame] | 162 | } |
| 163 | |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 164 | WL_EXPORT struct weston_zoom * |
| 165 | weston_zoom_run(struct weston_surface *surface, GLfloat start, GLfloat stop, |
| 166 | weston_zoom_done_func_t done, void *data) |
Kristian Høgsberg | 698c058 | 2011-12-04 15:20:19 -0500 | [diff] [blame] | 167 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 168 | struct weston_zoom *zoom; |
Kristian Høgsberg | 698c058 | 2011-12-04 15:20:19 -0500 | [diff] [blame] | 169 | |
| 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øgsberg | ef45824 | 2011-12-15 11:24:25 -0500 | [diff] [blame] | 177 | zoom->start = start; |
| 178 | zoom->stop = stop; |
Pekka Paalanen | bc0b7e7 | 2012-01-24 09:53:37 +0200 | [diff] [blame] | 179 | wl_list_insert(&surface->geometry.transformation_list, |
| 180 | &zoom->transform.link); |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 181 | weston_spring_init(&zoom->spring, 200.0, 0.0, 1.0); |
Kristian Høgsberg | ef45824 | 2011-12-15 11:24:25 -0500 | [diff] [blame] | 182 | zoom->spring.friction = 700; |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 183 | 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øgsberg | 698c058 | 2011-12-04 15:20:19 -0500 | [diff] [blame] | 186 | |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 187 | zoom->listener.notify = handle_zoom_surface_destroy; |
| 188 | wl_signal_add(&surface->surface.resource.destroy_signal, |
| 189 | &zoom->listener); |
Kristian Høgsberg | 698c058 | 2011-12-04 15:20:19 -0500 | [diff] [blame] | 190 | |
Pekka Paalanen | 7377204 | 2012-01-25 14:45:18 +0200 | [diff] [blame] | 191 | wl_list_insert(&surface->compositor->animation_list, |
Kristian Høgsberg | 698c058 | 2011-12-04 15:20:19 -0500 | [diff] [blame] | 192 | &zoom->animation.link); |
| 193 | |
| 194 | return zoom; |
| 195 | } |
Kristian Høgsberg | f47d8fe | 2011-12-19 15:16:06 -0500 | [diff] [blame] | 196 | |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 197 | struct weston_binding { |
Kristian Høgsberg | f47d8fe | 2011-12-19 15:16:06 -0500 | [diff] [blame] | 198 | uint32_t key; |
| 199 | uint32_t button; |
Scott Moreau | 6a3633d | 2012-03-20 08:47:59 -0600 | [diff] [blame] | 200 | uint32_t axis; |
Kristian Høgsberg | f47d8fe | 2011-12-19 15:16:06 -0500 | [diff] [blame] | 201 | uint32_t modifier; |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 202 | weston_binding_handler_t handler; |
Kristian Høgsberg | f47d8fe | 2011-12-19 15:16:06 -0500 | [diff] [blame] | 203 | void *data; |
| 204 | struct wl_list link; |
| 205 | }; |
| 206 | |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 207 | WL_EXPORT struct weston_binding * |
| 208 | weston_compositor_add_binding(struct weston_compositor *compositor, |
Scott Moreau | 6a3633d | 2012-03-20 08:47:59 -0600 | [diff] [blame] | 209 | uint32_t key, uint32_t button, uint32_t axis, uint32_t modifier, |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 210 | weston_binding_handler_t handler, void *data) |
Kristian Høgsberg | f47d8fe | 2011-12-19 15:16:06 -0500 | [diff] [blame] | 211 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 212 | struct weston_binding *binding; |
Kristian Høgsberg | f47d8fe | 2011-12-19 15:16:06 -0500 | [diff] [blame] | 213 | |
| 214 | binding = malloc(sizeof *binding); |
| 215 | if (binding == NULL) |
| 216 | return NULL; |
| 217 | |
| 218 | binding->key = key; |
| 219 | binding->button = button; |
Scott Moreau | 6a3633d | 2012-03-20 08:47:59 -0600 | [diff] [blame] | 220 | binding->axis = axis; |
Kristian Høgsberg | f47d8fe | 2011-12-19 15:16:06 -0500 | [diff] [blame] | 221 | binding->modifier = modifier; |
| 222 | binding->handler = handler; |
| 223 | binding->data = data; |
| 224 | wl_list_insert(compositor->binding_list.prev, &binding->link); |
| 225 | |
| 226 | return binding; |
| 227 | } |
| 228 | |
| 229 | WL_EXPORT void |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 230 | weston_binding_destroy(struct weston_binding *binding) |
Kristian Høgsberg | f47d8fe | 2011-12-19 15:16:06 -0500 | [diff] [blame] | 231 | { |
| 232 | wl_list_remove(&binding->link); |
| 233 | free(binding); |
| 234 | } |
| 235 | |
| 236 | WL_EXPORT void |
Kristian Høgsberg | 3466bc8 | 2012-01-03 11:29:15 -0500 | [diff] [blame] | 237 | weston_binding_list_destroy_all(struct wl_list *list) |
Pekka Paalanen | 4738f3b | 2012-01-02 15:47:07 +0200 | [diff] [blame] | 238 | { |
Kristian Høgsberg | 3466bc8 | 2012-01-03 11:29:15 -0500 | [diff] [blame] | 239 | struct weston_binding *binding, *tmp; |
Pekka Paalanen | 4738f3b | 2012-01-02 15:47:07 +0200 | [diff] [blame] | 240 | |
| 241 | wl_list_for_each_safe(binding, tmp, list, link) |
Kristian Høgsberg | 3466bc8 | 2012-01-03 11:29:15 -0500 | [diff] [blame] | 242 | weston_binding_destroy(binding); |
Pekka Paalanen | 4738f3b | 2012-01-02 15:47:07 +0200 | [diff] [blame] | 243 | } |
| 244 | |
Kristian Høgsberg | abcef3c | 2012-03-05 17:47:15 -0500 | [diff] [blame] | 245 | struct binding_keyboard_grab { |
| 246 | uint32_t key; |
| 247 | struct wl_keyboard_grab grab; |
| 248 | }; |
| 249 | |
| 250 | static void |
| 251 | binding_key(struct wl_keyboard_grab *grab, |
| 252 | uint32_t time, uint32_t key, int32_t state) |
| 253 | { |
| 254 | struct binding_keyboard_grab *b = |
| 255 | container_of(grab, struct binding_keyboard_grab, grab); |
| 256 | struct wl_resource *resource; |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 257 | struct wl_display *display; |
| 258 | uint32_t serial; |
Kristian Høgsberg | abcef3c | 2012-03-05 17:47:15 -0500 | [diff] [blame] | 259 | |
| 260 | resource = grab->input_device->keyboard_focus_resource; |
| 261 | if (key == b->key) { |
| 262 | if (!state) { |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 263 | wl_input_device_end_keyboard_grab(grab->input_device); |
Kristian Høgsberg | abcef3c | 2012-03-05 17:47:15 -0500 | [diff] [blame] | 264 | free(b); |
| 265 | } |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 266 | } else if (resource) { |
| 267 | display = wl_client_get_display(resource->client); |
| 268 | serial = wl_display_next_serial(display); |
| 269 | wl_input_device_send_key(resource, serial, time, key, state); |
| 270 | } |
Kristian Høgsberg | abcef3c | 2012-03-05 17:47:15 -0500 | [diff] [blame] | 271 | } |
| 272 | |
| 273 | static const struct wl_keyboard_grab_interface binding_grab = { |
| 274 | binding_key |
| 275 | }; |
| 276 | |
| 277 | static void |
| 278 | install_binding_grab(struct wl_input_device *device, |
| 279 | uint32_t time, uint32_t key) |
| 280 | { |
| 281 | struct binding_keyboard_grab *grab; |
| 282 | |
| 283 | grab = malloc(sizeof *grab); |
| 284 | grab->key = key; |
| 285 | grab->grab.interface = &binding_grab; |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 286 | wl_input_device_start_keyboard_grab(device, &grab->grab); |
Kristian Høgsberg | abcef3c | 2012-03-05 17:47:15 -0500 | [diff] [blame] | 287 | } |
| 288 | |
Pekka Paalanen | 4738f3b | 2012-01-02 15:47:07 +0200 | [diff] [blame] | 289 | WL_EXPORT void |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 290 | weston_compositor_run_binding(struct weston_compositor *compositor, |
Kristian Høgsberg | 3466bc8 | 2012-01-03 11:29:15 -0500 | [diff] [blame] | 291 | struct weston_input_device *device, |
Scott Moreau | 6a3633d | 2012-03-20 08:47:59 -0600 | [diff] [blame] | 292 | uint32_t time, uint32_t key, |
| 293 | uint32_t button, uint32_t axis, int32_t state) |
Kristian Høgsberg | f47d8fe | 2011-12-19 15:16:06 -0500 | [diff] [blame] | 294 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 295 | struct weston_binding *b; |
Kristian Høgsberg | f47d8fe | 2011-12-19 15:16:06 -0500 | [diff] [blame] | 296 | |
| 297 | wl_list_for_each(b, &compositor->binding_list, link) { |
Scott Moreau | 6a3633d | 2012-03-20 08:47:59 -0600 | [diff] [blame] | 298 | if (b->key == key && b->button == button && b->axis == axis && |
Kristian Høgsberg | f47d8fe | 2011-12-19 15:16:06 -0500 | [diff] [blame] | 299 | b->modifier == device->modifier_state && state) { |
| 300 | b->handler(&device->input_device, |
Scott Moreau | 6a3633d | 2012-03-20 08:47:59 -0600 | [diff] [blame] | 301 | time, key, button, axis, state, b->data); |
Kristian Høgsberg | abcef3c | 2012-03-05 17:47:15 -0500 | [diff] [blame] | 302 | |
| 303 | /* If this was a key binding and it didn't |
| 304 | * install a keyboard grab, install one now to |
| 305 | * swallow the key release. */ |
| 306 | if (b->key && |
| 307 | device->input_device.keyboard_grab == |
| 308 | &device->input_device.default_keyboard_grab) |
| 309 | install_binding_grab(&device->input_device, |
| 310 | time, key); |
Kristian Høgsberg | f47d8fe | 2011-12-19 15:16:06 -0500 | [diff] [blame] | 311 | } |
| 312 | } |
| 313 | } |
Benjamin Franzke | bfeda13 | 2012-01-30 14:04:04 +0100 | [diff] [blame] | 314 | |
| 315 | WL_EXPORT int |
| 316 | weston_environment_get_fd(const char *env) |
| 317 | { |
| 318 | char *e, *end; |
| 319 | int fd, flags; |
| 320 | |
| 321 | e = getenv(env); |
| 322 | if (!e) |
| 323 | return -1; |
| 324 | fd = strtol(e, &end, 0); |
| 325 | if (*end != '\0') |
| 326 | return -1; |
| 327 | |
| 328 | flags = fcntl(fd, F_GETFD); |
| 329 | if (flags == -1) |
| 330 | return -1; |
| 331 | |
| 332 | fcntl(fd, F_SETFD, flags | FD_CLOEXEC); |
| 333 | unsetenv(env); |
| 334 | |
| 335 | return fd; |
| 336 | } |
Juan Zhao | 2abd07b | 2012-04-25 19:09:51 +0800 | [diff] [blame^] | 337 | /*fade in and fade out animation*/ |
| 338 | static void |
| 339 | weston_fade_destroy(struct weston_fade *fade) |
| 340 | { |
| 341 | wl_list_remove(&fade->animation.link); |
| 342 | wl_list_remove(&fade->listener.link); |
| 343 | fade->surface->geometry.dirty = 1; |
| 344 | if (fade->done) |
| 345 | fade->done(fade, fade->data); |
| 346 | free(fade); |
| 347 | } |
| 348 | |
| 349 | static void |
| 350 | handle_fade_surface_destroy(struct wl_listener *listener, void *data) |
| 351 | { |
| 352 | struct weston_fade *fade = |
| 353 | container_of(listener, struct weston_fade, listener); |
| 354 | |
| 355 | weston_fade_destroy(fade); |
| 356 | } |
| 357 | |
| 358 | static void |
| 359 | weston_fade_frame(struct weston_animation *animation, |
| 360 | struct weston_output *output, uint32_t msecs) |
| 361 | { |
| 362 | struct weston_fade *fade = |
| 363 | container_of(animation, struct weston_fade, animation); |
| 364 | struct weston_surface *es = fade->surface; |
| 365 | float fade_factor; |
| 366 | |
| 367 | weston_spring_update(&fade->spring, msecs); |
| 368 | |
| 369 | if (weston_spring_done(&fade->spring)) { |
| 370 | weston_fade_destroy(fade); |
| 371 | return; |
| 372 | } |
| 373 | if (fade->spring.current > 1) |
| 374 | fade_factor = 1; |
| 375 | else if (fade->spring.current < 0 ) |
| 376 | fade_factor = 0; |
| 377 | else |
| 378 | fade_factor = fade->spring.current; |
| 379 | es->alpha = fade_factor * 255; |
| 380 | |
| 381 | fade->surface->geometry.dirty = 1; |
| 382 | weston_compositor_schedule_repaint(es->compositor); |
| 383 | } |
| 384 | |
| 385 | WL_EXPORT struct weston_fade * |
| 386 | weston_fade_run(struct weston_surface *surface, |
| 387 | weston_fade_done_func_t done, void *data) |
| 388 | { |
| 389 | struct weston_fade *fade; |
| 390 | |
| 391 | fade = malloc(sizeof *fade); |
| 392 | if (!fade) |
| 393 | return NULL; |
| 394 | |
| 395 | fade->surface = surface; |
| 396 | fade->done = done; |
| 397 | fade->data = data; |
| 398 | weston_spring_init(&fade->spring, 200.0, 0, 1.0); |
| 399 | fade->spring.friction = 700; |
| 400 | fade->spring.timestamp = weston_compositor_get_time(); |
| 401 | fade->animation.frame = weston_fade_frame; |
| 402 | weston_fade_frame(&fade->animation, NULL, fade->spring.timestamp); |
| 403 | |
| 404 | fade->listener.notify = handle_fade_surface_destroy; |
| 405 | wl_signal_add(&surface->surface.resource.destroy_signal, |
| 406 | &fade->listener); |
| 407 | |
| 408 | wl_list_insert(&surface->compositor->animation_list, |
| 409 | &fade->animation.link); |
| 410 | |
| 411 | return fade; |
| 412 | } |