Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright © 2013 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> |
| 24 | #include <stdint.h> |
| 25 | #include <string.h> |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 26 | #include <sys/mman.h> |
| 27 | #include <assert.h> |
| 28 | #include <unistd.h> |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 29 | |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 30 | #include "../shared/os-compatibility.h" |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 31 | #include "compositor.h" |
| 32 | |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 33 | static void |
| 34 | empty_region(pixman_region32_t *region) |
| 35 | { |
| 36 | pixman_region32_fini(region); |
| 37 | pixman_region32_init(region); |
| 38 | } |
| 39 | |
| 40 | static void unbind_resource(struct wl_resource *resource) |
| 41 | { |
| 42 | wl_list_remove(&resource->link); |
| 43 | free(resource); |
| 44 | } |
| 45 | |
| 46 | void |
Kristian Høgsberg | a71e8b2 | 2013-05-06 21:51:21 -0400 | [diff] [blame] | 47 | weston_seat_repick(struct weston_seat *seat) |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 48 | { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 49 | const struct weston_pointer_grab_interface *interface; |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 50 | struct weston_surface *surface, *focus; |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 51 | struct weston_pointer *pointer = seat->pointer; |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 52 | |
| 53 | if (!pointer) |
| 54 | return; |
| 55 | |
| 56 | surface = weston_compositor_pick_surface(seat->compositor, |
| 57 | pointer->x, |
| 58 | pointer->y, |
| 59 | &pointer->current_x, |
| 60 | &pointer->current_y); |
| 61 | |
Kristian Høgsberg | fe7aa90 | 2013-05-08 09:54:37 -0400 | [diff] [blame] | 62 | if (surface != pointer->current) { |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 63 | interface = pointer->grab->interface; |
Kristian Høgsberg | fe7aa90 | 2013-05-08 09:54:37 -0400 | [diff] [blame] | 64 | weston_pointer_set_current(pointer, surface); |
| 65 | interface->focus(pointer->grab, surface, |
| 66 | pointer->current_x, pointer->current_y); |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 67 | } |
| 68 | |
| 69 | focus = (struct weston_surface *) pointer->grab->focus; |
| 70 | if (focus) |
| 71 | weston_surface_from_global_fixed(focus, |
| 72 | pointer->x, |
| 73 | pointer->y, |
| 74 | &pointer->grab->x, |
| 75 | &pointer->grab->y); |
| 76 | } |
| 77 | |
| 78 | static void |
| 79 | weston_compositor_idle_inhibit(struct weston_compositor *compositor) |
| 80 | { |
| 81 | weston_compositor_wake(compositor); |
| 82 | compositor->idle_inhibit++; |
| 83 | } |
| 84 | |
| 85 | static void |
| 86 | weston_compositor_idle_release(struct weston_compositor *compositor) |
| 87 | { |
| 88 | compositor->idle_inhibit--; |
| 89 | weston_compositor_wake(compositor); |
| 90 | } |
| 91 | |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 92 | static void |
| 93 | lose_pointer_focus(struct wl_listener *listener, void *data) |
| 94 | { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 95 | struct weston_pointer *pointer = |
| 96 | container_of(listener, struct weston_pointer, focus_listener); |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 97 | |
| 98 | pointer->focus_resource = NULL; |
| 99 | } |
| 100 | |
| 101 | static void |
| 102 | lose_keyboard_focus(struct wl_listener *listener, void *data) |
| 103 | { |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 104 | struct weston_keyboard *keyboard = |
| 105 | container_of(listener, struct weston_keyboard, focus_listener); |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 106 | |
| 107 | keyboard->focus_resource = NULL; |
| 108 | } |
| 109 | |
| 110 | static void |
| 111 | lose_touch_focus(struct wl_listener *listener, void *data) |
| 112 | { |
Kristian Høgsberg | e329f36 | 2013-05-06 22:19:57 -0400 | [diff] [blame] | 113 | struct weston_touch *touch = |
| 114 | container_of(listener, struct weston_touch, focus_listener); |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 115 | |
| 116 | touch->focus_resource = NULL; |
| 117 | } |
| 118 | |
| 119 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 120 | default_grab_focus(struct weston_pointer_grab *grab, |
Kristian Høgsberg | fe7aa90 | 2013-05-08 09:54:37 -0400 | [diff] [blame] | 121 | struct weston_surface *surface, wl_fixed_t x, wl_fixed_t y) |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 122 | { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 123 | struct weston_pointer *pointer = grab->pointer; |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 124 | |
| 125 | if (pointer->button_count > 0) |
| 126 | return; |
| 127 | |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 128 | weston_pointer_set_focus(pointer, surface, x, y); |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 129 | } |
| 130 | |
| 131 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 132 | default_grab_motion(struct weston_pointer_grab *grab, |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 133 | uint32_t time, wl_fixed_t x, wl_fixed_t y) |
| 134 | { |
| 135 | struct wl_resource *resource; |
| 136 | |
| 137 | resource = grab->pointer->focus_resource; |
| 138 | if (resource) |
| 139 | wl_pointer_send_motion(resource, time, x, y); |
| 140 | } |
| 141 | |
| 142 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 143 | default_grab_button(struct weston_pointer_grab *grab, |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 144 | uint32_t time, uint32_t button, uint32_t state_w) |
| 145 | { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 146 | struct weston_pointer *pointer = grab->pointer; |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 147 | struct wl_resource *resource; |
| 148 | uint32_t serial; |
| 149 | enum wl_pointer_button_state state = state_w; |
| 150 | struct wl_display *display; |
| 151 | |
| 152 | resource = pointer->focus_resource; |
| 153 | if (resource) { |
| 154 | display = wl_client_get_display(resource->client); |
| 155 | serial = wl_display_next_serial(display); |
| 156 | wl_pointer_send_button(resource, serial, time, button, state_w); |
| 157 | } |
| 158 | |
| 159 | if (pointer->button_count == 0 && |
| 160 | state == WL_POINTER_BUTTON_STATE_RELEASED) |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 161 | weston_pointer_set_focus(pointer, pointer->current, |
| 162 | pointer->current_x, |
| 163 | pointer->current_y); |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 164 | } |
| 165 | |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 166 | static const struct weston_pointer_grab_interface |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 167 | default_pointer_grab_interface = { |
| 168 | default_grab_focus, |
| 169 | default_grab_motion, |
| 170 | default_grab_button |
| 171 | }; |
| 172 | |
Kristian Høgsberg | e329f36 | 2013-05-06 22:19:57 -0400 | [diff] [blame] | 173 | static void |
| 174 | default_grab_touch_down(struct weston_touch_grab *grab, uint32_t time, |
| 175 | int touch_id, wl_fixed_t sx, wl_fixed_t sy) |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 176 | { |
Kristian Høgsberg | e329f36 | 2013-05-06 22:19:57 -0400 | [diff] [blame] | 177 | struct weston_touch *touch = grab->touch; |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 178 | struct wl_display *display; |
| 179 | uint32_t serial; |
| 180 | |
| 181 | if (touch->focus_resource && touch->focus) { |
| 182 | display = wl_client_get_display(touch->focus_resource->client); |
| 183 | serial = wl_display_next_serial(display); |
| 184 | wl_touch_send_down(touch->focus_resource, serial, time, |
Kristian Høgsberg | e329f36 | 2013-05-06 22:19:57 -0400 | [diff] [blame] | 185 | &touch->focus->resource, |
| 186 | touch_id, sx, sy); |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 187 | } |
| 188 | } |
| 189 | |
Kristian Høgsberg | e329f36 | 2013-05-06 22:19:57 -0400 | [diff] [blame] | 190 | static void |
| 191 | default_grab_touch_up(struct weston_touch_grab *grab, |
| 192 | uint32_t time, int touch_id) |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 193 | { |
Kristian Høgsberg | e329f36 | 2013-05-06 22:19:57 -0400 | [diff] [blame] | 194 | struct weston_touch *touch = grab->touch; |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 195 | struct wl_display *display; |
| 196 | uint32_t serial; |
| 197 | |
| 198 | if (touch->focus_resource) { |
| 199 | display = wl_client_get_display(touch->focus_resource->client); |
| 200 | serial = wl_display_next_serial(display); |
| 201 | wl_touch_send_up(touch->focus_resource, serial, time, touch_id); |
| 202 | } |
| 203 | } |
| 204 | |
Kristian Høgsberg | e329f36 | 2013-05-06 22:19:57 -0400 | [diff] [blame] | 205 | static void |
| 206 | default_grab_touch_motion(struct weston_touch_grab *grab, uint32_t time, |
| 207 | int touch_id, wl_fixed_t sx, wl_fixed_t sy) |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 208 | { |
Kristian Høgsberg | e329f36 | 2013-05-06 22:19:57 -0400 | [diff] [blame] | 209 | struct weston_touch *touch = grab->touch; |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 210 | |
| 211 | if (touch->focus_resource) { |
| 212 | wl_touch_send_motion(touch->focus_resource, time, |
Kristian Høgsberg | e329f36 | 2013-05-06 22:19:57 -0400 | [diff] [blame] | 213 | touch_id, sx, sy); |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 214 | } |
| 215 | } |
| 216 | |
Kristian Høgsberg | e329f36 | 2013-05-06 22:19:57 -0400 | [diff] [blame] | 217 | static const struct weston_touch_grab_interface default_touch_grab_interface = { |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 218 | default_grab_touch_down, |
| 219 | default_grab_touch_up, |
| 220 | default_grab_touch_motion |
| 221 | }; |
| 222 | |
| 223 | static void |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 224 | default_grab_key(struct weston_keyboard_grab *grab, |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 225 | uint32_t time, uint32_t key, uint32_t state) |
| 226 | { |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 227 | struct weston_keyboard *keyboard = grab->keyboard; |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 228 | struct wl_resource *resource; |
| 229 | struct wl_display *display; |
| 230 | uint32_t serial; |
| 231 | |
| 232 | resource = keyboard->focus_resource; |
| 233 | if (resource) { |
| 234 | display = wl_client_get_display(resource->client); |
| 235 | serial = wl_display_next_serial(display); |
| 236 | wl_keyboard_send_key(resource, serial, time, key, state); |
| 237 | } |
| 238 | } |
| 239 | |
| 240 | static struct wl_resource * |
Kristian Høgsberg | fe7aa90 | 2013-05-08 09:54:37 -0400 | [diff] [blame] | 241 | find_resource_for_surface(struct wl_list *list, struct weston_surface *surface) |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 242 | { |
| 243 | struct wl_resource *r; |
| 244 | |
| 245 | if (!surface) |
| 246 | return NULL; |
| 247 | |
| 248 | wl_list_for_each(r, list, link) { |
| 249 | if (r->client == surface->resource.client) |
| 250 | return r; |
| 251 | } |
| 252 | |
| 253 | return NULL; |
| 254 | } |
| 255 | |
| 256 | static void |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 257 | default_grab_modifiers(struct weston_keyboard_grab *grab, uint32_t serial, |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 258 | uint32_t mods_depressed, uint32_t mods_latched, |
| 259 | uint32_t mods_locked, uint32_t group) |
| 260 | { |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 261 | struct weston_keyboard *keyboard = grab->keyboard; |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 262 | struct weston_pointer *pointer = keyboard->seat->pointer; |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 263 | struct wl_resource *resource, *pr; |
| 264 | |
| 265 | resource = keyboard->focus_resource; |
| 266 | if (!resource) |
| 267 | return; |
| 268 | |
| 269 | wl_keyboard_send_modifiers(resource, serial, mods_depressed, |
| 270 | mods_latched, mods_locked, group); |
| 271 | |
| 272 | if (pointer && pointer->focus && pointer->focus != keyboard->focus) { |
| 273 | pr = find_resource_for_surface(&keyboard->resource_list, |
| 274 | pointer->focus); |
| 275 | if (pr) { |
| 276 | wl_keyboard_send_modifiers(pr, |
| 277 | serial, |
| 278 | keyboard->modifiers.mods_depressed, |
| 279 | keyboard->modifiers.mods_latched, |
| 280 | keyboard->modifiers.mods_locked, |
| 281 | keyboard->modifiers.group); |
| 282 | } |
| 283 | } |
| 284 | } |
| 285 | |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 286 | static const struct weston_keyboard_grab_interface |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 287 | default_keyboard_grab_interface = { |
| 288 | default_grab_key, |
| 289 | default_grab_modifiers, |
| 290 | }; |
| 291 | |
Kristian Høgsberg | 195b869 | 2013-05-08 15:02:05 -0400 | [diff] [blame^] | 292 | static void |
| 293 | pointer_unmap_sprite(struct weston_pointer *pointer) |
| 294 | { |
| 295 | if (weston_surface_is_mapped(pointer->sprite)) |
| 296 | weston_surface_unmap(pointer->sprite); |
| 297 | |
| 298 | wl_list_remove(&pointer->sprite_destroy_listener.link); |
| 299 | pointer->sprite->configure = NULL; |
| 300 | pointer->sprite->configure_private = NULL; |
| 301 | pointer->sprite = NULL; |
| 302 | } |
| 303 | |
| 304 | static void |
| 305 | pointer_handle_sprite_destroy(struct wl_listener *listener, void *data) |
| 306 | { |
| 307 | struct weston_pointer *pointer = |
| 308 | container_of(listener, struct weston_pointer, |
| 309 | sprite_destroy_listener); |
| 310 | |
| 311 | pointer->sprite = NULL; |
| 312 | } |
| 313 | |
Kristian Høgsberg | a4036bb | 2013-05-07 23:52:07 -0400 | [diff] [blame] | 314 | WL_EXPORT struct weston_pointer * |
| 315 | weston_pointer_create(void) |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 316 | { |
Kristian Høgsberg | a4036bb | 2013-05-07 23:52:07 -0400 | [diff] [blame] | 317 | struct weston_pointer *pointer; |
| 318 | |
| 319 | pointer = malloc(sizeof *pointer); |
| 320 | if (pointer == NULL) |
| 321 | return NULL; |
| 322 | |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 323 | memset(pointer, 0, sizeof *pointer); |
| 324 | wl_list_init(&pointer->resource_list); |
| 325 | pointer->focus_listener.notify = lose_pointer_focus; |
| 326 | pointer->default_grab.interface = &default_pointer_grab_interface; |
| 327 | pointer->default_grab.pointer = pointer; |
| 328 | pointer->grab = &pointer->default_grab; |
| 329 | wl_signal_init(&pointer->focus_signal); |
| 330 | |
Kristian Høgsberg | 195b869 | 2013-05-08 15:02:05 -0400 | [diff] [blame^] | 331 | pointer->sprite_destroy_listener.notify = pointer_handle_sprite_destroy; |
| 332 | |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 333 | /* FIXME: Pick better co-ords. */ |
| 334 | pointer->x = wl_fixed_from_int(100); |
| 335 | pointer->y = wl_fixed_from_int(100); |
Kristian Høgsberg | a4036bb | 2013-05-07 23:52:07 -0400 | [diff] [blame] | 336 | |
| 337 | return pointer; |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 338 | } |
| 339 | |
| 340 | WL_EXPORT void |
Kristian Høgsberg | a4036bb | 2013-05-07 23:52:07 -0400 | [diff] [blame] | 341 | weston_pointer_destroy(struct weston_pointer *pointer) |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 342 | { |
Kristian Høgsberg | 195b869 | 2013-05-08 15:02:05 -0400 | [diff] [blame^] | 343 | if (pointer->sprite) |
| 344 | pointer_unmap_sprite(pointer); |
| 345 | |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 346 | /* XXX: What about pointer->resource_list? */ |
| 347 | if (pointer->focus_resource) |
| 348 | wl_list_remove(&pointer->focus_listener.link); |
Kristian Høgsberg | a4036bb | 2013-05-07 23:52:07 -0400 | [diff] [blame] | 349 | free(pointer); |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 350 | } |
| 351 | |
Kristian Høgsberg | a4036bb | 2013-05-07 23:52:07 -0400 | [diff] [blame] | 352 | WL_EXPORT struct weston_keyboard * |
| 353 | weston_keyboard_create(void) |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 354 | { |
Kristian Høgsberg | a4036bb | 2013-05-07 23:52:07 -0400 | [diff] [blame] | 355 | struct weston_keyboard *keyboard; |
| 356 | |
| 357 | keyboard = malloc(sizeof *keyboard); |
| 358 | if (keyboard == NULL) |
| 359 | return NULL; |
| 360 | |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 361 | memset(keyboard, 0, sizeof *keyboard); |
| 362 | wl_list_init(&keyboard->resource_list); |
| 363 | wl_array_init(&keyboard->keys); |
| 364 | keyboard->focus_listener.notify = lose_keyboard_focus; |
| 365 | keyboard->default_grab.interface = &default_keyboard_grab_interface; |
| 366 | keyboard->default_grab.keyboard = keyboard; |
| 367 | keyboard->grab = &keyboard->default_grab; |
| 368 | wl_signal_init(&keyboard->focus_signal); |
Kristian Høgsberg | a4036bb | 2013-05-07 23:52:07 -0400 | [diff] [blame] | 369 | |
| 370 | return keyboard; |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 371 | } |
| 372 | |
| 373 | WL_EXPORT void |
Kristian Høgsberg | a4036bb | 2013-05-07 23:52:07 -0400 | [diff] [blame] | 374 | weston_keyboard_destroy(struct weston_keyboard *keyboard) |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 375 | { |
| 376 | /* XXX: What about keyboard->resource_list? */ |
| 377 | if (keyboard->focus_resource) |
| 378 | wl_list_remove(&keyboard->focus_listener.link); |
| 379 | wl_array_release(&keyboard->keys); |
Kristian Høgsberg | a4036bb | 2013-05-07 23:52:07 -0400 | [diff] [blame] | 380 | free(keyboard); |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 381 | } |
| 382 | |
Kristian Høgsberg | a4036bb | 2013-05-07 23:52:07 -0400 | [diff] [blame] | 383 | WL_EXPORT struct weston_touch * |
| 384 | weston_touch_create(void) |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 385 | { |
Kristian Høgsberg | a4036bb | 2013-05-07 23:52:07 -0400 | [diff] [blame] | 386 | struct weston_touch *touch; |
| 387 | |
| 388 | touch = malloc(sizeof *touch); |
| 389 | if (touch == NULL) |
| 390 | return NULL; |
| 391 | |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 392 | memset(touch, 0, sizeof *touch); |
| 393 | wl_list_init(&touch->resource_list); |
| 394 | touch->focus_listener.notify = lose_touch_focus; |
| 395 | touch->default_grab.interface = &default_touch_grab_interface; |
| 396 | touch->default_grab.touch = touch; |
| 397 | touch->grab = &touch->default_grab; |
| 398 | wl_signal_init(&touch->focus_signal); |
Kristian Høgsberg | a4036bb | 2013-05-07 23:52:07 -0400 | [diff] [blame] | 399 | |
| 400 | return touch; |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 401 | } |
| 402 | |
| 403 | WL_EXPORT void |
Kristian Høgsberg | a4036bb | 2013-05-07 23:52:07 -0400 | [diff] [blame] | 404 | weston_touch_destroy(struct weston_touch *touch) |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 405 | { |
| 406 | /* XXX: What about touch->resource_list? */ |
| 407 | if (touch->focus_resource) |
| 408 | wl_list_remove(&touch->focus_listener.link); |
Kristian Høgsberg | a4036bb | 2013-05-07 23:52:07 -0400 | [diff] [blame] | 409 | free(touch); |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 410 | } |
| 411 | |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 412 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 413 | seat_send_updated_caps(struct weston_seat *seat) |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 414 | { |
| 415 | struct wl_resource *r; |
| 416 | enum wl_seat_capability caps = 0; |
| 417 | |
| 418 | if (seat->pointer) |
| 419 | caps |= WL_SEAT_CAPABILITY_POINTER; |
| 420 | if (seat->keyboard) |
| 421 | caps |= WL_SEAT_CAPABILITY_KEYBOARD; |
| 422 | if (seat->touch) |
| 423 | caps |= WL_SEAT_CAPABILITY_TOUCH; |
| 424 | |
| 425 | wl_list_for_each(r, &seat->base_resource_list, link) |
| 426 | wl_seat_send_capabilities(r, caps); |
| 427 | } |
| 428 | |
| 429 | WL_EXPORT void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 430 | weston_pointer_set_focus(struct weston_pointer *pointer, |
Kristian Høgsberg | fe7aa90 | 2013-05-08 09:54:37 -0400 | [diff] [blame] | 431 | struct weston_surface *surface, |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 432 | wl_fixed_t sx, wl_fixed_t sy) |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 433 | { |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 434 | struct weston_keyboard *kbd = pointer->seat->keyboard; |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 435 | struct wl_resource *resource, *kr; |
| 436 | struct wl_display *display; |
| 437 | uint32_t serial; |
| 438 | |
| 439 | resource = pointer->focus_resource; |
| 440 | if (resource && pointer->focus != surface) { |
| 441 | display = wl_client_get_display(resource->client); |
| 442 | serial = wl_display_next_serial(display); |
| 443 | wl_pointer_send_leave(resource, serial, |
| 444 | &pointer->focus->resource); |
| 445 | wl_list_remove(&pointer->focus_listener.link); |
| 446 | } |
| 447 | |
| 448 | resource = find_resource_for_surface(&pointer->resource_list, |
| 449 | surface); |
| 450 | if (resource && |
| 451 | (pointer->focus != surface || |
| 452 | pointer->focus_resource != resource)) { |
| 453 | display = wl_client_get_display(resource->client); |
| 454 | serial = wl_display_next_serial(display); |
| 455 | if (kbd) { |
| 456 | kr = find_resource_for_surface(&kbd->resource_list, |
| 457 | surface); |
| 458 | if (kr) { |
| 459 | wl_keyboard_send_modifiers(kr, |
| 460 | serial, |
| 461 | kbd->modifiers.mods_depressed, |
| 462 | kbd->modifiers.mods_latched, |
| 463 | kbd->modifiers.mods_locked, |
| 464 | kbd->modifiers.group); |
| 465 | } |
| 466 | } |
| 467 | wl_pointer_send_enter(resource, serial, &surface->resource, |
| 468 | sx, sy); |
| 469 | wl_signal_add(&resource->destroy_signal, |
| 470 | &pointer->focus_listener); |
| 471 | pointer->focus_serial = serial; |
| 472 | } |
| 473 | |
| 474 | pointer->focus_resource = resource; |
| 475 | pointer->focus = surface; |
| 476 | pointer->default_grab.focus = surface; |
| 477 | wl_signal_emit(&pointer->focus_signal, pointer); |
| 478 | } |
| 479 | |
| 480 | WL_EXPORT void |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 481 | weston_keyboard_set_focus(struct weston_keyboard *keyboard, |
Kristian Høgsberg | fe7aa90 | 2013-05-08 09:54:37 -0400 | [diff] [blame] | 482 | struct weston_surface *surface) |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 483 | { |
| 484 | struct wl_resource *resource; |
| 485 | struct wl_display *display; |
| 486 | uint32_t serial; |
| 487 | |
| 488 | if (keyboard->focus_resource && keyboard->focus != surface) { |
| 489 | resource = keyboard->focus_resource; |
| 490 | display = wl_client_get_display(resource->client); |
| 491 | serial = wl_display_next_serial(display); |
| 492 | wl_keyboard_send_leave(resource, serial, |
| 493 | &keyboard->focus->resource); |
| 494 | wl_list_remove(&keyboard->focus_listener.link); |
| 495 | } |
| 496 | |
| 497 | resource = find_resource_for_surface(&keyboard->resource_list, |
| 498 | surface); |
| 499 | if (resource && |
| 500 | (keyboard->focus != surface || |
| 501 | keyboard->focus_resource != resource)) { |
| 502 | display = wl_client_get_display(resource->client); |
| 503 | serial = wl_display_next_serial(display); |
| 504 | wl_keyboard_send_modifiers(resource, serial, |
| 505 | keyboard->modifiers.mods_depressed, |
| 506 | keyboard->modifiers.mods_latched, |
| 507 | keyboard->modifiers.mods_locked, |
| 508 | keyboard->modifiers.group); |
| 509 | wl_keyboard_send_enter(resource, serial, &surface->resource, |
| 510 | &keyboard->keys); |
| 511 | wl_signal_add(&resource->destroy_signal, |
| 512 | &keyboard->focus_listener); |
| 513 | keyboard->focus_serial = serial; |
| 514 | } |
| 515 | |
| 516 | keyboard->focus_resource = resource; |
| 517 | keyboard->focus = surface; |
| 518 | wl_signal_emit(&keyboard->focus_signal, keyboard); |
| 519 | } |
| 520 | |
| 521 | WL_EXPORT void |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 522 | weston_keyboard_start_grab(struct weston_keyboard *keyboard, |
| 523 | struct weston_keyboard_grab *grab) |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 524 | { |
| 525 | keyboard->grab = grab; |
| 526 | grab->keyboard = keyboard; |
| 527 | |
| 528 | /* XXX focus? */ |
| 529 | } |
| 530 | |
| 531 | WL_EXPORT void |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 532 | weston_keyboard_end_grab(struct weston_keyboard *keyboard) |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 533 | { |
| 534 | keyboard->grab = &keyboard->default_grab; |
| 535 | } |
| 536 | |
| 537 | WL_EXPORT void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 538 | weston_pointer_start_grab(struct weston_pointer *pointer, |
| 539 | struct weston_pointer_grab *grab) |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 540 | { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 541 | const struct weston_pointer_grab_interface *interface; |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 542 | |
| 543 | pointer->grab = grab; |
| 544 | interface = pointer->grab->interface; |
| 545 | grab->pointer = pointer; |
| 546 | |
| 547 | if (pointer->current) |
| 548 | interface->focus(pointer->grab, pointer->current, |
| 549 | pointer->current_x, pointer->current_y); |
| 550 | } |
| 551 | |
| 552 | WL_EXPORT void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 553 | weston_pointer_end_grab(struct weston_pointer *pointer) |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 554 | { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 555 | const struct weston_pointer_grab_interface *interface; |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 556 | |
| 557 | pointer->grab = &pointer->default_grab; |
| 558 | interface = pointer->grab->interface; |
| 559 | interface->focus(pointer->grab, pointer->current, |
| 560 | pointer->current_x, pointer->current_y); |
| 561 | } |
| 562 | |
| 563 | static void |
| 564 | current_surface_destroy(struct wl_listener *listener, void *data) |
| 565 | { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 566 | struct weston_pointer *pointer = |
| 567 | container_of(listener, struct weston_pointer, current_listener); |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 568 | |
| 569 | pointer->current = NULL; |
| 570 | } |
| 571 | |
| 572 | WL_EXPORT void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 573 | weston_pointer_set_current(struct weston_pointer *pointer, |
Kristian Høgsberg | fe7aa90 | 2013-05-08 09:54:37 -0400 | [diff] [blame] | 574 | struct weston_surface *surface) |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 575 | { |
| 576 | if (pointer->current) |
| 577 | wl_list_remove(&pointer->current_listener.link); |
| 578 | |
| 579 | pointer->current = surface; |
| 580 | |
| 581 | if (!surface) |
| 582 | return; |
| 583 | |
| 584 | wl_signal_add(&surface->resource.destroy_signal, |
| 585 | &pointer->current_listener); |
| 586 | pointer->current_listener.notify = current_surface_destroy; |
| 587 | } |
| 588 | |
| 589 | WL_EXPORT void |
Kristian Høgsberg | e329f36 | 2013-05-06 22:19:57 -0400 | [diff] [blame] | 590 | weston_touch_start_grab(struct weston_touch *touch, struct weston_touch_grab *grab) |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 591 | { |
| 592 | touch->grab = grab; |
| 593 | grab->touch = touch; |
| 594 | } |
| 595 | |
| 596 | WL_EXPORT void |
Kristian Høgsberg | e329f36 | 2013-05-06 22:19:57 -0400 | [diff] [blame] | 597 | weston_touch_end_grab(struct weston_touch *touch) |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 598 | { |
| 599 | touch->grab = &touch->default_grab; |
| 600 | } |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 601 | |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 602 | static void |
| 603 | clip_pointer_motion(struct weston_seat *seat, wl_fixed_t *fx, wl_fixed_t *fy) |
| 604 | { |
| 605 | struct weston_compositor *ec = seat->compositor; |
| 606 | struct weston_output *output, *prev = NULL; |
| 607 | int x, y, old_x, old_y, valid = 0; |
| 608 | |
| 609 | x = wl_fixed_to_int(*fx); |
| 610 | y = wl_fixed_to_int(*fy); |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 611 | old_x = wl_fixed_to_int(seat->pointer->x); |
| 612 | old_y = wl_fixed_to_int(seat->pointer->y); |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 613 | |
| 614 | wl_list_for_each(output, &ec->output_list, link) { |
| 615 | if (pixman_region32_contains_point(&output->region, |
| 616 | x, y, NULL)) |
| 617 | valid = 1; |
| 618 | if (pixman_region32_contains_point(&output->region, |
| 619 | old_x, old_y, NULL)) |
| 620 | prev = output; |
| 621 | } |
| 622 | |
| 623 | if (!valid) { |
| 624 | if (x < prev->x) |
| 625 | *fx = wl_fixed_from_int(prev->x); |
| 626 | else if (x >= prev->x + prev->width) |
| 627 | *fx = wl_fixed_from_int(prev->x + |
| 628 | prev->width - 1); |
| 629 | if (y < prev->y) |
| 630 | *fy = wl_fixed_from_int(prev->y); |
| 631 | else if (y >= prev->y + prev->current->height) |
| 632 | *fy = wl_fixed_from_int(prev->y + |
| 633 | prev->height - 1); |
| 634 | } |
| 635 | } |
| 636 | |
| 637 | /* Takes absolute values */ |
| 638 | static void |
| 639 | move_pointer(struct weston_seat *seat, wl_fixed_t x, wl_fixed_t y) |
| 640 | { |
| 641 | struct weston_compositor *ec = seat->compositor; |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 642 | struct weston_pointer *pointer = seat->pointer; |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 643 | struct weston_output *output; |
| 644 | int32_t ix, iy; |
| 645 | |
| 646 | clip_pointer_motion(seat, &x, &y); |
| 647 | |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 648 | pointer->x = x; |
| 649 | pointer->y = y; |
| 650 | |
| 651 | ix = wl_fixed_to_int(x); |
| 652 | iy = wl_fixed_to_int(y); |
| 653 | |
| 654 | wl_list_for_each(output, &ec->output_list, link) |
| 655 | if (output->zoom.active && |
| 656 | pixman_region32_contains_point(&output->region, |
| 657 | ix, iy, NULL)) |
| 658 | weston_output_update_zoom(output, ZOOM_FOCUS_POINTER); |
| 659 | |
Kristian Høgsberg | a71e8b2 | 2013-05-06 21:51:21 -0400 | [diff] [blame] | 660 | weston_seat_repick(seat); |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 661 | |
Kristian Høgsberg | 195b869 | 2013-05-08 15:02:05 -0400 | [diff] [blame^] | 662 | if (pointer->sprite) { |
| 663 | weston_surface_set_position(pointer->sprite, |
| 664 | ix - pointer->hotspot_x, |
| 665 | iy - pointer->hotspot_y); |
| 666 | weston_surface_schedule_repaint(pointer->sprite); |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 667 | } |
| 668 | } |
| 669 | |
| 670 | WL_EXPORT void |
| 671 | notify_motion(struct weston_seat *seat, |
| 672 | uint32_t time, wl_fixed_t dx, wl_fixed_t dy) |
| 673 | { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 674 | const struct weston_pointer_grab_interface *interface; |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 675 | struct weston_compositor *ec = seat->compositor; |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 676 | struct weston_pointer *pointer = seat->pointer; |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 677 | |
| 678 | weston_compositor_wake(ec); |
| 679 | |
| 680 | move_pointer(seat, pointer->x + dx, pointer->y + dy); |
| 681 | |
| 682 | interface = pointer->grab->interface; |
| 683 | interface->motion(pointer->grab, time, |
| 684 | pointer->grab->x, pointer->grab->y); |
| 685 | } |
| 686 | |
| 687 | WL_EXPORT void |
| 688 | notify_motion_absolute(struct weston_seat *seat, |
| 689 | uint32_t time, wl_fixed_t x, wl_fixed_t y) |
| 690 | { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 691 | const struct weston_pointer_grab_interface *interface; |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 692 | struct weston_compositor *ec = seat->compositor; |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 693 | struct weston_pointer *pointer = seat->pointer; |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 694 | |
| 695 | weston_compositor_wake(ec); |
| 696 | |
| 697 | move_pointer(seat, x, y); |
| 698 | |
| 699 | interface = pointer->grab->interface; |
| 700 | interface->motion(pointer->grab, time, |
| 701 | pointer->grab->x, pointer->grab->y); |
| 702 | } |
| 703 | |
| 704 | WL_EXPORT void |
| 705 | weston_surface_activate(struct weston_surface *surface, |
| 706 | struct weston_seat *seat) |
| 707 | { |
| 708 | struct weston_compositor *compositor = seat->compositor; |
| 709 | |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 710 | if (seat->keyboard) { |
Kristian Høgsberg | fe7aa90 | 2013-05-08 09:54:37 -0400 | [diff] [blame] | 711 | weston_keyboard_set_focus(seat->keyboard, surface); |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 712 | wl_data_device_set_keyboard_focus(seat); |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 713 | } |
| 714 | |
| 715 | wl_signal_emit(&compositor->activate_signal, surface); |
| 716 | } |
| 717 | |
| 718 | WL_EXPORT void |
| 719 | notify_button(struct weston_seat *seat, uint32_t time, int32_t button, |
| 720 | enum wl_pointer_button_state state) |
| 721 | { |
| 722 | struct weston_compositor *compositor = seat->compositor; |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 723 | struct weston_pointer *pointer = seat->pointer; |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 724 | struct weston_surface *focus = |
| 725 | (struct weston_surface *) pointer->focus; |
| 726 | uint32_t serial = wl_display_next_serial(compositor->wl_display); |
| 727 | |
| 728 | if (state == WL_POINTER_BUTTON_STATE_PRESSED) { |
| 729 | if (compositor->ping_handler && focus) |
| 730 | compositor->ping_handler(focus, serial); |
| 731 | weston_compositor_idle_inhibit(compositor); |
| 732 | if (pointer->button_count == 0) { |
| 733 | pointer->grab_button = button; |
| 734 | pointer->grab_time = time; |
| 735 | pointer->grab_x = pointer->x; |
| 736 | pointer->grab_y = pointer->y; |
| 737 | } |
| 738 | pointer->button_count++; |
| 739 | } else { |
| 740 | weston_compositor_idle_release(compositor); |
| 741 | pointer->button_count--; |
| 742 | } |
| 743 | |
| 744 | weston_compositor_run_button_binding(compositor, seat, time, button, |
| 745 | state); |
| 746 | |
| 747 | pointer->grab->interface->button(pointer->grab, time, button, state); |
| 748 | |
| 749 | if (pointer->button_count == 1) |
| 750 | pointer->grab_serial = |
| 751 | wl_display_get_serial(compositor->wl_display); |
| 752 | } |
| 753 | |
| 754 | WL_EXPORT void |
| 755 | notify_axis(struct weston_seat *seat, uint32_t time, uint32_t axis, |
| 756 | wl_fixed_t value) |
| 757 | { |
| 758 | struct weston_compositor *compositor = seat->compositor; |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 759 | struct weston_pointer *pointer = seat->pointer; |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 760 | struct weston_surface *focus = |
| 761 | (struct weston_surface *) pointer->focus; |
| 762 | uint32_t serial = wl_display_next_serial(compositor->wl_display); |
| 763 | |
| 764 | if (compositor->ping_handler && focus) |
| 765 | compositor->ping_handler(focus, serial); |
| 766 | |
| 767 | weston_compositor_wake(compositor); |
| 768 | |
| 769 | if (!value) |
| 770 | return; |
| 771 | |
| 772 | if (weston_compositor_run_axis_binding(compositor, seat, |
| 773 | time, axis, value)) |
| 774 | return; |
| 775 | |
| 776 | if (pointer->focus_resource) |
| 777 | wl_pointer_send_axis(pointer->focus_resource, time, axis, |
| 778 | value); |
| 779 | } |
| 780 | |
| 781 | WL_EXPORT void |
| 782 | notify_modifiers(struct weston_seat *seat, uint32_t serial) |
| 783 | { |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 784 | struct weston_keyboard *keyboard = seat->keyboard; |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 785 | struct weston_keyboard_grab *grab = keyboard->grab; |
| 786 | uint32_t mods_depressed, mods_latched, mods_locked, group; |
| 787 | uint32_t mods_lookup; |
| 788 | enum weston_led leds = 0; |
| 789 | int changed = 0; |
| 790 | |
| 791 | /* Serialize and update our internal state, checking to see if it's |
| 792 | * different to the previous state. */ |
| 793 | mods_depressed = xkb_state_serialize_mods(seat->xkb_state.state, |
| 794 | XKB_STATE_DEPRESSED); |
| 795 | mods_latched = xkb_state_serialize_mods(seat->xkb_state.state, |
| 796 | XKB_STATE_LATCHED); |
| 797 | mods_locked = xkb_state_serialize_mods(seat->xkb_state.state, |
| 798 | XKB_STATE_LOCKED); |
| 799 | group = xkb_state_serialize_group(seat->xkb_state.state, |
| 800 | XKB_STATE_EFFECTIVE); |
| 801 | |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 802 | if (mods_depressed != seat->keyboard->modifiers.mods_depressed || |
| 803 | mods_latched != seat->keyboard->modifiers.mods_latched || |
| 804 | mods_locked != seat->keyboard->modifiers.mods_locked || |
| 805 | group != seat->keyboard->modifiers.group) |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 806 | changed = 1; |
| 807 | |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 808 | seat->keyboard->modifiers.mods_depressed = mods_depressed; |
| 809 | seat->keyboard->modifiers.mods_latched = mods_latched; |
| 810 | seat->keyboard->modifiers.mods_locked = mods_locked; |
| 811 | seat->keyboard->modifiers.group = group; |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 812 | |
| 813 | /* And update the modifier_state for bindings. */ |
| 814 | mods_lookup = mods_depressed | mods_latched; |
| 815 | seat->modifier_state = 0; |
| 816 | if (mods_lookup & (1 << seat->xkb_info.ctrl_mod)) |
| 817 | seat->modifier_state |= MODIFIER_CTRL; |
| 818 | if (mods_lookup & (1 << seat->xkb_info.alt_mod)) |
| 819 | seat->modifier_state |= MODIFIER_ALT; |
| 820 | if (mods_lookup & (1 << seat->xkb_info.super_mod)) |
| 821 | seat->modifier_state |= MODIFIER_SUPER; |
| 822 | if (mods_lookup & (1 << seat->xkb_info.shift_mod)) |
| 823 | seat->modifier_state |= MODIFIER_SHIFT; |
| 824 | |
| 825 | /* Finally, notify the compositor that LEDs have changed. */ |
| 826 | if (xkb_state_led_index_is_active(seat->xkb_state.state, |
| 827 | seat->xkb_info.num_led)) |
| 828 | leds |= LED_NUM_LOCK; |
| 829 | if (xkb_state_led_index_is_active(seat->xkb_state.state, |
| 830 | seat->xkb_info.caps_led)) |
| 831 | leds |= LED_CAPS_LOCK; |
| 832 | if (xkb_state_led_index_is_active(seat->xkb_state.state, |
| 833 | seat->xkb_info.scroll_led)) |
| 834 | leds |= LED_SCROLL_LOCK; |
| 835 | if (leds != seat->xkb_state.leds && seat->led_update) |
| 836 | seat->led_update(seat, leds); |
| 837 | seat->xkb_state.leds = leds; |
| 838 | |
| 839 | if (changed) { |
| 840 | grab->interface->modifiers(grab, |
| 841 | serial, |
| 842 | keyboard->modifiers.mods_depressed, |
| 843 | keyboard->modifiers.mods_latched, |
| 844 | keyboard->modifiers.mods_locked, |
| 845 | keyboard->modifiers.group); |
| 846 | } |
| 847 | } |
| 848 | |
| 849 | static void |
| 850 | update_modifier_state(struct weston_seat *seat, uint32_t serial, uint32_t key, |
| 851 | enum wl_keyboard_key_state state) |
| 852 | { |
| 853 | enum xkb_key_direction direction; |
| 854 | |
| 855 | if (state == WL_KEYBOARD_KEY_STATE_PRESSED) |
| 856 | direction = XKB_KEY_DOWN; |
| 857 | else |
| 858 | direction = XKB_KEY_UP; |
| 859 | |
| 860 | /* Offset the keycode by 8, as the evdev XKB rules reflect X's |
| 861 | * broken keycode system, which starts at 8. */ |
| 862 | xkb_state_update_key(seat->xkb_state.state, key + 8, direction); |
| 863 | |
| 864 | notify_modifiers(seat, serial); |
| 865 | } |
| 866 | |
| 867 | WL_EXPORT void |
| 868 | notify_key(struct weston_seat *seat, uint32_t time, uint32_t key, |
| 869 | enum wl_keyboard_key_state state, |
| 870 | enum weston_key_state_update update_state) |
| 871 | { |
| 872 | struct weston_compositor *compositor = seat->compositor; |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 873 | struct weston_keyboard *keyboard = seat->keyboard; |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 874 | struct weston_surface *focus = |
| 875 | (struct weston_surface *) keyboard->focus; |
| 876 | struct weston_keyboard_grab *grab = keyboard->grab; |
| 877 | uint32_t serial = wl_display_next_serial(compositor->wl_display); |
| 878 | uint32_t *k, *end; |
| 879 | |
| 880 | if (state == WL_KEYBOARD_KEY_STATE_PRESSED) { |
| 881 | if (compositor->ping_handler && focus) |
| 882 | compositor->ping_handler(focus, serial); |
| 883 | |
| 884 | weston_compositor_idle_inhibit(compositor); |
| 885 | keyboard->grab_key = key; |
| 886 | keyboard->grab_time = time; |
| 887 | } else { |
| 888 | weston_compositor_idle_release(compositor); |
| 889 | } |
| 890 | |
| 891 | end = keyboard->keys.data + keyboard->keys.size; |
| 892 | for (k = keyboard->keys.data; k < end; k++) { |
| 893 | if (*k == key) { |
| 894 | /* Ignore server-generated repeats. */ |
| 895 | if (state == WL_KEYBOARD_KEY_STATE_PRESSED) |
| 896 | return; |
| 897 | *k = *--end; |
| 898 | } |
| 899 | } |
| 900 | keyboard->keys.size = (void *) end - keyboard->keys.data; |
| 901 | if (state == WL_KEYBOARD_KEY_STATE_PRESSED) { |
| 902 | k = wl_array_add(&keyboard->keys, sizeof *k); |
| 903 | *k = key; |
| 904 | } |
| 905 | |
| 906 | if (grab == &keyboard->default_grab || |
| 907 | grab == &keyboard->input_method_grab) { |
| 908 | weston_compositor_run_key_binding(compositor, seat, time, key, |
| 909 | state); |
| 910 | grab = keyboard->grab; |
| 911 | } |
| 912 | |
| 913 | grab->interface->key(grab, time, key, state); |
| 914 | |
| 915 | if (update_state == STATE_UPDATE_AUTOMATIC) { |
| 916 | update_modifier_state(seat, |
| 917 | wl_display_get_serial(compositor->wl_display), |
| 918 | key, |
| 919 | state); |
| 920 | } |
| 921 | } |
| 922 | |
| 923 | WL_EXPORT void |
| 924 | notify_pointer_focus(struct weston_seat *seat, struct weston_output *output, |
| 925 | wl_fixed_t x, wl_fixed_t y) |
| 926 | { |
| 927 | struct weston_compositor *compositor = seat->compositor; |
| 928 | |
| 929 | if (output) { |
| 930 | move_pointer(seat, x, y); |
| 931 | compositor->focus = 1; |
| 932 | } else { |
| 933 | compositor->focus = 0; |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 934 | /* FIXME: We should call weston_pointer_set_focus(seat, |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 935 | * NULL) here, but somehow that breaks re-entry... */ |
| 936 | } |
| 937 | } |
| 938 | |
| 939 | static void |
| 940 | destroy_device_saved_kbd_focus(struct wl_listener *listener, void *data) |
| 941 | { |
| 942 | struct weston_seat *ws; |
| 943 | |
| 944 | ws = container_of(listener, struct weston_seat, |
| 945 | saved_kbd_focus_listener); |
| 946 | |
| 947 | ws->saved_kbd_focus = NULL; |
| 948 | } |
| 949 | |
| 950 | WL_EXPORT void |
| 951 | notify_keyboard_focus_in(struct weston_seat *seat, struct wl_array *keys, |
| 952 | enum weston_key_state_update update_state) |
| 953 | { |
| 954 | struct weston_compositor *compositor = seat->compositor; |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 955 | struct weston_keyboard *keyboard = seat->keyboard; |
Kristian Høgsberg | fe7aa90 | 2013-05-08 09:54:37 -0400 | [diff] [blame] | 956 | struct weston_surface *surface; |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 957 | uint32_t *k, serial; |
| 958 | |
| 959 | serial = wl_display_next_serial(compositor->wl_display); |
| 960 | wl_array_copy(&keyboard->keys, keys); |
| 961 | wl_array_for_each(k, &keyboard->keys) { |
| 962 | weston_compositor_idle_inhibit(compositor); |
| 963 | if (update_state == STATE_UPDATE_AUTOMATIC) |
| 964 | update_modifier_state(seat, serial, *k, |
| 965 | WL_KEYBOARD_KEY_STATE_PRESSED); |
| 966 | } |
| 967 | |
| 968 | /* Run key bindings after we've updated the state. */ |
| 969 | wl_array_for_each(k, &keyboard->keys) { |
| 970 | weston_compositor_run_key_binding(compositor, seat, 0, *k, |
| 971 | WL_KEYBOARD_KEY_STATE_PRESSED); |
| 972 | } |
| 973 | |
| 974 | surface = seat->saved_kbd_focus; |
| 975 | |
| 976 | if (surface) { |
| 977 | wl_list_remove(&seat->saved_kbd_focus_listener.link); |
| 978 | weston_keyboard_set_focus(keyboard, surface); |
| 979 | seat->saved_kbd_focus = NULL; |
| 980 | } |
| 981 | } |
| 982 | |
| 983 | WL_EXPORT void |
| 984 | notify_keyboard_focus_out(struct weston_seat *seat) |
| 985 | { |
| 986 | struct weston_compositor *compositor = seat->compositor; |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 987 | struct weston_keyboard *keyboard = seat->keyboard; |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 988 | uint32_t *k, serial; |
| 989 | |
| 990 | serial = wl_display_next_serial(compositor->wl_display); |
| 991 | wl_array_for_each(k, &keyboard->keys) { |
| 992 | weston_compositor_idle_release(compositor); |
| 993 | update_modifier_state(seat, serial, *k, |
| 994 | WL_KEYBOARD_KEY_STATE_RELEASED); |
| 995 | } |
| 996 | |
| 997 | seat->modifier_state = 0; |
| 998 | |
| 999 | if (keyboard->focus) { |
| 1000 | seat->saved_kbd_focus = keyboard->focus; |
| 1001 | seat->saved_kbd_focus_listener.notify = |
| 1002 | destroy_device_saved_kbd_focus; |
| 1003 | wl_signal_add(&keyboard->focus->resource.destroy_signal, |
| 1004 | &seat->saved_kbd_focus_listener); |
| 1005 | } |
| 1006 | |
| 1007 | weston_keyboard_set_focus(keyboard, NULL); |
| 1008 | /* FIXME: We really need keyboard grab cancel here to |
| 1009 | * let the grab shut down properly. As it is we leak |
| 1010 | * the grab data. */ |
| 1011 | weston_keyboard_end_grab(keyboard); |
| 1012 | } |
| 1013 | |
| 1014 | static void |
Kristian Høgsberg | fe7aa90 | 2013-05-08 09:54:37 -0400 | [diff] [blame] | 1015 | touch_set_focus(struct weston_seat *seat, struct weston_surface *surface) |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1016 | { |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1017 | struct wl_resource *resource; |
| 1018 | |
| 1019 | if (seat->touch->focus == surface) |
| 1020 | return; |
| 1021 | |
| 1022 | if (seat->touch->focus_resource) |
| 1023 | wl_list_remove(&seat->touch->focus_listener.link); |
| 1024 | seat->touch->focus = NULL; |
| 1025 | seat->touch->focus_resource = NULL; |
| 1026 | |
| 1027 | if (surface) { |
| 1028 | resource = |
Kristian Høgsberg | 80fb82d | 2013-05-06 21:49:55 -0400 | [diff] [blame] | 1029 | find_resource_for_surface(&seat->touch->resource_list, |
| 1030 | surface); |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1031 | if (!resource) { |
| 1032 | weston_log("couldn't find resource\n"); |
| 1033 | return; |
| 1034 | } |
| 1035 | |
| 1036 | seat->touch->focus = surface; |
| 1037 | seat->touch->focus_resource = resource; |
| 1038 | wl_signal_add(&resource->destroy_signal, |
| 1039 | &seat->touch->focus_listener); |
| 1040 | } |
| 1041 | } |
| 1042 | |
| 1043 | /** |
| 1044 | * notify_touch - emulates button touches and notifies surfaces accordingly. |
| 1045 | * |
| 1046 | * It assumes always the correct cycle sequence until it gets here: touch_down |
| 1047 | * → touch_update → ... → touch_update → touch_end. The driver is responsible |
| 1048 | * for sending along such order. |
| 1049 | * |
| 1050 | */ |
| 1051 | WL_EXPORT void |
| 1052 | notify_touch(struct weston_seat *seat, uint32_t time, int touch_id, |
| 1053 | wl_fixed_t x, wl_fixed_t y, int touch_type) |
| 1054 | { |
| 1055 | struct weston_compositor *ec = seat->compositor; |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1056 | struct weston_touch *touch = seat->touch; |
Kristian Høgsberg | e329f36 | 2013-05-06 22:19:57 -0400 | [diff] [blame] | 1057 | struct weston_touch_grab *grab = touch->grab; |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1058 | struct weston_surface *es; |
| 1059 | wl_fixed_t sx, sy; |
| 1060 | |
| 1061 | /* Update grab's global coordinates. */ |
| 1062 | touch->grab_x = x; |
| 1063 | touch->grab_y = y; |
| 1064 | |
| 1065 | switch (touch_type) { |
| 1066 | case WL_TOUCH_DOWN: |
| 1067 | weston_compositor_idle_inhibit(ec); |
| 1068 | |
| 1069 | seat->num_tp++; |
| 1070 | |
| 1071 | /* the first finger down picks the surface, and all further go |
| 1072 | * to that surface for the remainder of the touch session i.e. |
| 1073 | * until all touch points are up again. */ |
| 1074 | if (seat->num_tp == 1) { |
| 1075 | es = weston_compositor_pick_surface(ec, x, y, &sx, &sy); |
Kristian Høgsberg | fe7aa90 | 2013-05-08 09:54:37 -0400 | [diff] [blame] | 1076 | touch_set_focus(seat, es); |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1077 | } else if (touch->focus) { |
| 1078 | es = (struct weston_surface *) touch->focus; |
| 1079 | weston_surface_from_global_fixed(es, x, y, &sx, &sy); |
| 1080 | } else { |
| 1081 | /* Unexpected condition: We have non-initial touch but |
| 1082 | * there is no focused surface. |
| 1083 | */ |
| 1084 | weston_log("touch event received with %d points down" |
| 1085 | "but no surface focused\n", seat->num_tp); |
| 1086 | return; |
| 1087 | } |
| 1088 | |
| 1089 | grab->interface->down(grab, time, touch_id, sx, sy); |
| 1090 | break; |
| 1091 | case WL_TOUCH_MOTION: |
| 1092 | es = (struct weston_surface *) touch->focus; |
| 1093 | if (!es) |
| 1094 | break; |
| 1095 | |
| 1096 | weston_surface_from_global_fixed(es, x, y, &sx, &sy); |
| 1097 | grab->interface->motion(grab, time, touch_id, sx, sy); |
| 1098 | break; |
| 1099 | case WL_TOUCH_UP: |
| 1100 | weston_compositor_idle_release(ec); |
| 1101 | seat->num_tp--; |
| 1102 | |
| 1103 | grab->interface->up(grab, time, touch_id); |
| 1104 | if (seat->num_tp == 0) |
| 1105 | touch_set_focus(seat, NULL); |
| 1106 | break; |
| 1107 | } |
| 1108 | } |
| 1109 | |
| 1110 | static void |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1111 | pointer_cursor_surface_configure(struct weston_surface *es, |
| 1112 | int32_t dx, int32_t dy, int32_t width, int32_t height) |
| 1113 | { |
Kristian Høgsberg | 195b869 | 2013-05-08 15:02:05 -0400 | [diff] [blame^] | 1114 | struct weston_pointer *pointer = es->configure_private; |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1115 | int x, y; |
| 1116 | |
| 1117 | if (width == 0) |
| 1118 | return; |
| 1119 | |
Kristian Høgsberg | 195b869 | 2013-05-08 15:02:05 -0400 | [diff] [blame^] | 1120 | assert(es == pointer->sprite); |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1121 | |
Kristian Høgsberg | 195b869 | 2013-05-08 15:02:05 -0400 | [diff] [blame^] | 1122 | pointer->hotspot_x -= dx; |
| 1123 | pointer->hotspot_y -= dy; |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1124 | |
Kristian Høgsberg | 195b869 | 2013-05-08 15:02:05 -0400 | [diff] [blame^] | 1125 | x = wl_fixed_to_int(pointer->x) - pointer->hotspot_x; |
| 1126 | y = wl_fixed_to_int(pointer->y) - pointer->hotspot_y; |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1127 | |
Kristian Høgsberg | 195b869 | 2013-05-08 15:02:05 -0400 | [diff] [blame^] | 1128 | weston_surface_configure(pointer->sprite, x, y, width, height); |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1129 | |
| 1130 | empty_region(&es->pending.input); |
| 1131 | |
| 1132 | if (!weston_surface_is_mapped(es)) { |
| 1133 | wl_list_insert(&es->compositor->cursor_layer.surface_list, |
| 1134 | &es->layer_link); |
| 1135 | weston_surface_update_transform(es); |
| 1136 | } |
| 1137 | } |
| 1138 | |
| 1139 | static void |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1140 | pointer_set_cursor(struct wl_client *client, struct wl_resource *resource, |
| 1141 | uint32_t serial, struct wl_resource *surface_resource, |
| 1142 | int32_t x, int32_t y) |
| 1143 | { |
Kristian Høgsberg | 195b869 | 2013-05-08 15:02:05 -0400 | [diff] [blame^] | 1144 | struct weston_pointer *pointer = resource->data; |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1145 | struct weston_surface *surface = NULL; |
| 1146 | |
| 1147 | if (surface_resource) |
| 1148 | surface = surface_resource->data; |
| 1149 | |
Kristian Høgsberg | 195b869 | 2013-05-08 15:02:05 -0400 | [diff] [blame^] | 1150 | if (pointer->focus == NULL) |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1151 | return; |
Kristian Høgsberg | 195b869 | 2013-05-08 15:02:05 -0400 | [diff] [blame^] | 1152 | if (pointer->focus->resource.client != client) |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1153 | return; |
Kristian Høgsberg | 195b869 | 2013-05-08 15:02:05 -0400 | [diff] [blame^] | 1154 | if (pointer->focus_serial - serial > UINT32_MAX / 2) |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1155 | return; |
| 1156 | |
Kristian Høgsberg | 195b869 | 2013-05-08 15:02:05 -0400 | [diff] [blame^] | 1157 | if (surface && surface != pointer->sprite) { |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1158 | if (surface->configure) { |
Kristian Høgsberg | fe7aa90 | 2013-05-08 09:54:37 -0400 | [diff] [blame] | 1159 | wl_resource_post_error(&surface->resource, |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1160 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 1161 | "surface->configure already " |
| 1162 | "set"); |
| 1163 | return; |
| 1164 | } |
| 1165 | } |
| 1166 | |
Kristian Høgsberg | 195b869 | 2013-05-08 15:02:05 -0400 | [diff] [blame^] | 1167 | if (pointer->sprite) |
| 1168 | pointer_unmap_sprite(pointer); |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1169 | |
| 1170 | if (!surface) |
| 1171 | return; |
| 1172 | |
Kristian Høgsberg | fe7aa90 | 2013-05-08 09:54:37 -0400 | [diff] [blame] | 1173 | wl_signal_add(&surface->resource.destroy_signal, |
Kristian Høgsberg | 195b869 | 2013-05-08 15:02:05 -0400 | [diff] [blame^] | 1174 | &pointer->sprite_destroy_listener); |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1175 | |
| 1176 | surface->configure = pointer_cursor_surface_configure; |
Kristian Høgsberg | 195b869 | 2013-05-08 15:02:05 -0400 | [diff] [blame^] | 1177 | surface->configure_private = pointer; |
| 1178 | pointer->sprite = surface; |
| 1179 | pointer->hotspot_x = x; |
| 1180 | pointer->hotspot_y = y; |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1181 | |
| 1182 | if (surface->buffer_ref.buffer) |
| 1183 | pointer_cursor_surface_configure(surface, 0, 0, weston_surface_buffer_width(surface), |
| 1184 | weston_surface_buffer_height(surface)); |
| 1185 | } |
| 1186 | |
| 1187 | static const struct wl_pointer_interface pointer_interface = { |
| 1188 | pointer_set_cursor |
| 1189 | }; |
| 1190 | |
| 1191 | static void |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1192 | seat_get_pointer(struct wl_client *client, struct wl_resource *resource, |
| 1193 | uint32_t id) |
| 1194 | { |
| 1195 | struct weston_seat *seat = resource->data; |
| 1196 | struct wl_resource *cr; |
| 1197 | |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1198 | if (!seat->pointer) |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1199 | return; |
| 1200 | |
| 1201 | cr = wl_client_add_object(client, &wl_pointer_interface, |
Kristian Høgsberg | 195b869 | 2013-05-08 15:02:05 -0400 | [diff] [blame^] | 1202 | &pointer_interface, id, seat->pointer); |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1203 | wl_list_insert(&seat->pointer->resource_list, &cr->link); |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1204 | cr->destroy = unbind_resource; |
| 1205 | |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1206 | if (seat->pointer->focus && |
| 1207 | seat->pointer->focus->resource.client == client) { |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1208 | struct weston_surface *surface; |
| 1209 | wl_fixed_t sx, sy; |
| 1210 | |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1211 | surface = (struct weston_surface *) seat->pointer->focus; |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1212 | weston_surface_from_global_fixed(surface, |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1213 | seat->pointer->x, |
| 1214 | seat->pointer->y, |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1215 | &sx, |
| 1216 | &sy); |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1217 | weston_pointer_set_focus(seat->pointer, |
| 1218 | seat->pointer->focus, |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1219 | sx, |
| 1220 | sy); |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1221 | } |
| 1222 | } |
| 1223 | |
| 1224 | static void |
| 1225 | seat_get_keyboard(struct wl_client *client, struct wl_resource *resource, |
| 1226 | uint32_t id) |
| 1227 | { |
| 1228 | struct weston_seat *seat = resource->data; |
| 1229 | struct wl_resource *cr; |
| 1230 | |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1231 | if (!seat->keyboard) |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1232 | return; |
| 1233 | |
| 1234 | cr = wl_client_add_object(client, &wl_keyboard_interface, NULL, id, |
| 1235 | seat); |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1236 | wl_list_insert(&seat->keyboard->resource_list, &cr->link); |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1237 | cr->destroy = unbind_resource; |
| 1238 | |
| 1239 | wl_keyboard_send_keymap(cr, WL_KEYBOARD_KEYMAP_FORMAT_XKB_V1, |
| 1240 | seat->xkb_info.keymap_fd, |
| 1241 | seat->xkb_info.keymap_size); |
| 1242 | |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1243 | if (seat->keyboard->focus && |
| 1244 | seat->keyboard->focus->resource.client == client) { |
| 1245 | weston_keyboard_set_focus(seat->keyboard, |
| 1246 | seat->keyboard->focus); |
| 1247 | wl_data_device_set_keyboard_focus(seat); |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1248 | } |
| 1249 | } |
| 1250 | |
| 1251 | static void |
| 1252 | seat_get_touch(struct wl_client *client, struct wl_resource *resource, |
| 1253 | uint32_t id) |
| 1254 | { |
| 1255 | struct weston_seat *seat = resource->data; |
| 1256 | struct wl_resource *cr; |
| 1257 | |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1258 | if (!seat->touch) |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1259 | return; |
| 1260 | |
| 1261 | cr = wl_client_add_object(client, &wl_touch_interface, NULL, id, seat); |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1262 | wl_list_insert(&seat->touch->resource_list, &cr->link); |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1263 | cr->destroy = unbind_resource; |
| 1264 | } |
| 1265 | |
| 1266 | static const struct wl_seat_interface seat_interface = { |
| 1267 | seat_get_pointer, |
| 1268 | seat_get_keyboard, |
| 1269 | seat_get_touch, |
| 1270 | }; |
| 1271 | |
| 1272 | static void |
| 1273 | bind_seat(struct wl_client *client, void *data, uint32_t version, uint32_t id) |
| 1274 | { |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1275 | struct weston_seat *seat = data; |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1276 | struct wl_resource *resource; |
| 1277 | enum wl_seat_capability caps = 0; |
| 1278 | |
| 1279 | resource = wl_client_add_object(client, &wl_seat_interface, |
| 1280 | &seat_interface, id, data); |
| 1281 | wl_list_insert(&seat->base_resource_list, &resource->link); |
| 1282 | resource->destroy = unbind_resource; |
| 1283 | |
| 1284 | if (seat->pointer) |
| 1285 | caps |= WL_SEAT_CAPABILITY_POINTER; |
| 1286 | if (seat->keyboard) |
| 1287 | caps |= WL_SEAT_CAPABILITY_KEYBOARD; |
| 1288 | if (seat->touch) |
| 1289 | caps |= WL_SEAT_CAPABILITY_TOUCH; |
| 1290 | |
| 1291 | wl_seat_send_capabilities(resource, caps); |
| 1292 | } |
| 1293 | |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1294 | int |
| 1295 | weston_compositor_xkb_init(struct weston_compositor *ec, |
| 1296 | struct xkb_rule_names *names) |
| 1297 | { |
| 1298 | if (ec->xkb_context == NULL) { |
| 1299 | ec->xkb_context = xkb_context_new(0); |
| 1300 | if (ec->xkb_context == NULL) { |
| 1301 | weston_log("failed to create XKB context\n"); |
| 1302 | return -1; |
| 1303 | } |
| 1304 | } |
| 1305 | |
| 1306 | if (names) |
| 1307 | ec->xkb_names = *names; |
| 1308 | if (!ec->xkb_names.rules) |
| 1309 | ec->xkb_names.rules = strdup("evdev"); |
| 1310 | if (!ec->xkb_names.model) |
| 1311 | ec->xkb_names.model = strdup("pc105"); |
| 1312 | if (!ec->xkb_names.layout) |
| 1313 | ec->xkb_names.layout = strdup("us"); |
| 1314 | |
| 1315 | return 0; |
| 1316 | } |
| 1317 | |
| 1318 | static void xkb_info_destroy(struct weston_xkb_info *xkb_info) |
| 1319 | { |
| 1320 | if (xkb_info->keymap) |
| 1321 | xkb_map_unref(xkb_info->keymap); |
| 1322 | |
| 1323 | if (xkb_info->keymap_area) |
| 1324 | munmap(xkb_info->keymap_area, xkb_info->keymap_size); |
| 1325 | if (xkb_info->keymap_fd >= 0) |
| 1326 | close(xkb_info->keymap_fd); |
| 1327 | } |
| 1328 | |
| 1329 | void |
| 1330 | weston_compositor_xkb_destroy(struct weston_compositor *ec) |
| 1331 | { |
| 1332 | free((char *) ec->xkb_names.rules); |
| 1333 | free((char *) ec->xkb_names.model); |
| 1334 | free((char *) ec->xkb_names.layout); |
| 1335 | free((char *) ec->xkb_names.variant); |
| 1336 | free((char *) ec->xkb_names.options); |
| 1337 | |
| 1338 | xkb_info_destroy(&ec->xkb_info); |
| 1339 | xkb_context_unref(ec->xkb_context); |
| 1340 | } |
| 1341 | |
| 1342 | static int |
| 1343 | weston_xkb_info_new_keymap(struct weston_xkb_info *xkb_info) |
| 1344 | { |
| 1345 | char *keymap_str; |
| 1346 | |
| 1347 | xkb_info->shift_mod = xkb_map_mod_get_index(xkb_info->keymap, |
| 1348 | XKB_MOD_NAME_SHIFT); |
| 1349 | xkb_info->caps_mod = xkb_map_mod_get_index(xkb_info->keymap, |
| 1350 | XKB_MOD_NAME_CAPS); |
| 1351 | xkb_info->ctrl_mod = xkb_map_mod_get_index(xkb_info->keymap, |
| 1352 | XKB_MOD_NAME_CTRL); |
| 1353 | xkb_info->alt_mod = xkb_map_mod_get_index(xkb_info->keymap, |
| 1354 | XKB_MOD_NAME_ALT); |
| 1355 | xkb_info->mod2_mod = xkb_map_mod_get_index(xkb_info->keymap, "Mod2"); |
| 1356 | xkb_info->mod3_mod = xkb_map_mod_get_index(xkb_info->keymap, "Mod3"); |
| 1357 | xkb_info->super_mod = xkb_map_mod_get_index(xkb_info->keymap, |
| 1358 | XKB_MOD_NAME_LOGO); |
| 1359 | xkb_info->mod5_mod = xkb_map_mod_get_index(xkb_info->keymap, "Mod5"); |
| 1360 | |
| 1361 | xkb_info->num_led = xkb_map_led_get_index(xkb_info->keymap, |
| 1362 | XKB_LED_NAME_NUM); |
| 1363 | xkb_info->caps_led = xkb_map_led_get_index(xkb_info->keymap, |
| 1364 | XKB_LED_NAME_CAPS); |
| 1365 | xkb_info->scroll_led = xkb_map_led_get_index(xkb_info->keymap, |
| 1366 | XKB_LED_NAME_SCROLL); |
| 1367 | |
| 1368 | keymap_str = xkb_map_get_as_string(xkb_info->keymap); |
| 1369 | if (keymap_str == NULL) { |
| 1370 | weston_log("failed to get string version of keymap\n"); |
| 1371 | return -1; |
| 1372 | } |
| 1373 | xkb_info->keymap_size = strlen(keymap_str) + 1; |
| 1374 | |
| 1375 | xkb_info->keymap_fd = os_create_anonymous_file(xkb_info->keymap_size); |
| 1376 | if (xkb_info->keymap_fd < 0) { |
| 1377 | weston_log("creating a keymap file for %lu bytes failed: %m\n", |
| 1378 | (unsigned long) xkb_info->keymap_size); |
| 1379 | goto err_keymap_str; |
| 1380 | } |
| 1381 | |
| 1382 | xkb_info->keymap_area = mmap(NULL, xkb_info->keymap_size, |
| 1383 | PROT_READ | PROT_WRITE, |
| 1384 | MAP_SHARED, xkb_info->keymap_fd, 0); |
| 1385 | if (xkb_info->keymap_area == MAP_FAILED) { |
| 1386 | weston_log("failed to mmap() %lu bytes\n", |
| 1387 | (unsigned long) xkb_info->keymap_size); |
| 1388 | goto err_dev_zero; |
| 1389 | } |
| 1390 | strcpy(xkb_info->keymap_area, keymap_str); |
| 1391 | free(keymap_str); |
| 1392 | |
| 1393 | return 0; |
| 1394 | |
| 1395 | err_dev_zero: |
| 1396 | close(xkb_info->keymap_fd); |
| 1397 | xkb_info->keymap_fd = -1; |
| 1398 | err_keymap_str: |
| 1399 | free(keymap_str); |
| 1400 | return -1; |
| 1401 | } |
| 1402 | |
| 1403 | static int |
| 1404 | weston_compositor_build_global_keymap(struct weston_compositor *ec) |
| 1405 | { |
| 1406 | if (ec->xkb_info.keymap != NULL) |
| 1407 | return 0; |
| 1408 | |
| 1409 | ec->xkb_info.keymap = xkb_map_new_from_names(ec->xkb_context, |
| 1410 | &ec->xkb_names, |
| 1411 | 0); |
| 1412 | if (ec->xkb_info.keymap == NULL) { |
| 1413 | weston_log("failed to compile global XKB keymap\n"); |
| 1414 | weston_log(" tried rules %s, model %s, layout %s, variant %s, " |
| 1415 | "options %s\n", |
| 1416 | ec->xkb_names.rules, ec->xkb_names.model, |
| 1417 | ec->xkb_names.layout, ec->xkb_names.variant, |
| 1418 | ec->xkb_names.options); |
| 1419 | return -1; |
| 1420 | } |
| 1421 | |
| 1422 | if (weston_xkb_info_new_keymap(&ec->xkb_info) < 0) |
| 1423 | return -1; |
| 1424 | |
| 1425 | return 0; |
| 1426 | } |
| 1427 | |
| 1428 | WL_EXPORT int |
| 1429 | weston_seat_init_keyboard(struct weston_seat *seat, struct xkb_keymap *keymap) |
| 1430 | { |
Kristian Høgsberg | a4036bb | 2013-05-07 23:52:07 -0400 | [diff] [blame] | 1431 | struct weston_keyboard *keyboard; |
| 1432 | |
Kristian Høgsberg | 2bf8762 | 2013-05-07 23:17:41 -0400 | [diff] [blame] | 1433 | if (seat->keyboard) |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1434 | return 0; |
| 1435 | |
| 1436 | if (keymap != NULL) { |
| 1437 | seat->xkb_info.keymap = xkb_map_ref(keymap); |
| 1438 | if (weston_xkb_info_new_keymap(&seat->xkb_info) < 0) |
| 1439 | return -1; |
| 1440 | } else { |
| 1441 | if (weston_compositor_build_global_keymap(seat->compositor) < 0) |
| 1442 | return -1; |
| 1443 | seat->xkb_info = seat->compositor->xkb_info; |
| 1444 | seat->xkb_info.keymap = xkb_map_ref(seat->xkb_info.keymap); |
| 1445 | } |
| 1446 | |
| 1447 | seat->xkb_state.state = xkb_state_new(seat->xkb_info.keymap); |
| 1448 | if (seat->xkb_state.state == NULL) { |
| 1449 | weston_log("failed to initialise XKB state\n"); |
| 1450 | return -1; |
| 1451 | } |
| 1452 | |
| 1453 | seat->xkb_state.leds = 0; |
| 1454 | |
Kristian Høgsberg | a4036bb | 2013-05-07 23:52:07 -0400 | [diff] [blame] | 1455 | keyboard = weston_keyboard_create(); |
| 1456 | if (keyboard == NULL) { |
| 1457 | weston_log("failed to allocate weston keyboard struct\n"); |
| 1458 | return -1; |
| 1459 | } |
| 1460 | |
| 1461 | seat->keyboard = keyboard; |
| 1462 | keyboard->seat = seat; |
| 1463 | |
| 1464 | seat_send_updated_caps(seat); |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1465 | |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1466 | return 0; |
| 1467 | } |
| 1468 | |
| 1469 | WL_EXPORT void |
| 1470 | weston_seat_init_pointer(struct weston_seat *seat) |
| 1471 | { |
Kristian Høgsberg | a4036bb | 2013-05-07 23:52:07 -0400 | [diff] [blame] | 1472 | struct weston_pointer *pointer; |
| 1473 | |
Kristian Høgsberg | 2bf8762 | 2013-05-07 23:17:41 -0400 | [diff] [blame] | 1474 | if (seat->pointer) |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1475 | return; |
| 1476 | |
Kristian Høgsberg | a4036bb | 2013-05-07 23:52:07 -0400 | [diff] [blame] | 1477 | pointer = weston_pointer_create(); |
| 1478 | if (pointer == NULL) |
| 1479 | return; |
| 1480 | |
| 1481 | seat->pointer = pointer; |
| 1482 | pointer->seat = seat; |
| 1483 | |
| 1484 | seat_send_updated_caps(seat); |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1485 | } |
| 1486 | |
| 1487 | WL_EXPORT void |
| 1488 | weston_seat_init_touch(struct weston_seat *seat) |
| 1489 | { |
Kristian Høgsberg | a4036bb | 2013-05-07 23:52:07 -0400 | [diff] [blame] | 1490 | struct weston_touch *touch; |
| 1491 | |
Kristian Høgsberg | 2bf8762 | 2013-05-07 23:17:41 -0400 | [diff] [blame] | 1492 | if (seat->touch) |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1493 | return; |
| 1494 | |
Kristian Høgsberg | a4036bb | 2013-05-07 23:52:07 -0400 | [diff] [blame] | 1495 | touch = weston_touch_create(); |
| 1496 | if (touch == NULL) |
| 1497 | return; |
| 1498 | |
| 1499 | seat->touch = touch; |
| 1500 | touch->seat = seat; |
| 1501 | |
| 1502 | seat_send_updated_caps(seat); |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1503 | } |
| 1504 | |
| 1505 | WL_EXPORT void |
| 1506 | weston_seat_init(struct weston_seat *seat, struct weston_compositor *ec) |
| 1507 | { |
Kristian Høgsberg | 4a2a274 | 2013-05-06 22:24:50 -0400 | [diff] [blame] | 1508 | memset(seat, 0, sizeof *seat); |
| 1509 | |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1510 | seat->selection_data_source = NULL; |
| 1511 | wl_list_init(&seat->base_resource_list); |
| 1512 | wl_signal_init(&seat->selection_signal); |
| 1513 | wl_list_init(&seat->drag_resource_list); |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1514 | wl_signal_init(&seat->destroy_signal); |
Kristian Høgsberg | 4a2a274 | 2013-05-06 22:24:50 -0400 | [diff] [blame] | 1515 | |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1516 | wl_display_add_global(ec->wl_display, &wl_seat_interface, seat, |
| 1517 | bind_seat); |
| 1518 | |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1519 | seat->compositor = ec; |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1520 | seat->modifier_state = 0; |
| 1521 | seat->num_tp = 0; |
| 1522 | |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1523 | wl_list_insert(ec->seat_list.prev, &seat->link); |
| 1524 | |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1525 | clipboard_create(seat); |
| 1526 | |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1527 | wl_signal_emit(&ec->seat_created_signal, seat); |
| 1528 | } |
| 1529 | |
| 1530 | WL_EXPORT void |
| 1531 | weston_seat_release(struct weston_seat *seat) |
| 1532 | { |
| 1533 | wl_list_remove(&seat->link); |
| 1534 | /* The global object is destroyed at wl_display_destroy() time. */ |
| 1535 | |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1536 | if (seat->xkb_state.state != NULL) |
| 1537 | xkb_state_unref(seat->xkb_state.state); |
| 1538 | xkb_info_destroy(&seat->xkb_info); |
| 1539 | |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1540 | if (seat->pointer) |
Kristian Høgsberg | a4036bb | 2013-05-07 23:52:07 -0400 | [diff] [blame] | 1541 | weston_pointer_destroy(seat->pointer); |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1542 | if (seat->keyboard) |
Kristian Høgsberg | a4036bb | 2013-05-07 23:52:07 -0400 | [diff] [blame] | 1543 | weston_keyboard_destroy(seat->keyboard); |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1544 | if (seat->touch) |
Kristian Høgsberg | a4036bb | 2013-05-07 23:52:07 -0400 | [diff] [blame] | 1545 | weston_touch_destroy(seat->touch); |
Kristian Høgsberg | 4a2a274 | 2013-05-06 22:24:50 -0400 | [diff] [blame] | 1546 | |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1547 | wl_signal_emit(&seat->destroy_signal, seat); |
| 1548 | } |