Ander Conselvan de Oliveira | cbdebc2 | 2013-02-21 18:35:16 +0200 | [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 | |
Daniel Stone | c228e23 | 2013-05-22 18:03:19 +0300 | [diff] [blame] | 23 | #include "config.h" |
| 24 | |
Ander Conselvan de Oliveira | cbdebc2 | 2013-02-21 18:35:16 +0200 | [diff] [blame] | 25 | #include <stdlib.h> |
| 26 | |
| 27 | #include "compositor.h" |
| 28 | |
| 29 | struct weston_binding { |
| 30 | uint32_t key; |
| 31 | uint32_t button; |
| 32 | uint32_t axis; |
| 33 | uint32_t modifier; |
| 34 | void *handler; |
| 35 | void *data; |
| 36 | struct wl_list link; |
| 37 | }; |
| 38 | |
| 39 | static struct weston_binding * |
| 40 | weston_compositor_add_binding(struct weston_compositor *compositor, |
| 41 | uint32_t key, uint32_t button, uint32_t axis, |
| 42 | uint32_t modifier, void *handler, void *data) |
| 43 | { |
| 44 | struct weston_binding *binding; |
| 45 | |
| 46 | binding = malloc(sizeof *binding); |
| 47 | if (binding == NULL) |
| 48 | return NULL; |
| 49 | |
| 50 | binding->key = key; |
| 51 | binding->button = button; |
| 52 | binding->axis = axis; |
| 53 | binding->modifier = modifier; |
| 54 | binding->handler = handler; |
| 55 | binding->data = data; |
| 56 | |
| 57 | return binding; |
| 58 | } |
| 59 | |
| 60 | WL_EXPORT struct weston_binding * |
| 61 | weston_compositor_add_key_binding(struct weston_compositor *compositor, |
| 62 | uint32_t key, uint32_t modifier, |
| 63 | weston_key_binding_handler_t handler, |
| 64 | void *data) |
| 65 | { |
| 66 | struct weston_binding *binding; |
| 67 | |
| 68 | binding = weston_compositor_add_binding(compositor, key, 0, 0, |
| 69 | modifier, handler, data); |
| 70 | if (binding == NULL) |
| 71 | return NULL; |
| 72 | |
| 73 | wl_list_insert(compositor->key_binding_list.prev, &binding->link); |
| 74 | |
| 75 | return binding; |
| 76 | } |
| 77 | |
| 78 | WL_EXPORT struct weston_binding * |
Daniel Stone | 96d47c0 | 2013-11-19 11:37:12 +0100 | [diff] [blame] | 79 | weston_compositor_add_modifier_binding(struct weston_compositor *compositor, |
| 80 | uint32_t modifier, |
| 81 | weston_modifier_binding_handler_t handler, |
| 82 | void *data) |
| 83 | { |
| 84 | struct weston_binding *binding; |
| 85 | |
| 86 | binding = weston_compositor_add_binding(compositor, 0, 0, 0, |
| 87 | modifier, handler, data); |
| 88 | if (binding == NULL) |
| 89 | return NULL; |
| 90 | |
| 91 | wl_list_insert(compositor->modifier_binding_list.prev, &binding->link); |
| 92 | |
| 93 | return binding; |
| 94 | } |
| 95 | |
| 96 | WL_EXPORT struct weston_binding * |
Ander Conselvan de Oliveira | cbdebc2 | 2013-02-21 18:35:16 +0200 | [diff] [blame] | 97 | weston_compositor_add_button_binding(struct weston_compositor *compositor, |
| 98 | uint32_t button, uint32_t modifier, |
| 99 | weston_button_binding_handler_t handler, |
| 100 | void *data) |
| 101 | { |
| 102 | struct weston_binding *binding; |
| 103 | |
| 104 | binding = weston_compositor_add_binding(compositor, 0, button, 0, |
| 105 | modifier, handler, data); |
| 106 | if (binding == NULL) |
| 107 | return NULL; |
| 108 | |
| 109 | wl_list_insert(compositor->button_binding_list.prev, &binding->link); |
| 110 | |
| 111 | return binding; |
| 112 | } |
| 113 | |
| 114 | WL_EXPORT struct weston_binding * |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 115 | weston_compositor_add_touch_binding(struct weston_compositor *compositor, |
| 116 | uint32_t modifier, |
| 117 | weston_touch_binding_handler_t handler, |
| 118 | void *data) |
| 119 | { |
| 120 | struct weston_binding *binding; |
| 121 | |
| 122 | binding = weston_compositor_add_binding(compositor, 0, 0, 0, |
| 123 | modifier, handler, data); |
| 124 | if (binding == NULL) |
| 125 | return NULL; |
| 126 | |
| 127 | wl_list_insert(compositor->touch_binding_list.prev, &binding->link); |
| 128 | |
| 129 | return binding; |
| 130 | } |
| 131 | |
| 132 | WL_EXPORT struct weston_binding * |
Ander Conselvan de Oliveira | cbdebc2 | 2013-02-21 18:35:16 +0200 | [diff] [blame] | 133 | weston_compositor_add_axis_binding(struct weston_compositor *compositor, |
| 134 | uint32_t axis, uint32_t modifier, |
| 135 | weston_axis_binding_handler_t handler, |
| 136 | void *data) |
| 137 | { |
| 138 | struct weston_binding *binding; |
| 139 | |
| 140 | binding = weston_compositor_add_binding(compositor, 0, 0, axis, |
| 141 | modifier, handler, data); |
| 142 | if (binding == NULL) |
| 143 | return NULL; |
| 144 | |
| 145 | wl_list_insert(compositor->axis_binding_list.prev, &binding->link); |
| 146 | |
| 147 | return binding; |
| 148 | } |
| 149 | |
| 150 | WL_EXPORT struct weston_binding * |
| 151 | weston_compositor_add_debug_binding(struct weston_compositor *compositor, |
| 152 | uint32_t key, |
| 153 | weston_key_binding_handler_t handler, |
| 154 | void *data) |
| 155 | { |
| 156 | struct weston_binding *binding; |
| 157 | |
| 158 | binding = weston_compositor_add_binding(compositor, key, 0, 0, 0, |
| 159 | handler, data); |
| 160 | |
| 161 | wl_list_insert(compositor->debug_binding_list.prev, &binding->link); |
| 162 | |
| 163 | return binding; |
| 164 | } |
| 165 | |
| 166 | WL_EXPORT void |
| 167 | weston_binding_destroy(struct weston_binding *binding) |
| 168 | { |
| 169 | wl_list_remove(&binding->link); |
| 170 | free(binding); |
| 171 | } |
| 172 | |
| 173 | WL_EXPORT void |
| 174 | weston_binding_list_destroy_all(struct wl_list *list) |
| 175 | { |
| 176 | struct weston_binding *binding, *tmp; |
| 177 | |
| 178 | wl_list_for_each_safe(binding, tmp, list, link) |
| 179 | weston_binding_destroy(binding); |
| 180 | } |
| 181 | |
| 182 | struct binding_keyboard_grab { |
| 183 | uint32_t key; |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 184 | struct weston_keyboard_grab grab; |
Ander Conselvan de Oliveira | cbdebc2 | 2013-02-21 18:35:16 +0200 | [diff] [blame] | 185 | }; |
| 186 | |
| 187 | static void |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 188 | binding_key(struct weston_keyboard_grab *grab, |
Ander Conselvan de Oliveira | cbdebc2 | 2013-02-21 18:35:16 +0200 | [diff] [blame] | 189 | uint32_t time, uint32_t key, uint32_t state_w) |
| 190 | { |
| 191 | struct binding_keyboard_grab *b = |
| 192 | container_of(grab, struct binding_keyboard_grab, grab); |
| 193 | struct wl_resource *resource; |
Ander Conselvan de Oliveira | cbdebc2 | 2013-02-21 18:35:16 +0200 | [diff] [blame] | 194 | enum wl_keyboard_key_state state = state_w; |
| 195 | uint32_t serial; |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 196 | struct weston_keyboard *keyboard = grab->keyboard; |
Rob Bradford | 880ebc7 | 2013-07-22 17:31:38 +0100 | [diff] [blame] | 197 | struct wl_display *display = keyboard->seat->compositor->wl_display; |
Ander Conselvan de Oliveira | cbdebc2 | 2013-02-21 18:35:16 +0200 | [diff] [blame] | 198 | |
Ander Conselvan de Oliveira | cbdebc2 | 2013-02-21 18:35:16 +0200 | [diff] [blame] | 199 | if (key == b->key) { |
| 200 | if (state == WL_KEYBOARD_KEY_STATE_RELEASED) { |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 201 | weston_keyboard_end_grab(grab->keyboard); |
Ander Conselvan de Oliveira | cbdebc2 | 2013-02-21 18:35:16 +0200 | [diff] [blame] | 202 | if (keyboard->input_method_resource) |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 203 | keyboard->grab = &keyboard->input_method_grab; |
Ander Conselvan de Oliveira | cbdebc2 | 2013-02-21 18:35:16 +0200 | [diff] [blame] | 204 | free(b); |
Giulio Camuffo | 943b46e | 2014-12-05 18:02:58 +0200 | [diff] [blame^] | 205 | } else { |
| 206 | /* Don't send the key press event for the binding key */ |
| 207 | return; |
Ander Conselvan de Oliveira | cbdebc2 | 2013-02-21 18:35:16 +0200 | [diff] [blame] | 208 | } |
Giulio Camuffo | a20ca81 | 2014-11-22 11:16:56 +0200 | [diff] [blame] | 209 | } |
| 210 | if (!wl_list_empty(&keyboard->focus_resource_list)) { |
Ander Conselvan de Oliveira | cbdebc2 | 2013-02-21 18:35:16 +0200 | [diff] [blame] | 211 | serial = wl_display_next_serial(display); |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 212 | wl_resource_for_each(resource, &keyboard->focus_resource_list) { |
| 213 | wl_keyboard_send_key(resource, |
| 214 | serial, |
| 215 | time, |
| 216 | key, |
| 217 | state); |
| 218 | } |
Ander Conselvan de Oliveira | cbdebc2 | 2013-02-21 18:35:16 +0200 | [diff] [blame] | 219 | } |
| 220 | } |
| 221 | |
| 222 | static void |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 223 | binding_modifiers(struct weston_keyboard_grab *grab, uint32_t serial, |
Ander Conselvan de Oliveira | cbdebc2 | 2013-02-21 18:35:16 +0200 | [diff] [blame] | 224 | uint32_t mods_depressed, uint32_t mods_latched, |
| 225 | uint32_t mods_locked, uint32_t group) |
| 226 | { |
| 227 | struct wl_resource *resource; |
| 228 | |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 229 | wl_resource_for_each(resource, &grab->keyboard->focus_resource_list) { |
| 230 | wl_keyboard_send_modifiers(resource, serial, mods_depressed, |
| 231 | mods_latched, mods_locked, group); |
| 232 | } |
Ander Conselvan de Oliveira | cbdebc2 | 2013-02-21 18:35:16 +0200 | [diff] [blame] | 233 | } |
| 234 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 235 | static void |
| 236 | binding_cancel(struct weston_keyboard_grab *grab) |
| 237 | { |
| 238 | struct binding_keyboard_grab *binding_grab = |
| 239 | container_of(grab, struct binding_keyboard_grab, grab); |
| 240 | |
| 241 | weston_keyboard_end_grab(grab->keyboard); |
| 242 | free(binding_grab); |
| 243 | } |
| 244 | |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 245 | static const struct weston_keyboard_grab_interface binding_grab = { |
Ander Conselvan de Oliveira | cbdebc2 | 2013-02-21 18:35:16 +0200 | [diff] [blame] | 246 | binding_key, |
| 247 | binding_modifiers, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 248 | binding_cancel, |
Ander Conselvan de Oliveira | cbdebc2 | 2013-02-21 18:35:16 +0200 | [diff] [blame] | 249 | }; |
| 250 | |
| 251 | static void |
Giulio Camuffo | a20ca81 | 2014-11-22 11:16:56 +0200 | [diff] [blame] | 252 | install_binding_grab(struct weston_seat *seat, uint32_t time, uint32_t key, |
| 253 | struct weston_surface *focus) |
Ander Conselvan de Oliveira | cbdebc2 | 2013-02-21 18:35:16 +0200 | [diff] [blame] | 254 | { |
| 255 | struct binding_keyboard_grab *grab; |
| 256 | |
| 257 | grab = malloc(sizeof *grab); |
| 258 | grab->key = key; |
| 259 | grab->grab.interface = &binding_grab; |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 260 | weston_keyboard_start_grab(seat->keyboard, &grab->grab); |
Giulio Camuffo | a20ca81 | 2014-11-22 11:16:56 +0200 | [diff] [blame] | 261 | |
| 262 | /* Notify the surface which had the focus before this binding |
| 263 | * triggered that we stole a keypress from under it, by forcing |
| 264 | * a wl_keyboard leave/enter pair. The enter event will contain |
| 265 | * the pressed key in the keys array, so the client will know |
| 266 | * the exact state of the keyboard. |
| 267 | * If the old focus surface is different than the new one it |
| 268 | * means it was changed in the binding handler, so it received |
| 269 | * the enter event already. */ |
| 270 | if (focus && seat->keyboard->focus == focus) { |
| 271 | weston_keyboard_set_focus(seat->keyboard, NULL); |
| 272 | weston_keyboard_set_focus(seat->keyboard, focus); |
| 273 | } |
Ander Conselvan de Oliveira | cbdebc2 | 2013-02-21 18:35:16 +0200 | [diff] [blame] | 274 | } |
| 275 | |
Pekka Paalanen | 86b5396 | 2014-11-19 13:43:32 +0200 | [diff] [blame] | 276 | WL_EXPORT void |
Ander Conselvan de Oliveira | cbdebc2 | 2013-02-21 18:35:16 +0200 | [diff] [blame] | 277 | weston_compositor_run_key_binding(struct weston_compositor *compositor, |
| 278 | struct weston_seat *seat, |
| 279 | uint32_t time, uint32_t key, |
| 280 | enum wl_keyboard_key_state state) |
| 281 | { |
Giulio Camuffo | 24b98d0 | 2014-10-03 23:36:34 +0300 | [diff] [blame] | 282 | struct weston_binding *b, *tmp; |
Giulio Camuffo | a20ca81 | 2014-11-22 11:16:56 +0200 | [diff] [blame] | 283 | struct weston_surface *focus; |
Ander Conselvan de Oliveira | cbdebc2 | 2013-02-21 18:35:16 +0200 | [diff] [blame] | 284 | |
| 285 | if (state == WL_KEYBOARD_KEY_STATE_RELEASED) |
Pekka Paalanen | 86b5396 | 2014-11-19 13:43:32 +0200 | [diff] [blame] | 286 | return; |
Ander Conselvan de Oliveira | cbdebc2 | 2013-02-21 18:35:16 +0200 | [diff] [blame] | 287 | |
Daniel Stone | 96d47c0 | 2013-11-19 11:37:12 +0100 | [diff] [blame] | 288 | /* Invalidate all active modifier bindings. */ |
| 289 | wl_list_for_each(b, &compositor->modifier_binding_list, link) |
| 290 | b->key = key; |
| 291 | |
Giulio Camuffo | 24b98d0 | 2014-10-03 23:36:34 +0300 | [diff] [blame] | 292 | wl_list_for_each_safe(b, tmp, &compositor->key_binding_list, link) { |
Ander Conselvan de Oliveira | cbdebc2 | 2013-02-21 18:35:16 +0200 | [diff] [blame] | 293 | if (b->key == key && b->modifier == seat->modifier_state) { |
| 294 | weston_key_binding_handler_t handler = b->handler; |
Giulio Camuffo | a20ca81 | 2014-11-22 11:16:56 +0200 | [diff] [blame] | 295 | focus = seat->keyboard->focus; |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 296 | handler(seat, time, key, b->data); |
Ander Conselvan de Oliveira | cbdebc2 | 2013-02-21 18:35:16 +0200 | [diff] [blame] | 297 | |
| 298 | /* If this was a key binding and it didn't |
| 299 | * install a keyboard grab, install one now to |
Giulio Camuffo | 943b46e | 2014-12-05 18:02:58 +0200 | [diff] [blame^] | 300 | * swallow the key press. */ |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 301 | if (seat->keyboard->grab == |
| 302 | &seat->keyboard->default_grab) |
Giulio Camuffo | a20ca81 | 2014-11-22 11:16:56 +0200 | [diff] [blame] | 303 | install_binding_grab(seat, time, key, focus); |
Ander Conselvan de Oliveira | cbdebc2 | 2013-02-21 18:35:16 +0200 | [diff] [blame] | 304 | } |
| 305 | } |
| 306 | } |
| 307 | |
| 308 | WL_EXPORT void |
Daniel Stone | 96d47c0 | 2013-11-19 11:37:12 +0100 | [diff] [blame] | 309 | weston_compositor_run_modifier_binding(struct weston_compositor *compositor, |
| 310 | struct weston_seat *seat, |
| 311 | enum weston_keyboard_modifier modifier, |
| 312 | enum wl_keyboard_key_state state) |
| 313 | { |
Giulio Camuffo | 24b98d0 | 2014-10-03 23:36:34 +0300 | [diff] [blame] | 314 | struct weston_binding *b, *tmp; |
Daniel Stone | 96d47c0 | 2013-11-19 11:37:12 +0100 | [diff] [blame] | 315 | |
Emilio Pozuelo Monfort | 1539ea2 | 2013-11-27 10:34:32 +0100 | [diff] [blame] | 316 | if (seat->keyboard->grab != &seat->keyboard->default_grab) |
| 317 | return; |
| 318 | |
Giulio Camuffo | 24b98d0 | 2014-10-03 23:36:34 +0300 | [diff] [blame] | 319 | wl_list_for_each_safe(b, tmp, &compositor->modifier_binding_list, link) { |
Daniel Stone | 96d47c0 | 2013-11-19 11:37:12 +0100 | [diff] [blame] | 320 | weston_modifier_binding_handler_t handler = b->handler; |
| 321 | |
| 322 | if (b->modifier != modifier) |
| 323 | continue; |
| 324 | |
| 325 | /* Prime the modifier binding. */ |
| 326 | if (state == WL_KEYBOARD_KEY_STATE_PRESSED) { |
| 327 | b->key = 0; |
| 328 | continue; |
| 329 | } |
| 330 | /* Ignore the binding if a key was pressed in between. */ |
| 331 | else if (b->key != 0) { |
| 332 | return; |
| 333 | } |
| 334 | |
| 335 | handler(seat, modifier, b->data); |
| 336 | } |
| 337 | } |
| 338 | |
| 339 | WL_EXPORT void |
Ander Conselvan de Oliveira | cbdebc2 | 2013-02-21 18:35:16 +0200 | [diff] [blame] | 340 | weston_compositor_run_button_binding(struct weston_compositor *compositor, |
| 341 | struct weston_seat *seat, |
| 342 | uint32_t time, uint32_t button, |
| 343 | enum wl_pointer_button_state state) |
| 344 | { |
Giulio Camuffo | 24b98d0 | 2014-10-03 23:36:34 +0300 | [diff] [blame] | 345 | struct weston_binding *b, *tmp; |
Ander Conselvan de Oliveira | cbdebc2 | 2013-02-21 18:35:16 +0200 | [diff] [blame] | 346 | |
| 347 | if (state == WL_POINTER_BUTTON_STATE_RELEASED) |
| 348 | return; |
| 349 | |
Daniel Stone | 96d47c0 | 2013-11-19 11:37:12 +0100 | [diff] [blame] | 350 | /* Invalidate all active modifier bindings. */ |
| 351 | wl_list_for_each(b, &compositor->modifier_binding_list, link) |
| 352 | b->key = button; |
| 353 | |
Giulio Camuffo | 24b98d0 | 2014-10-03 23:36:34 +0300 | [diff] [blame] | 354 | wl_list_for_each_safe(b, tmp, &compositor->button_binding_list, link) { |
Ander Conselvan de Oliveira | cbdebc2 | 2013-02-21 18:35:16 +0200 | [diff] [blame] | 355 | if (b->button == button && b->modifier == seat->modifier_state) { |
| 356 | weston_button_binding_handler_t handler = b->handler; |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 357 | handler(seat, time, button, b->data); |
Ander Conselvan de Oliveira | cbdebc2 | 2013-02-21 18:35:16 +0200 | [diff] [blame] | 358 | } |
| 359 | } |
| 360 | } |
| 361 | |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 362 | WL_EXPORT void |
| 363 | weston_compositor_run_touch_binding(struct weston_compositor *compositor, |
| 364 | struct weston_seat *seat, uint32_t time, |
| 365 | int touch_type) |
| 366 | { |
Giulio Camuffo | 24b98d0 | 2014-10-03 23:36:34 +0300 | [diff] [blame] | 367 | struct weston_binding *b, *tmp; |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 368 | |
Jonas Ådahl | 9484b69 | 2013-12-02 22:05:03 +0100 | [diff] [blame] | 369 | if (seat->touch->num_tp != 1 || touch_type != WL_TOUCH_DOWN) |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 370 | return; |
| 371 | |
Giulio Camuffo | 24b98d0 | 2014-10-03 23:36:34 +0300 | [diff] [blame] | 372 | wl_list_for_each_safe(b, tmp, &compositor->touch_binding_list, link) { |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 373 | if (b->modifier == seat->modifier_state) { |
| 374 | weston_touch_binding_handler_t handler = b->handler; |
| 375 | handler(seat, time, b->data); |
| 376 | } |
| 377 | } |
| 378 | } |
| 379 | |
Rune K. Svendsen | 14b2fe7 | 2013-03-07 21:50:00 +0100 | [diff] [blame] | 380 | WL_EXPORT int |
Ander Conselvan de Oliveira | cbdebc2 | 2013-02-21 18:35:16 +0200 | [diff] [blame] | 381 | weston_compositor_run_axis_binding(struct weston_compositor *compositor, |
| 382 | struct weston_seat *seat, |
| 383 | uint32_t time, uint32_t axis, |
| 384 | wl_fixed_t value) |
| 385 | { |
Giulio Camuffo | 24b98d0 | 2014-10-03 23:36:34 +0300 | [diff] [blame] | 386 | struct weston_binding *b, *tmp; |
Ander Conselvan de Oliveira | cbdebc2 | 2013-02-21 18:35:16 +0200 | [diff] [blame] | 387 | |
Daniel Stone | 96d47c0 | 2013-11-19 11:37:12 +0100 | [diff] [blame] | 388 | /* Invalidate all active modifier bindings. */ |
| 389 | wl_list_for_each(b, &compositor->modifier_binding_list, link) |
| 390 | b->key = axis; |
| 391 | |
Giulio Camuffo | 24b98d0 | 2014-10-03 23:36:34 +0300 | [diff] [blame] | 392 | wl_list_for_each_safe(b, tmp, &compositor->axis_binding_list, link) { |
Ander Conselvan de Oliveira | cbdebc2 | 2013-02-21 18:35:16 +0200 | [diff] [blame] | 393 | if (b->axis == axis && b->modifier == seat->modifier_state) { |
| 394 | weston_axis_binding_handler_t handler = b->handler; |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 395 | handler(seat, time, axis, value, b->data); |
Rune K. Svendsen | 14b2fe7 | 2013-03-07 21:50:00 +0100 | [diff] [blame] | 396 | return 1; |
Ander Conselvan de Oliveira | cbdebc2 | 2013-02-21 18:35:16 +0200 | [diff] [blame] | 397 | } |
| 398 | } |
Rune K. Svendsen | 14b2fe7 | 2013-03-07 21:50:00 +0100 | [diff] [blame] | 399 | |
| 400 | return 0; |
Ander Conselvan de Oliveira | cbdebc2 | 2013-02-21 18:35:16 +0200 | [diff] [blame] | 401 | } |
| 402 | |
| 403 | WL_EXPORT int |
| 404 | weston_compositor_run_debug_binding(struct weston_compositor *compositor, |
| 405 | struct weston_seat *seat, |
| 406 | uint32_t time, uint32_t key, |
| 407 | enum wl_keyboard_key_state state) |
| 408 | { |
| 409 | weston_key_binding_handler_t handler; |
Giulio Camuffo | 24b98d0 | 2014-10-03 23:36:34 +0300 | [diff] [blame] | 410 | struct weston_binding *binding, *tmp; |
Ander Conselvan de Oliveira | cbdebc2 | 2013-02-21 18:35:16 +0200 | [diff] [blame] | 411 | int count = 0; |
| 412 | |
Giulio Camuffo | 24b98d0 | 2014-10-03 23:36:34 +0300 | [diff] [blame] | 413 | wl_list_for_each_safe(binding, tmp, &compositor->debug_binding_list, link) { |
Ander Conselvan de Oliveira | cbdebc2 | 2013-02-21 18:35:16 +0200 | [diff] [blame] | 414 | if (key != binding->key) |
| 415 | continue; |
| 416 | |
| 417 | count++; |
| 418 | handler = binding->handler; |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 419 | handler(seat, time, key, binding->data); |
Ander Conselvan de Oliveira | cbdebc2 | 2013-02-21 18:35:16 +0200 | [diff] [blame] | 420 | } |
| 421 | |
| 422 | return count; |
| 423 | } |