Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright © 2013 Intel Corporation |
Louis-Francis Ratté-Boulianne | 6ef59c9 | 2017-11-28 20:42:47 -0500 | [diff] [blame] | 3 | * Copyright 2017-2018 Collabora, Ltd. |
| 4 | * Copyright 2017-2018 General Electric Company |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 5 | * |
Bryce Harrington | a0bbfea | 2015-06-11 15:35:43 -0700 | [diff] [blame] | 6 | * Permission is hereby granted, free of charge, to any person obtaining |
| 7 | * a copy of this software and associated documentation files (the |
| 8 | * "Software"), to deal in the Software without restriction, including |
| 9 | * without limitation the rights to use, copy, modify, merge, publish, |
| 10 | * distribute, sublicense, and/or sell copies of the Software, and to |
| 11 | * permit persons to whom the Software is furnished to do so, subject to |
| 12 | * the following conditions: |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 13 | * |
Bryce Harrington | a0bbfea | 2015-06-11 15:35:43 -0700 | [diff] [blame] | 14 | * The above copyright notice and this permission notice (including the |
| 15 | * next paragraph) shall be included in all copies or substantial |
| 16 | * portions of the Software. |
| 17 | * |
| 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
| 19 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| 20 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
| 21 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS |
| 22 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN |
| 23 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN |
| 24 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 25 | * SOFTWARE. |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 26 | */ |
| 27 | |
Daniel Stone | 8e7a8bd | 2013-08-15 01:10:24 +0100 | [diff] [blame] | 28 | #include "config.h" |
| 29 | |
Jonas Ådahl | d3414f2 | 2016-07-22 17:56:31 +0800 | [diff] [blame] | 30 | #include <stdbool.h> |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 31 | #include <stdlib.h> |
| 32 | #include <stdint.h> |
| 33 | #include <string.h> |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 34 | #include <sys/mman.h> |
| 35 | #include <assert.h> |
| 36 | #include <unistd.h> |
Jonas Ådahl | d0be2bb | 2015-04-30 17:56:37 +0800 | [diff] [blame] | 37 | #include <values.h> |
Matt Roper | 01a9273 | 2013-06-24 16:52:44 +0100 | [diff] [blame] | 38 | #include <fcntl.h> |
Ander Conselvan de Oliveira | 54e90c7 | 2013-12-13 22:10:56 +0200 | [diff] [blame] | 39 | #include <limits.h> |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 40 | |
Jon Cruz | 35b2eaa | 2015-06-15 15:37:08 -0700 | [diff] [blame] | 41 | #include "shared/helpers.h" |
Jon Cruz | 4678bab | 2015-06-15 15:37:07 -0700 | [diff] [blame] | 42 | #include "shared/os-compatibility.h" |
Alexandros Frantzis | 84b31f8 | 2017-11-24 18:01:46 +0200 | [diff] [blame] | 43 | #include "shared/timespec-util.h" |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 44 | #include "compositor.h" |
Daniel Stone | 7dbb0e1 | 2016-11-24 15:30:41 +0000 | [diff] [blame] | 45 | #include "relative-pointer-unstable-v1-server-protocol.h" |
| 46 | #include "pointer-constraints-unstable-v1-server-protocol.h" |
Alexandros Frantzis | 538749d | 2018-02-16 18:44:16 +0200 | [diff] [blame] | 47 | #include "input-timestamps-unstable-v1-server-protocol.h" |
Jonas Ådahl | d3414f2 | 2016-07-22 17:56:31 +0800 | [diff] [blame] | 48 | |
| 49 | enum pointer_constraint_type { |
| 50 | POINTER_CONSTRAINT_TYPE_LOCK, |
| 51 | POINTER_CONSTRAINT_TYPE_CONFINE, |
| 52 | }; |
| 53 | |
Jonas Ådahl | d0be2bb | 2015-04-30 17:56:37 +0800 | [diff] [blame] | 54 | enum motion_direction { |
| 55 | MOTION_DIRECTION_POSITIVE_X = 1 << 0, |
| 56 | MOTION_DIRECTION_NEGATIVE_X = 1 << 1, |
| 57 | MOTION_DIRECTION_POSITIVE_Y = 1 << 2, |
| 58 | MOTION_DIRECTION_NEGATIVE_Y = 1 << 3, |
| 59 | }; |
| 60 | |
| 61 | struct vec2d { |
| 62 | double x, y; |
| 63 | }; |
| 64 | |
| 65 | struct line { |
| 66 | struct vec2d a; |
| 67 | struct vec2d b; |
| 68 | }; |
| 69 | |
| 70 | struct border { |
| 71 | struct line line; |
| 72 | enum motion_direction blocking_dir; |
| 73 | }; |
| 74 | |
Jonas Ådahl | d3414f2 | 2016-07-22 17:56:31 +0800 | [diff] [blame] | 75 | static void |
| 76 | maybe_warp_confined_pointer(struct weston_pointer_constraint *constraint); |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 77 | |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 78 | static void |
| 79 | empty_region(pixman_region32_t *region) |
| 80 | { |
| 81 | pixman_region32_fini(region); |
| 82 | pixman_region32_init(region); |
| 83 | } |
| 84 | |
Jonas Ådahl | d3414f2 | 2016-07-22 17:56:31 +0800 | [diff] [blame] | 85 | static void |
| 86 | region_init_infinite(pixman_region32_t *region) |
| 87 | { |
| 88 | pixman_region32_init_rect(region, INT32_MIN, INT32_MIN, |
| 89 | UINT32_MAX, UINT32_MAX); |
| 90 | } |
| 91 | |
Alexandros Frantzis | 2b44248 | 2018-02-20 14:05:50 +0200 | [diff] [blame] | 92 | static void |
| 93 | send_timestamp(struct wl_resource *resource, |
| 94 | const struct timespec *time) |
| 95 | { |
| 96 | uint32_t tv_sec_hi, tv_sec_lo, tv_nsec; |
| 97 | |
| 98 | timespec_to_proto(time, &tv_sec_hi, &tv_sec_lo, &tv_nsec); |
| 99 | zwp_input_timestamps_v1_send_timestamp(resource, tv_sec_hi, tv_sec_lo, |
| 100 | tv_nsec); |
| 101 | } |
| 102 | |
| 103 | static void |
| 104 | send_timestamps_for_input_resource(struct wl_resource *input_resource, |
| 105 | struct wl_list *list, |
| 106 | const struct timespec *time) |
| 107 | { |
| 108 | struct wl_resource *resource; |
| 109 | |
| 110 | wl_resource_for_each(resource, list) { |
| 111 | if (wl_resource_get_user_data(resource) == input_resource) |
| 112 | send_timestamp(resource, time); |
| 113 | } |
| 114 | } |
| 115 | |
| 116 | static void |
| 117 | remove_input_resource_from_timestamps(struct wl_resource *input_resource, |
| 118 | struct wl_list *list) |
| 119 | { |
| 120 | struct wl_resource *resource; |
| 121 | |
| 122 | wl_resource_for_each(resource, list) { |
| 123 | if (wl_resource_get_user_data(resource) == input_resource) |
| 124 | wl_resource_set_user_data(resource, NULL); |
| 125 | } |
| 126 | } |
| 127 | |
Louis-Francis Ratté-Boulianne | 6ef59c9 | 2017-11-28 20:42:47 -0500 | [diff] [blame] | 128 | /** Register a touchscreen input device |
| 129 | * |
| 130 | * \param touch The parent weston_touch that identifies the seat. |
| 131 | * \param syspath Unique device name. |
| 132 | * \param backend_data Backend private data if necessary. |
| 133 | * \param ops Calibration operations, or NULL for not able to run calibration. |
| 134 | * \return New touch device, or NULL on failure. |
| 135 | */ |
| 136 | WL_EXPORT struct weston_touch_device * |
| 137 | weston_touch_create_touch_device(struct weston_touch *touch, |
| 138 | const char *syspath, |
| 139 | void *backend_data, |
| 140 | const struct weston_touch_device_ops *ops) |
| 141 | { |
| 142 | struct weston_touch_device *device; |
| 143 | |
| 144 | assert(syspath); |
| 145 | if (ops) { |
| 146 | assert(ops->get_output); |
| 147 | assert(ops->get_calibration_head_name); |
| 148 | assert(ops->get_calibration); |
| 149 | assert(ops->set_calibration); |
| 150 | } |
| 151 | |
| 152 | device = zalloc(sizeof *device); |
| 153 | if (!device) |
| 154 | return NULL; |
| 155 | |
| 156 | wl_signal_init(&device->destroy_signal); |
| 157 | |
| 158 | device->syspath = strdup(syspath); |
| 159 | if (!device->syspath) { |
| 160 | free(device); |
| 161 | return NULL; |
| 162 | } |
| 163 | |
| 164 | device->backend_data = backend_data; |
| 165 | device->ops = ops; |
| 166 | |
| 167 | device->aggregate = touch; |
| 168 | wl_list_insert(touch->device_list.prev, &device->link); |
| 169 | |
| 170 | return device; |
| 171 | } |
| 172 | |
| 173 | /** Destroy the touch device. */ |
| 174 | WL_EXPORT void |
| 175 | weston_touch_device_destroy(struct weston_touch_device *device) |
| 176 | { |
| 177 | wl_list_remove(&device->link); |
| 178 | wl_signal_emit(&device->destroy_signal, device); |
| 179 | free(device->syspath); |
| 180 | free(device); |
| 181 | } |
| 182 | |
| 183 | /** Is it possible to run calibration on this touch device? */ |
| 184 | WL_EXPORT bool |
| 185 | weston_touch_device_can_calibrate(struct weston_touch_device *device) |
| 186 | { |
| 187 | return !!device->ops; |
| 188 | } |
| 189 | |
Jonas Ådahl | 2cbf293 | 2015-07-22 12:05:38 +0800 | [diff] [blame] | 190 | static struct weston_pointer_client * |
| 191 | weston_pointer_client_create(struct wl_client *client) |
| 192 | { |
| 193 | struct weston_pointer_client *pointer_client; |
| 194 | |
| 195 | pointer_client = zalloc(sizeof *pointer_client); |
| 196 | if (!pointer_client) |
| 197 | return NULL; |
| 198 | |
| 199 | pointer_client->client = client; |
| 200 | wl_list_init(&pointer_client->pointer_resources); |
Jonas Ådahl | 30d61d8 | 2014-10-22 21:21:17 +0200 | [diff] [blame] | 201 | wl_list_init(&pointer_client->relative_pointer_resources); |
Jonas Ådahl | 2cbf293 | 2015-07-22 12:05:38 +0800 | [diff] [blame] | 202 | |
| 203 | return pointer_client; |
| 204 | } |
| 205 | |
| 206 | static void |
| 207 | weston_pointer_client_destroy(struct weston_pointer_client *pointer_client) |
| 208 | { |
Alexandros Frantzis | 1c3a40e | 2018-02-08 15:37:53 +0200 | [diff] [blame] | 209 | struct wl_resource *resource; |
| 210 | |
| 211 | wl_resource_for_each(resource, &pointer_client->pointer_resources) { |
| 212 | wl_resource_set_user_data(resource, NULL); |
| 213 | } |
| 214 | |
| 215 | wl_resource_for_each(resource, |
| 216 | &pointer_client->relative_pointer_resources) { |
| 217 | wl_resource_set_user_data(resource, NULL); |
| 218 | } |
| 219 | |
| 220 | wl_list_remove(&pointer_client->pointer_resources); |
| 221 | wl_list_remove(&pointer_client->relative_pointer_resources); |
Jonas Ådahl | 2cbf293 | 2015-07-22 12:05:38 +0800 | [diff] [blame] | 222 | free(pointer_client); |
| 223 | } |
| 224 | |
| 225 | static bool |
| 226 | weston_pointer_client_is_empty(struct weston_pointer_client *pointer_client) |
| 227 | { |
Jonas Ådahl | 30d61d8 | 2014-10-22 21:21:17 +0200 | [diff] [blame] | 228 | return (wl_list_empty(&pointer_client->pointer_resources) && |
| 229 | wl_list_empty(&pointer_client->relative_pointer_resources)); |
Jonas Ådahl | 2cbf293 | 2015-07-22 12:05:38 +0800 | [diff] [blame] | 230 | } |
| 231 | |
| 232 | static struct weston_pointer_client * |
| 233 | weston_pointer_get_pointer_client(struct weston_pointer *pointer, |
| 234 | struct wl_client *client) |
| 235 | { |
| 236 | struct weston_pointer_client *pointer_client; |
| 237 | |
| 238 | wl_list_for_each(pointer_client, &pointer->pointer_clients, link) { |
| 239 | if (pointer_client->client == client) |
| 240 | return pointer_client; |
| 241 | } |
| 242 | |
| 243 | return NULL; |
| 244 | } |
| 245 | |
| 246 | static struct weston_pointer_client * |
| 247 | weston_pointer_ensure_pointer_client(struct weston_pointer *pointer, |
| 248 | struct wl_client *client) |
| 249 | { |
| 250 | struct weston_pointer_client *pointer_client; |
| 251 | |
| 252 | pointer_client = weston_pointer_get_pointer_client(pointer, client); |
| 253 | if (pointer_client) |
| 254 | return pointer_client; |
| 255 | |
| 256 | pointer_client = weston_pointer_client_create(client); |
| 257 | wl_list_insert(&pointer->pointer_clients, &pointer_client->link); |
| 258 | |
| 259 | if (pointer->focus && |
| 260 | pointer->focus->surface->resource && |
| 261 | wl_resource_get_client(pointer->focus->surface->resource) == client) { |
| 262 | pointer->focus_client = pointer_client; |
| 263 | } |
| 264 | |
| 265 | return pointer_client; |
| 266 | } |
| 267 | |
| 268 | static void |
| 269 | weston_pointer_cleanup_pointer_client(struct weston_pointer *pointer, |
| 270 | struct weston_pointer_client *pointer_client) |
| 271 | { |
| 272 | if (weston_pointer_client_is_empty(pointer_client)) { |
| 273 | if (pointer->focus_client == pointer_client) |
| 274 | pointer->focus_client = NULL; |
| 275 | wl_list_remove(&pointer_client->link); |
| 276 | weston_pointer_client_destroy(pointer_client); |
| 277 | } |
| 278 | } |
| 279 | |
| 280 | static void |
| 281 | unbind_pointer_client_resource(struct wl_resource *resource) |
| 282 | { |
| 283 | struct weston_pointer *pointer = wl_resource_get_user_data(resource); |
| 284 | struct wl_client *client = wl_resource_get_client(resource); |
| 285 | struct weston_pointer_client *pointer_client; |
| 286 | |
Jonas Ådahl | 2cbf293 | 2015-07-22 12:05:38 +0800 | [diff] [blame] | 287 | wl_list_remove(wl_resource_get_link(resource)); |
Alexandros Frantzis | 1c3a40e | 2018-02-08 15:37:53 +0200 | [diff] [blame] | 288 | |
| 289 | if (pointer) { |
| 290 | pointer_client = weston_pointer_get_pointer_client(pointer, |
| 291 | client); |
| 292 | assert(pointer_client); |
Alexandros Frantzis | db907b7 | 2018-02-20 14:06:26 +0200 | [diff] [blame] | 293 | remove_input_resource_from_timestamps(resource, |
| 294 | &pointer->timestamps_list); |
Alexandros Frantzis | 1c3a40e | 2018-02-08 15:37:53 +0200 | [diff] [blame] | 295 | weston_pointer_cleanup_pointer_client(pointer, pointer_client); |
| 296 | } |
Jonas Ådahl | 2cbf293 | 2015-07-22 12:05:38 +0800 | [diff] [blame] | 297 | } |
| 298 | |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 299 | static void unbind_resource(struct wl_resource *resource) |
| 300 | { |
Jason Ekstrand | 44a3863 | 2013-06-14 10:08:00 -0500 | [diff] [blame] | 301 | wl_list_remove(wl_resource_get_link(resource)); |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 302 | } |
| 303 | |
Jonas Ådahl | 3042ffe | 2013-10-17 23:04:08 +0200 | [diff] [blame] | 304 | WL_EXPORT void |
Jonas Ådahl | 30d61d8 | 2014-10-22 21:21:17 +0200 | [diff] [blame] | 305 | weston_pointer_motion_to_abs(struct weston_pointer *pointer, |
| 306 | struct weston_pointer_motion_event *event, |
| 307 | wl_fixed_t *x, wl_fixed_t *y) |
| 308 | { |
| 309 | if (event->mask & WESTON_POINTER_MOTION_ABS) { |
| 310 | *x = wl_fixed_from_double(event->x); |
| 311 | *y = wl_fixed_from_double(event->y); |
| 312 | } else if (event->mask & WESTON_POINTER_MOTION_REL) { |
| 313 | *x = pointer->x + wl_fixed_from_double(event->dx); |
| 314 | *y = pointer->y + wl_fixed_from_double(event->dy); |
| 315 | } else { |
| 316 | assert(!"invalid motion event"); |
| 317 | *x = *y = 0; |
| 318 | } |
| 319 | } |
| 320 | |
| 321 | static bool |
| 322 | weston_pointer_motion_to_rel(struct weston_pointer *pointer, |
| 323 | struct weston_pointer_motion_event *event, |
| 324 | double *dx, double *dy, |
| 325 | double *dx_unaccel, double *dy_unaccel) |
| 326 | { |
| 327 | if (event->mask & WESTON_POINTER_MOTION_REL && |
| 328 | event->mask & WESTON_POINTER_MOTION_REL_UNACCEL) { |
| 329 | *dx = event->dx; |
| 330 | *dy = event->dy; |
| 331 | *dx_unaccel = event->dx_unaccel; |
| 332 | *dy_unaccel = event->dy_unaccel; |
| 333 | return true; |
| 334 | } else if (event->mask & WESTON_POINTER_MOTION_REL) { |
| 335 | *dx_unaccel = *dx = event->dx; |
| 336 | *dy_unaccel = *dy = event->dy; |
| 337 | return true; |
| 338 | } else if (event->mask & WESTON_POINTER_MOTION_REL_UNACCEL) { |
| 339 | *dx_unaccel = *dx = event->dx_unaccel; |
| 340 | *dy_unaccel = *dy = event->dy_unaccel; |
| 341 | return true; |
| 342 | } else { |
| 343 | return false; |
| 344 | } |
| 345 | } |
| 346 | |
| 347 | WL_EXPORT void |
Kristian Høgsberg | a71e8b2 | 2013-05-06 21:51:21 -0400 | [diff] [blame] | 348 | weston_seat_repick(struct weston_seat *seat) |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 349 | { |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 350 | const struct weston_pointer *pointer = weston_seat_get_pointer(seat); |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 351 | |
Derek Foreman | 1b786ee | 2015-06-03 15:53:23 -0500 | [diff] [blame] | 352 | if (!pointer) |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 353 | return; |
| 354 | |
Derek Foreman | 1b786ee | 2015-06-03 15:53:23 -0500 | [diff] [blame] | 355 | pointer->grab->interface->focus(pointer->grab); |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 356 | } |
| 357 | |
| 358 | static void |
| 359 | weston_compositor_idle_inhibit(struct weston_compositor *compositor) |
| 360 | { |
| 361 | weston_compositor_wake(compositor); |
| 362 | compositor->idle_inhibit++; |
| 363 | } |
| 364 | |
| 365 | static void |
| 366 | weston_compositor_idle_release(struct weston_compositor *compositor) |
| 367 | { |
| 368 | compositor->idle_inhibit--; |
| 369 | weston_compositor_wake(compositor); |
| 370 | } |
| 371 | |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 372 | static void |
Giulio Camuffo | 576fe2a | 2013-11-20 18:00:24 +0100 | [diff] [blame] | 373 | pointer_focus_view_destroyed(struct wl_listener *listener, void *data) |
| 374 | { |
| 375 | struct weston_pointer *pointer = |
| 376 | container_of(listener, struct weston_pointer, |
| 377 | focus_view_listener); |
| 378 | |
Derek Foreman | f9318d1 | 2015-05-11 15:40:11 -0500 | [diff] [blame] | 379 | weston_pointer_clear_focus(pointer); |
Giulio Camuffo | 576fe2a | 2013-11-20 18:00:24 +0100 | [diff] [blame] | 380 | } |
| 381 | |
| 382 | static void |
| 383 | pointer_focus_resource_destroyed(struct wl_listener *listener, void *data) |
| 384 | { |
| 385 | struct weston_pointer *pointer = |
| 386 | container_of(listener, struct weston_pointer, |
| 387 | focus_resource_listener); |
| 388 | |
Derek Foreman | f9318d1 | 2015-05-11 15:40:11 -0500 | [diff] [blame] | 389 | weston_pointer_clear_focus(pointer); |
Giulio Camuffo | 576fe2a | 2013-11-20 18:00:24 +0100 | [diff] [blame] | 390 | } |
| 391 | |
| 392 | static void |
| 393 | keyboard_focus_resource_destroyed(struct wl_listener *listener, void *data) |
| 394 | { |
| 395 | struct weston_keyboard *keyboard = |
| 396 | container_of(listener, struct weston_keyboard, |
| 397 | focus_resource_listener); |
| 398 | |
| 399 | weston_keyboard_set_focus(keyboard, NULL); |
| 400 | } |
| 401 | |
| 402 | static void |
| 403 | touch_focus_view_destroyed(struct wl_listener *listener, void *data) |
| 404 | { |
| 405 | struct weston_touch *touch = |
| 406 | container_of(listener, struct weston_touch, |
| 407 | focus_view_listener); |
| 408 | |
Derek Foreman | 4c93c08 | 2015-04-30 16:45:41 -0500 | [diff] [blame] | 409 | weston_touch_set_focus(touch, NULL); |
Giulio Camuffo | 576fe2a | 2013-11-20 18:00:24 +0100 | [diff] [blame] | 410 | } |
| 411 | |
| 412 | static void |
| 413 | touch_focus_resource_destroyed(struct wl_listener *listener, void *data) |
| 414 | { |
| 415 | struct weston_touch *touch = |
| 416 | container_of(listener, struct weston_touch, |
| 417 | focus_resource_listener); |
| 418 | |
Derek Foreman | 4c93c08 | 2015-04-30 16:45:41 -0500 | [diff] [blame] | 419 | weston_touch_set_focus(touch, NULL); |
Giulio Camuffo | 576fe2a | 2013-11-20 18:00:24 +0100 | [diff] [blame] | 420 | } |
| 421 | |
| 422 | static void |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 423 | move_resources(struct wl_list *destination, struct wl_list *source) |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 424 | { |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 425 | wl_list_insert_list(destination, source); |
| 426 | wl_list_init(source); |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 427 | } |
| 428 | |
| 429 | static void |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 430 | move_resources_for_client(struct wl_list *destination, |
| 431 | struct wl_list *source, |
| 432 | struct wl_client *client) |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 433 | { |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 434 | struct wl_resource *resource, *tmp; |
| 435 | wl_resource_for_each_safe(resource, tmp, source) { |
| 436 | if (wl_resource_get_client(resource) == client) { |
| 437 | wl_list_remove(wl_resource_get_link(resource)); |
| 438 | wl_list_insert(destination, |
| 439 | wl_resource_get_link(resource)); |
| 440 | } |
| 441 | } |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 442 | } |
| 443 | |
| 444 | static void |
Kristian Høgsberg | b27901c | 2013-10-28 15:32:02 -0700 | [diff] [blame] | 445 | default_grab_pointer_focus(struct weston_pointer_grab *grab) |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 446 | { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 447 | struct weston_pointer *pointer = grab->pointer; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 448 | struct weston_view *view; |
Kristian Høgsberg | 6848c25 | 2013-05-08 22:02:59 -0400 | [diff] [blame] | 449 | wl_fixed_t sx, sy; |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 450 | |
| 451 | if (pointer->button_count > 0) |
| 452 | return; |
| 453 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 454 | view = weston_compositor_pick_view(pointer->seat->compositor, |
| 455 | pointer->x, pointer->y, |
| 456 | &sx, &sy); |
Kristian Høgsberg | 6848c25 | 2013-05-08 22:02:59 -0400 | [diff] [blame] | 457 | |
Kristian Høgsberg | db1fccb | 2014-02-05 17:14:42 -0800 | [diff] [blame] | 458 | if (pointer->focus != view || pointer->sx != sx || pointer->sy != sy) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 459 | weston_pointer_set_focus(pointer, view, sx, sy); |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 460 | } |
| 461 | |
| 462 | static void |
Quentin Glidic | cde1345 | 2016-08-12 10:41:32 +0200 | [diff] [blame] | 463 | pointer_send_relative_motion(struct weston_pointer *pointer, |
Alexandros Frantzis | 84b31f8 | 2017-11-24 18:01:46 +0200 | [diff] [blame] | 464 | const struct timespec *time, |
Quentin Glidic | cde1345 | 2016-08-12 10:41:32 +0200 | [diff] [blame] | 465 | struct weston_pointer_motion_event *event) |
Jonas Ådahl | 30d61d8 | 2014-10-22 21:21:17 +0200 | [diff] [blame] | 466 | { |
| 467 | uint64_t time_usec; |
| 468 | double dx, dy, dx_unaccel, dy_unaccel; |
| 469 | wl_fixed_t dxf, dyf, dxf_unaccel, dyf_unaccel; |
| 470 | struct wl_list *resource_list; |
| 471 | struct wl_resource *resource; |
| 472 | |
| 473 | if (!pointer->focus_client) |
| 474 | return; |
| 475 | |
| 476 | if (!weston_pointer_motion_to_rel(pointer, event, |
| 477 | &dx, &dy, |
| 478 | &dx_unaccel, &dy_unaccel)) |
| 479 | return; |
| 480 | |
| 481 | resource_list = &pointer->focus_client->relative_pointer_resources; |
Alexandros Frantzis | 84b31f8 | 2017-11-24 18:01:46 +0200 | [diff] [blame] | 482 | time_usec = timespec_to_usec(&event->time); |
Jonas Ådahl | 30d61d8 | 2014-10-22 21:21:17 +0200 | [diff] [blame] | 483 | if (time_usec == 0) |
Alexandros Frantzis | 84b31f8 | 2017-11-24 18:01:46 +0200 | [diff] [blame] | 484 | time_usec = timespec_to_usec(time); |
Jonas Ådahl | 30d61d8 | 2014-10-22 21:21:17 +0200 | [diff] [blame] | 485 | |
| 486 | dxf = wl_fixed_from_double(dx); |
| 487 | dyf = wl_fixed_from_double(dy); |
| 488 | dxf_unaccel = wl_fixed_from_double(dx_unaccel); |
| 489 | dyf_unaccel = wl_fixed_from_double(dy_unaccel); |
| 490 | |
| 491 | wl_resource_for_each(resource, resource_list) { |
| 492 | zwp_relative_pointer_v1_send_relative_motion( |
| 493 | resource, |
| 494 | (uint32_t) (time_usec >> 32), |
| 495 | (uint32_t) time_usec, |
| 496 | dxf, dyf, |
| 497 | dxf_unaccel, dyf_unaccel); |
| 498 | } |
| 499 | } |
| 500 | |
| 501 | static void |
Alexandros Frantzis | 84b31f8 | 2017-11-24 18:01:46 +0200 | [diff] [blame] | 502 | pointer_send_motion(struct weston_pointer *pointer, |
| 503 | const struct timespec *time, |
Quentin Glidic | cde1345 | 2016-08-12 10:41:32 +0200 | [diff] [blame] | 504 | wl_fixed_t sx, wl_fixed_t sy) |
Jonas Ådahl | f44942e | 2016-07-22 17:54:55 +0800 | [diff] [blame] | 505 | { |
| 506 | struct wl_list *resource_list; |
| 507 | struct wl_resource *resource; |
Alexandros Frantzis | 84b31f8 | 2017-11-24 18:01:46 +0200 | [diff] [blame] | 508 | uint32_t msecs; |
Jonas Ådahl | f44942e | 2016-07-22 17:54:55 +0800 | [diff] [blame] | 509 | |
| 510 | if (!pointer->focus_client) |
| 511 | return; |
| 512 | |
| 513 | resource_list = &pointer->focus_client->pointer_resources; |
Alexandros Frantzis | 84b31f8 | 2017-11-24 18:01:46 +0200 | [diff] [blame] | 514 | msecs = timespec_to_msec(time); |
Alexandros Frantzis | db907b7 | 2018-02-20 14:06:26 +0200 | [diff] [blame] | 515 | wl_resource_for_each(resource, resource_list) { |
| 516 | send_timestamps_for_input_resource(resource, |
| 517 | &pointer->timestamps_list, |
| 518 | time); |
Alexandros Frantzis | 84b31f8 | 2017-11-24 18:01:46 +0200 | [diff] [blame] | 519 | wl_pointer_send_motion(resource, msecs, sx, sy); |
Alexandros Frantzis | db907b7 | 2018-02-20 14:06:26 +0200 | [diff] [blame] | 520 | } |
Jonas Ådahl | f44942e | 2016-07-22 17:54:55 +0800 | [diff] [blame] | 521 | } |
| 522 | |
Quentin Glidic | cde1345 | 2016-08-12 10:41:32 +0200 | [diff] [blame] | 523 | WL_EXPORT void |
Alexandros Frantzis | 84b31f8 | 2017-11-24 18:01:46 +0200 | [diff] [blame] | 524 | weston_pointer_send_motion(struct weston_pointer *pointer, |
| 525 | const struct timespec *time, |
Quentin Glidic | cde1345 | 2016-08-12 10:41:32 +0200 | [diff] [blame] | 526 | struct weston_pointer_motion_event *event) |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 527 | { |
Jonas Ådahl | d251010 | 2014-10-05 21:39:14 +0200 | [diff] [blame] | 528 | wl_fixed_t x, y; |
Jonas Ådahl | 8283c34 | 2015-04-24 15:26:17 +0800 | [diff] [blame] | 529 | wl_fixed_t old_sx = pointer->sx; |
| 530 | wl_fixed_t old_sy = pointer->sy; |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 531 | |
Jonas Ådahl | d251010 | 2014-10-05 21:39:14 +0200 | [diff] [blame] | 532 | if (pointer->focus) { |
| 533 | weston_pointer_motion_to_abs(pointer, event, &x, &y); |
Kristian Høgsberg | db1fccb | 2014-02-05 17:14:42 -0800 | [diff] [blame] | 534 | weston_view_from_global_fixed(pointer->focus, x, y, |
| 535 | &pointer->sx, &pointer->sy); |
Jonas Ådahl | d251010 | 2014-10-05 21:39:14 +0200 | [diff] [blame] | 536 | } |
Kristian Høgsberg | db1fccb | 2014-02-05 17:14:42 -0800 | [diff] [blame] | 537 | |
Jonas Ådahl | d251010 | 2014-10-05 21:39:14 +0200 | [diff] [blame] | 538 | weston_pointer_move(pointer, event); |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 539 | |
Jonas Ådahl | f44942e | 2016-07-22 17:54:55 +0800 | [diff] [blame] | 540 | if (old_sx != pointer->sx || old_sy != pointer->sy) { |
Quentin Glidic | cde1345 | 2016-08-12 10:41:32 +0200 | [diff] [blame] | 541 | pointer_send_motion(pointer, time, |
| 542 | pointer->sx, pointer->sy); |
Kristian Høgsberg | be6403e | 2013-05-08 21:03:21 -0400 | [diff] [blame] | 543 | } |
Jonas Ådahl | 30d61d8 | 2014-10-22 21:21:17 +0200 | [diff] [blame] | 544 | |
Quentin Glidic | cde1345 | 2016-08-12 10:41:32 +0200 | [diff] [blame] | 545 | pointer_send_relative_motion(pointer, time, event); |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 546 | } |
| 547 | |
| 548 | static void |
Alexandros Frantzis | 84b31f8 | 2017-11-24 18:01:46 +0200 | [diff] [blame] | 549 | default_grab_pointer_motion(struct weston_pointer_grab *grab, |
| 550 | const struct timespec *time, |
Quentin Glidic | cde1345 | 2016-08-12 10:41:32 +0200 | [diff] [blame] | 551 | struct weston_pointer_motion_event *event) |
| 552 | { |
| 553 | weston_pointer_send_motion(grab->pointer, time, event); |
| 554 | } |
| 555 | |
| 556 | /** Check if the pointer has focused resources. |
| 557 | * |
| 558 | * \param pointer The pointer to check for focused resources. |
| 559 | * \return Whether or not this pointer has focused resources |
| 560 | */ |
| 561 | WL_EXPORT bool |
| 562 | weston_pointer_has_focus_resource(struct weston_pointer *pointer) |
| 563 | { |
| 564 | if (!pointer->focus_client) |
| 565 | return false; |
| 566 | |
| 567 | if (wl_list_empty(&pointer->focus_client->pointer_resources)) |
| 568 | return false; |
| 569 | |
| 570 | return true; |
| 571 | } |
| 572 | |
| 573 | /** Send wl_pointer.button events to focused resources. |
| 574 | * |
| 575 | * \param pointer The pointer where the button events originates from. |
| 576 | * \param time The timestamp of the event |
| 577 | * \param button The button value of the event |
| 578 | * \param value The state enum value of the event |
| 579 | * |
| 580 | * For every resource that is currently in focus, send a wl_pointer.button event |
| 581 | * with the passed parameters. The focused resources are the wl_pointer |
| 582 | * resources of the client which currently has the surface with pointer focus. |
| 583 | */ |
| 584 | WL_EXPORT void |
Jonas Ådahl | c02ac11 | 2016-07-22 17:55:43 +0800 | [diff] [blame] | 585 | weston_pointer_send_button(struct weston_pointer *pointer, |
Alexandros Frantzis | 215bedc | 2017-11-16 18:20:55 +0200 | [diff] [blame] | 586 | const struct timespec *time, uint32_t button, |
Quentin Glidic | cde1345 | 2016-08-12 10:41:32 +0200 | [diff] [blame] | 587 | enum wl_pointer_button_state state) |
Jonas Ådahl | c02ac11 | 2016-07-22 17:55:43 +0800 | [diff] [blame] | 588 | { |
| 589 | struct wl_display *display = pointer->seat->compositor->wl_display; |
| 590 | struct wl_list *resource_list; |
| 591 | struct wl_resource *resource; |
| 592 | uint32_t serial; |
Alexandros Frantzis | 215bedc | 2017-11-16 18:20:55 +0200 | [diff] [blame] | 593 | uint32_t msecs; |
Jonas Ådahl | c02ac11 | 2016-07-22 17:55:43 +0800 | [diff] [blame] | 594 | |
Quentin Glidic | cde1345 | 2016-08-12 10:41:32 +0200 | [diff] [blame] | 595 | if (!weston_pointer_has_focus_resource(pointer)) |
Jonas Ådahl | c02ac11 | 2016-07-22 17:55:43 +0800 | [diff] [blame] | 596 | return; |
| 597 | |
| 598 | resource_list = &pointer->focus_client->pointer_resources; |
Quentin Glidic | cde1345 | 2016-08-12 10:41:32 +0200 | [diff] [blame] | 599 | serial = wl_display_next_serial(display); |
Alexandros Frantzis | 215bedc | 2017-11-16 18:20:55 +0200 | [diff] [blame] | 600 | msecs = timespec_to_msec(time); |
Alexandros Frantzis | db907b7 | 2018-02-20 14:06:26 +0200 | [diff] [blame] | 601 | wl_resource_for_each(resource, resource_list) { |
| 602 | send_timestamps_for_input_resource(resource, |
| 603 | &pointer->timestamps_list, |
| 604 | time); |
Alexandros Frantzis | 215bedc | 2017-11-16 18:20:55 +0200 | [diff] [blame] | 605 | wl_pointer_send_button(resource, serial, msecs, button, state); |
Alexandros Frantzis | db907b7 | 2018-02-20 14:06:26 +0200 | [diff] [blame] | 606 | } |
Jonas Ådahl | c02ac11 | 2016-07-22 17:55:43 +0800 | [diff] [blame] | 607 | } |
| 608 | |
| 609 | static void |
Kristian Høgsberg | b27901c | 2013-10-28 15:32:02 -0700 | [diff] [blame] | 610 | default_grab_pointer_button(struct weston_pointer_grab *grab, |
Alexandros Frantzis | 215bedc | 2017-11-16 18:20:55 +0200 | [diff] [blame] | 611 | const struct timespec *time, uint32_t button, |
Quentin Glidic | cde1345 | 2016-08-12 10:41:32 +0200 | [diff] [blame] | 612 | enum wl_pointer_button_state state) |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 613 | { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 614 | struct weston_pointer *pointer = grab->pointer; |
Kristian Høgsberg | e122b7b | 2013-05-08 16:47:00 -0400 | [diff] [blame] | 615 | struct weston_compositor *compositor = pointer->seat->compositor; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 616 | struct weston_view *view; |
Kristian Høgsberg | e122b7b | 2013-05-08 16:47:00 -0400 | [diff] [blame] | 617 | wl_fixed_t sx, sy; |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 618 | |
Quentin Glidic | cde1345 | 2016-08-12 10:41:32 +0200 | [diff] [blame] | 619 | weston_pointer_send_button(pointer, time, button, state); |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 620 | |
| 621 | if (pointer->button_count == 0 && |
Kristian Høgsberg | e122b7b | 2013-05-08 16:47:00 -0400 | [diff] [blame] | 622 | state == WL_POINTER_BUTTON_STATE_RELEASED) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 623 | view = weston_compositor_pick_view(compositor, |
| 624 | pointer->x, pointer->y, |
| 625 | &sx, &sy); |
Kristian Høgsberg | e122b7b | 2013-05-08 16:47:00 -0400 | [diff] [blame] | 626 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 627 | weston_pointer_set_focus(pointer, view, sx, sy); |
Kristian Høgsberg | e122b7b | 2013-05-08 16:47:00 -0400 | [diff] [blame] | 628 | } |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 629 | } |
| 630 | |
Jonas Ådahl | 0336ca0 | 2014-10-04 16:28:29 +0200 | [diff] [blame] | 631 | /** Send wl_pointer.axis events to focused resources. |
| 632 | * |
| 633 | * \param pointer The pointer where the axis events originates from. |
| 634 | * \param time The timestamp of the event |
| 635 | * \param axis The axis enum value of the event |
| 636 | * \param value The axis value of the event |
| 637 | * |
| 638 | * For every resource that is currently in focus, send a wl_pointer.axis event |
| 639 | * with the passed parameters. The focused resources are the wl_pointer |
| 640 | * resources of the client which currently has the surface with pointer focus. |
| 641 | */ |
| 642 | WL_EXPORT void |
| 643 | weston_pointer_send_axis(struct weston_pointer *pointer, |
Alexandros Frantzis | 8032194 | 2017-11-16 18:20:56 +0200 | [diff] [blame] | 644 | const struct timespec *time, |
Peter Hutterer | 89b6a49 | 2016-01-18 15:58:17 +1000 | [diff] [blame] | 645 | struct weston_pointer_axis_event *event) |
Jonas Ådahl | 0336ca0 | 2014-10-04 16:28:29 +0200 | [diff] [blame] | 646 | { |
| 647 | struct wl_resource *resource; |
| 648 | struct wl_list *resource_list; |
Alexandros Frantzis | 8032194 | 2017-11-16 18:20:56 +0200 | [diff] [blame] | 649 | uint32_t msecs; |
Jonas Ådahl | 0336ca0 | 2014-10-04 16:28:29 +0200 | [diff] [blame] | 650 | |
Quentin Glidic | cde1345 | 2016-08-12 10:41:32 +0200 | [diff] [blame] | 651 | if (!weston_pointer_has_focus_resource(pointer)) |
Jonas Ådahl | 2cbf293 | 2015-07-22 12:05:38 +0800 | [diff] [blame] | 652 | return; |
| 653 | |
| 654 | resource_list = &pointer->focus_client->pointer_resources; |
Alexandros Frantzis | 8032194 | 2017-11-16 18:20:56 +0200 | [diff] [blame] | 655 | msecs = timespec_to_msec(time); |
Peter Hutterer | 87743e9 | 2016-01-18 16:38:22 +1000 | [diff] [blame] | 656 | wl_resource_for_each(resource, resource_list) { |
| 657 | if (event->has_discrete && |
| 658 | wl_resource_get_version(resource) >= |
| 659 | WL_POINTER_AXIS_DISCRETE_SINCE_VERSION) |
| 660 | wl_pointer_send_axis_discrete(resource, event->axis, |
| 661 | event->discrete); |
| 662 | |
Alexandros Frantzis | db907b7 | 2018-02-20 14:06:26 +0200 | [diff] [blame] | 663 | if (event->value) { |
| 664 | send_timestamps_for_input_resource(resource, |
| 665 | &pointer->timestamps_list, |
| 666 | time); |
Alexandros Frantzis | 8032194 | 2017-11-16 18:20:56 +0200 | [diff] [blame] | 667 | wl_pointer_send_axis(resource, msecs, |
Giulio Camuffo | 90a6fc6 | 2016-03-22 17:44:54 +0200 | [diff] [blame] | 668 | event->axis, |
| 669 | wl_fixed_from_double(event->value)); |
Alexandros Frantzis | db907b7 | 2018-02-20 14:06:26 +0200 | [diff] [blame] | 670 | } else if (wl_resource_get_version(resource) >= |
| 671 | WL_POINTER_AXIS_STOP_SINCE_VERSION) { |
| 672 | send_timestamps_for_input_resource(resource, |
| 673 | &pointer->timestamps_list, |
| 674 | time); |
Alexandros Frantzis | 8032194 | 2017-11-16 18:20:56 +0200 | [diff] [blame] | 675 | wl_pointer_send_axis_stop(resource, msecs, |
Peter Hutterer | 87743e9 | 2016-01-18 16:38:22 +1000 | [diff] [blame] | 676 | event->axis); |
Alexandros Frantzis | db907b7 | 2018-02-20 14:06:26 +0200 | [diff] [blame] | 677 | } |
Peter Hutterer | 87743e9 | 2016-01-18 16:38:22 +1000 | [diff] [blame] | 678 | } |
| 679 | } |
| 680 | |
Quentin Glidic | cde1345 | 2016-08-12 10:41:32 +0200 | [diff] [blame] | 681 | /** Send wl_pointer.axis_source events to focused resources. |
| 682 | * |
| 683 | * \param pointer The pointer where the axis_source events originates from. |
| 684 | * \param source The axis_source enum value of the event |
| 685 | * |
| 686 | * For every resource that is currently in focus, send a wl_pointer.axis_source |
| 687 | * event with the passed parameter. The focused resources are the wl_pointer |
| 688 | * resources of the client which currently has the surface with pointer focus. |
| 689 | */ |
Peter Hutterer | 87743e9 | 2016-01-18 16:38:22 +1000 | [diff] [blame] | 690 | WL_EXPORT void |
Quentin Glidic | cde1345 | 2016-08-12 10:41:32 +0200 | [diff] [blame] | 691 | weston_pointer_send_axis_source(struct weston_pointer *pointer, |
| 692 | enum wl_pointer_axis_source source) |
Peter Hutterer | 87743e9 | 2016-01-18 16:38:22 +1000 | [diff] [blame] | 693 | { |
| 694 | struct wl_resource *resource; |
| 695 | struct wl_list *resource_list; |
| 696 | |
Quentin Glidic | cde1345 | 2016-08-12 10:41:32 +0200 | [diff] [blame] | 697 | if (!weston_pointer_has_focus_resource(pointer)) |
Jonas Ådahl | ed6014a | 2016-04-21 10:21:48 +0800 | [diff] [blame] | 698 | return; |
| 699 | |
Peter Hutterer | 87743e9 | 2016-01-18 16:38:22 +1000 | [diff] [blame] | 700 | resource_list = &pointer->focus_client->pointer_resources; |
| 701 | wl_resource_for_each(resource, resource_list) { |
| 702 | if (wl_resource_get_version(resource) >= |
| 703 | WL_POINTER_AXIS_SOURCE_SINCE_VERSION) { |
| 704 | wl_pointer_send_axis_source(resource, source); |
| 705 | } |
| 706 | } |
| 707 | } |
| 708 | |
| 709 | static void |
| 710 | pointer_send_frame(struct wl_resource *resource) |
| 711 | { |
| 712 | if (wl_resource_get_version(resource) >= |
| 713 | WL_POINTER_FRAME_SINCE_VERSION) { |
| 714 | wl_pointer_send_frame(resource); |
| 715 | } |
| 716 | } |
| 717 | |
Quentin Glidic | cde1345 | 2016-08-12 10:41:32 +0200 | [diff] [blame] | 718 | /** Send wl_pointer.frame events to focused resources. |
| 719 | * |
| 720 | * \param pointer The pointer where the frame events originates from. |
| 721 | * |
| 722 | * For every resource that is currently in focus, send a wl_pointer.frame event. |
| 723 | * The focused resources are the wl_pointer resources of the client which |
| 724 | * currently has the surface with pointer focus. |
| 725 | */ |
Peter Hutterer | 87743e9 | 2016-01-18 16:38:22 +1000 | [diff] [blame] | 726 | WL_EXPORT void |
| 727 | weston_pointer_send_frame(struct weston_pointer *pointer) |
| 728 | { |
| 729 | struct wl_resource *resource; |
| 730 | struct wl_list *resource_list; |
| 731 | |
Quentin Glidic | cde1345 | 2016-08-12 10:41:32 +0200 | [diff] [blame] | 732 | if (!weston_pointer_has_focus_resource(pointer)) |
Derek Foreman | 8efa31b | 2016-01-29 10:29:46 -0600 | [diff] [blame] | 733 | return; |
| 734 | |
Peter Hutterer | 87743e9 | 2016-01-18 16:38:22 +1000 | [diff] [blame] | 735 | resource_list = &pointer->focus_client->pointer_resources; |
Jonas Ådahl | 0336ca0 | 2014-10-04 16:28:29 +0200 | [diff] [blame] | 736 | wl_resource_for_each(resource, resource_list) |
Peter Hutterer | 87743e9 | 2016-01-18 16:38:22 +1000 | [diff] [blame] | 737 | pointer_send_frame(resource); |
Jonas Ådahl | 0336ca0 | 2014-10-04 16:28:29 +0200 | [diff] [blame] | 738 | } |
| 739 | |
| 740 | static void |
| 741 | default_grab_pointer_axis(struct weston_pointer_grab *grab, |
Alexandros Frantzis | 8032194 | 2017-11-16 18:20:56 +0200 | [diff] [blame] | 742 | const struct timespec *time, |
Peter Hutterer | 89b6a49 | 2016-01-18 15:58:17 +1000 | [diff] [blame] | 743 | struct weston_pointer_axis_event *event) |
Jonas Ådahl | 0336ca0 | 2014-10-04 16:28:29 +0200 | [diff] [blame] | 744 | { |
Peter Hutterer | 89b6a49 | 2016-01-18 15:58:17 +1000 | [diff] [blame] | 745 | weston_pointer_send_axis(grab->pointer, time, event); |
Jonas Ådahl | 0336ca0 | 2014-10-04 16:28:29 +0200 | [diff] [blame] | 746 | } |
| 747 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 748 | static void |
Peter Hutterer | 87743e9 | 2016-01-18 16:38:22 +1000 | [diff] [blame] | 749 | default_grab_pointer_axis_source(struct weston_pointer_grab *grab, |
Quentin Glidic | cde1345 | 2016-08-12 10:41:32 +0200 | [diff] [blame] | 750 | enum wl_pointer_axis_source source) |
Peter Hutterer | 87743e9 | 2016-01-18 16:38:22 +1000 | [diff] [blame] | 751 | { |
| 752 | weston_pointer_send_axis_source(grab->pointer, source); |
| 753 | } |
| 754 | |
| 755 | static void |
| 756 | default_grab_pointer_frame(struct weston_pointer_grab *grab) |
| 757 | { |
| 758 | weston_pointer_send_frame(grab->pointer); |
| 759 | } |
| 760 | |
| 761 | static void |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 762 | default_grab_pointer_cancel(struct weston_pointer_grab *grab) |
| 763 | { |
| 764 | } |
| 765 | |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 766 | static const struct weston_pointer_grab_interface |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 767 | default_pointer_grab_interface = { |
Kristian Høgsberg | b27901c | 2013-10-28 15:32:02 -0700 | [diff] [blame] | 768 | default_grab_pointer_focus, |
| 769 | default_grab_pointer_motion, |
| 770 | default_grab_pointer_button, |
Jonas Ådahl | 0336ca0 | 2014-10-04 16:28:29 +0200 | [diff] [blame] | 771 | default_grab_pointer_axis, |
Peter Hutterer | 87743e9 | 2016-01-18 16:38:22 +1000 | [diff] [blame] | 772 | default_grab_pointer_axis_source, |
| 773 | default_grab_pointer_frame, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 774 | default_grab_pointer_cancel, |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 775 | }; |
| 776 | |
Quentin Glidic | cde1345 | 2016-08-12 10:41:32 +0200 | [diff] [blame] | 777 | /** Check if the touch has focused resources. |
| 778 | * |
| 779 | * \param touch The touch to check for focused resources. |
| 780 | * \return Whether or not this touch has focused resources |
| 781 | */ |
| 782 | WL_EXPORT bool |
| 783 | weston_touch_has_focus_resource(struct weston_touch *touch) |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 784 | { |
Quentin Glidic | cde1345 | 2016-08-12 10:41:32 +0200 | [diff] [blame] | 785 | if (!touch->focus) |
| 786 | return false; |
| 787 | |
| 788 | if (wl_list_empty(&touch->focus_resource_list)) |
| 789 | return false; |
| 790 | |
| 791 | return true; |
| 792 | } |
| 793 | |
| 794 | /** Send wl_touch.down events to focused resources. |
| 795 | * |
| 796 | * \param touch The touch where the down events originates from. |
| 797 | * \param time The timestamp of the event |
| 798 | * \param touch_id The touch_id value of the event |
| 799 | * \param x The x value of the event |
| 800 | * \param y The y value of the event |
| 801 | * |
| 802 | * For every resource that is currently in focus, send a wl_touch.down event |
| 803 | * with the passed parameters. The focused resources are the wl_touch |
| 804 | * resources of the client which currently has the surface with touch focus. |
| 805 | */ |
| 806 | WL_EXPORT void |
Alexandros Frantzis | 9448deb | 2017-11-16 18:20:58 +0200 | [diff] [blame] | 807 | weston_touch_send_down(struct weston_touch *touch, const struct timespec *time, |
Quentin Glidic | cde1345 | 2016-08-12 10:41:32 +0200 | [diff] [blame] | 808 | int touch_id, wl_fixed_t x, wl_fixed_t y) |
| 809 | { |
Rob Bradford | 880ebc7 | 2013-07-22 17:31:38 +0100 | [diff] [blame] | 810 | struct wl_display *display = touch->seat->compositor->wl_display; |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 811 | uint32_t serial; |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 812 | struct wl_resource *resource; |
| 813 | struct wl_list *resource_list; |
Giulio Camuffo | 61ed7b6 | 2015-07-08 11:55:28 +0300 | [diff] [blame] | 814 | wl_fixed_t sx, sy; |
Alexandros Frantzis | 9448deb | 2017-11-16 18:20:58 +0200 | [diff] [blame] | 815 | uint32_t msecs; |
Giulio Camuffo | 61ed7b6 | 2015-07-08 11:55:28 +0300 | [diff] [blame] | 816 | |
Quentin Glidic | cde1345 | 2016-08-12 10:41:32 +0200 | [diff] [blame] | 817 | if (!weston_touch_has_focus_resource(touch)) |
Bryce Harrington | 2c40d1d | 2016-02-02 10:18:48 -0800 | [diff] [blame] | 818 | return; |
| 819 | |
Giulio Camuffo | 61ed7b6 | 2015-07-08 11:55:28 +0300 | [diff] [blame] | 820 | weston_view_from_global_fixed(touch->focus, x, y, &sx, &sy); |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 821 | |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 822 | resource_list = &touch->focus_resource_list; |
Quentin Glidic | cde1345 | 2016-08-12 10:41:32 +0200 | [diff] [blame] | 823 | serial = wl_display_next_serial(display); |
Alexandros Frantzis | 9448deb | 2017-11-16 18:20:58 +0200 | [diff] [blame] | 824 | msecs = timespec_to_msec(time); |
Alexandros Frantzis | d715784 | 2018-02-20 14:07:03 +0200 | [diff] [blame] | 825 | wl_resource_for_each(resource, resource_list) { |
| 826 | send_timestamps_for_input_resource(resource, |
| 827 | &touch->timestamps_list, |
| 828 | time); |
| 829 | wl_touch_send_down(resource, serial, msecs, |
| 830 | touch->focus->surface->resource, |
| 831 | touch_id, sx, sy); |
| 832 | } |
Quentin Glidic | cde1345 | 2016-08-12 10:41:32 +0200 | [diff] [blame] | 833 | } |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 834 | |
Quentin Glidic | cde1345 | 2016-08-12 10:41:32 +0200 | [diff] [blame] | 835 | static void |
Alexandros Frantzis | 9448deb | 2017-11-16 18:20:58 +0200 | [diff] [blame] | 836 | default_grab_touch_down(struct weston_touch_grab *grab, |
| 837 | const struct timespec *time, int touch_id, |
| 838 | wl_fixed_t x, wl_fixed_t y) |
Quentin Glidic | cde1345 | 2016-08-12 10:41:32 +0200 | [diff] [blame] | 839 | { |
| 840 | weston_touch_send_down(grab->touch, time, touch_id, x, y); |
| 841 | } |
| 842 | |
| 843 | /** Send wl_touch.up events to focused resources. |
| 844 | * |
| 845 | * \param touch The touch where the up events originates from. |
| 846 | * \param time The timestamp of the event |
| 847 | * \param touch_id The touch_id value of the event |
| 848 | * |
| 849 | * For every resource that is currently in focus, send a wl_touch.up event |
| 850 | * with the passed parameters. The focused resources are the wl_touch |
| 851 | * resources of the client which currently has the surface with touch focus. |
| 852 | */ |
| 853 | WL_EXPORT void |
Alexandros Frantzis | 27a51b8 | 2017-11-16 18:20:59 +0200 | [diff] [blame] | 854 | weston_touch_send_up(struct weston_touch *touch, const struct timespec *time, |
| 855 | int touch_id) |
Quentin Glidic | cde1345 | 2016-08-12 10:41:32 +0200 | [diff] [blame] | 856 | { |
| 857 | struct wl_display *display = touch->seat->compositor->wl_display; |
| 858 | uint32_t serial; |
| 859 | struct wl_resource *resource; |
| 860 | struct wl_list *resource_list; |
Alexandros Frantzis | 27a51b8 | 2017-11-16 18:20:59 +0200 | [diff] [blame] | 861 | uint32_t msecs; |
Quentin Glidic | cde1345 | 2016-08-12 10:41:32 +0200 | [diff] [blame] | 862 | |
| 863 | if (!weston_touch_has_focus_resource(touch)) |
| 864 | return; |
| 865 | |
| 866 | resource_list = &touch->focus_resource_list; |
| 867 | serial = wl_display_next_serial(display); |
Alexandros Frantzis | 27a51b8 | 2017-11-16 18:20:59 +0200 | [diff] [blame] | 868 | msecs = timespec_to_msec(time); |
Alexandros Frantzis | d715784 | 2018-02-20 14:07:03 +0200 | [diff] [blame] | 869 | wl_resource_for_each(resource, resource_list) { |
| 870 | send_timestamps_for_input_resource(resource, |
| 871 | &touch->timestamps_list, |
| 872 | time); |
Alexandros Frantzis | 27a51b8 | 2017-11-16 18:20:59 +0200 | [diff] [blame] | 873 | wl_touch_send_up(resource, serial, msecs, touch_id); |
Alexandros Frantzis | d715784 | 2018-02-20 14:07:03 +0200 | [diff] [blame] | 874 | } |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 875 | } |
| 876 | |
Kristian Høgsberg | e329f36 | 2013-05-06 22:19:57 -0400 | [diff] [blame] | 877 | static void |
| 878 | default_grab_touch_up(struct weston_touch_grab *grab, |
Alexandros Frantzis | 27a51b8 | 2017-11-16 18:20:59 +0200 | [diff] [blame] | 879 | const struct timespec *time, int touch_id) |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 880 | { |
Quentin Glidic | cde1345 | 2016-08-12 10:41:32 +0200 | [diff] [blame] | 881 | weston_touch_send_up(grab->touch, time, touch_id); |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 882 | } |
| 883 | |
Quentin Glidic | cde1345 | 2016-08-12 10:41:32 +0200 | [diff] [blame] | 884 | /** Send wl_touch.motion events to focused resources. |
| 885 | * |
| 886 | * \param touch The touch where the motion events originates from. |
| 887 | * \param time The timestamp of the event |
| 888 | * \param touch_id The touch_id value of the event |
| 889 | * \param x The x value of the event |
| 890 | * \param y The y value of the event |
| 891 | * |
| 892 | * For every resource that is currently in focus, send a wl_touch.motion event |
| 893 | * with the passed parameters. The focused resources are the wl_touch |
| 894 | * resources of the client which currently has the surface with touch focus. |
| 895 | */ |
| 896 | WL_EXPORT void |
Alexandros Frantzis | 7d2abcf | 2017-11-16 18:21:00 +0200 | [diff] [blame] | 897 | weston_touch_send_motion(struct weston_touch *touch, |
| 898 | const struct timespec *time, int touch_id, |
| 899 | wl_fixed_t x, wl_fixed_t y) |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 900 | { |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 901 | struct wl_resource *resource; |
| 902 | struct wl_list *resource_list; |
Giulio Camuffo | 61ed7b6 | 2015-07-08 11:55:28 +0300 | [diff] [blame] | 903 | wl_fixed_t sx, sy; |
Alexandros Frantzis | 7d2abcf | 2017-11-16 18:21:00 +0200 | [diff] [blame] | 904 | uint32_t msecs; |
Giulio Camuffo | 61ed7b6 | 2015-07-08 11:55:28 +0300 | [diff] [blame] | 905 | |
Quentin Glidic | cde1345 | 2016-08-12 10:41:32 +0200 | [diff] [blame] | 906 | if (!weston_touch_has_focus_resource(touch)) |
| 907 | return; |
| 908 | |
Giulio Camuffo | 61ed7b6 | 2015-07-08 11:55:28 +0300 | [diff] [blame] | 909 | weston_view_from_global_fixed(touch->focus, x, y, &sx, &sy); |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 910 | |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 911 | resource_list = &touch->focus_resource_list; |
Alexandros Frantzis | 7d2abcf | 2017-11-16 18:21:00 +0200 | [diff] [blame] | 912 | msecs = timespec_to_msec(time); |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 913 | wl_resource_for_each(resource, resource_list) { |
Alexandros Frantzis | d715784 | 2018-02-20 14:07:03 +0200 | [diff] [blame] | 914 | send_timestamps_for_input_resource(resource, |
| 915 | &touch->timestamps_list, |
| 916 | time); |
Alexandros Frantzis | 7d2abcf | 2017-11-16 18:21:00 +0200 | [diff] [blame] | 917 | wl_touch_send_motion(resource, msecs, |
Kristian Høgsberg | e329f36 | 2013-05-06 22:19:57 -0400 | [diff] [blame] | 918 | touch_id, sx, sy); |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 919 | } |
| 920 | } |
| 921 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 922 | static void |
Alexandros Frantzis | 7d2abcf | 2017-11-16 18:21:00 +0200 | [diff] [blame] | 923 | default_grab_touch_motion(struct weston_touch_grab *grab, |
| 924 | const struct timespec *time, int touch_id, |
| 925 | wl_fixed_t x, wl_fixed_t y) |
Quentin Glidic | cde1345 | 2016-08-12 10:41:32 +0200 | [diff] [blame] | 926 | { |
| 927 | weston_touch_send_motion(grab->touch, time, touch_id, x, y); |
| 928 | } |
| 929 | |
| 930 | |
| 931 | /** Send wl_touch.frame events to focused resources. |
| 932 | * |
| 933 | * \param touch The touch where the frame events originates from. |
| 934 | * |
| 935 | * For every resource that is currently in focus, send a wl_touch.frame event. |
| 936 | * The focused resources are the wl_touch resources of the client which |
| 937 | * currently has the surface with touch focus. |
| 938 | */ |
| 939 | WL_EXPORT void |
| 940 | weston_touch_send_frame(struct weston_touch *touch) |
Jonas Ådahl | 1679f23 | 2014-04-12 09:39:51 +0200 | [diff] [blame] | 941 | { |
| 942 | struct wl_resource *resource; |
| 943 | |
Quentin Glidic | cde1345 | 2016-08-12 10:41:32 +0200 | [diff] [blame] | 944 | if (!weston_touch_has_focus_resource(touch)) |
| 945 | return; |
| 946 | |
| 947 | wl_resource_for_each(resource, &touch->focus_resource_list) |
Jonas Ådahl | 1679f23 | 2014-04-12 09:39:51 +0200 | [diff] [blame] | 948 | wl_touch_send_frame(resource); |
| 949 | } |
| 950 | |
| 951 | static void |
Quentin Glidic | cde1345 | 2016-08-12 10:41:32 +0200 | [diff] [blame] | 952 | default_grab_touch_frame(struct weston_touch_grab *grab) |
| 953 | { |
| 954 | weston_touch_send_frame(grab->touch); |
| 955 | } |
| 956 | |
| 957 | static void |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 958 | default_grab_touch_cancel(struct weston_touch_grab *grab) |
| 959 | { |
| 960 | } |
| 961 | |
Kristian Høgsberg | e329f36 | 2013-05-06 22:19:57 -0400 | [diff] [blame] | 962 | static const struct weston_touch_grab_interface default_touch_grab_interface = { |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 963 | default_grab_touch_down, |
| 964 | default_grab_touch_up, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 965 | default_grab_touch_motion, |
Jonas Ådahl | 1679f23 | 2014-04-12 09:39:51 +0200 | [diff] [blame] | 966 | default_grab_touch_frame, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 967 | default_grab_touch_cancel, |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 968 | }; |
| 969 | |
Quentin Glidic | cde1345 | 2016-08-12 10:41:32 +0200 | [diff] [blame] | 970 | /** Check if the keyboard has focused resources. |
| 971 | * |
| 972 | * \param keyboard The keyboard to check for focused resources. |
| 973 | * \return Whether or not this keyboard has focused resources |
| 974 | */ |
| 975 | WL_EXPORT bool |
| 976 | weston_keyboard_has_focus_resource(struct weston_keyboard *keyboard) |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 977 | { |
Quentin Glidic | cde1345 | 2016-08-12 10:41:32 +0200 | [diff] [blame] | 978 | if (!keyboard->focus) |
| 979 | return false; |
| 980 | |
| 981 | if (wl_list_empty(&keyboard->focus_resource_list)) |
| 982 | return false; |
| 983 | |
| 984 | return true; |
| 985 | } |
| 986 | |
| 987 | /** Send wl_keyboard.key events to focused resources. |
| 988 | * |
| 989 | * \param keyboard The keyboard where the key events originates from. |
| 990 | * \param time The timestamp of the event |
| 991 | * \param key The key value of the event |
| 992 | * \param state The state enum value of the event |
| 993 | * |
| 994 | * For every resource that is currently in focus, send a wl_keyboard.key event |
| 995 | * with the passed parameters. The focused resources are the wl_keyboard |
| 996 | * resources of the client which currently has the surface with keyboard focus. |
| 997 | */ |
| 998 | WL_EXPORT void |
| 999 | weston_keyboard_send_key(struct weston_keyboard *keyboard, |
Alexandros Frantzis | 47e79c8 | 2017-11-16 18:20:57 +0200 | [diff] [blame] | 1000 | const struct timespec *time, uint32_t key, |
Quentin Glidic | cde1345 | 2016-08-12 10:41:32 +0200 | [diff] [blame] | 1001 | enum wl_keyboard_key_state state) |
| 1002 | { |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 1003 | struct wl_resource *resource; |
Rob Bradford | 880ebc7 | 2013-07-22 17:31:38 +0100 | [diff] [blame] | 1004 | struct wl_display *display = keyboard->seat->compositor->wl_display; |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 1005 | uint32_t serial; |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 1006 | struct wl_list *resource_list; |
Alexandros Frantzis | 47e79c8 | 2017-11-16 18:20:57 +0200 | [diff] [blame] | 1007 | uint32_t msecs; |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 1008 | |
Quentin Glidic | cde1345 | 2016-08-12 10:41:32 +0200 | [diff] [blame] | 1009 | if (!weston_keyboard_has_focus_resource(keyboard)) |
| 1010 | return; |
| 1011 | |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 1012 | resource_list = &keyboard->focus_resource_list; |
Quentin Glidic | cde1345 | 2016-08-12 10:41:32 +0200 | [diff] [blame] | 1013 | serial = wl_display_next_serial(display); |
Alexandros Frantzis | 47e79c8 | 2017-11-16 18:20:57 +0200 | [diff] [blame] | 1014 | msecs = timespec_to_msec(time); |
Alexandros Frantzis | 2b44248 | 2018-02-20 14:05:50 +0200 | [diff] [blame] | 1015 | wl_resource_for_each(resource, resource_list) { |
| 1016 | send_timestamps_for_input_resource(resource, |
| 1017 | &keyboard->timestamps_list, |
| 1018 | time); |
Alexandros Frantzis | 47e79c8 | 2017-11-16 18:20:57 +0200 | [diff] [blame] | 1019 | wl_keyboard_send_key(resource, serial, msecs, key, state); |
Alexandros Frantzis | 2b44248 | 2018-02-20 14:05:50 +0200 | [diff] [blame] | 1020 | } |
Quentin Glidic | cde1345 | 2016-08-12 10:41:32 +0200 | [diff] [blame] | 1021 | }; |
| 1022 | |
| 1023 | static void |
| 1024 | default_grab_keyboard_key(struct weston_keyboard_grab *grab, |
Alexandros Frantzis | 47e79c8 | 2017-11-16 18:20:57 +0200 | [diff] [blame] | 1025 | const struct timespec *time, uint32_t key, |
| 1026 | uint32_t state) |
Quentin Glidic | cde1345 | 2016-08-12 10:41:32 +0200 | [diff] [blame] | 1027 | { |
| 1028 | weston_keyboard_send_key(grab->keyboard, time, key, state); |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 1029 | } |
| 1030 | |
| 1031 | static void |
| 1032 | send_modifiers_to_resource(struct weston_keyboard *keyboard, |
| 1033 | struct wl_resource *resource, |
| 1034 | uint32_t serial) |
| 1035 | { |
| 1036 | wl_keyboard_send_modifiers(resource, |
| 1037 | serial, |
| 1038 | keyboard->modifiers.mods_depressed, |
| 1039 | keyboard->modifiers.mods_latched, |
| 1040 | keyboard->modifiers.mods_locked, |
| 1041 | keyboard->modifiers.group); |
| 1042 | } |
| 1043 | |
| 1044 | static void |
| 1045 | send_modifiers_to_client_in_list(struct wl_client *client, |
| 1046 | struct wl_list *list, |
| 1047 | uint32_t serial, |
| 1048 | struct weston_keyboard *keyboard) |
| 1049 | { |
| 1050 | struct wl_resource *resource; |
| 1051 | |
| 1052 | wl_resource_for_each(resource, list) { |
| 1053 | if (wl_resource_get_client(resource) == client) |
| 1054 | send_modifiers_to_resource(keyboard, |
| 1055 | resource, |
| 1056 | serial); |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 1057 | } |
| 1058 | } |
| 1059 | |
Jonas Ådahl | 2cbf293 | 2015-07-22 12:05:38 +0800 | [diff] [blame] | 1060 | static struct weston_pointer_client * |
| 1061 | find_pointer_client_for_surface(struct weston_pointer *pointer, |
| 1062 | struct weston_surface *surface) |
| 1063 | { |
| 1064 | struct wl_client *client; |
| 1065 | |
| 1066 | if (!surface) |
| 1067 | return NULL; |
| 1068 | |
| 1069 | if (!surface->resource) |
| 1070 | return NULL; |
| 1071 | |
| 1072 | client = wl_resource_get_client(surface->resource); |
| 1073 | return weston_pointer_get_pointer_client(pointer, client); |
| 1074 | } |
| 1075 | |
| 1076 | static struct weston_pointer_client * |
| 1077 | find_pointer_client_for_view(struct weston_pointer *pointer, struct weston_view *view) |
| 1078 | { |
| 1079 | if (!view) |
| 1080 | return NULL; |
| 1081 | |
| 1082 | return find_pointer_client_for_surface(pointer, view->surface); |
| 1083 | } |
| 1084 | |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 1085 | static struct wl_resource * |
Kristian Høgsberg | fe7aa90 | 2013-05-08 09:54:37 -0400 | [diff] [blame] | 1086 | 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] | 1087 | { |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 1088 | if (!surface) |
| 1089 | return NULL; |
| 1090 | |
Jason Ekstrand | 44a3863 | 2013-06-14 10:08:00 -0500 | [diff] [blame] | 1091 | if (!surface->resource) |
| 1092 | return NULL; |
Stefan Schmidt | fda2652 | 2013-09-17 10:54:09 +0100 | [diff] [blame] | 1093 | |
Jason Ekstrand | 44a3863 | 2013-06-14 10:08:00 -0500 | [diff] [blame] | 1094 | return wl_resource_find_for_client(list, wl_resource_get_client(surface->resource)); |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 1095 | } |
| 1096 | |
Quentin Glidic | cde1345 | 2016-08-12 10:41:32 +0200 | [diff] [blame] | 1097 | /** Send wl_keyboard.modifiers events to focused resources and pointer |
| 1098 | * focused resources. |
| 1099 | * |
| 1100 | * \param keyboard The keyboard where the modifiers events originates from. |
| 1101 | * \param serial The serial of the event |
| 1102 | * \param mods_depressed The mods_depressed value of the event |
| 1103 | * \param mods_latched The mods_latched value of the event |
| 1104 | * \param mods_locked The mods_locked value of the event |
| 1105 | * \param group The group value of the event |
| 1106 | * |
| 1107 | * For every resource that is currently in focus, send a wl_keyboard.modifiers |
| 1108 | * event with the passed parameters. The focused resources are the wl_keyboard |
| 1109 | * resources of the client which currently has the surface with keyboard focus. |
| 1110 | * This also sends wl_keyboard.modifiers events to the wl_keyboard resources of |
| 1111 | * the client having pointer focus (if different from the keyboard focus client). |
| 1112 | */ |
| 1113 | WL_EXPORT void |
| 1114 | weston_keyboard_send_modifiers(struct weston_keyboard *keyboard, |
| 1115 | uint32_t serial, uint32_t mods_depressed, |
| 1116 | uint32_t mods_latched, |
| 1117 | uint32_t mods_locked, uint32_t group) |
| 1118 | { |
| 1119 | struct weston_pointer *pointer = |
| 1120 | weston_seat_get_pointer(keyboard->seat); |
| 1121 | |
| 1122 | if (weston_keyboard_has_focus_resource(keyboard)) { |
| 1123 | struct wl_list *resource_list; |
| 1124 | struct wl_resource *resource; |
| 1125 | |
| 1126 | resource_list = &keyboard->focus_resource_list; |
| 1127 | wl_resource_for_each(resource, resource_list) { |
| 1128 | wl_keyboard_send_modifiers(resource, serial, |
| 1129 | mods_depressed, mods_latched, |
| 1130 | mods_locked, group); |
| 1131 | } |
| 1132 | } |
| 1133 | |
| 1134 | if (pointer && pointer->focus && pointer->focus->surface->resource && |
| 1135 | pointer->focus->surface != keyboard->focus) { |
| 1136 | struct wl_client *pointer_client = |
| 1137 | wl_resource_get_client(pointer->focus->surface->resource); |
| 1138 | |
| 1139 | send_modifiers_to_client_in_list(pointer_client, |
| 1140 | &keyboard->resource_list, |
| 1141 | serial, |
| 1142 | keyboard); |
| 1143 | } |
| 1144 | } |
| 1145 | |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 1146 | static void |
Kristian Høgsberg | b27901c | 2013-10-28 15:32:02 -0700 | [diff] [blame] | 1147 | default_grab_keyboard_modifiers(struct weston_keyboard_grab *grab, |
| 1148 | uint32_t serial, uint32_t mods_depressed, |
| 1149 | uint32_t mods_latched, |
| 1150 | uint32_t mods_locked, uint32_t group) |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 1151 | { |
Quentin Glidic | cde1345 | 2016-08-12 10:41:32 +0200 | [diff] [blame] | 1152 | weston_keyboard_send_modifiers(grab->keyboard, serial, mods_depressed, |
| 1153 | mods_latched, mods_locked, group); |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 1154 | } |
| 1155 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1156 | static void |
| 1157 | default_grab_keyboard_cancel(struct weston_keyboard_grab *grab) |
| 1158 | { |
| 1159 | } |
| 1160 | |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 1161 | static const struct weston_keyboard_grab_interface |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 1162 | default_keyboard_grab_interface = { |
Kristian Høgsberg | b27901c | 2013-10-28 15:32:02 -0700 | [diff] [blame] | 1163 | default_grab_keyboard_key, |
| 1164 | default_grab_keyboard_modifiers, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1165 | default_grab_keyboard_cancel, |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 1166 | }; |
| 1167 | |
Kristian Høgsberg | 195b869 | 2013-05-08 15:02:05 -0400 | [diff] [blame] | 1168 | static void |
| 1169 | pointer_unmap_sprite(struct weston_pointer *pointer) |
| 1170 | { |
Pekka Paalanen | c557ff7 | 2014-11-12 16:42:52 +0200 | [diff] [blame] | 1171 | struct weston_surface *surface = pointer->sprite->surface; |
| 1172 | |
| 1173 | if (weston_surface_is_mapped(surface)) |
| 1174 | weston_surface_unmap(surface); |
Kristian Høgsberg | 195b869 | 2013-05-08 15:02:05 -0400 | [diff] [blame] | 1175 | |
| 1176 | wl_list_remove(&pointer->sprite_destroy_listener.link); |
Quentin Glidic | 2edc3d5 | 2016-08-12 10:41:33 +0200 | [diff] [blame] | 1177 | surface->committed = NULL; |
| 1178 | surface->committed_private = NULL; |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 1179 | weston_surface_set_label_func(surface, NULL); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1180 | weston_view_destroy(pointer->sprite); |
Kristian Høgsberg | 195b869 | 2013-05-08 15:02:05 -0400 | [diff] [blame] | 1181 | pointer->sprite = NULL; |
| 1182 | } |
| 1183 | |
| 1184 | static void |
| 1185 | pointer_handle_sprite_destroy(struct wl_listener *listener, void *data) |
| 1186 | { |
| 1187 | struct weston_pointer *pointer = |
| 1188 | container_of(listener, struct weston_pointer, |
| 1189 | sprite_destroy_listener); |
| 1190 | |
| 1191 | pointer->sprite = NULL; |
| 1192 | } |
| 1193 | |
Jonas Ådahl | 3e12e63 | 2013-12-02 22:05:05 +0100 | [diff] [blame] | 1194 | static void |
| 1195 | weston_pointer_reset_state(struct weston_pointer *pointer) |
| 1196 | { |
| 1197 | pointer->button_count = 0; |
| 1198 | } |
| 1199 | |
Ander Conselvan de Oliveira | f84327a | 2014-01-29 18:47:51 +0200 | [diff] [blame] | 1200 | static void |
| 1201 | weston_pointer_handle_output_destroy(struct wl_listener *listener, void *data); |
| 1202 | |
Pekka Paalanen | 1b043b1 | 2018-02-26 14:55:32 +0200 | [diff] [blame] | 1203 | static struct weston_pointer * |
Giulio Camuffo | cdb4d29 | 2013-11-14 23:42:53 +0100 | [diff] [blame] | 1204 | weston_pointer_create(struct weston_seat *seat) |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 1205 | { |
Kristian Høgsberg | a4036bb | 2013-05-07 23:52:07 -0400 | [diff] [blame] | 1206 | struct weston_pointer *pointer; |
| 1207 | |
Peter Hutterer | f3d6227 | 2013-08-08 11:57:05 +1000 | [diff] [blame] | 1208 | pointer = zalloc(sizeof *pointer); |
Kristian Høgsberg | a4036bb | 2013-05-07 23:52:07 -0400 | [diff] [blame] | 1209 | if (pointer == NULL) |
| 1210 | return NULL; |
| 1211 | |
Jonas Ådahl | 2cbf293 | 2015-07-22 12:05:38 +0800 | [diff] [blame] | 1212 | wl_list_init(&pointer->pointer_clients); |
Giulio Camuffo | cdb4d29 | 2013-11-14 23:42:53 +0100 | [diff] [blame] | 1213 | weston_pointer_set_default_grab(pointer, |
| 1214 | seat->compositor->default_pointer_grab); |
Giulio Camuffo | 576fe2a | 2013-11-20 18:00:24 +0100 | [diff] [blame] | 1215 | wl_list_init(&pointer->focus_resource_listener.link); |
| 1216 | pointer->focus_resource_listener.notify = pointer_focus_resource_destroyed; |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 1217 | pointer->default_grab.pointer = pointer; |
| 1218 | pointer->grab = &pointer->default_grab; |
Giulio Camuffo | 6fcb378 | 2013-11-14 23:42:50 +0100 | [diff] [blame] | 1219 | wl_signal_init(&pointer->motion_signal); |
Emilio Pozuelo Monfort | aa7a476 | 2013-11-19 11:37:15 +0100 | [diff] [blame] | 1220 | wl_signal_init(&pointer->focus_signal); |
Giulio Camuffo | 576fe2a | 2013-11-20 18:00:24 +0100 | [diff] [blame] | 1221 | wl_list_init(&pointer->focus_view_listener.link); |
Jonas Ådahl | 3eb4ddd | 2016-07-22 17:52:58 +0800 | [diff] [blame] | 1222 | wl_signal_init(&pointer->destroy_signal); |
Alexandros Frantzis | db907b7 | 2018-02-20 14:06:26 +0200 | [diff] [blame] | 1223 | wl_list_init(&pointer->timestamps_list); |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 1224 | |
Kristian Høgsberg | 195b869 | 2013-05-08 15:02:05 -0400 | [diff] [blame] | 1225 | pointer->sprite_destroy_listener.notify = pointer_handle_sprite_destroy; |
| 1226 | |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 1227 | /* FIXME: Pick better co-ords. */ |
| 1228 | pointer->x = wl_fixed_from_int(100); |
| 1229 | pointer->y = wl_fixed_from_int(100); |
Kristian Høgsberg | a4036bb | 2013-05-07 23:52:07 -0400 | [diff] [blame] | 1230 | |
Ander Conselvan de Oliveira | f84327a | 2014-01-29 18:47:51 +0200 | [diff] [blame] | 1231 | pointer->output_destroy_listener.notify = |
| 1232 | weston_pointer_handle_output_destroy; |
| 1233 | wl_signal_add(&seat->compositor->output_destroyed_signal, |
| 1234 | &pointer->output_destroy_listener); |
| 1235 | |
Derek Foreman | f9318d1 | 2015-05-11 15:40:11 -0500 | [diff] [blame] | 1236 | pointer->sx = wl_fixed_from_int(-1000000); |
| 1237 | pointer->sy = wl_fixed_from_int(-1000000); |
| 1238 | |
Kristian Høgsberg | a4036bb | 2013-05-07 23:52:07 -0400 | [diff] [blame] | 1239 | return pointer; |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 1240 | } |
| 1241 | |
Pekka Paalanen | 1b043b1 | 2018-02-26 14:55:32 +0200 | [diff] [blame] | 1242 | static void |
Kristian Høgsberg | a4036bb | 2013-05-07 23:52:07 -0400 | [diff] [blame] | 1243 | weston_pointer_destroy(struct weston_pointer *pointer) |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 1244 | { |
Alexandros Frantzis | 1c3a40e | 2018-02-08 15:37:53 +0200 | [diff] [blame] | 1245 | struct weston_pointer_client *pointer_client, *tmp; |
| 1246 | |
Jonas Ådahl | 3eb4ddd | 2016-07-22 17:52:58 +0800 | [diff] [blame] | 1247 | wl_signal_emit(&pointer->destroy_signal, pointer); |
| 1248 | |
Kristian Høgsberg | 195b869 | 2013-05-08 15:02:05 -0400 | [diff] [blame] | 1249 | if (pointer->sprite) |
| 1250 | pointer_unmap_sprite(pointer); |
| 1251 | |
Alexandros Frantzis | 1c3a40e | 2018-02-08 15:37:53 +0200 | [diff] [blame] | 1252 | wl_list_for_each_safe(pointer_client, tmp, &pointer->pointer_clients, |
| 1253 | link) { |
| 1254 | wl_list_remove(&pointer_client->link); |
| 1255 | weston_pointer_client_destroy(pointer_client); |
| 1256 | } |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 1257 | |
Giulio Camuffo | 576fe2a | 2013-11-20 18:00:24 +0100 | [diff] [blame] | 1258 | wl_list_remove(&pointer->focus_resource_listener.link); |
| 1259 | wl_list_remove(&pointer->focus_view_listener.link); |
Ander Conselvan de Oliveira | f84327a | 2014-01-29 18:47:51 +0200 | [diff] [blame] | 1260 | wl_list_remove(&pointer->output_destroy_listener.link); |
Alexandros Frantzis | db907b7 | 2018-02-20 14:06:26 +0200 | [diff] [blame] | 1261 | wl_list_remove(&pointer->timestamps_list); |
Kristian Høgsberg | a4036bb | 2013-05-07 23:52:07 -0400 | [diff] [blame] | 1262 | free(pointer); |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 1263 | } |
| 1264 | |
Giulio Camuffo | cdb4d29 | 2013-11-14 23:42:53 +0100 | [diff] [blame] | 1265 | void |
| 1266 | weston_pointer_set_default_grab(struct weston_pointer *pointer, |
| 1267 | const struct weston_pointer_grab_interface *interface) |
| 1268 | { |
| 1269 | if (interface) |
| 1270 | pointer->default_grab.interface = interface; |
| 1271 | else |
| 1272 | pointer->default_grab.interface = |
| 1273 | &default_pointer_grab_interface; |
| 1274 | } |
| 1275 | |
Pekka Paalanen | 1b043b1 | 2018-02-26 14:55:32 +0200 | [diff] [blame] | 1276 | static struct weston_keyboard * |
Kristian Høgsberg | a4036bb | 2013-05-07 23:52:07 -0400 | [diff] [blame] | 1277 | weston_keyboard_create(void) |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 1278 | { |
Kristian Høgsberg | a4036bb | 2013-05-07 23:52:07 -0400 | [diff] [blame] | 1279 | struct weston_keyboard *keyboard; |
| 1280 | |
Peter Hutterer | f3d6227 | 2013-08-08 11:57:05 +1000 | [diff] [blame] | 1281 | keyboard = zalloc(sizeof *keyboard); |
Kristian Høgsberg | a4036bb | 2013-05-07 23:52:07 -0400 | [diff] [blame] | 1282 | if (keyboard == NULL) |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 1283 | return NULL; |
Kristian Høgsberg | a4036bb | 2013-05-07 23:52:07 -0400 | [diff] [blame] | 1284 | |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 1285 | wl_list_init(&keyboard->resource_list); |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 1286 | wl_list_init(&keyboard->focus_resource_list); |
Giulio Camuffo | 576fe2a | 2013-11-20 18:00:24 +0100 | [diff] [blame] | 1287 | wl_list_init(&keyboard->focus_resource_listener.link); |
| 1288 | keyboard->focus_resource_listener.notify = keyboard_focus_resource_destroyed; |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 1289 | wl_array_init(&keyboard->keys); |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 1290 | keyboard->default_grab.interface = &default_keyboard_grab_interface; |
| 1291 | keyboard->default_grab.keyboard = keyboard; |
| 1292 | keyboard->grab = &keyboard->default_grab; |
| 1293 | wl_signal_init(&keyboard->focus_signal); |
Alexandros Frantzis | 2b44248 | 2018-02-20 14:05:50 +0200 | [diff] [blame] | 1294 | wl_list_init(&keyboard->timestamps_list); |
Kristian Høgsberg | a4036bb | 2013-05-07 23:52:07 -0400 | [diff] [blame] | 1295 | |
| 1296 | return keyboard; |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 1297 | } |
| 1298 | |
Jonas Ådahl | 7395ea0 | 2013-12-03 09:14:26 +0100 | [diff] [blame] | 1299 | static void |
| 1300 | weston_xkb_info_destroy(struct weston_xkb_info *xkb_info); |
| 1301 | |
Pekka Paalanen | 1b043b1 | 2018-02-26 14:55:32 +0200 | [diff] [blame] | 1302 | static void |
Kristian Høgsberg | a4036bb | 2013-05-07 23:52:07 -0400 | [diff] [blame] | 1303 | weston_keyboard_destroy(struct weston_keyboard *keyboard) |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 1304 | { |
Alexandros Frantzis | 7a314d6 | 2018-01-26 18:47:56 +0200 | [diff] [blame] | 1305 | struct wl_resource *resource; |
| 1306 | |
| 1307 | wl_resource_for_each(resource, &keyboard->resource_list) { |
| 1308 | wl_resource_set_user_data(resource, NULL); |
| 1309 | } |
| 1310 | |
| 1311 | wl_resource_for_each(resource, &keyboard->focus_resource_list) { |
| 1312 | wl_resource_set_user_data(resource, NULL); |
| 1313 | } |
| 1314 | |
| 1315 | wl_list_remove(&keyboard->resource_list); |
| 1316 | wl_list_remove(&keyboard->focus_resource_list); |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 1317 | |
Derek Foreman | 185d158 | 2017-06-28 11:17:23 -0500 | [diff] [blame] | 1318 | xkb_state_unref(keyboard->xkb_state.state); |
| 1319 | if (keyboard->xkb_info) |
| 1320 | weston_xkb_info_destroy(keyboard->xkb_info); |
| 1321 | xkb_keymap_unref(keyboard->pending_keymap); |
Jonas Ådahl | 7395ea0 | 2013-12-03 09:14:26 +0100 | [diff] [blame] | 1322 | |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 1323 | wl_array_release(&keyboard->keys); |
Giulio Camuffo | 576fe2a | 2013-11-20 18:00:24 +0100 | [diff] [blame] | 1324 | wl_list_remove(&keyboard->focus_resource_listener.link); |
Alexandros Frantzis | 2b44248 | 2018-02-20 14:05:50 +0200 | [diff] [blame] | 1325 | wl_list_remove(&keyboard->timestamps_list); |
Kristian Høgsberg | a4036bb | 2013-05-07 23:52:07 -0400 | [diff] [blame] | 1326 | free(keyboard); |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 1327 | } |
| 1328 | |
Jonas Ådahl | cbfa7f7 | 2013-12-02 22:05:04 +0100 | [diff] [blame] | 1329 | static void |
| 1330 | weston_touch_reset_state(struct weston_touch *touch) |
| 1331 | { |
| 1332 | touch->num_tp = 0; |
| 1333 | } |
| 1334 | |
Pekka Paalanen | 1b043b1 | 2018-02-26 14:55:32 +0200 | [diff] [blame] | 1335 | static struct weston_touch * |
Kristian Høgsberg | a4036bb | 2013-05-07 23:52:07 -0400 | [diff] [blame] | 1336 | weston_touch_create(void) |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 1337 | { |
Kristian Høgsberg | a4036bb | 2013-05-07 23:52:07 -0400 | [diff] [blame] | 1338 | struct weston_touch *touch; |
| 1339 | |
Peter Hutterer | f3d6227 | 2013-08-08 11:57:05 +1000 | [diff] [blame] | 1340 | touch = zalloc(sizeof *touch); |
Kristian Høgsberg | a4036bb | 2013-05-07 23:52:07 -0400 | [diff] [blame] | 1341 | if (touch == NULL) |
| 1342 | return NULL; |
| 1343 | |
Louis-Francis Ratté-Boulianne | 6ef59c9 | 2017-11-28 20:42:47 -0500 | [diff] [blame] | 1344 | wl_list_init(&touch->device_list); |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 1345 | wl_list_init(&touch->resource_list); |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 1346 | wl_list_init(&touch->focus_resource_list); |
Giulio Camuffo | 576fe2a | 2013-11-20 18:00:24 +0100 | [diff] [blame] | 1347 | wl_list_init(&touch->focus_view_listener.link); |
| 1348 | touch->focus_view_listener.notify = touch_focus_view_destroyed; |
| 1349 | wl_list_init(&touch->focus_resource_listener.link); |
| 1350 | touch->focus_resource_listener.notify = touch_focus_resource_destroyed; |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 1351 | touch->default_grab.interface = &default_touch_grab_interface; |
| 1352 | touch->default_grab.touch = touch; |
| 1353 | touch->grab = &touch->default_grab; |
| 1354 | wl_signal_init(&touch->focus_signal); |
Alexandros Frantzis | d715784 | 2018-02-20 14:07:03 +0200 | [diff] [blame] | 1355 | wl_list_init(&touch->timestamps_list); |
Kristian Høgsberg | a4036bb | 2013-05-07 23:52:07 -0400 | [diff] [blame] | 1356 | |
| 1357 | return touch; |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 1358 | } |
| 1359 | |
Pekka Paalanen | 1b043b1 | 2018-02-26 14:55:32 +0200 | [diff] [blame] | 1360 | static void |
Kristian Høgsberg | a4036bb | 2013-05-07 23:52:07 -0400 | [diff] [blame] | 1361 | weston_touch_destroy(struct weston_touch *touch) |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 1362 | { |
Alexandros Frantzis | b0b598c | 2018-01-26 18:47:57 +0200 | [diff] [blame] | 1363 | struct wl_resource *resource; |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 1364 | |
Louis-Francis Ratté-Boulianne | 6ef59c9 | 2017-11-28 20:42:47 -0500 | [diff] [blame] | 1365 | assert(wl_list_empty(&touch->device_list)); |
| 1366 | |
Alexandros Frantzis | b0b598c | 2018-01-26 18:47:57 +0200 | [diff] [blame] | 1367 | wl_resource_for_each(resource, &touch->resource_list) { |
| 1368 | wl_resource_set_user_data(resource, NULL); |
| 1369 | } |
| 1370 | |
| 1371 | wl_resource_for_each(resource, &touch->focus_resource_list) { |
| 1372 | wl_resource_set_user_data(resource, NULL); |
| 1373 | } |
| 1374 | |
| 1375 | wl_list_remove(&touch->resource_list); |
| 1376 | wl_list_remove(&touch->focus_resource_list); |
Giulio Camuffo | 576fe2a | 2013-11-20 18:00:24 +0100 | [diff] [blame] | 1377 | wl_list_remove(&touch->focus_view_listener.link); |
| 1378 | wl_list_remove(&touch->focus_resource_listener.link); |
Alexandros Frantzis | d715784 | 2018-02-20 14:07:03 +0200 | [diff] [blame] | 1379 | wl_list_remove(&touch->timestamps_list); |
Kristian Høgsberg | a4036bb | 2013-05-07 23:52:07 -0400 | [diff] [blame] | 1380 | free(touch); |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 1381 | } |
| 1382 | |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 1383 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1384 | seat_send_updated_caps(struct weston_seat *seat) |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 1385 | { |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 1386 | enum wl_seat_capability caps = 0; |
Rob Bradford | 6e737f5 | 2013-09-06 17:48:19 +0100 | [diff] [blame] | 1387 | struct wl_resource *resource; |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 1388 | |
Jonas Ådahl | d6e1c34 | 2013-10-17 23:04:05 +0200 | [diff] [blame] | 1389 | if (seat->pointer_device_count > 0) |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 1390 | caps |= WL_SEAT_CAPABILITY_POINTER; |
Jonas Ådahl | d6e1c34 | 2013-10-17 23:04:05 +0200 | [diff] [blame] | 1391 | if (seat->keyboard_device_count > 0) |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 1392 | caps |= WL_SEAT_CAPABILITY_KEYBOARD; |
Jonas Ådahl | d6e1c34 | 2013-10-17 23:04:05 +0200 | [diff] [blame] | 1393 | if (seat->touch_device_count > 0) |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 1394 | caps |= WL_SEAT_CAPABILITY_TOUCH; |
| 1395 | |
Rob Bradford | 6e737f5 | 2013-09-06 17:48:19 +0100 | [diff] [blame] | 1396 | wl_resource_for_each(resource, &seat->base_resource_list) { |
| 1397 | wl_seat_send_capabilities(resource, caps); |
Jason Ekstrand | 44a3863 | 2013-06-14 10:08:00 -0500 | [diff] [blame] | 1398 | } |
Jason Ekstrand | a4ab542 | 2014-04-02 19:53:45 -0500 | [diff] [blame] | 1399 | wl_signal_emit(&seat->updated_caps_signal, seat); |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 1400 | } |
| 1401 | |
Derek Foreman | f9318d1 | 2015-05-11 15:40:11 -0500 | [diff] [blame] | 1402 | |
| 1403 | /** Clear the pointer focus |
| 1404 | * |
| 1405 | * \param pointer the pointer to clear focus for. |
| 1406 | * |
| 1407 | * This can be used to unset pointer focus and set the co-ordinates to the |
| 1408 | * arbitrary values we use for the no focus case. |
| 1409 | * |
| 1410 | * There's no requirement to use this function. For example, passing the |
| 1411 | * results of a weston_compositor_pick_view() directly to |
| 1412 | * weston_pointer_set_focus() will do the right thing when no view is found. |
| 1413 | */ |
| 1414 | WL_EXPORT void |
| 1415 | weston_pointer_clear_focus(struct weston_pointer *pointer) |
| 1416 | { |
| 1417 | weston_pointer_set_focus(pointer, NULL, |
| 1418 | wl_fixed_from_int(-1000000), |
| 1419 | wl_fixed_from_int(-1000000)); |
| 1420 | } |
| 1421 | |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 1422 | WL_EXPORT void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1423 | weston_pointer_set_focus(struct weston_pointer *pointer, |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1424 | struct weston_view *view, |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1425 | wl_fixed_t sx, wl_fixed_t sy) |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 1426 | { |
Jonas Ådahl | 2cbf293 | 2015-07-22 12:05:38 +0800 | [diff] [blame] | 1427 | struct weston_pointer_client *pointer_client; |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 1428 | struct weston_keyboard *kbd = weston_seat_get_keyboard(pointer->seat); |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 1429 | struct wl_resource *resource; |
Jonas Ådahl | 2cbf293 | 2015-07-22 12:05:38 +0800 | [diff] [blame] | 1430 | struct wl_resource *surface_resource; |
Rob Bradford | 880ebc7 | 2013-07-22 17:31:38 +0100 | [diff] [blame] | 1431 | struct wl_display *display = pointer->seat->compositor->wl_display; |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 1432 | uint32_t serial; |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 1433 | struct wl_list *focus_resource_list; |
Kristian Høgsberg | db1fccb | 2014-02-05 17:14:42 -0800 | [diff] [blame] | 1434 | int refocus = 0; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1435 | |
| 1436 | if ((!pointer->focus && view) || |
| 1437 | (pointer->focus && !view) || |
Kristian Høgsberg | db1fccb | 2014-02-05 17:14:42 -0800 | [diff] [blame] | 1438 | (pointer->focus && pointer->focus->surface != view->surface) || |
| 1439 | pointer->sx != sx || pointer->sy != sy) |
| 1440 | refocus = 1; |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 1441 | |
Jonas Ådahl | 2cbf293 | 2015-07-22 12:05:38 +0800 | [diff] [blame] | 1442 | if (pointer->focus_client && refocus) { |
| 1443 | focus_resource_list = &pointer->focus_client->pointer_resources; |
| 1444 | if (!wl_list_empty(focus_resource_list)) { |
| 1445 | serial = wl_display_next_serial(display); |
| 1446 | surface_resource = pointer->focus->surface->resource; |
| 1447 | wl_resource_for_each(resource, focus_resource_list) { |
| 1448 | wl_pointer_send_leave(resource, serial, |
| 1449 | surface_resource); |
Peter Hutterer | 87743e9 | 2016-01-18 16:38:22 +1000 | [diff] [blame] | 1450 | pointer_send_frame(resource); |
Jonas Ådahl | 2cbf293 | 2015-07-22 12:05:38 +0800 | [diff] [blame] | 1451 | } |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 1452 | } |
| 1453 | |
Jonas Ådahl | 2cbf293 | 2015-07-22 12:05:38 +0800 | [diff] [blame] | 1454 | pointer->focus_client = NULL; |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 1455 | } |
| 1456 | |
Jonas Ådahl | 2cbf293 | 2015-07-22 12:05:38 +0800 | [diff] [blame] | 1457 | pointer_client = find_pointer_client_for_view(pointer, view); |
| 1458 | if (pointer_client && refocus) { |
| 1459 | struct wl_client *surface_client = pointer_client->client; |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 1460 | |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 1461 | serial = wl_display_next_serial(display); |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 1462 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1463 | if (kbd && kbd->focus != view->surface) |
Kristian Høgsberg | cb406f1 | 2013-10-09 10:54:03 -0700 | [diff] [blame] | 1464 | send_modifiers_to_client_in_list(surface_client, |
| 1465 | &kbd->resource_list, |
| 1466 | serial, |
| 1467 | kbd); |
| 1468 | |
Jonas Ådahl | 2cbf293 | 2015-07-22 12:05:38 +0800 | [diff] [blame] | 1469 | pointer->focus_client = pointer_client; |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 1470 | |
Jonas Ådahl | 2cbf293 | 2015-07-22 12:05:38 +0800 | [diff] [blame] | 1471 | focus_resource_list = &pointer->focus_client->pointer_resources; |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 1472 | wl_resource_for_each(resource, focus_resource_list) { |
| 1473 | wl_pointer_send_enter(resource, |
| 1474 | serial, |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1475 | view->surface->resource, |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 1476 | sx, sy); |
Peter Hutterer | 87743e9 | 2016-01-18 16:38:22 +1000 | [diff] [blame] | 1477 | pointer_send_frame(resource); |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 1478 | } |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 1479 | |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 1480 | pointer->focus_serial = serial; |
| 1481 | } |
| 1482 | |
Giulio Camuffo | 65a07f8 | 2013-12-06 12:46:27 +0100 | [diff] [blame] | 1483 | wl_list_remove(&pointer->focus_view_listener.link); |
| 1484 | wl_list_init(&pointer->focus_view_listener.link); |
| 1485 | wl_list_remove(&pointer->focus_resource_listener.link); |
| 1486 | wl_list_init(&pointer->focus_resource_listener.link); |
Emilio Pozuelo Monfort | aa7a476 | 2013-11-19 11:37:15 +0100 | [diff] [blame] | 1487 | if (view) |
Giulio Camuffo | 576fe2a | 2013-11-20 18:00:24 +0100 | [diff] [blame] | 1488 | wl_signal_add(&view->destroy_signal, &pointer->focus_view_listener); |
Giulio Camuffo | 65a07f8 | 2013-12-06 12:46:27 +0100 | [diff] [blame] | 1489 | if (view && view->surface->resource) |
| 1490 | wl_resource_add_destroy_listener(view->surface->resource, |
| 1491 | &pointer->focus_resource_listener); |
| 1492 | |
| 1493 | pointer->focus = view; |
| 1494 | pointer->focus_view_listener.notify = pointer_focus_view_destroyed; |
Kristian Høgsberg | db1fccb | 2014-02-05 17:14:42 -0800 | [diff] [blame] | 1495 | pointer->sx = sx; |
| 1496 | pointer->sy = sy; |
| 1497 | |
Derek Foreman | f9318d1 | 2015-05-11 15:40:11 -0500 | [diff] [blame] | 1498 | assert(view || sx == wl_fixed_from_int(-1000000)); |
| 1499 | assert(view || sy == wl_fixed_from_int(-1000000)); |
| 1500 | |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 1501 | wl_signal_emit(&pointer->focus_signal, pointer); |
| 1502 | } |
| 1503 | |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 1504 | static void |
| 1505 | send_enter_to_resource_list(struct wl_list *list, |
| 1506 | struct weston_keyboard *keyboard, |
| 1507 | struct weston_surface *surface, |
| 1508 | uint32_t serial) |
| 1509 | { |
| 1510 | struct wl_resource *resource; |
| 1511 | |
| 1512 | wl_resource_for_each(resource, list) { |
| 1513 | send_modifiers_to_resource(keyboard, resource, serial); |
| 1514 | wl_keyboard_send_enter(resource, serial, |
| 1515 | surface->resource, |
| 1516 | &keyboard->keys); |
| 1517 | } |
| 1518 | } |
| 1519 | |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 1520 | WL_EXPORT void |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 1521 | weston_keyboard_set_focus(struct weston_keyboard *keyboard, |
Kristian Høgsberg | fe7aa90 | 2013-05-08 09:54:37 -0400 | [diff] [blame] | 1522 | struct weston_surface *surface) |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 1523 | { |
Quentin Glidic | 85d5554 | 2017-07-21 14:02:40 +0200 | [diff] [blame] | 1524 | struct weston_seat *seat = keyboard->seat; |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 1525 | struct wl_resource *resource; |
Rob Bradford | 880ebc7 | 2013-07-22 17:31:38 +0100 | [diff] [blame] | 1526 | struct wl_display *display = keyboard->seat->compositor->wl_display; |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 1527 | uint32_t serial; |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 1528 | struct wl_list *focus_resource_list; |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 1529 | |
Pekka Paalanen | 72e183b | 2018-02-22 16:55:15 +0200 | [diff] [blame] | 1530 | /* Keyboard focus on a surface without a client is equivalent to NULL |
| 1531 | * focus as nothing would react to the keyboard events anyway. |
| 1532 | * Just set focus to NULL instead - the destroy listener hangs on the |
| 1533 | * wl_resource anyway. |
| 1534 | */ |
| 1535 | if (surface && !surface->resource) |
| 1536 | surface = NULL; |
| 1537 | |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 1538 | focus_resource_list = &keyboard->focus_resource_list; |
| 1539 | |
| 1540 | if (!wl_list_empty(focus_resource_list) && keyboard->focus != surface) { |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 1541 | serial = wl_display_next_serial(display); |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 1542 | wl_resource_for_each(resource, focus_resource_list) { |
| 1543 | wl_keyboard_send_leave(resource, serial, |
| 1544 | keyboard->focus->resource); |
| 1545 | } |
| 1546 | move_resources(&keyboard->resource_list, focus_resource_list); |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 1547 | } |
| 1548 | |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 1549 | if (find_resource_for_surface(&keyboard->resource_list, surface) && |
| 1550 | keyboard->focus != surface) { |
| 1551 | struct wl_client *surface_client = |
| 1552 | wl_resource_get_client(surface->resource); |
| 1553 | |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 1554 | serial = wl_display_next_serial(display); |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 1555 | |
| 1556 | move_resources_for_client(focus_resource_list, |
| 1557 | &keyboard->resource_list, |
| 1558 | surface_client); |
| 1559 | send_enter_to_resource_list(focus_resource_list, |
| 1560 | keyboard, |
| 1561 | surface, |
| 1562 | serial); |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 1563 | keyboard->focus_serial = serial; |
Giulio Camuffo | 65a07f8 | 2013-12-06 12:46:27 +0100 | [diff] [blame] | 1564 | } |
| 1565 | |
Quentin Glidic | 85d5554 | 2017-07-21 14:02:40 +0200 | [diff] [blame] | 1566 | if (seat->saved_kbd_focus) { |
| 1567 | wl_list_remove(&seat->saved_kbd_focus_listener.link); |
| 1568 | seat->saved_kbd_focus = NULL; |
| 1569 | } |
| 1570 | |
Giulio Camuffo | 65a07f8 | 2013-12-06 12:46:27 +0100 | [diff] [blame] | 1571 | wl_list_remove(&keyboard->focus_resource_listener.link); |
| 1572 | wl_list_init(&keyboard->focus_resource_listener.link); |
Pekka Paalanen | 72e183b | 2018-02-22 16:55:15 +0200 | [diff] [blame] | 1573 | if (surface) |
Giulio Camuffo | 576fe2a | 2013-11-20 18:00:24 +0100 | [diff] [blame] | 1574 | wl_resource_add_destroy_listener(surface->resource, |
| 1575 | &keyboard->focus_resource_listener); |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 1576 | |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 1577 | keyboard->focus = surface; |
| 1578 | wl_signal_emit(&keyboard->focus_signal, keyboard); |
| 1579 | } |
| 1580 | |
Giulio Camuffo | a20ca81 | 2014-11-22 11:16:56 +0200 | [diff] [blame] | 1581 | /* Users of this function must manually manage the keyboard focus */ |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 1582 | WL_EXPORT void |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 1583 | weston_keyboard_start_grab(struct weston_keyboard *keyboard, |
| 1584 | struct weston_keyboard_grab *grab) |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 1585 | { |
| 1586 | keyboard->grab = grab; |
| 1587 | grab->keyboard = keyboard; |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 1588 | } |
| 1589 | |
| 1590 | WL_EXPORT void |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 1591 | weston_keyboard_end_grab(struct weston_keyboard *keyboard) |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 1592 | { |
| 1593 | keyboard->grab = &keyboard->default_grab; |
| 1594 | } |
| 1595 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1596 | static void |
| 1597 | weston_keyboard_cancel_grab(struct weston_keyboard *keyboard) |
| 1598 | { |
| 1599 | keyboard->grab->interface->cancel(keyboard->grab); |
| 1600 | } |
| 1601 | |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 1602 | WL_EXPORT void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1603 | weston_pointer_start_grab(struct weston_pointer *pointer, |
| 1604 | struct weston_pointer_grab *grab) |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 1605 | { |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 1606 | pointer->grab = grab; |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 1607 | grab->pointer = pointer; |
Kristian Høgsberg | da751b8 | 2013-07-04 00:58:07 -0400 | [diff] [blame] | 1608 | pointer->grab->interface->focus(pointer->grab); |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 1609 | } |
| 1610 | |
| 1611 | WL_EXPORT void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1612 | weston_pointer_end_grab(struct weston_pointer *pointer) |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 1613 | { |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 1614 | pointer->grab = &pointer->default_grab; |
Kristian Høgsberg | da751b8 | 2013-07-04 00:58:07 -0400 | [diff] [blame] | 1615 | pointer->grab->interface->focus(pointer->grab); |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 1616 | } |
| 1617 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1618 | static void |
| 1619 | weston_pointer_cancel_grab(struct weston_pointer *pointer) |
| 1620 | { |
| 1621 | pointer->grab->interface->cancel(pointer->grab); |
| 1622 | } |
| 1623 | |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 1624 | WL_EXPORT void |
Kristian Høgsberg | e329f36 | 2013-05-06 22:19:57 -0400 | [diff] [blame] | 1625 | 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] | 1626 | { |
| 1627 | touch->grab = grab; |
| 1628 | grab->touch = touch; |
| 1629 | } |
| 1630 | |
| 1631 | WL_EXPORT void |
Kristian Høgsberg | e329f36 | 2013-05-06 22:19:57 -0400 | [diff] [blame] | 1632 | weston_touch_end_grab(struct weston_touch *touch) |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 1633 | { |
| 1634 | touch->grab = &touch->default_grab; |
| 1635 | } |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1636 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1637 | static void |
| 1638 | weston_touch_cancel_grab(struct weston_touch *touch) |
| 1639 | { |
| 1640 | touch->grab->interface->cancel(touch->grab); |
| 1641 | } |
| 1642 | |
Ander Conselvan de Oliveira | 54e90c7 | 2013-12-13 22:10:56 +0200 | [diff] [blame] | 1643 | static void |
| 1644 | weston_pointer_clamp_for_output(struct weston_pointer *pointer, |
| 1645 | struct weston_output *output, |
| 1646 | wl_fixed_t *fx, wl_fixed_t *fy) |
| 1647 | { |
| 1648 | int x, y; |
| 1649 | |
| 1650 | x = wl_fixed_to_int(*fx); |
| 1651 | y = wl_fixed_to_int(*fy); |
| 1652 | |
| 1653 | if (x < output->x) |
| 1654 | *fx = wl_fixed_from_int(output->x); |
| 1655 | else if (x >= output->x + output->width) |
| 1656 | *fx = wl_fixed_from_int(output->x + |
| 1657 | output->width - 1); |
| 1658 | if (y < output->y) |
| 1659 | *fy = wl_fixed_from_int(output->y); |
| 1660 | else if (y >= output->y + output->height) |
| 1661 | *fy = wl_fixed_from_int(output->y + |
| 1662 | output->height - 1); |
| 1663 | } |
| 1664 | |
Rob Bradford | 806d8c0 | 2013-06-25 18:56:41 +0100 | [diff] [blame] | 1665 | WL_EXPORT void |
| 1666 | weston_pointer_clamp(struct weston_pointer *pointer, wl_fixed_t *fx, wl_fixed_t *fy) |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1667 | { |
Rob Bradford | 806d8c0 | 2013-06-25 18:56:41 +0100 | [diff] [blame] | 1668 | struct weston_compositor *ec = pointer->seat->compositor; |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1669 | struct weston_output *output, *prev = NULL; |
| 1670 | int x, y, old_x, old_y, valid = 0; |
| 1671 | |
| 1672 | x = wl_fixed_to_int(*fx); |
| 1673 | y = wl_fixed_to_int(*fy); |
Rob Bradford | 806d8c0 | 2013-06-25 18:56:41 +0100 | [diff] [blame] | 1674 | old_x = wl_fixed_to_int(pointer->x); |
| 1675 | old_y = wl_fixed_to_int(pointer->y); |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1676 | |
| 1677 | wl_list_for_each(output, &ec->output_list, link) { |
Rob Bradford | 66bd9f5 | 2013-06-25 18:56:42 +0100 | [diff] [blame] | 1678 | if (pointer->seat->output && pointer->seat->output != output) |
| 1679 | continue; |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1680 | if (pixman_region32_contains_point(&output->region, |
| 1681 | x, y, NULL)) |
| 1682 | valid = 1; |
| 1683 | if (pixman_region32_contains_point(&output->region, |
| 1684 | old_x, old_y, NULL)) |
| 1685 | prev = output; |
| 1686 | } |
| 1687 | |
Rob Bradford | 66bd9f5 | 2013-06-25 18:56:42 +0100 | [diff] [blame] | 1688 | if (!prev) |
| 1689 | prev = pointer->seat->output; |
| 1690 | |
Ander Conselvan de Oliveira | 54e90c7 | 2013-12-13 22:10:56 +0200 | [diff] [blame] | 1691 | if (prev && !valid) |
| 1692 | weston_pointer_clamp_for_output(pointer, prev, fx, fy); |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1693 | } |
| 1694 | |
Jonas Ådahl | d251010 | 2014-10-05 21:39:14 +0200 | [diff] [blame] | 1695 | static void |
| 1696 | weston_pointer_move_to(struct weston_pointer *pointer, |
| 1697 | wl_fixed_t x, wl_fixed_t y) |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1698 | { |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1699 | int32_t ix, iy; |
| 1700 | |
Rob Bradford | 806d8c0 | 2013-06-25 18:56:41 +0100 | [diff] [blame] | 1701 | weston_pointer_clamp (pointer, &x, &y); |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1702 | |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1703 | pointer->x = x; |
| 1704 | pointer->y = y; |
| 1705 | |
| 1706 | ix = wl_fixed_to_int(x); |
| 1707 | iy = wl_fixed_to_int(y); |
| 1708 | |
Kristian Høgsberg | 195b869 | 2013-05-08 15:02:05 -0400 | [diff] [blame] | 1709 | if (pointer->sprite) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1710 | weston_view_set_position(pointer->sprite, |
| 1711 | ix - pointer->hotspot_x, |
| 1712 | iy - pointer->hotspot_y); |
| 1713 | weston_view_schedule_repaint(pointer->sprite); |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1714 | } |
Giulio Camuffo | 6fcb378 | 2013-11-14 23:42:50 +0100 | [diff] [blame] | 1715 | |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 1716 | pointer->grab->interface->focus(pointer->grab); |
Giulio Camuffo | 6fcb378 | 2013-11-14 23:42:50 +0100 | [diff] [blame] | 1717 | wl_signal_emit(&pointer->motion_signal, pointer); |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1718 | } |
| 1719 | |
Jonas Ådahl | d251010 | 2014-10-05 21:39:14 +0200 | [diff] [blame] | 1720 | WL_EXPORT void |
Jonas Ådahl | d251010 | 2014-10-05 21:39:14 +0200 | [diff] [blame] | 1721 | weston_pointer_move(struct weston_pointer *pointer, |
| 1722 | struct weston_pointer_motion_event *event) |
| 1723 | { |
| 1724 | wl_fixed_t x, y; |
| 1725 | |
| 1726 | weston_pointer_motion_to_abs(pointer, event, &x, &y); |
| 1727 | weston_pointer_move_to(pointer, x, y); |
| 1728 | } |
| 1729 | |
Ander Conselvan de Oliveira | 54e90c7 | 2013-12-13 22:10:56 +0200 | [diff] [blame] | 1730 | /** Verify if the pointer is in a valid position and move it if it isn't. |
| 1731 | */ |
Ander Conselvan de Oliveira | f84327a | 2014-01-29 18:47:51 +0200 | [diff] [blame] | 1732 | static void |
| 1733 | weston_pointer_handle_output_destroy(struct wl_listener *listener, void *data) |
Ander Conselvan de Oliveira | 54e90c7 | 2013-12-13 22:10:56 +0200 | [diff] [blame] | 1734 | { |
Ander Conselvan de Oliveira | f84327a | 2014-01-29 18:47:51 +0200 | [diff] [blame] | 1735 | struct weston_pointer *pointer; |
| 1736 | struct weston_compositor *ec; |
Ander Conselvan de Oliveira | 54e90c7 | 2013-12-13 22:10:56 +0200 | [diff] [blame] | 1737 | struct weston_output *output, *closest = NULL; |
| 1738 | int x, y, distance, min = INT_MAX; |
| 1739 | wl_fixed_t fx, fy; |
| 1740 | |
Ander Conselvan de Oliveira | f84327a | 2014-01-29 18:47:51 +0200 | [diff] [blame] | 1741 | pointer = container_of(listener, struct weston_pointer, |
| 1742 | output_destroy_listener); |
| 1743 | ec = pointer->seat->compositor; |
| 1744 | |
Ander Conselvan de Oliveira | 54e90c7 | 2013-12-13 22:10:56 +0200 | [diff] [blame] | 1745 | x = wl_fixed_to_int(pointer->x); |
| 1746 | y = wl_fixed_to_int(pointer->y); |
| 1747 | |
| 1748 | wl_list_for_each(output, &ec->output_list, link) { |
| 1749 | if (pixman_region32_contains_point(&output->region, |
| 1750 | x, y, NULL)) |
| 1751 | return; |
| 1752 | |
| 1753 | /* Aproximante the distance from the pointer to the center of |
| 1754 | * the output. */ |
| 1755 | distance = abs(output->x + output->width / 2 - x) + |
| 1756 | abs(output->y + output->height / 2 - y); |
| 1757 | if (distance < min) { |
| 1758 | min = distance; |
| 1759 | closest = output; |
| 1760 | } |
| 1761 | } |
| 1762 | |
| 1763 | /* Nothing to do if there's no output left. */ |
| 1764 | if (!closest) |
| 1765 | return; |
| 1766 | |
| 1767 | fx = pointer->x; |
| 1768 | fy = pointer->y; |
| 1769 | |
| 1770 | weston_pointer_clamp_for_output(pointer, closest, &fx, &fy); |
Jonas Ådahl | d251010 | 2014-10-05 21:39:14 +0200 | [diff] [blame] | 1771 | weston_pointer_move_to(pointer, fx, fy); |
Ander Conselvan de Oliveira | 54e90c7 | 2013-12-13 22:10:56 +0200 | [diff] [blame] | 1772 | } |
| 1773 | |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1774 | WL_EXPORT void |
| 1775 | notify_motion(struct weston_seat *seat, |
Alexandros Frantzis | 84b31f8 | 2017-11-24 18:01:46 +0200 | [diff] [blame] | 1776 | const struct timespec *time, |
Jonas Ådahl | d251010 | 2014-10-05 21:39:14 +0200 | [diff] [blame] | 1777 | struct weston_pointer_motion_event *event) |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1778 | { |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1779 | struct weston_compositor *ec = seat->compositor; |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 1780 | struct weston_pointer *pointer = weston_seat_get_pointer(seat); |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1781 | |
| 1782 | weston_compositor_wake(ec); |
Jonas Ådahl | d251010 | 2014-10-05 21:39:14 +0200 | [diff] [blame] | 1783 | pointer->grab->interface->motion(pointer->grab, time, event); |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1784 | } |
| 1785 | |
Daniel Stone | 96d47c0 | 2013-11-19 11:37:12 +0100 | [diff] [blame] | 1786 | static void |
| 1787 | run_modifier_bindings(struct weston_seat *seat, uint32_t old, uint32_t new) |
| 1788 | { |
| 1789 | struct weston_compositor *compositor = seat->compositor; |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 1790 | struct weston_keyboard *keyboard = weston_seat_get_keyboard(seat); |
Daniel Stone | 96d47c0 | 2013-11-19 11:37:12 +0100 | [diff] [blame] | 1791 | uint32_t diff; |
| 1792 | unsigned int i; |
| 1793 | struct { |
| 1794 | uint32_t xkb; |
| 1795 | enum weston_keyboard_modifier weston; |
| 1796 | } mods[] = { |
Jonas Ådahl | 7395ea0 | 2013-12-03 09:14:26 +0100 | [diff] [blame] | 1797 | { keyboard->xkb_info->ctrl_mod, MODIFIER_CTRL }, |
| 1798 | { keyboard->xkb_info->alt_mod, MODIFIER_ALT }, |
| 1799 | { keyboard->xkb_info->super_mod, MODIFIER_SUPER }, |
| 1800 | { keyboard->xkb_info->shift_mod, MODIFIER_SHIFT }, |
Daniel Stone | 96d47c0 | 2013-11-19 11:37:12 +0100 | [diff] [blame] | 1801 | }; |
| 1802 | |
| 1803 | diff = new & ~old; |
| 1804 | for (i = 0; i < ARRAY_LENGTH(mods); i++) { |
| 1805 | if (diff & (1 << mods[i].xkb)) |
| 1806 | weston_compositor_run_modifier_binding(compositor, |
Derek Foreman | 99a6a2d | 2015-07-15 13:00:43 -0500 | [diff] [blame] | 1807 | keyboard, |
Daniel Stone | 96d47c0 | 2013-11-19 11:37:12 +0100 | [diff] [blame] | 1808 | mods[i].weston, |
| 1809 | WL_KEYBOARD_KEY_STATE_PRESSED); |
| 1810 | } |
| 1811 | |
| 1812 | diff = old & ~new; |
| 1813 | for (i = 0; i < ARRAY_LENGTH(mods); i++) { |
| 1814 | if (diff & (1 << mods[i].xkb)) |
| 1815 | weston_compositor_run_modifier_binding(compositor, |
Derek Foreman | 99a6a2d | 2015-07-15 13:00:43 -0500 | [diff] [blame] | 1816 | keyboard, |
Daniel Stone | 96d47c0 | 2013-11-19 11:37:12 +0100 | [diff] [blame] | 1817 | mods[i].weston, |
| 1818 | WL_KEYBOARD_KEY_STATE_RELEASED); |
| 1819 | } |
| 1820 | } |
| 1821 | |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1822 | WL_EXPORT void |
Alexandros Frantzis | 84b31f8 | 2017-11-24 18:01:46 +0200 | [diff] [blame] | 1823 | notify_motion_absolute(struct weston_seat *seat, const struct timespec *time, |
| 1824 | double x, double y) |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1825 | { |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1826 | struct weston_compositor *ec = seat->compositor; |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 1827 | struct weston_pointer *pointer = weston_seat_get_pointer(seat); |
Jonas Ådahl | d251010 | 2014-10-05 21:39:14 +0200 | [diff] [blame] | 1828 | struct weston_pointer_motion_event event = { 0 }; |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1829 | |
| 1830 | weston_compositor_wake(ec); |
Jonas Ådahl | d251010 | 2014-10-05 21:39:14 +0200 | [diff] [blame] | 1831 | |
| 1832 | event = (struct weston_pointer_motion_event) { |
| 1833 | .mask = WESTON_POINTER_MOTION_ABS, |
Giulio Camuffo | 90a6fc6 | 2016-03-22 17:44:54 +0200 | [diff] [blame] | 1834 | .x = x, |
| 1835 | .y = y, |
Jonas Ådahl | d251010 | 2014-10-05 21:39:14 +0200 | [diff] [blame] | 1836 | }; |
| 1837 | |
| 1838 | pointer->grab->interface->motion(pointer->grab, time, &event); |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1839 | } |
| 1840 | |
Jonas Ådahl | 94e2e2d | 2014-10-18 18:42:19 +0200 | [diff] [blame] | 1841 | static unsigned int |
| 1842 | peek_next_activate_serial(struct weston_compositor *c) |
| 1843 | { |
| 1844 | unsigned serial = c->activate_serial + 1; |
| 1845 | |
| 1846 | return serial == 0 ? 1 : serial; |
| 1847 | } |
| 1848 | |
| 1849 | static void |
| 1850 | inc_activate_serial(struct weston_compositor *c) |
| 1851 | { |
| 1852 | c->activate_serial = peek_next_activate_serial (c); |
| 1853 | } |
| 1854 | |
| 1855 | WL_EXPORT void |
| 1856 | weston_view_activate(struct weston_view *view, |
| 1857 | struct weston_seat *seat, |
| 1858 | uint32_t flags) |
| 1859 | { |
| 1860 | struct weston_compositor *compositor = seat->compositor; |
| 1861 | |
| 1862 | if (flags & WESTON_ACTIVATE_FLAG_CLICKED) { |
| 1863 | view->click_to_activate_serial = |
| 1864 | peek_next_activate_serial(compositor); |
| 1865 | } |
| 1866 | |
| 1867 | weston_seat_set_keyboard_focus(seat, view->surface); |
| 1868 | } |
| 1869 | |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1870 | WL_EXPORT void |
Alexandros Frantzis | 215bedc | 2017-11-16 18:20:55 +0200 | [diff] [blame] | 1871 | notify_button(struct weston_seat *seat, const struct timespec *time, |
| 1872 | int32_t button, enum wl_pointer_button_state state) |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1873 | { |
| 1874 | struct weston_compositor *compositor = seat->compositor; |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 1875 | struct weston_pointer *pointer = weston_seat_get_pointer(seat); |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1876 | |
| 1877 | if (state == WL_POINTER_BUTTON_STATE_PRESSED) { |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1878 | weston_compositor_idle_inhibit(compositor); |
| 1879 | if (pointer->button_count == 0) { |
| 1880 | pointer->grab_button = button; |
Alexandros Frantzis | 215bedc | 2017-11-16 18:20:55 +0200 | [diff] [blame] | 1881 | pointer->grab_time = *time; |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1882 | pointer->grab_x = pointer->x; |
| 1883 | pointer->grab_y = pointer->y; |
| 1884 | } |
| 1885 | pointer->button_count++; |
| 1886 | } else { |
| 1887 | weston_compositor_idle_release(compositor); |
| 1888 | pointer->button_count--; |
| 1889 | } |
| 1890 | |
Derek Foreman | 99a6a2d | 2015-07-15 13:00:43 -0500 | [diff] [blame] | 1891 | weston_compositor_run_button_binding(compositor, pointer, time, button, |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1892 | state); |
| 1893 | |
| 1894 | pointer->grab->interface->button(pointer->grab, time, button, state); |
| 1895 | |
| 1896 | if (pointer->button_count == 1) |
| 1897 | pointer->grab_serial = |
| 1898 | wl_display_get_serial(compositor->wl_display); |
| 1899 | } |
| 1900 | |
| 1901 | WL_EXPORT void |
Alexandros Frantzis | 8032194 | 2017-11-16 18:20:56 +0200 | [diff] [blame] | 1902 | notify_axis(struct weston_seat *seat, const struct timespec *time, |
Peter Hutterer | 89b6a49 | 2016-01-18 15:58:17 +1000 | [diff] [blame] | 1903 | struct weston_pointer_axis_event *event) |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1904 | { |
| 1905 | struct weston_compositor *compositor = seat->compositor; |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 1906 | struct weston_pointer *pointer = weston_seat_get_pointer(seat); |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1907 | |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1908 | weston_compositor_wake(compositor); |
| 1909 | |
Derek Foreman | 99a6a2d | 2015-07-15 13:00:43 -0500 | [diff] [blame] | 1910 | if (weston_compositor_run_axis_binding(compositor, pointer, |
Peter Hutterer | 89b6a49 | 2016-01-18 15:58:17 +1000 | [diff] [blame] | 1911 | time, event)) |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1912 | return; |
| 1913 | |
Peter Hutterer | 89b6a49 | 2016-01-18 15:58:17 +1000 | [diff] [blame] | 1914 | pointer->grab->interface->axis(pointer->grab, time, event); |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1915 | } |
| 1916 | |
Peter Hutterer | 87743e9 | 2016-01-18 16:38:22 +1000 | [diff] [blame] | 1917 | WL_EXPORT void |
| 1918 | notify_axis_source(struct weston_seat *seat, uint32_t source) |
| 1919 | { |
| 1920 | struct weston_compositor *compositor = seat->compositor; |
| 1921 | struct weston_pointer *pointer = weston_seat_get_pointer(seat); |
| 1922 | |
| 1923 | weston_compositor_wake(compositor); |
| 1924 | |
| 1925 | pointer->grab->interface->axis_source(pointer->grab, source); |
| 1926 | } |
| 1927 | |
| 1928 | WL_EXPORT void |
| 1929 | notify_pointer_frame(struct weston_seat *seat) |
| 1930 | { |
| 1931 | struct weston_compositor *compositor = seat->compositor; |
| 1932 | struct weston_pointer *pointer = weston_seat_get_pointer(seat); |
| 1933 | |
| 1934 | weston_compositor_wake(compositor); |
| 1935 | |
| 1936 | pointer->grab->interface->frame(pointer->grab); |
| 1937 | } |
| 1938 | |
Giulio Camuffo | 6ef444d | 2014-08-28 19:44:09 +0300 | [diff] [blame] | 1939 | WL_EXPORT int |
| 1940 | weston_keyboard_set_locks(struct weston_keyboard *keyboard, |
| 1941 | uint32_t mask, uint32_t value) |
| 1942 | { |
Giulio Camuffo | 6ef444d | 2014-08-28 19:44:09 +0300 | [diff] [blame] | 1943 | uint32_t serial; |
| 1944 | xkb_mod_mask_t mods_depressed, mods_latched, mods_locked, group; |
| 1945 | xkb_mod_mask_t num, caps; |
| 1946 | |
| 1947 | /* We don't want the leds to go out of sync with the actual state |
| 1948 | * so if the backend has no way to change the leds don't try to |
| 1949 | * change the state */ |
| 1950 | if (!keyboard->seat->led_update) |
| 1951 | return -1; |
| 1952 | |
| 1953 | mods_depressed = xkb_state_serialize_mods(keyboard->xkb_state.state, |
| 1954 | XKB_STATE_DEPRESSED); |
| 1955 | mods_latched = xkb_state_serialize_mods(keyboard->xkb_state.state, |
| 1956 | XKB_STATE_LATCHED); |
| 1957 | mods_locked = xkb_state_serialize_mods(keyboard->xkb_state.state, |
| 1958 | XKB_STATE_LOCKED); |
| 1959 | group = xkb_state_serialize_group(keyboard->xkb_state.state, |
| 1960 | XKB_STATE_EFFECTIVE); |
| 1961 | |
| 1962 | num = (1 << keyboard->xkb_info->mod2_mod); |
| 1963 | caps = (1 << keyboard->xkb_info->caps_mod); |
| 1964 | if (mask & WESTON_NUM_LOCK) { |
| 1965 | if (value & WESTON_NUM_LOCK) |
| 1966 | mods_locked |= num; |
| 1967 | else |
| 1968 | mods_locked &= ~num; |
| 1969 | } |
| 1970 | if (mask & WESTON_CAPS_LOCK) { |
| 1971 | if (value & WESTON_CAPS_LOCK) |
| 1972 | mods_locked |= caps; |
| 1973 | else |
| 1974 | mods_locked &= ~caps; |
| 1975 | } |
| 1976 | |
| 1977 | xkb_state_update_mask(keyboard->xkb_state.state, mods_depressed, |
| 1978 | mods_latched, mods_locked, 0, 0, group); |
| 1979 | |
| 1980 | serial = wl_display_next_serial( |
| 1981 | keyboard->seat->compositor->wl_display); |
| 1982 | notify_modifiers(keyboard->seat, serial); |
| 1983 | |
| 1984 | return 0; |
Giulio Camuffo | 6ef444d | 2014-08-28 19:44:09 +0300 | [diff] [blame] | 1985 | } |
| 1986 | |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1987 | WL_EXPORT void |
| 1988 | notify_modifiers(struct weston_seat *seat, uint32_t serial) |
| 1989 | { |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 1990 | struct weston_keyboard *keyboard = weston_seat_get_keyboard(seat); |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 1991 | struct weston_keyboard_grab *grab = keyboard->grab; |
| 1992 | uint32_t mods_depressed, mods_latched, mods_locked, group; |
| 1993 | uint32_t mods_lookup; |
| 1994 | enum weston_led leds = 0; |
| 1995 | int changed = 0; |
| 1996 | |
| 1997 | /* Serialize and update our internal state, checking to see if it's |
| 1998 | * different to the previous state. */ |
Jonas Ådahl | 7395ea0 | 2013-12-03 09:14:26 +0100 | [diff] [blame] | 1999 | mods_depressed = xkb_state_serialize_mods(keyboard->xkb_state.state, |
Ran Benita | 2e1968f | 2014-08-19 23:59:51 +0300 | [diff] [blame] | 2000 | XKB_STATE_MODS_DEPRESSED); |
Jonas Ådahl | 7395ea0 | 2013-12-03 09:14:26 +0100 | [diff] [blame] | 2001 | mods_latched = xkb_state_serialize_mods(keyboard->xkb_state.state, |
Ran Benita | 2e1968f | 2014-08-19 23:59:51 +0300 | [diff] [blame] | 2002 | XKB_STATE_MODS_LATCHED); |
Jonas Ådahl | 7395ea0 | 2013-12-03 09:14:26 +0100 | [diff] [blame] | 2003 | mods_locked = xkb_state_serialize_mods(keyboard->xkb_state.state, |
Ran Benita | 2e1968f | 2014-08-19 23:59:51 +0300 | [diff] [blame] | 2004 | XKB_STATE_MODS_LOCKED); |
| 2005 | group = xkb_state_serialize_layout(keyboard->xkb_state.state, |
| 2006 | XKB_STATE_LAYOUT_EFFECTIVE); |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 2007 | |
Derek Foreman | 244e99e | 2015-06-03 15:53:26 -0500 | [diff] [blame] | 2008 | if (mods_depressed != keyboard->modifiers.mods_depressed || |
| 2009 | mods_latched != keyboard->modifiers.mods_latched || |
| 2010 | mods_locked != keyboard->modifiers.mods_locked || |
| 2011 | group != keyboard->modifiers.group) |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 2012 | changed = 1; |
| 2013 | |
Derek Foreman | 244e99e | 2015-06-03 15:53:26 -0500 | [diff] [blame] | 2014 | run_modifier_bindings(seat, keyboard->modifiers.mods_depressed, |
Daniel Stone | 96d47c0 | 2013-11-19 11:37:12 +0100 | [diff] [blame] | 2015 | mods_depressed); |
| 2016 | |
Derek Foreman | 244e99e | 2015-06-03 15:53:26 -0500 | [diff] [blame] | 2017 | keyboard->modifiers.mods_depressed = mods_depressed; |
| 2018 | keyboard->modifiers.mods_latched = mods_latched; |
| 2019 | keyboard->modifiers.mods_locked = mods_locked; |
| 2020 | keyboard->modifiers.group = group; |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 2021 | |
| 2022 | /* And update the modifier_state for bindings. */ |
| 2023 | mods_lookup = mods_depressed | mods_latched; |
| 2024 | seat->modifier_state = 0; |
Jonas Ådahl | 7395ea0 | 2013-12-03 09:14:26 +0100 | [diff] [blame] | 2025 | if (mods_lookup & (1 << keyboard->xkb_info->ctrl_mod)) |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 2026 | seat->modifier_state |= MODIFIER_CTRL; |
Jonas Ådahl | 7395ea0 | 2013-12-03 09:14:26 +0100 | [diff] [blame] | 2027 | if (mods_lookup & (1 << keyboard->xkb_info->alt_mod)) |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 2028 | seat->modifier_state |= MODIFIER_ALT; |
Jonas Ådahl | 7395ea0 | 2013-12-03 09:14:26 +0100 | [diff] [blame] | 2029 | if (mods_lookup & (1 << keyboard->xkb_info->super_mod)) |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 2030 | seat->modifier_state |= MODIFIER_SUPER; |
Jonas Ådahl | 7395ea0 | 2013-12-03 09:14:26 +0100 | [diff] [blame] | 2031 | if (mods_lookup & (1 << keyboard->xkb_info->shift_mod)) |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 2032 | seat->modifier_state |= MODIFIER_SHIFT; |
| 2033 | |
| 2034 | /* Finally, notify the compositor that LEDs have changed. */ |
Jonas Ådahl | 7395ea0 | 2013-12-03 09:14:26 +0100 | [diff] [blame] | 2035 | if (xkb_state_led_index_is_active(keyboard->xkb_state.state, |
| 2036 | keyboard->xkb_info->num_led)) |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 2037 | leds |= LED_NUM_LOCK; |
Jonas Ådahl | 7395ea0 | 2013-12-03 09:14:26 +0100 | [diff] [blame] | 2038 | if (xkb_state_led_index_is_active(keyboard->xkb_state.state, |
| 2039 | keyboard->xkb_info->caps_led)) |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 2040 | leds |= LED_CAPS_LOCK; |
Jonas Ådahl | 7395ea0 | 2013-12-03 09:14:26 +0100 | [diff] [blame] | 2041 | if (xkb_state_led_index_is_active(keyboard->xkb_state.state, |
| 2042 | keyboard->xkb_info->scroll_led)) |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 2043 | leds |= LED_SCROLL_LOCK; |
Jonas Ådahl | 7395ea0 | 2013-12-03 09:14:26 +0100 | [diff] [blame] | 2044 | if (leds != keyboard->xkb_state.leds && seat->led_update) |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 2045 | seat->led_update(seat, leds); |
Jonas Ådahl | 7395ea0 | 2013-12-03 09:14:26 +0100 | [diff] [blame] | 2046 | keyboard->xkb_state.leds = leds; |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 2047 | |
| 2048 | if (changed) { |
| 2049 | grab->interface->modifiers(grab, |
| 2050 | serial, |
| 2051 | keyboard->modifiers.mods_depressed, |
| 2052 | keyboard->modifiers.mods_latched, |
| 2053 | keyboard->modifiers.mods_locked, |
| 2054 | keyboard->modifiers.group); |
| 2055 | } |
| 2056 | } |
| 2057 | |
| 2058 | static void |
| 2059 | update_modifier_state(struct weston_seat *seat, uint32_t serial, uint32_t key, |
| 2060 | enum wl_keyboard_key_state state) |
| 2061 | { |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 2062 | struct weston_keyboard *keyboard = weston_seat_get_keyboard(seat); |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 2063 | enum xkb_key_direction direction; |
| 2064 | |
| 2065 | if (state == WL_KEYBOARD_KEY_STATE_PRESSED) |
| 2066 | direction = XKB_KEY_DOWN; |
| 2067 | else |
| 2068 | direction = XKB_KEY_UP; |
| 2069 | |
| 2070 | /* Offset the keycode by 8, as the evdev XKB rules reflect X's |
| 2071 | * broken keycode system, which starts at 8. */ |
Jonas Ådahl | 7395ea0 | 2013-12-03 09:14:26 +0100 | [diff] [blame] | 2072 | xkb_state_update_key(keyboard->xkb_state.state, key + 8, direction); |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 2073 | |
| 2074 | notify_modifiers(seat, serial); |
| 2075 | } |
Rui Matos | 65196bc | 2013-10-10 19:44:19 +0200 | [diff] [blame] | 2076 | |
| 2077 | static void |
| 2078 | send_keymap(struct wl_resource *resource, struct weston_xkb_info *xkb_info) |
| 2079 | { |
| 2080 | wl_keyboard_send_keymap(resource, |
| 2081 | WL_KEYBOARD_KEYMAP_FORMAT_XKB_V1, |
| 2082 | xkb_info->keymap_fd, |
| 2083 | xkb_info->keymap_size); |
| 2084 | } |
| 2085 | |
| 2086 | static void |
| 2087 | send_modifiers(struct wl_resource *resource, uint32_t serial, struct weston_keyboard *keyboard) |
| 2088 | { |
| 2089 | wl_keyboard_send_modifiers(resource, serial, |
| 2090 | keyboard->modifiers.mods_depressed, |
| 2091 | keyboard->modifiers.mods_latched, |
| 2092 | keyboard->modifiers.mods_locked, |
| 2093 | keyboard->modifiers.group); |
| 2094 | } |
| 2095 | |
| 2096 | static struct weston_xkb_info * |
| 2097 | weston_xkb_info_create(struct xkb_keymap *keymap); |
Rui Matos | 65196bc | 2013-10-10 19:44:19 +0200 | [diff] [blame] | 2098 | |
| 2099 | static void |
| 2100 | update_keymap(struct weston_seat *seat) |
| 2101 | { |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 2102 | struct weston_keyboard *keyboard = weston_seat_get_keyboard(seat); |
Rui Matos | 65196bc | 2013-10-10 19:44:19 +0200 | [diff] [blame] | 2103 | struct wl_resource *resource; |
| 2104 | struct weston_xkb_info *xkb_info; |
| 2105 | struct xkb_state *state; |
| 2106 | xkb_mod_mask_t latched_mods; |
| 2107 | xkb_mod_mask_t locked_mods; |
| 2108 | |
Jonas Ådahl | 7395ea0 | 2013-12-03 09:14:26 +0100 | [diff] [blame] | 2109 | xkb_info = weston_xkb_info_create(keyboard->pending_keymap); |
Rui Matos | 65196bc | 2013-10-10 19:44:19 +0200 | [diff] [blame] | 2110 | |
Jonas Ådahl | 7395ea0 | 2013-12-03 09:14:26 +0100 | [diff] [blame] | 2111 | xkb_keymap_unref(keyboard->pending_keymap); |
| 2112 | keyboard->pending_keymap = NULL; |
Rui Matos | 65196bc | 2013-10-10 19:44:19 +0200 | [diff] [blame] | 2113 | |
| 2114 | if (!xkb_info) { |
| 2115 | weston_log("failed to create XKB info\n"); |
| 2116 | return; |
| 2117 | } |
| 2118 | |
| 2119 | state = xkb_state_new(xkb_info->keymap); |
| 2120 | if (!state) { |
| 2121 | weston_log("failed to initialise XKB state\n"); |
| 2122 | weston_xkb_info_destroy(xkb_info); |
| 2123 | return; |
| 2124 | } |
| 2125 | |
Jonas Ådahl | 7395ea0 | 2013-12-03 09:14:26 +0100 | [diff] [blame] | 2126 | latched_mods = xkb_state_serialize_mods(keyboard->xkb_state.state, |
| 2127 | XKB_STATE_MODS_LATCHED); |
| 2128 | locked_mods = xkb_state_serialize_mods(keyboard->xkb_state.state, |
| 2129 | XKB_STATE_MODS_LOCKED); |
Rui Matos | 65196bc | 2013-10-10 19:44:19 +0200 | [diff] [blame] | 2130 | xkb_state_update_mask(state, |
| 2131 | 0, /* depressed */ |
| 2132 | latched_mods, |
| 2133 | locked_mods, |
| 2134 | 0, 0, 0); |
| 2135 | |
Jonas Ådahl | 7395ea0 | 2013-12-03 09:14:26 +0100 | [diff] [blame] | 2136 | weston_xkb_info_destroy(keyboard->xkb_info); |
| 2137 | keyboard->xkb_info = xkb_info; |
Rui Matos | 65196bc | 2013-10-10 19:44:19 +0200 | [diff] [blame] | 2138 | |
Jonas Ådahl | 7395ea0 | 2013-12-03 09:14:26 +0100 | [diff] [blame] | 2139 | xkb_state_unref(keyboard->xkb_state.state); |
| 2140 | keyboard->xkb_state.state = state; |
Rui Matos | 65196bc | 2013-10-10 19:44:19 +0200 | [diff] [blame] | 2141 | |
Derek Foreman | bc91e54 | 2015-06-03 15:53:27 -0500 | [diff] [blame] | 2142 | wl_resource_for_each(resource, &keyboard->resource_list) |
Rui Matos | 65196bc | 2013-10-10 19:44:19 +0200 | [diff] [blame] | 2143 | send_keymap(resource, xkb_info); |
Derek Foreman | bc91e54 | 2015-06-03 15:53:27 -0500 | [diff] [blame] | 2144 | wl_resource_for_each(resource, &keyboard->focus_resource_list) |
Rui Matos | 65196bc | 2013-10-10 19:44:19 +0200 | [diff] [blame] | 2145 | send_keymap(resource, xkb_info); |
| 2146 | |
| 2147 | notify_modifiers(seat, wl_display_next_serial(seat->compositor->wl_display)); |
| 2148 | |
| 2149 | if (!latched_mods && !locked_mods) |
| 2150 | return; |
| 2151 | |
Derek Foreman | bc91e54 | 2015-06-03 15:53:27 -0500 | [diff] [blame] | 2152 | wl_resource_for_each(resource, &keyboard->resource_list) |
| 2153 | send_modifiers(resource, wl_display_get_serial(seat->compositor->wl_display), keyboard); |
| 2154 | wl_resource_for_each(resource, &keyboard->focus_resource_list) |
| 2155 | send_modifiers(resource, wl_display_get_serial(seat->compositor->wl_display), keyboard); |
Rui Matos | 65196bc | 2013-10-10 19:44:19 +0200 | [diff] [blame] | 2156 | } |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 2157 | |
| 2158 | WL_EXPORT void |
Alexandros Frantzis | 47e79c8 | 2017-11-16 18:20:57 +0200 | [diff] [blame] | 2159 | notify_key(struct weston_seat *seat, const struct timespec *time, uint32_t key, |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 2160 | enum wl_keyboard_key_state state, |
| 2161 | enum weston_key_state_update update_state) |
| 2162 | { |
| 2163 | struct weston_compositor *compositor = seat->compositor; |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 2164 | struct weston_keyboard *keyboard = weston_seat_get_keyboard(seat); |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 2165 | struct weston_keyboard_grab *grab = keyboard->grab; |
Pekka Paalanen | 86b5396 | 2014-11-19 13:43:32 +0200 | [diff] [blame] | 2166 | uint32_t *k, *end; |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 2167 | |
| 2168 | if (state == WL_KEYBOARD_KEY_STATE_PRESSED) { |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 2169 | weston_compositor_idle_inhibit(compositor); |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 2170 | } else { |
| 2171 | weston_compositor_idle_release(compositor); |
| 2172 | } |
| 2173 | |
Pekka Paalanen | 86b5396 | 2014-11-19 13:43:32 +0200 | [diff] [blame] | 2174 | end = keyboard->keys.data + keyboard->keys.size; |
| 2175 | for (k = keyboard->keys.data; k < end; k++) { |
| 2176 | if (*k == key) { |
| 2177 | /* Ignore server-generated repeats. */ |
| 2178 | if (state == WL_KEYBOARD_KEY_STATE_PRESSED) |
| 2179 | return; |
| 2180 | *k = *--end; |
| 2181 | } |
| 2182 | } |
| 2183 | keyboard->keys.size = (void *) end - keyboard->keys.data; |
| 2184 | if (state == WL_KEYBOARD_KEY_STATE_PRESSED) { |
| 2185 | k = wl_array_add(&keyboard->keys, sizeof *k); |
| 2186 | *k = key; |
| 2187 | } |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 2188 | |
| 2189 | if (grab == &keyboard->default_grab || |
| 2190 | grab == &keyboard->input_method_grab) { |
Derek Foreman | 99a6a2d | 2015-07-15 13:00:43 -0500 | [diff] [blame] | 2191 | weston_compositor_run_key_binding(compositor, keyboard, time, |
| 2192 | key, state); |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 2193 | grab = keyboard->grab; |
| 2194 | } |
| 2195 | |
| 2196 | grab->interface->key(grab, time, key, state); |
| 2197 | |
Jonas Ådahl | 7395ea0 | 2013-12-03 09:14:26 +0100 | [diff] [blame] | 2198 | if (keyboard->pending_keymap && |
Pekka Paalanen | 86b5396 | 2014-11-19 13:43:32 +0200 | [diff] [blame] | 2199 | keyboard->keys.size == 0) |
Rui Matos | 65196bc | 2013-10-10 19:44:19 +0200 | [diff] [blame] | 2200 | update_keymap(seat); |
| 2201 | |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 2202 | if (update_state == STATE_UPDATE_AUTOMATIC) { |
| 2203 | update_modifier_state(seat, |
| 2204 | wl_display_get_serial(compositor->wl_display), |
| 2205 | key, |
| 2206 | state); |
| 2207 | } |
Giulio Camuffo | b6ddf6c | 2015-02-06 19:06:54 +0200 | [diff] [blame] | 2208 | |
Olivier Fourdan | df84dbe | 2016-06-30 16:01:56 +0200 | [diff] [blame] | 2209 | keyboard->grab_serial = wl_display_get_serial(compositor->wl_display); |
Giulio Camuffo | b6ddf6c | 2015-02-06 19:06:54 +0200 | [diff] [blame] | 2210 | if (state == WL_KEYBOARD_KEY_STATE_PRESSED) { |
Alexandros Frantzis | 47e79c8 | 2017-11-16 18:20:57 +0200 | [diff] [blame] | 2211 | keyboard->grab_time = *time; |
Giulio Camuffo | b6ddf6c | 2015-02-06 19:06:54 +0200 | [diff] [blame] | 2212 | keyboard->grab_key = key; |
| 2213 | } |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 2214 | } |
| 2215 | |
| 2216 | WL_EXPORT void |
| 2217 | notify_pointer_focus(struct weston_seat *seat, struct weston_output *output, |
Giulio Camuffo | 90a6fc6 | 2016-03-22 17:44:54 +0200 | [diff] [blame] | 2218 | double x, double y) |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 2219 | { |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 2220 | struct weston_pointer *pointer = weston_seat_get_pointer(seat); |
| 2221 | |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 2222 | if (output) { |
Giulio Camuffo | 90a6fc6 | 2016-03-22 17:44:54 +0200 | [diff] [blame] | 2223 | weston_pointer_move_to(pointer, |
| 2224 | wl_fixed_from_double(x), |
| 2225 | wl_fixed_from_double(y)); |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 2226 | } else { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2227 | /* FIXME: We should call weston_pointer_set_focus(seat, |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 2228 | * NULL) here, but somehow that breaks re-entry... */ |
| 2229 | } |
| 2230 | } |
| 2231 | |
| 2232 | static void |
| 2233 | destroy_device_saved_kbd_focus(struct wl_listener *listener, void *data) |
| 2234 | { |
| 2235 | struct weston_seat *ws; |
| 2236 | |
| 2237 | ws = container_of(listener, struct weston_seat, |
| 2238 | saved_kbd_focus_listener); |
| 2239 | |
| 2240 | ws->saved_kbd_focus = NULL; |
| 2241 | } |
| 2242 | |
| 2243 | WL_EXPORT void |
| 2244 | notify_keyboard_focus_in(struct weston_seat *seat, struct wl_array *keys, |
| 2245 | enum weston_key_state_update update_state) |
| 2246 | { |
| 2247 | struct weston_compositor *compositor = seat->compositor; |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 2248 | struct weston_keyboard *keyboard = weston_seat_get_keyboard(seat); |
Kristian Høgsberg | fe7aa90 | 2013-05-08 09:54:37 -0400 | [diff] [blame] | 2249 | struct weston_surface *surface; |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 2250 | uint32_t *k, serial; |
| 2251 | |
| 2252 | serial = wl_display_next_serial(compositor->wl_display); |
| 2253 | wl_array_copy(&keyboard->keys, keys); |
| 2254 | wl_array_for_each(k, &keyboard->keys) { |
| 2255 | weston_compositor_idle_inhibit(compositor); |
| 2256 | if (update_state == STATE_UPDATE_AUTOMATIC) |
| 2257 | update_modifier_state(seat, serial, *k, |
| 2258 | WL_KEYBOARD_KEY_STATE_PRESSED); |
| 2259 | } |
| 2260 | |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 2261 | surface = seat->saved_kbd_focus; |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 2262 | if (surface) { |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 2263 | weston_keyboard_set_focus(keyboard, surface); |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 2264 | } |
| 2265 | } |
| 2266 | |
| 2267 | WL_EXPORT void |
| 2268 | notify_keyboard_focus_out(struct weston_seat *seat) |
| 2269 | { |
| 2270 | struct weston_compositor *compositor = seat->compositor; |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 2271 | struct weston_keyboard *keyboard = weston_seat_get_keyboard(seat); |
| 2272 | struct weston_pointer *pointer = weston_seat_get_pointer(seat); |
Quentin Glidic | 85d5554 | 2017-07-21 14:02:40 +0200 | [diff] [blame] | 2273 | struct weston_surface *focus = keyboard->focus; |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 2274 | uint32_t *k, serial; |
| 2275 | |
| 2276 | serial = wl_display_next_serial(compositor->wl_display); |
| 2277 | wl_array_for_each(k, &keyboard->keys) { |
| 2278 | weston_compositor_idle_release(compositor); |
| 2279 | update_modifier_state(seat, serial, *k, |
| 2280 | WL_KEYBOARD_KEY_STATE_RELEASED); |
| 2281 | } |
| 2282 | |
| 2283 | seat->modifier_state = 0; |
| 2284 | |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 2285 | weston_keyboard_set_focus(keyboard, NULL); |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 2286 | weston_keyboard_cancel_grab(keyboard); |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 2287 | if (pointer) |
| 2288 | weston_pointer_cancel_grab(pointer); |
Quentin Glidic | 85d5554 | 2017-07-21 14:02:40 +0200 | [diff] [blame] | 2289 | |
| 2290 | if (focus) { |
| 2291 | seat->saved_kbd_focus = focus; |
| 2292 | seat->saved_kbd_focus_listener.notify = |
| 2293 | destroy_device_saved_kbd_focus; |
| 2294 | wl_signal_add(&focus->destroy_signal, |
| 2295 | &seat->saved_kbd_focus_listener); |
| 2296 | } |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 2297 | } |
| 2298 | |
Michael Fu | a2bb791 | 2013-07-23 15:51:06 +0800 | [diff] [blame] | 2299 | WL_EXPORT void |
Derek Foreman | 4c93c08 | 2015-04-30 16:45:41 -0500 | [diff] [blame] | 2300 | weston_touch_set_focus(struct weston_touch *touch, struct weston_view *view) |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 2301 | { |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 2302 | struct wl_list *focus_resource_list; |
| 2303 | |
Derek Foreman | 4c93c08 | 2015-04-30 16:45:41 -0500 | [diff] [blame] | 2304 | focus_resource_list = &touch->focus_resource_list; |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 2305 | |
Derek Foreman | 4c93c08 | 2015-04-30 16:45:41 -0500 | [diff] [blame] | 2306 | if (view && touch->focus && |
| 2307 | touch->focus->surface == view->surface) { |
| 2308 | touch->focus = view; |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 2309 | return; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2310 | } |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 2311 | |
Derek Foreman | 4c93c08 | 2015-04-30 16:45:41 -0500 | [diff] [blame] | 2312 | wl_list_remove(&touch->focus_resource_listener.link); |
| 2313 | wl_list_init(&touch->focus_resource_listener.link); |
| 2314 | wl_list_remove(&touch->focus_view_listener.link); |
| 2315 | wl_list_init(&touch->focus_view_listener.link); |
Giulio Camuffo | 576fe2a | 2013-11-20 18:00:24 +0100 | [diff] [blame] | 2316 | |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 2317 | if (!wl_list_empty(focus_resource_list)) { |
Derek Foreman | 4c93c08 | 2015-04-30 16:45:41 -0500 | [diff] [blame] | 2318 | move_resources(&touch->resource_list, |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 2319 | focus_resource_list); |
| 2320 | } |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 2321 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2322 | if (view) { |
Derek Foreman | 362656b | 2014-09-04 10:23:05 -0500 | [diff] [blame] | 2323 | struct wl_client *surface_client; |
| 2324 | |
| 2325 | if (!view->surface->resource) { |
Derek Foreman | 4c93c08 | 2015-04-30 16:45:41 -0500 | [diff] [blame] | 2326 | touch->focus = NULL; |
Derek Foreman | 362656b | 2014-09-04 10:23:05 -0500 | [diff] [blame] | 2327 | return; |
| 2328 | } |
| 2329 | |
| 2330 | surface_client = wl_resource_get_client(view->surface->resource); |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 2331 | move_resources_for_client(focus_resource_list, |
Derek Foreman | 4c93c08 | 2015-04-30 16:45:41 -0500 | [diff] [blame] | 2332 | &touch->resource_list, |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 2333 | surface_client); |
Giulio Camuffo | 576fe2a | 2013-11-20 18:00:24 +0100 | [diff] [blame] | 2334 | wl_resource_add_destroy_listener(view->surface->resource, |
Derek Foreman | 4c93c08 | 2015-04-30 16:45:41 -0500 | [diff] [blame] | 2335 | &touch->focus_resource_listener); |
| 2336 | wl_signal_add(&view->destroy_signal, &touch->focus_view_listener); |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 2337 | } |
Derek Foreman | 4c93c08 | 2015-04-30 16:45:41 -0500 | [diff] [blame] | 2338 | touch->focus = view; |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 2339 | } |
| 2340 | |
| 2341 | /** |
| 2342 | * notify_touch - emulates button touches and notifies surfaces accordingly. |
| 2343 | * |
| 2344 | * It assumes always the correct cycle sequence until it gets here: touch_down |
| 2345 | * → touch_update → ... → touch_update → touch_end. The driver is responsible |
| 2346 | * for sending along such order. |
| 2347 | * |
| 2348 | */ |
| 2349 | WL_EXPORT void |
Alexandros Frantzis | 9448deb | 2017-11-16 18:20:58 +0200 | [diff] [blame] | 2350 | notify_touch(struct weston_seat *seat, const struct timespec *time, |
| 2351 | int touch_id, double double_x, double double_y, int touch_type) |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 2352 | { |
| 2353 | struct weston_compositor *ec = seat->compositor; |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 2354 | struct weston_touch *touch = weston_seat_get_touch(seat); |
Kristian Høgsberg | e329f36 | 2013-05-06 22:19:57 -0400 | [diff] [blame] | 2355 | struct weston_touch_grab *grab = touch->grab; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2356 | struct weston_view *ev; |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 2357 | wl_fixed_t sx, sy; |
Giulio Camuffo | 90a6fc6 | 2016-03-22 17:44:54 +0200 | [diff] [blame] | 2358 | wl_fixed_t x = wl_fixed_from_double(double_x); |
| 2359 | wl_fixed_t y = wl_fixed_from_double(double_y); |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 2360 | |
| 2361 | /* Update grab's global coordinates. */ |
Neil Roberts | 306fe08 | 2013-10-03 16:43:06 +0100 | [diff] [blame] | 2362 | if (touch_id == touch->grab_touch_id && touch_type != WL_TOUCH_UP) { |
| 2363 | touch->grab_x = x; |
| 2364 | touch->grab_y = y; |
| 2365 | } |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 2366 | |
| 2367 | switch (touch_type) { |
| 2368 | case WL_TOUCH_DOWN: |
| 2369 | weston_compositor_idle_inhibit(ec); |
| 2370 | |
Jonas Ådahl | 9484b69 | 2013-12-02 22:05:03 +0100 | [diff] [blame] | 2371 | touch->num_tp++; |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 2372 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2373 | /* the first finger down picks the view, and all further go |
| 2374 | * to that view for the remainder of the touch session i.e. |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 2375 | * until all touch points are up again. */ |
Jonas Ådahl | 9484b69 | 2013-12-02 22:05:03 +0100 | [diff] [blame] | 2376 | if (touch->num_tp == 1) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2377 | ev = weston_compositor_pick_view(ec, x, y, &sx, &sy); |
Derek Foreman | 4c93c08 | 2015-04-30 16:45:41 -0500 | [diff] [blame] | 2378 | weston_touch_set_focus(touch, ev); |
Giulio Camuffo | 61ed7b6 | 2015-07-08 11:55:28 +0300 | [diff] [blame] | 2379 | } else if (!touch->focus) { |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 2380 | /* Unexpected condition: We have non-initial touch but |
| 2381 | * there is no focused surface. |
| 2382 | */ |
Chris Michael | 3f607d3 | 2015-10-07 11:59:49 -0400 | [diff] [blame] | 2383 | weston_log("touch event received with %d points down " |
Jonas Ådahl | 9484b69 | 2013-12-02 22:05:03 +0100 | [diff] [blame] | 2384 | "but no surface focused\n", touch->num_tp); |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 2385 | return; |
| 2386 | } |
| 2387 | |
Derek Foreman | 99a6a2d | 2015-07-15 13:00:43 -0500 | [diff] [blame] | 2388 | weston_compositor_run_touch_binding(ec, touch, |
Kristian Høgsberg | c896401 | 2014-02-05 14:25:18 -0800 | [diff] [blame] | 2389 | time, touch_type); |
| 2390 | |
Giulio Camuffo | 61ed7b6 | 2015-07-08 11:55:28 +0300 | [diff] [blame] | 2391 | grab->interface->down(grab, time, touch_id, x, y); |
Jonas Ådahl | 9484b69 | 2013-12-02 22:05:03 +0100 | [diff] [blame] | 2392 | if (touch->num_tp == 1) { |
Rusty Lynch | f1407ff | 2013-08-08 21:13:57 -0700 | [diff] [blame] | 2393 | touch->grab_serial = |
| 2394 | wl_display_get_serial(ec->wl_display); |
Neil Roberts | 306fe08 | 2013-10-03 16:43:06 +0100 | [diff] [blame] | 2395 | touch->grab_touch_id = touch_id; |
Alexandros Frantzis | 9448deb | 2017-11-16 18:20:58 +0200 | [diff] [blame] | 2396 | touch->grab_time = *time; |
Rusty Lynch | f1407ff | 2013-08-08 21:13:57 -0700 | [diff] [blame] | 2397 | touch->grab_x = x; |
| 2398 | touch->grab_y = y; |
| 2399 | } |
| 2400 | |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 2401 | break; |
| 2402 | case WL_TOUCH_MOTION: |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2403 | ev = touch->focus; |
| 2404 | if (!ev) |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 2405 | break; |
| 2406 | |
Alexandros Frantzis | 7d2abcf | 2017-11-16 18:21:00 +0200 | [diff] [blame] | 2407 | grab->interface->motion(grab, time, touch_id, x, y); |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 2408 | break; |
| 2409 | case WL_TOUCH_UP: |
Kristian Høgsberg | a30e29a | 2014-01-08 22:29:20 -0800 | [diff] [blame] | 2410 | if (touch->num_tp == 0) { |
| 2411 | /* This can happen if we start out with one or |
| 2412 | * more fingers on the touch screen, in which |
| 2413 | * case we didn't get the corresponding down |
| 2414 | * event. */ |
| 2415 | weston_log("unmatched touch up event\n"); |
| 2416 | break; |
| 2417 | } |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 2418 | weston_compositor_idle_release(ec); |
Jonas Ådahl | 9484b69 | 2013-12-02 22:05:03 +0100 | [diff] [blame] | 2419 | touch->num_tp--; |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 2420 | |
Alexandros Frantzis | 27a51b8 | 2017-11-16 18:20:59 +0200 | [diff] [blame] | 2421 | grab->interface->up(grab, time, touch_id); |
Jonas Ådahl | 9484b69 | 2013-12-02 22:05:03 +0100 | [diff] [blame] | 2422 | if (touch->num_tp == 0) |
Derek Foreman | 4c93c08 | 2015-04-30 16:45:41 -0500 | [diff] [blame] | 2423 | weston_touch_set_focus(touch, NULL); |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 2424 | break; |
| 2425 | } |
| 2426 | } |
| 2427 | |
Jonas Ådahl | 1679f23 | 2014-04-12 09:39:51 +0200 | [diff] [blame] | 2428 | WL_EXPORT void |
| 2429 | notify_touch_frame(struct weston_seat *seat) |
| 2430 | { |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 2431 | struct weston_touch *touch = weston_seat_get_touch(seat); |
Jonas Ådahl | 1679f23 | 2014-04-12 09:39:51 +0200 | [diff] [blame] | 2432 | struct weston_touch_grab *grab = touch->grab; |
| 2433 | |
| 2434 | grab->interface->frame(grab); |
| 2435 | } |
| 2436 | |
Derek Foreman | 3cc004a | 2015-11-06 15:56:09 -0600 | [diff] [blame] | 2437 | WL_EXPORT void |
| 2438 | notify_touch_cancel(struct weston_seat *seat) |
| 2439 | { |
| 2440 | struct weston_touch *touch = weston_seat_get_touch(seat); |
| 2441 | struct weston_touch_grab *grab = touch->grab; |
| 2442 | |
| 2443 | grab->interface->cancel(grab); |
| 2444 | } |
| 2445 | |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 2446 | static int |
| 2447 | pointer_cursor_surface_get_label(struct weston_surface *surface, |
| 2448 | char *buf, size_t len) |
| 2449 | { |
| 2450 | return snprintf(buf, len, "cursor"); |
| 2451 | } |
| 2452 | |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 2453 | static void |
Quentin Glidic | 2edc3d5 | 2016-08-12 10:41:33 +0200 | [diff] [blame] | 2454 | pointer_cursor_surface_committed(struct weston_surface *es, |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 2455 | int32_t dx, int32_t dy) |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 2456 | { |
Quentin Glidic | 2edc3d5 | 2016-08-12 10:41:33 +0200 | [diff] [blame] | 2457 | struct weston_pointer *pointer = es->committed_private; |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 2458 | int x, y; |
| 2459 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 2460 | if (es->width == 0) |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 2461 | return; |
| 2462 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2463 | assert(es == pointer->sprite->surface); |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 2464 | |
Kristian Høgsberg | 195b869 | 2013-05-08 15:02:05 -0400 | [diff] [blame] | 2465 | pointer->hotspot_x -= dx; |
| 2466 | pointer->hotspot_y -= dy; |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 2467 | |
Kristian Høgsberg | 195b869 | 2013-05-08 15:02:05 -0400 | [diff] [blame] | 2468 | x = wl_fixed_to_int(pointer->x) - pointer->hotspot_x; |
| 2469 | y = wl_fixed_to_int(pointer->y) - pointer->hotspot_y; |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 2470 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 2471 | weston_view_set_position(pointer->sprite, x, y); |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 2472 | |
| 2473 | empty_region(&es->pending.input); |
Ander Conselvan de Oliveira | 23900f7 | 2014-01-31 16:07:51 +0200 | [diff] [blame] | 2474 | empty_region(&es->input); |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 2475 | |
| 2476 | if (!weston_surface_is_mapped(es)) { |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 2477 | weston_layer_entry_insert(&es->compositor->cursor_layer.view_list, |
| 2478 | &pointer->sprite->layer_link); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2479 | weston_view_update_transform(pointer->sprite); |
Armin Krezović | f8486c3 | 2016-06-30 06:04:28 +0200 | [diff] [blame] | 2480 | es->is_mapped = true; |
| 2481 | pointer->sprite->is_mapped = true; |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 2482 | } |
| 2483 | } |
| 2484 | |
| 2485 | static void |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 2486 | pointer_set_cursor(struct wl_client *client, struct wl_resource *resource, |
| 2487 | uint32_t serial, struct wl_resource *surface_resource, |
| 2488 | int32_t x, int32_t y) |
| 2489 | { |
Jason Ekstrand | 44a3863 | 2013-06-14 10:08:00 -0500 | [diff] [blame] | 2490 | struct weston_pointer *pointer = wl_resource_get_user_data(resource); |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 2491 | struct weston_surface *surface = NULL; |
| 2492 | |
Alexandros Frantzis | 1c3a40e | 2018-02-08 15:37:53 +0200 | [diff] [blame] | 2493 | if (!pointer) |
| 2494 | return; |
| 2495 | |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 2496 | if (surface_resource) |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 2497 | surface = wl_resource_get_user_data(surface_resource); |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 2498 | |
Kristian Høgsberg | 195b869 | 2013-05-08 15:02:05 -0400 | [diff] [blame] | 2499 | if (pointer->focus == NULL) |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 2500 | return; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2501 | /* pointer->focus->surface->resource can be NULL. Surfaces like the |
Giulio Camuffo | 1fd4b01 | 2013-06-20 18:13:07 +0200 | [diff] [blame] | 2502 | black_surface used in shell.c for fullscreen don't have |
| 2503 | a resource, but can still have focus */ |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2504 | if (pointer->focus->surface->resource == NULL) |
Giulio Camuffo | 1fd4b01 | 2013-06-20 18:13:07 +0200 | [diff] [blame] | 2505 | return; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2506 | if (wl_resource_get_client(pointer->focus->surface->resource) != client) |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 2507 | return; |
Kristian Høgsberg | 195b869 | 2013-05-08 15:02:05 -0400 | [diff] [blame] | 2508 | if (pointer->focus_serial - serial > UINT32_MAX / 2) |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 2509 | return; |
| 2510 | |
Derek Foreman | 4e53c53 | 2015-03-23 10:55:32 -0500 | [diff] [blame] | 2511 | if (!surface) { |
| 2512 | if (pointer->sprite) |
| 2513 | pointer_unmap_sprite(pointer); |
| 2514 | return; |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 2515 | } |
| 2516 | |
Jonas Ådahl | b407024 | 2015-03-18 15:08:03 +0800 | [diff] [blame] | 2517 | if (pointer->sprite && pointer->sprite->surface == surface && |
| 2518 | pointer->hotspot_x == x && pointer->hotspot_y == y) |
| 2519 | return; |
| 2520 | |
Derek Foreman | 4e53c53 | 2015-03-23 10:55:32 -0500 | [diff] [blame] | 2521 | if (!pointer->sprite || pointer->sprite->surface != surface) { |
| 2522 | if (weston_surface_set_role(surface, "wl_pointer-cursor", |
| 2523 | resource, |
| 2524 | WL_POINTER_ERROR_ROLE) < 0) |
| 2525 | return; |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 2526 | |
Derek Foreman | 4e53c53 | 2015-03-23 10:55:32 -0500 | [diff] [blame] | 2527 | if (pointer->sprite) |
| 2528 | pointer_unmap_sprite(pointer); |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 2529 | |
Derek Foreman | 4e53c53 | 2015-03-23 10:55:32 -0500 | [diff] [blame] | 2530 | wl_signal_add(&surface->destroy_signal, |
| 2531 | &pointer->sprite_destroy_listener); |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 2532 | |
Quentin Glidic | 2edc3d5 | 2016-08-12 10:41:33 +0200 | [diff] [blame] | 2533 | surface->committed = pointer_cursor_surface_committed; |
| 2534 | surface->committed_private = pointer; |
Derek Foreman | 4e53c53 | 2015-03-23 10:55:32 -0500 | [diff] [blame] | 2535 | weston_surface_set_label_func(surface, |
| 2536 | pointer_cursor_surface_get_label); |
| 2537 | pointer->sprite = weston_view_create(surface); |
| 2538 | } |
| 2539 | |
Kristian Høgsberg | 195b869 | 2013-05-08 15:02:05 -0400 | [diff] [blame] | 2540 | pointer->hotspot_x = x; |
| 2541 | pointer->hotspot_y = y; |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 2542 | |
Jonas Ådahl | 16fe4dc | 2014-09-08 19:33:41 +0200 | [diff] [blame] | 2543 | if (surface->buffer_ref.buffer) { |
Quentin Glidic | 2edc3d5 | 2016-08-12 10:41:33 +0200 | [diff] [blame] | 2544 | pointer_cursor_surface_committed(surface, 0, 0); |
Jonas Ådahl | 16fe4dc | 2014-09-08 19:33:41 +0200 | [diff] [blame] | 2545 | weston_view_schedule_repaint(pointer->sprite); |
| 2546 | } |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 2547 | } |
| 2548 | |
Kristian Høgsberg | 69e25fc | 2013-08-13 20:11:02 +0100 | [diff] [blame] | 2549 | static void |
| 2550 | pointer_release(struct wl_client *client, struct wl_resource *resource) |
| 2551 | { |
| 2552 | wl_resource_destroy(resource); |
| 2553 | } |
| 2554 | |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 2555 | static const struct wl_pointer_interface pointer_interface = { |
Kristian Høgsberg | 69e25fc | 2013-08-13 20:11:02 +0100 | [diff] [blame] | 2556 | pointer_set_cursor, |
| 2557 | pointer_release |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 2558 | }; |
| 2559 | |
| 2560 | static void |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 2561 | seat_get_pointer(struct wl_client *client, struct wl_resource *resource, |
| 2562 | uint32_t id) |
| 2563 | { |
Jason Ekstrand | 44a3863 | 2013-06-14 10:08:00 -0500 | [diff] [blame] | 2564 | struct weston_seat *seat = wl_resource_get_user_data(resource); |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 2565 | /* We use the pointer_state directly, which means we'll |
| 2566 | * give a wl_pointer if the seat has ever had one - even though |
| 2567 | * the spec explicitly states that this request only takes effect |
| 2568 | * if the seat has the pointer capability. |
| 2569 | * |
| 2570 | * This prevents a race between the compositor sending new |
| 2571 | * capabilities and the client trying to use the old ones. |
| 2572 | */ |
Alexandros Frantzis | 8480d13 | 2018-02-15 13:07:09 +0200 | [diff] [blame] | 2573 | struct weston_pointer *pointer = seat ? seat->pointer_state : NULL; |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 2574 | struct wl_resource *cr; |
Jonas Ådahl | 2cbf293 | 2015-07-22 12:05:38 +0800 | [diff] [blame] | 2575 | struct weston_pointer_client *pointer_client; |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 2576 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 2577 | cr = wl_resource_create(client, &wl_pointer_interface, |
| 2578 | wl_resource_get_version(resource), id); |
Kristian Høgsberg | 0ff7908 | 2013-08-06 16:46:25 -0700 | [diff] [blame] | 2579 | if (cr == NULL) { |
| 2580 | wl_client_post_no_memory(client); |
| 2581 | return; |
| 2582 | } |
| 2583 | |
Alexandros Frantzis | 8480d13 | 2018-02-15 13:07:09 +0200 | [diff] [blame] | 2584 | wl_list_init(wl_resource_get_link(cr)); |
| 2585 | wl_resource_set_implementation(cr, &pointer_interface, pointer, |
| 2586 | unbind_pointer_client_resource); |
| 2587 | |
| 2588 | /* If we don't have a pointer_state, the resource is inert, so there |
| 2589 | * is nothing more to set up */ |
| 2590 | if (!pointer) |
| 2591 | return; |
| 2592 | |
Jonas Ådahl | 2cbf293 | 2015-07-22 12:05:38 +0800 | [diff] [blame] | 2593 | pointer_client = weston_pointer_ensure_pointer_client(pointer, client); |
| 2594 | if (!pointer_client) { |
| 2595 | wl_client_post_no_memory(client); |
| 2596 | return; |
| 2597 | } |
| 2598 | |
| 2599 | wl_list_insert(&pointer_client->pointer_resources, |
| 2600 | wl_resource_get_link(cr)); |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 2601 | |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 2602 | if (pointer->focus && pointer->focus->surface->resource && |
| 2603 | wl_resource_get_client(pointer->focus->surface->resource) == client) { |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 2604 | wl_fixed_t sx, sy; |
| 2605 | |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 2606 | weston_view_from_global_fixed(pointer->focus, |
| 2607 | pointer->x, |
| 2608 | pointer->y, |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2609 | &sx, &sy); |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 2610 | |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 2611 | wl_pointer_send_enter(cr, |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 2612 | pointer->focus_serial, |
| 2613 | pointer->focus->surface->resource, |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 2614 | sx, sy); |
Peter Hutterer | 87743e9 | 2016-01-18 16:38:22 +1000 | [diff] [blame] | 2615 | pointer_send_frame(cr); |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 2616 | } |
| 2617 | } |
| 2618 | |
| 2619 | static void |
Alexandros Frantzis | 2b44248 | 2018-02-20 14:05:50 +0200 | [diff] [blame] | 2620 | destroy_keyboard_resource(struct wl_resource *resource) |
| 2621 | { |
| 2622 | struct weston_keyboard *keyboard = wl_resource_get_user_data(resource); |
| 2623 | |
| 2624 | wl_list_remove(wl_resource_get_link(resource)); |
| 2625 | |
| 2626 | if (keyboard) { |
| 2627 | remove_input_resource_from_timestamps(resource, |
| 2628 | &keyboard->timestamps_list); |
| 2629 | } |
| 2630 | } |
| 2631 | |
| 2632 | static void |
Kristian Høgsberg | 69e25fc | 2013-08-13 20:11:02 +0100 | [diff] [blame] | 2633 | keyboard_release(struct wl_client *client, struct wl_resource *resource) |
| 2634 | { |
| 2635 | wl_resource_destroy(resource); |
| 2636 | } |
| 2637 | |
| 2638 | static const struct wl_keyboard_interface keyboard_interface = { |
| 2639 | keyboard_release |
| 2640 | }; |
| 2641 | |
Derek Foreman | 280e7dd | 2014-10-03 13:13:42 -0500 | [diff] [blame] | 2642 | static bool |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 2643 | should_send_modifiers_to_client(struct weston_seat *seat, |
| 2644 | struct wl_client *client) |
| 2645 | { |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 2646 | struct weston_keyboard *keyboard = weston_seat_get_keyboard(seat); |
| 2647 | struct weston_pointer *pointer = weston_seat_get_pointer(seat); |
| 2648 | |
| 2649 | if (keyboard && |
| 2650 | keyboard->focus && |
| 2651 | keyboard->focus->resource && |
| 2652 | wl_resource_get_client(keyboard->focus->resource) == client) |
Derek Foreman | 280e7dd | 2014-10-03 13:13:42 -0500 | [diff] [blame] | 2653 | return true; |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 2654 | |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 2655 | if (pointer && |
| 2656 | pointer->focus && |
| 2657 | pointer->focus->surface->resource && |
| 2658 | wl_resource_get_client(pointer->focus->surface->resource) == client) |
Derek Foreman | 280e7dd | 2014-10-03 13:13:42 -0500 | [diff] [blame] | 2659 | return true; |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 2660 | |
Derek Foreman | 280e7dd | 2014-10-03 13:13:42 -0500 | [diff] [blame] | 2661 | return false; |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 2662 | } |
| 2663 | |
Kristian Høgsberg | 69e25fc | 2013-08-13 20:11:02 +0100 | [diff] [blame] | 2664 | static void |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 2665 | seat_get_keyboard(struct wl_client *client, struct wl_resource *resource, |
| 2666 | uint32_t id) |
| 2667 | { |
Jason Ekstrand | 44a3863 | 2013-06-14 10:08:00 -0500 | [diff] [blame] | 2668 | struct weston_seat *seat = wl_resource_get_user_data(resource); |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 2669 | /* We use the keyboard_state directly, which means we'll |
| 2670 | * give a wl_keyboard if the seat has ever had one - even though |
| 2671 | * the spec explicitly states that this request only takes effect |
| 2672 | * if the seat has the keyboard capability. |
| 2673 | * |
| 2674 | * This prevents a race between the compositor sending new |
| 2675 | * capabilities and the client trying to use the old ones. |
| 2676 | */ |
Alexandros Frantzis | 8480d13 | 2018-02-15 13:07:09 +0200 | [diff] [blame] | 2677 | struct weston_keyboard *keyboard = seat ? seat->keyboard_state : NULL; |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 2678 | struct wl_resource *cr; |
| 2679 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 2680 | cr = wl_resource_create(client, &wl_keyboard_interface, |
| 2681 | wl_resource_get_version(resource), id); |
Kristian Høgsberg | 0ff7908 | 2013-08-06 16:46:25 -0700 | [diff] [blame] | 2682 | if (cr == NULL) { |
| 2683 | wl_client_post_no_memory(client); |
| 2684 | return; |
| 2685 | } |
| 2686 | |
Alexandros Frantzis | 8480d13 | 2018-02-15 13:07:09 +0200 | [diff] [blame] | 2687 | wl_list_init(wl_resource_get_link(cr)); |
| 2688 | wl_resource_set_implementation(cr, &keyboard_interface, |
Alexandros Frantzis | 2b44248 | 2018-02-20 14:05:50 +0200 | [diff] [blame] | 2689 | keyboard, destroy_keyboard_resource); |
Alexandros Frantzis | 8480d13 | 2018-02-15 13:07:09 +0200 | [diff] [blame] | 2690 | |
| 2691 | /* If we don't have a keyboard_state, the resource is inert, so there |
| 2692 | * is nothing more to set up */ |
| 2693 | if (!keyboard) |
| 2694 | return; |
| 2695 | |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 2696 | /* May be moved to focused list later by either |
| 2697 | * weston_keyboard_set_focus or directly if this client is already |
| 2698 | * focused */ |
Derek Foreman | 345c9f3 | 2015-06-03 15:53:28 -0500 | [diff] [blame] | 2699 | wl_list_insert(&keyboard->resource_list, wl_resource_get_link(cr)); |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 2700 | |
Jonny Lamb | 66a41a0 | 2014-08-12 14:58:25 +0200 | [diff] [blame] | 2701 | if (wl_resource_get_version(cr) >= WL_KEYBOARD_REPEAT_INFO_SINCE_VERSION) { |
| 2702 | wl_keyboard_send_repeat_info(cr, |
| 2703 | seat->compositor->kb_repeat_rate, |
| 2704 | seat->compositor->kb_repeat_delay); |
| 2705 | } |
Jasper St. Pierre | d8c6aeb | 2014-08-04 13:43:24 -0400 | [diff] [blame] | 2706 | |
Derek Foreman | 185d158 | 2017-06-28 11:17:23 -0500 | [diff] [blame] | 2707 | wl_keyboard_send_keymap(cr, WL_KEYBOARD_KEYMAP_FORMAT_XKB_V1, |
| 2708 | keyboard->xkb_info->keymap_fd, |
| 2709 | keyboard->xkb_info->keymap_size); |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 2710 | |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 2711 | if (should_send_modifiers_to_client(seat, client)) { |
Derek Foreman | 345c9f3 | 2015-06-03 15:53:28 -0500 | [diff] [blame] | 2712 | send_modifiers_to_resource(keyboard, |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 2713 | cr, |
Derek Foreman | 345c9f3 | 2015-06-03 15:53:28 -0500 | [diff] [blame] | 2714 | keyboard->focus_serial); |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 2715 | } |
| 2716 | |
Derek Foreman | 345c9f3 | 2015-06-03 15:53:28 -0500 | [diff] [blame] | 2717 | if (keyboard->focus && keyboard->focus->resource && |
| 2718 | wl_resource_get_client(keyboard->focus->resource) == client) { |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 2719 | struct weston_surface *surface = |
Derek Foreman | 345c9f3 | 2015-06-03 15:53:28 -0500 | [diff] [blame] | 2720 | (struct weston_surface *)keyboard->focus; |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 2721 | |
| 2722 | wl_list_remove(wl_resource_get_link(cr)); |
Derek Foreman | 345c9f3 | 2015-06-03 15:53:28 -0500 | [diff] [blame] | 2723 | wl_list_insert(&keyboard->focus_resource_list, |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 2724 | wl_resource_get_link(cr)); |
| 2725 | wl_keyboard_send_enter(cr, |
Derek Foreman | 345c9f3 | 2015-06-03 15:53:28 -0500 | [diff] [blame] | 2726 | keyboard->focus_serial, |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 2727 | surface->resource, |
Derek Foreman | 345c9f3 | 2015-06-03 15:53:28 -0500 | [diff] [blame] | 2728 | &keyboard->keys); |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 2729 | |
| 2730 | /* If this is the first keyboard resource for this |
| 2731 | * client... */ |
Derek Foreman | 345c9f3 | 2015-06-03 15:53:28 -0500 | [diff] [blame] | 2732 | if (keyboard->focus_resource_list.prev == |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 2733 | wl_resource_get_link(cr)) |
| 2734 | wl_data_device_set_keyboard_focus(seat); |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 2735 | } |
| 2736 | } |
| 2737 | |
| 2738 | static void |
Alexandros Frantzis | d715784 | 2018-02-20 14:07:03 +0200 | [diff] [blame] | 2739 | destroy_touch_resource(struct wl_resource *resource) |
| 2740 | { |
| 2741 | struct weston_touch *touch = wl_resource_get_user_data(resource); |
| 2742 | |
| 2743 | wl_list_remove(wl_resource_get_link(resource)); |
| 2744 | |
| 2745 | if (touch) { |
| 2746 | remove_input_resource_from_timestamps(resource, |
| 2747 | &touch->timestamps_list); |
| 2748 | } |
| 2749 | } |
| 2750 | |
| 2751 | static void |
Kristian Høgsberg | 69e25fc | 2013-08-13 20:11:02 +0100 | [diff] [blame] | 2752 | touch_release(struct wl_client *client, struct wl_resource *resource) |
| 2753 | { |
| 2754 | wl_resource_destroy(resource); |
| 2755 | } |
| 2756 | |
| 2757 | static const struct wl_touch_interface touch_interface = { |
| 2758 | touch_release |
| 2759 | }; |
| 2760 | |
| 2761 | static void |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 2762 | seat_get_touch(struct wl_client *client, struct wl_resource *resource, |
| 2763 | uint32_t id) |
| 2764 | { |
Jason Ekstrand | 44a3863 | 2013-06-14 10:08:00 -0500 | [diff] [blame] | 2765 | struct weston_seat *seat = wl_resource_get_user_data(resource); |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 2766 | /* We use the touch_state directly, which means we'll |
| 2767 | * give a wl_touch if the seat has ever had one - even though |
| 2768 | * the spec explicitly states that this request only takes effect |
| 2769 | * if the seat has the touch capability. |
| 2770 | * |
| 2771 | * This prevents a race between the compositor sending new |
| 2772 | * capabilities and the client trying to use the old ones. |
| 2773 | */ |
Alexandros Frantzis | 8480d13 | 2018-02-15 13:07:09 +0200 | [diff] [blame] | 2774 | struct weston_touch *touch = seat ? seat->touch_state : NULL; |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 2775 | struct wl_resource *cr; |
| 2776 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 2777 | cr = wl_resource_create(client, &wl_touch_interface, |
| 2778 | wl_resource_get_version(resource), id); |
Kristian Høgsberg | 0ff7908 | 2013-08-06 16:46:25 -0700 | [diff] [blame] | 2779 | if (cr == NULL) { |
| 2780 | wl_client_post_no_memory(client); |
| 2781 | return; |
| 2782 | } |
| 2783 | |
Alexandros Frantzis | 8480d13 | 2018-02-15 13:07:09 +0200 | [diff] [blame] | 2784 | wl_list_init(wl_resource_get_link(cr)); |
| 2785 | wl_resource_set_implementation(cr, &touch_interface, |
Alexandros Frantzis | d715784 | 2018-02-20 14:07:03 +0200 | [diff] [blame] | 2786 | touch, destroy_touch_resource); |
Alexandros Frantzis | 8480d13 | 2018-02-15 13:07:09 +0200 | [diff] [blame] | 2787 | |
| 2788 | /* If we don't have a touch_state, the resource is inert, so there |
| 2789 | * is nothing more to set up */ |
| 2790 | if (!touch) |
| 2791 | return; |
| 2792 | |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 2793 | if (touch->focus && |
| 2794 | wl_resource_get_client(touch->focus->surface->resource) == client) { |
Chokshi, Mitul | d669714 | 2015-10-09 08:28:47 +0000 | [diff] [blame] | 2795 | wl_list_insert(&touch->focus_resource_list, |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 2796 | wl_resource_get_link(cr)); |
| 2797 | } else { |
Chokshi, Mitul | d669714 | 2015-10-09 08:28:47 +0000 | [diff] [blame] | 2798 | wl_list_insert(&touch->resource_list, |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 2799 | wl_resource_get_link(cr)); |
| 2800 | } |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 2801 | } |
| 2802 | |
Quentin Glidic | aab1d36 | 2016-03-13 17:49:08 +0100 | [diff] [blame] | 2803 | static void |
| 2804 | seat_release(struct wl_client *client, struct wl_resource *resource) |
| 2805 | { |
| 2806 | wl_resource_destroy(resource); |
| 2807 | } |
| 2808 | |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 2809 | static const struct wl_seat_interface seat_interface = { |
| 2810 | seat_get_pointer, |
| 2811 | seat_get_keyboard, |
| 2812 | seat_get_touch, |
Quentin Glidic | aab1d36 | 2016-03-13 17:49:08 +0100 | [diff] [blame] | 2813 | seat_release, |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 2814 | }; |
| 2815 | |
| 2816 | static void |
| 2817 | bind_seat(struct wl_client *client, void *data, uint32_t version, uint32_t id) |
| 2818 | { |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 2819 | struct weston_seat *seat = data; |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 2820 | struct wl_resource *resource; |
| 2821 | enum wl_seat_capability caps = 0; |
| 2822 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 2823 | resource = wl_resource_create(client, |
Derek Foreman | 1909c10 | 2015-11-26 14:17:47 -0600 | [diff] [blame] | 2824 | &wl_seat_interface, version, id); |
Jason Ekstrand | 44a3863 | 2013-06-14 10:08:00 -0500 | [diff] [blame] | 2825 | wl_list_insert(&seat->base_resource_list, wl_resource_get_link(resource)); |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 2826 | wl_resource_set_implementation(resource, &seat_interface, data, |
| 2827 | unbind_resource); |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 2828 | |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 2829 | if (weston_seat_get_pointer(seat)) |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 2830 | caps |= WL_SEAT_CAPABILITY_POINTER; |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 2831 | if (weston_seat_get_keyboard(seat)) |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 2832 | caps |= WL_SEAT_CAPABILITY_KEYBOARD; |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 2833 | if (weston_seat_get_touch(seat)) |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 2834 | caps |= WL_SEAT_CAPABILITY_TOUCH; |
| 2835 | |
| 2836 | wl_seat_send_capabilities(resource, caps); |
Jasper St. Pierre | 0013a29 | 2014-08-07 16:43:11 -0400 | [diff] [blame] | 2837 | if (version >= WL_SEAT_NAME_SINCE_VERSION) |
Rob Bradford | e445ae6 | 2013-05-31 18:09:51 +0100 | [diff] [blame] | 2838 | wl_seat_send_name(resource, seat->seat_name); |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 2839 | } |
| 2840 | |
Jonas Ådahl | 30d61d8 | 2014-10-22 21:21:17 +0200 | [diff] [blame] | 2841 | static void |
| 2842 | relative_pointer_destroy(struct wl_client *client, |
| 2843 | struct wl_resource *resource) |
| 2844 | { |
| 2845 | wl_resource_destroy(resource); |
| 2846 | } |
| 2847 | |
| 2848 | static const struct zwp_relative_pointer_v1_interface relative_pointer_interface = { |
| 2849 | relative_pointer_destroy |
| 2850 | }; |
| 2851 | |
| 2852 | static void |
| 2853 | relative_pointer_manager_destroy(struct wl_client *client, |
| 2854 | struct wl_resource *resource) |
| 2855 | { |
| 2856 | wl_resource_destroy(resource); |
| 2857 | } |
| 2858 | |
| 2859 | static void |
| 2860 | relative_pointer_manager_get_relative_pointer(struct wl_client *client, |
| 2861 | struct wl_resource *resource, |
| 2862 | uint32_t id, |
| 2863 | struct wl_resource *pointer_resource) |
| 2864 | { |
| 2865 | struct weston_pointer *pointer = |
| 2866 | wl_resource_get_user_data(pointer_resource); |
| 2867 | struct weston_pointer_client *pointer_client; |
| 2868 | struct wl_resource *cr; |
| 2869 | |
| 2870 | cr = wl_resource_create(client, &zwp_relative_pointer_v1_interface, |
| 2871 | wl_resource_get_version(resource), id); |
| 2872 | if (cr == NULL) { |
| 2873 | wl_client_post_no_memory(client); |
| 2874 | return; |
| 2875 | } |
| 2876 | |
| 2877 | pointer_client = weston_pointer_ensure_pointer_client(pointer, client); |
| 2878 | if (!pointer_client) { |
| 2879 | wl_client_post_no_memory(client); |
| 2880 | return; |
| 2881 | } |
| 2882 | |
| 2883 | wl_list_insert(&pointer_client->relative_pointer_resources, |
| 2884 | wl_resource_get_link(cr)); |
| 2885 | wl_resource_set_implementation(cr, &relative_pointer_interface, |
| 2886 | pointer, |
| 2887 | unbind_pointer_client_resource); |
| 2888 | } |
| 2889 | |
| 2890 | static const struct zwp_relative_pointer_manager_v1_interface relative_pointer_manager = { |
| 2891 | relative_pointer_manager_destroy, |
| 2892 | relative_pointer_manager_get_relative_pointer, |
| 2893 | }; |
| 2894 | |
| 2895 | static void |
| 2896 | bind_relative_pointer_manager(struct wl_client *client, void *data, |
| 2897 | uint32_t version, uint32_t id) |
| 2898 | { |
| 2899 | struct weston_compositor *compositor = data; |
| 2900 | struct wl_resource *resource; |
| 2901 | |
| 2902 | resource = wl_resource_create(client, |
| 2903 | &zwp_relative_pointer_manager_v1_interface, |
| 2904 | 1, id); |
| 2905 | |
| 2906 | wl_resource_set_implementation(resource, &relative_pointer_manager, |
| 2907 | compositor, |
| 2908 | NULL); |
| 2909 | } |
| 2910 | |
Giulio Camuffo | 0358af4 | 2016-06-02 21:48:08 +0300 | [diff] [blame] | 2911 | WL_EXPORT int |
| 2912 | weston_compositor_set_xkb_rule_names(struct weston_compositor *ec, |
| 2913 | struct xkb_rule_names *names) |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 2914 | { |
| 2915 | if (ec->xkb_context == NULL) { |
| 2916 | ec->xkb_context = xkb_context_new(0); |
| 2917 | if (ec->xkb_context == NULL) { |
| 2918 | weston_log("failed to create XKB context\n"); |
| 2919 | return -1; |
| 2920 | } |
| 2921 | } |
| 2922 | |
| 2923 | if (names) |
| 2924 | ec->xkb_names = *names; |
| 2925 | if (!ec->xkb_names.rules) |
| 2926 | ec->xkb_names.rules = strdup("evdev"); |
| 2927 | if (!ec->xkb_names.model) |
| 2928 | ec->xkb_names.model = strdup("pc105"); |
| 2929 | if (!ec->xkb_names.layout) |
| 2930 | ec->xkb_names.layout = strdup("us"); |
| 2931 | |
| 2932 | return 0; |
| 2933 | } |
| 2934 | |
Stefan Schmidt | fda2652 | 2013-09-17 10:54:09 +0100 | [diff] [blame] | 2935 | static void |
Andrew Wedgbury | 9a6f02a | 2013-09-05 13:31:40 +0000 | [diff] [blame] | 2936 | weston_xkb_info_destroy(struct weston_xkb_info *xkb_info) |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 2937 | { |
Andrew Wedgbury | 9a6f02a | 2013-09-05 13:31:40 +0000 | [diff] [blame] | 2938 | if (--xkb_info->ref_count > 0) |
| 2939 | return; |
| 2940 | |
Ran Benita | c9c7415 | 2014-08-19 23:59:52 +0300 | [diff] [blame] | 2941 | xkb_keymap_unref(xkb_info->keymap); |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 2942 | |
| 2943 | if (xkb_info->keymap_area) |
| 2944 | munmap(xkb_info->keymap_area, xkb_info->keymap_size); |
| 2945 | if (xkb_info->keymap_fd >= 0) |
| 2946 | close(xkb_info->keymap_fd); |
Andrew Wedgbury | 9a6f02a | 2013-09-05 13:31:40 +0000 | [diff] [blame] | 2947 | free(xkb_info); |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 2948 | } |
| 2949 | |
| 2950 | void |
| 2951 | weston_compositor_xkb_destroy(struct weston_compositor *ec) |
| 2952 | { |
| 2953 | free((char *) ec->xkb_names.rules); |
| 2954 | free((char *) ec->xkb_names.model); |
| 2955 | free((char *) ec->xkb_names.layout); |
| 2956 | free((char *) ec->xkb_names.variant); |
| 2957 | free((char *) ec->xkb_names.options); |
Stefan Schmidt | fda2652 | 2013-09-17 10:54:09 +0100 | [diff] [blame] | 2958 | |
Andrew Wedgbury | 9a6f02a | 2013-09-05 13:31:40 +0000 | [diff] [blame] | 2959 | if (ec->xkb_info) |
| 2960 | weston_xkb_info_destroy(ec->xkb_info); |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 2961 | xkb_context_unref(ec->xkb_context); |
| 2962 | } |
| 2963 | |
Andrew Wedgbury | 9a6f02a | 2013-09-05 13:31:40 +0000 | [diff] [blame] | 2964 | static struct weston_xkb_info * |
| 2965 | weston_xkb_info_create(struct xkb_keymap *keymap) |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 2966 | { |
Andrew Wedgbury | 9a6f02a | 2013-09-05 13:31:40 +0000 | [diff] [blame] | 2967 | struct weston_xkb_info *xkb_info = zalloc(sizeof *xkb_info); |
| 2968 | if (xkb_info == NULL) |
| 2969 | return NULL; |
| 2970 | |
Ran Benita | 2e1968f | 2014-08-19 23:59:51 +0300 | [diff] [blame] | 2971 | xkb_info->keymap = xkb_keymap_ref(keymap); |
Andrew Wedgbury | 9a6f02a | 2013-09-05 13:31:40 +0000 | [diff] [blame] | 2972 | xkb_info->ref_count = 1; |
| 2973 | |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 2974 | char *keymap_str; |
| 2975 | |
Ran Benita | 2e1968f | 2014-08-19 23:59:51 +0300 | [diff] [blame] | 2976 | xkb_info->shift_mod = xkb_keymap_mod_get_index(xkb_info->keymap, |
| 2977 | XKB_MOD_NAME_SHIFT); |
| 2978 | xkb_info->caps_mod = xkb_keymap_mod_get_index(xkb_info->keymap, |
| 2979 | XKB_MOD_NAME_CAPS); |
| 2980 | xkb_info->ctrl_mod = xkb_keymap_mod_get_index(xkb_info->keymap, |
| 2981 | XKB_MOD_NAME_CTRL); |
| 2982 | xkb_info->alt_mod = xkb_keymap_mod_get_index(xkb_info->keymap, |
| 2983 | XKB_MOD_NAME_ALT); |
| 2984 | xkb_info->mod2_mod = xkb_keymap_mod_get_index(xkb_info->keymap, |
| 2985 | "Mod2"); |
| 2986 | xkb_info->mod3_mod = xkb_keymap_mod_get_index(xkb_info->keymap, |
| 2987 | "Mod3"); |
| 2988 | xkb_info->super_mod = xkb_keymap_mod_get_index(xkb_info->keymap, |
| 2989 | XKB_MOD_NAME_LOGO); |
| 2990 | xkb_info->mod5_mod = xkb_keymap_mod_get_index(xkb_info->keymap, |
| 2991 | "Mod5"); |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 2992 | |
Ran Benita | 2e1968f | 2014-08-19 23:59:51 +0300 | [diff] [blame] | 2993 | xkb_info->num_led = xkb_keymap_led_get_index(xkb_info->keymap, |
| 2994 | XKB_LED_NAME_NUM); |
| 2995 | xkb_info->caps_led = xkb_keymap_led_get_index(xkb_info->keymap, |
| 2996 | XKB_LED_NAME_CAPS); |
| 2997 | xkb_info->scroll_led = xkb_keymap_led_get_index(xkb_info->keymap, |
| 2998 | XKB_LED_NAME_SCROLL); |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 2999 | |
Ran Benita | 2e1968f | 2014-08-19 23:59:51 +0300 | [diff] [blame] | 3000 | keymap_str = xkb_keymap_get_as_string(xkb_info->keymap, |
| 3001 | XKB_KEYMAP_FORMAT_TEXT_V1); |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 3002 | if (keymap_str == NULL) { |
| 3003 | weston_log("failed to get string version of keymap\n"); |
Andrew Wedgbury | 9a6f02a | 2013-09-05 13:31:40 +0000 | [diff] [blame] | 3004 | goto err_keymap; |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 3005 | } |
| 3006 | xkb_info->keymap_size = strlen(keymap_str) + 1; |
| 3007 | |
| 3008 | xkb_info->keymap_fd = os_create_anonymous_file(xkb_info->keymap_size); |
| 3009 | if (xkb_info->keymap_fd < 0) { |
| 3010 | weston_log("creating a keymap file for %lu bytes failed: %m\n", |
| 3011 | (unsigned long) xkb_info->keymap_size); |
| 3012 | goto err_keymap_str; |
| 3013 | } |
| 3014 | |
| 3015 | xkb_info->keymap_area = mmap(NULL, xkb_info->keymap_size, |
| 3016 | PROT_READ | PROT_WRITE, |
| 3017 | MAP_SHARED, xkb_info->keymap_fd, 0); |
| 3018 | if (xkb_info->keymap_area == MAP_FAILED) { |
| 3019 | weston_log("failed to mmap() %lu bytes\n", |
| 3020 | (unsigned long) xkb_info->keymap_size); |
| 3021 | goto err_dev_zero; |
| 3022 | } |
| 3023 | strcpy(xkb_info->keymap_area, keymap_str); |
| 3024 | free(keymap_str); |
| 3025 | |
Andrew Wedgbury | 9a6f02a | 2013-09-05 13:31:40 +0000 | [diff] [blame] | 3026 | return xkb_info; |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 3027 | |
| 3028 | err_dev_zero: |
| 3029 | close(xkb_info->keymap_fd); |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 3030 | err_keymap_str: |
| 3031 | free(keymap_str); |
Andrew Wedgbury | 9a6f02a | 2013-09-05 13:31:40 +0000 | [diff] [blame] | 3032 | err_keymap: |
Ran Benita | 2e1968f | 2014-08-19 23:59:51 +0300 | [diff] [blame] | 3033 | xkb_keymap_unref(xkb_info->keymap); |
Andrew Wedgbury | 9a6f02a | 2013-09-05 13:31:40 +0000 | [diff] [blame] | 3034 | free(xkb_info); |
| 3035 | return NULL; |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 3036 | } |
| 3037 | |
| 3038 | static int |
| 3039 | weston_compositor_build_global_keymap(struct weston_compositor *ec) |
| 3040 | { |
Andrew Wedgbury | 9a6f02a | 2013-09-05 13:31:40 +0000 | [diff] [blame] | 3041 | struct xkb_keymap *keymap; |
| 3042 | |
| 3043 | if (ec->xkb_info != NULL) |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 3044 | return 0; |
| 3045 | |
Ran Benita | 2e1968f | 2014-08-19 23:59:51 +0300 | [diff] [blame] | 3046 | keymap = xkb_keymap_new_from_names(ec->xkb_context, |
| 3047 | &ec->xkb_names, |
| 3048 | 0); |
Andrew Wedgbury | 9a6f02a | 2013-09-05 13:31:40 +0000 | [diff] [blame] | 3049 | if (keymap == NULL) { |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 3050 | weston_log("failed to compile global XKB keymap\n"); |
| 3051 | weston_log(" tried rules %s, model %s, layout %s, variant %s, " |
| 3052 | "options %s\n", |
| 3053 | ec->xkb_names.rules, ec->xkb_names.model, |
| 3054 | ec->xkb_names.layout, ec->xkb_names.variant, |
| 3055 | ec->xkb_names.options); |
| 3056 | return -1; |
| 3057 | } |
| 3058 | |
Andrew Wedgbury | 9a6f02a | 2013-09-05 13:31:40 +0000 | [diff] [blame] | 3059 | ec->xkb_info = weston_xkb_info_create(keymap); |
Rui Matos | 73d9395 | 2013-10-24 19:28:41 +0200 | [diff] [blame] | 3060 | xkb_keymap_unref(keymap); |
Stefan Schmidt | fda2652 | 2013-09-17 10:54:09 +0100 | [diff] [blame] | 3061 | if (ec->xkb_info == NULL) |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 3062 | return -1; |
| 3063 | |
| 3064 | return 0; |
| 3065 | } |
| 3066 | |
Rui Matos | 65196bc | 2013-10-10 19:44:19 +0200 | [diff] [blame] | 3067 | WL_EXPORT void |
| 3068 | weston_seat_update_keymap(struct weston_seat *seat, struct xkb_keymap *keymap) |
| 3069 | { |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 3070 | struct weston_keyboard *keyboard = weston_seat_get_keyboard(seat); |
| 3071 | |
| 3072 | if (!keyboard || !keymap) |
Rui Matos | 65196bc | 2013-10-10 19:44:19 +0200 | [diff] [blame] | 3073 | return; |
| 3074 | |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 3075 | xkb_keymap_unref(keyboard->pending_keymap); |
| 3076 | keyboard->pending_keymap = xkb_keymap_ref(keymap); |
Rui Matos | 65196bc | 2013-10-10 19:44:19 +0200 | [diff] [blame] | 3077 | |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 3078 | if (keyboard->keys.size == 0) |
Rui Matos | 65196bc | 2013-10-10 19:44:19 +0200 | [diff] [blame] | 3079 | update_keymap(seat); |
Rui Matos | 65196bc | 2013-10-10 19:44:19 +0200 | [diff] [blame] | 3080 | } |
| 3081 | |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 3082 | WL_EXPORT int |
| 3083 | weston_seat_init_keyboard(struct weston_seat *seat, struct xkb_keymap *keymap) |
| 3084 | { |
Kristian Høgsberg | a4036bb | 2013-05-07 23:52:07 -0400 | [diff] [blame] | 3085 | struct weston_keyboard *keyboard; |
| 3086 | |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 3087 | if (seat->keyboard_state) { |
Jonas Ådahl | d6e1c34 | 2013-10-17 23:04:05 +0200 | [diff] [blame] | 3088 | seat->keyboard_device_count += 1; |
| 3089 | if (seat->keyboard_device_count == 1) |
| 3090 | seat_send_updated_caps(seat); |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 3091 | return 0; |
Jonas Ådahl | d6e1c34 | 2013-10-17 23:04:05 +0200 | [diff] [blame] | 3092 | } |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 3093 | |
Kristian Høgsberg | a4036bb | 2013-05-07 23:52:07 -0400 | [diff] [blame] | 3094 | keyboard = weston_keyboard_create(); |
| 3095 | if (keyboard == NULL) { |
| 3096 | weston_log("failed to allocate weston keyboard struct\n"); |
| 3097 | return -1; |
| 3098 | } |
| 3099 | |
Derek Foreman | 185d158 | 2017-06-28 11:17:23 -0500 | [diff] [blame] | 3100 | if (keymap != NULL) { |
| 3101 | keyboard->xkb_info = weston_xkb_info_create(keymap); |
| 3102 | if (keyboard->xkb_info == NULL) |
Ander Conselvan de Oliveira | 4d363cf | 2014-01-31 17:35:45 +0200 | [diff] [blame] | 3103 | goto err; |
Derek Foreman | 185d158 | 2017-06-28 11:17:23 -0500 | [diff] [blame] | 3104 | } else { |
| 3105 | if (weston_compositor_build_global_keymap(seat->compositor) < 0) |
| 3106 | goto err; |
| 3107 | keyboard->xkb_info = seat->compositor->xkb_info; |
| 3108 | keyboard->xkb_info->ref_count++; |
Jonas Ådahl | 7395ea0 | 2013-12-03 09:14:26 +0100 | [diff] [blame] | 3109 | } |
Derek Foreman | 185d158 | 2017-06-28 11:17:23 -0500 | [diff] [blame] | 3110 | |
| 3111 | keyboard->xkb_state.state = xkb_state_new(keyboard->xkb_info->keymap); |
| 3112 | if (keyboard->xkb_state.state == NULL) { |
| 3113 | weston_log("failed to initialise XKB state\n"); |
| 3114 | goto err; |
| 3115 | } |
| 3116 | |
| 3117 | keyboard->xkb_state.leds = 0; |
Jonas Ådahl | 7395ea0 | 2013-12-03 09:14:26 +0100 | [diff] [blame] | 3118 | |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 3119 | seat->keyboard_state = keyboard; |
Ander Conselvan de Oliveira | 4d363cf | 2014-01-31 17:35:45 +0200 | [diff] [blame] | 3120 | seat->keyboard_device_count = 1; |
| 3121 | keyboard->seat = seat; |
| 3122 | |
Kristian Høgsberg | a4036bb | 2013-05-07 23:52:07 -0400 | [diff] [blame] | 3123 | seat_send_updated_caps(seat); |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 3124 | |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 3125 | return 0; |
Ander Conselvan de Oliveira | 4d363cf | 2014-01-31 17:35:45 +0200 | [diff] [blame] | 3126 | |
| 3127 | err: |
| 3128 | if (keyboard->xkb_info) |
| 3129 | weston_xkb_info_destroy(keyboard->xkb_info); |
| 3130 | free(keyboard); |
| 3131 | |
| 3132 | return -1; |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 3133 | } |
| 3134 | |
Jonas Ådahl | 91fed54 | 2013-12-03 09:14:27 +0100 | [diff] [blame] | 3135 | static void |
| 3136 | weston_keyboard_reset_state(struct weston_keyboard *keyboard) |
| 3137 | { |
| 3138 | struct weston_seat *seat = keyboard->seat; |
| 3139 | struct xkb_state *state; |
| 3140 | |
Derek Foreman | 185d158 | 2017-06-28 11:17:23 -0500 | [diff] [blame] | 3141 | state = xkb_state_new(keyboard->xkb_info->keymap); |
| 3142 | if (!state) { |
| 3143 | weston_log("failed to reset XKB state\n"); |
| 3144 | return; |
Jonas Ådahl | 91fed54 | 2013-12-03 09:14:27 +0100 | [diff] [blame] | 3145 | } |
Derek Foreman | 185d158 | 2017-06-28 11:17:23 -0500 | [diff] [blame] | 3146 | xkb_state_unref(keyboard->xkb_state.state); |
| 3147 | keyboard->xkb_state.state = state; |
| 3148 | |
| 3149 | keyboard->xkb_state.leds = 0; |
Jonas Ådahl | 91fed54 | 2013-12-03 09:14:27 +0100 | [diff] [blame] | 3150 | |
| 3151 | seat->modifier_state = 0; |
| 3152 | } |
| 3153 | |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 3154 | WL_EXPORT void |
Jonas Ådahl | d6e1c34 | 2013-10-17 23:04:05 +0200 | [diff] [blame] | 3155 | weston_seat_release_keyboard(struct weston_seat *seat) |
| 3156 | { |
| 3157 | seat->keyboard_device_count--; |
Derek Foreman | d621df2 | 2014-11-19 11:04:12 -0600 | [diff] [blame] | 3158 | assert(seat->keyboard_device_count >= 0); |
Jonas Ådahl | d6e1c34 | 2013-10-17 23:04:05 +0200 | [diff] [blame] | 3159 | if (seat->keyboard_device_count == 0) { |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 3160 | weston_keyboard_set_focus(seat->keyboard_state, NULL); |
| 3161 | weston_keyboard_cancel_grab(seat->keyboard_state); |
| 3162 | weston_keyboard_reset_state(seat->keyboard_state); |
Jonas Ådahl | d6e1c34 | 2013-10-17 23:04:05 +0200 | [diff] [blame] | 3163 | seat_send_updated_caps(seat); |
| 3164 | } |
| 3165 | } |
| 3166 | |
| 3167 | WL_EXPORT void |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 3168 | weston_seat_init_pointer(struct weston_seat *seat) |
| 3169 | { |
Kristian Høgsberg | a4036bb | 2013-05-07 23:52:07 -0400 | [diff] [blame] | 3170 | struct weston_pointer *pointer; |
| 3171 | |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 3172 | if (seat->pointer_state) { |
Jonas Ådahl | d6e1c34 | 2013-10-17 23:04:05 +0200 | [diff] [blame] | 3173 | seat->pointer_device_count += 1; |
| 3174 | if (seat->pointer_device_count == 1) |
| 3175 | seat_send_updated_caps(seat); |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 3176 | return; |
Jonas Ådahl | d6e1c34 | 2013-10-17 23:04:05 +0200 | [diff] [blame] | 3177 | } |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 3178 | |
Giulio Camuffo | cdb4d29 | 2013-11-14 23:42:53 +0100 | [diff] [blame] | 3179 | pointer = weston_pointer_create(seat); |
Kristian Høgsberg | a4036bb | 2013-05-07 23:52:07 -0400 | [diff] [blame] | 3180 | if (pointer == NULL) |
| 3181 | return; |
| 3182 | |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 3183 | seat->pointer_state = pointer; |
Jonas Ådahl | d6e1c34 | 2013-10-17 23:04:05 +0200 | [diff] [blame] | 3184 | seat->pointer_device_count = 1; |
| 3185 | pointer->seat = seat; |
Kristian Høgsberg | a4036bb | 2013-05-07 23:52:07 -0400 | [diff] [blame] | 3186 | |
| 3187 | seat_send_updated_caps(seat); |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 3188 | } |
| 3189 | |
| 3190 | WL_EXPORT void |
Jonas Ådahl | d6e1c34 | 2013-10-17 23:04:05 +0200 | [diff] [blame] | 3191 | weston_seat_release_pointer(struct weston_seat *seat) |
| 3192 | { |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 3193 | struct weston_pointer *pointer = seat->pointer_state; |
Jonas Ådahl | d6e1c34 | 2013-10-17 23:04:05 +0200 | [diff] [blame] | 3194 | |
| 3195 | seat->pointer_device_count--; |
| 3196 | if (seat->pointer_device_count == 0) { |
Derek Foreman | f9318d1 | 2015-05-11 15:40:11 -0500 | [diff] [blame] | 3197 | weston_pointer_clear_focus(pointer); |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 3198 | weston_pointer_cancel_grab(pointer); |
Jonas Ådahl | 630bae8 | 2013-10-17 23:04:06 +0200 | [diff] [blame] | 3199 | |
Jonas Ådahl | a493274 | 2013-10-17 23:04:07 +0200 | [diff] [blame] | 3200 | if (pointer->sprite) |
| 3201 | pointer_unmap_sprite(pointer); |
| 3202 | |
Jonas Ådahl | 3e12e63 | 2013-12-02 22:05:05 +0100 | [diff] [blame] | 3203 | weston_pointer_reset_state(pointer); |
Jonas Ådahl | d6e1c34 | 2013-10-17 23:04:05 +0200 | [diff] [blame] | 3204 | seat_send_updated_caps(seat); |
Derek Foreman | fd5ca51 | 2015-01-07 15:00:25 -0600 | [diff] [blame] | 3205 | |
| 3206 | /* seat->pointer is intentionally not destroyed so that |
| 3207 | * a newly attached pointer on this seat will retain |
| 3208 | * the previous cursor co-ordinates. |
| 3209 | */ |
Jonas Ådahl | d6e1c34 | 2013-10-17 23:04:05 +0200 | [diff] [blame] | 3210 | } |
| 3211 | } |
| 3212 | |
| 3213 | WL_EXPORT void |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 3214 | weston_seat_init_touch(struct weston_seat *seat) |
| 3215 | { |
Kristian Høgsberg | a4036bb | 2013-05-07 23:52:07 -0400 | [diff] [blame] | 3216 | struct weston_touch *touch; |
| 3217 | |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 3218 | if (seat->touch_state) { |
Jonas Ådahl | d6e1c34 | 2013-10-17 23:04:05 +0200 | [diff] [blame] | 3219 | seat->touch_device_count += 1; |
| 3220 | if (seat->touch_device_count == 1) |
| 3221 | seat_send_updated_caps(seat); |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 3222 | return; |
Jonas Ådahl | d6e1c34 | 2013-10-17 23:04:05 +0200 | [diff] [blame] | 3223 | } |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 3224 | |
Kristian Høgsberg | a4036bb | 2013-05-07 23:52:07 -0400 | [diff] [blame] | 3225 | touch = weston_touch_create(); |
| 3226 | if (touch == NULL) |
| 3227 | return; |
| 3228 | |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 3229 | seat->touch_state = touch; |
Jonas Ådahl | d6e1c34 | 2013-10-17 23:04:05 +0200 | [diff] [blame] | 3230 | seat->touch_device_count = 1; |
Kristian Høgsberg | a4036bb | 2013-05-07 23:52:07 -0400 | [diff] [blame] | 3231 | touch->seat = seat; |
| 3232 | |
| 3233 | seat_send_updated_caps(seat); |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 3234 | } |
| 3235 | |
| 3236 | WL_EXPORT void |
Jonas Ådahl | d6e1c34 | 2013-10-17 23:04:05 +0200 | [diff] [blame] | 3237 | weston_seat_release_touch(struct weston_seat *seat) |
| 3238 | { |
| 3239 | seat->touch_device_count--; |
| 3240 | if (seat->touch_device_count == 0) { |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 3241 | weston_touch_set_focus(seat->touch_state, NULL); |
| 3242 | weston_touch_cancel_grab(seat->touch_state); |
| 3243 | weston_touch_reset_state(seat->touch_state); |
Jonas Ådahl | d6e1c34 | 2013-10-17 23:04:05 +0200 | [diff] [blame] | 3244 | seat_send_updated_caps(seat); |
| 3245 | } |
| 3246 | } |
| 3247 | |
| 3248 | WL_EXPORT void |
Rob Bradford | 9af5f9e | 2013-05-31 18:09:50 +0100 | [diff] [blame] | 3249 | weston_seat_init(struct weston_seat *seat, struct weston_compositor *ec, |
| 3250 | const char *seat_name) |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 3251 | { |
Kristian Høgsberg | 4a2a274 | 2013-05-06 22:24:50 -0400 | [diff] [blame] | 3252 | memset(seat, 0, sizeof *seat); |
| 3253 | |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 3254 | seat->selection_data_source = NULL; |
| 3255 | wl_list_init(&seat->base_resource_list); |
| 3256 | wl_signal_init(&seat->selection_signal); |
| 3257 | wl_list_init(&seat->drag_resource_list); |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 3258 | wl_signal_init(&seat->destroy_signal); |
Jason Ekstrand | a4ab542 | 2014-04-02 19:53:45 -0500 | [diff] [blame] | 3259 | wl_signal_init(&seat->updated_caps_signal); |
Kristian Høgsberg | 4a2a274 | 2013-05-06 22:24:50 -0400 | [diff] [blame] | 3260 | |
Peter Hutterer | 87743e9 | 2016-01-18 16:38:22 +1000 | [diff] [blame] | 3261 | seat->global = wl_global_create(ec->wl_display, &wl_seat_interface, 5, |
Kristian Høgsberg | 919cddb | 2013-07-08 19:03:57 -0400 | [diff] [blame] | 3262 | seat, bind_seat); |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 3263 | |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 3264 | seat->compositor = ec; |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 3265 | seat->modifier_state = 0; |
Rob Bradford | 9af5f9e | 2013-05-31 18:09:50 +0100 | [diff] [blame] | 3266 | seat->seat_name = strdup(seat_name); |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 3267 | |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 3268 | wl_list_insert(ec->seat_list.prev, &seat->link); |
| 3269 | |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 3270 | clipboard_create(seat); |
| 3271 | |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 3272 | wl_signal_emit(&ec->seat_created_signal, seat); |
| 3273 | } |
| 3274 | |
| 3275 | WL_EXPORT void |
| 3276 | weston_seat_release(struct weston_seat *seat) |
| 3277 | { |
Alexandros Frantzis | 8480d13 | 2018-02-15 13:07:09 +0200 | [diff] [blame] | 3278 | struct wl_resource *resource; |
| 3279 | |
| 3280 | wl_resource_for_each(resource, &seat->base_resource_list) { |
| 3281 | wl_resource_set_user_data(resource, NULL); |
| 3282 | } |
| 3283 | |
| 3284 | wl_resource_for_each(resource, &seat->drag_resource_list) { |
| 3285 | wl_resource_set_user_data(resource, NULL); |
| 3286 | } |
| 3287 | |
| 3288 | wl_list_remove(&seat->base_resource_list); |
| 3289 | wl_list_remove(&seat->drag_resource_list); |
| 3290 | |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 3291 | wl_list_remove(&seat->link); |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 3292 | |
Jonas Ådahl | 1afb238 | 2014-01-03 19:46:51 +0100 | [diff] [blame] | 3293 | if (seat->saved_kbd_focus) |
| 3294 | wl_list_remove(&seat->saved_kbd_focus_listener.link); |
| 3295 | |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 3296 | if (seat->pointer_state) |
| 3297 | weston_pointer_destroy(seat->pointer_state); |
| 3298 | if (seat->keyboard_state) |
| 3299 | weston_keyboard_destroy(seat->keyboard_state); |
| 3300 | if (seat->touch_state) |
| 3301 | weston_touch_destroy(seat->touch_state); |
Kristian Høgsberg | 4a2a274 | 2013-05-06 22:24:50 -0400 | [diff] [blame] | 3302 | |
Rob Bradford | 9af5f9e | 2013-05-31 18:09:50 +0100 | [diff] [blame] | 3303 | free (seat->seat_name); |
| 3304 | |
Kristian Høgsberg | 919cddb | 2013-07-08 19:03:57 -0400 | [diff] [blame] | 3305 | wl_global_destroy(seat->global); |
Kristian Høgsberg | aaadc77 | 2013-07-08 16:20:31 -0400 | [diff] [blame] | 3306 | |
Kristian Høgsberg | b5e2610 | 2013-04-18 15:40:10 -0400 | [diff] [blame] | 3307 | wl_signal_emit(&seat->destroy_signal, seat); |
| 3308 | } |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 3309 | |
| 3310 | /** Get a seat's keyboard pointer |
| 3311 | * |
| 3312 | * \param seat The seat to query |
| 3313 | * \return The seat's keyboard pointer, or NULL if no keyboard is present |
| 3314 | * |
| 3315 | * The keyboard pointer for a seat isn't freed when all keyboards are removed, |
| 3316 | * so it should only be used when the seat's keyboard_device_count is greater |
| 3317 | * than zero. This function does that test and only returns a pointer |
| 3318 | * when a keyboard is present. |
| 3319 | */ |
| 3320 | WL_EXPORT struct weston_keyboard * |
| 3321 | weston_seat_get_keyboard(struct weston_seat *seat) |
| 3322 | { |
| 3323 | if (!seat) |
| 3324 | return NULL; |
| 3325 | |
| 3326 | if (seat->keyboard_device_count) |
| 3327 | return seat->keyboard_state; |
| 3328 | |
| 3329 | return NULL; |
| 3330 | } |
| 3331 | |
| 3332 | /** Get a seat's pointer pointer |
| 3333 | * |
| 3334 | * \param seat The seat to query |
| 3335 | * \return The seat's pointer pointer, or NULL if no pointer device is present |
| 3336 | * |
| 3337 | * The pointer pointer for a seat isn't freed when all mice are removed, |
| 3338 | * so it should only be used when the seat's pointer_device_count is greater |
| 3339 | * than zero. This function does that test and only returns a pointer |
| 3340 | * when a pointing device is present. |
| 3341 | */ |
| 3342 | WL_EXPORT struct weston_pointer * |
| 3343 | weston_seat_get_pointer(struct weston_seat *seat) |
| 3344 | { |
| 3345 | if (!seat) |
| 3346 | return NULL; |
| 3347 | |
| 3348 | if (seat->pointer_device_count) |
| 3349 | return seat->pointer_state; |
| 3350 | |
| 3351 | return NULL; |
| 3352 | } |
| 3353 | |
Jonas Ådahl | d3414f2 | 2016-07-22 17:56:31 +0800 | [diff] [blame] | 3354 | static const struct zwp_locked_pointer_v1_interface locked_pointer_interface; |
| 3355 | static const struct zwp_confined_pointer_v1_interface confined_pointer_interface; |
| 3356 | |
| 3357 | static enum pointer_constraint_type |
| 3358 | pointer_constraint_get_type(struct weston_pointer_constraint *constraint) |
| 3359 | { |
| 3360 | if (wl_resource_instance_of(constraint->resource, |
| 3361 | &zwp_locked_pointer_v1_interface, |
| 3362 | &locked_pointer_interface)) { |
| 3363 | return POINTER_CONSTRAINT_TYPE_LOCK; |
| 3364 | } else if (wl_resource_instance_of(constraint->resource, |
| 3365 | &zwp_confined_pointer_v1_interface, |
| 3366 | &confined_pointer_interface)) { |
| 3367 | return POINTER_CONSTRAINT_TYPE_CONFINE; |
| 3368 | } |
| 3369 | |
| 3370 | abort(); |
| 3371 | return 0; |
| 3372 | } |
| 3373 | |
| 3374 | static void |
| 3375 | pointer_constraint_notify_activated(struct weston_pointer_constraint *constraint) |
| 3376 | { |
| 3377 | struct wl_resource *resource = constraint->resource; |
| 3378 | |
| 3379 | switch (pointer_constraint_get_type(constraint)) { |
| 3380 | case POINTER_CONSTRAINT_TYPE_LOCK: |
| 3381 | zwp_locked_pointer_v1_send_locked(resource); |
| 3382 | break; |
| 3383 | case POINTER_CONSTRAINT_TYPE_CONFINE: |
| 3384 | zwp_confined_pointer_v1_send_confined(resource); |
| 3385 | break; |
| 3386 | } |
| 3387 | } |
| 3388 | |
| 3389 | static void |
| 3390 | pointer_constraint_notify_deactivated(struct weston_pointer_constraint *constraint) |
| 3391 | { |
| 3392 | struct wl_resource *resource = constraint->resource; |
| 3393 | |
| 3394 | switch (pointer_constraint_get_type(constraint)) { |
| 3395 | case POINTER_CONSTRAINT_TYPE_LOCK: |
| 3396 | zwp_locked_pointer_v1_send_unlocked(resource); |
| 3397 | break; |
| 3398 | case POINTER_CONSTRAINT_TYPE_CONFINE: |
| 3399 | zwp_confined_pointer_v1_send_unconfined(resource); |
| 3400 | break; |
| 3401 | } |
| 3402 | } |
| 3403 | |
| 3404 | static struct weston_pointer_constraint * |
| 3405 | get_pointer_constraint_for_pointer(struct weston_surface *surface, |
| 3406 | struct weston_pointer *pointer) |
| 3407 | { |
| 3408 | struct weston_pointer_constraint *constraint; |
| 3409 | |
| 3410 | wl_list_for_each(constraint, &surface->pointer_constraints, link) { |
| 3411 | if (constraint->pointer == pointer) |
| 3412 | return constraint; |
| 3413 | } |
| 3414 | |
| 3415 | return NULL; |
| 3416 | } |
| 3417 | |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 3418 | /** Get a seat's touch pointer |
| 3419 | * |
| 3420 | * \param seat The seat to query |
| 3421 | * \return The seat's touch pointer, or NULL if no touch device is present |
| 3422 | * |
| 3423 | * The touch pointer for a seat isn't freed when all touch devices are removed, |
| 3424 | * so it should only be used when the seat's touch_device_count is greater |
| 3425 | * than zero. This function does that test and only returns a pointer |
| 3426 | * when a touch device is present. |
| 3427 | */ |
| 3428 | WL_EXPORT struct weston_touch * |
| 3429 | weston_seat_get_touch(struct weston_seat *seat) |
| 3430 | { |
| 3431 | if (!seat) |
| 3432 | return NULL; |
| 3433 | |
| 3434 | if (seat->touch_device_count) |
| 3435 | return seat->touch_state; |
| 3436 | |
| 3437 | return NULL; |
| 3438 | } |
Bryce Harrington | 24f917e | 2016-06-29 19:04:07 -0700 | [diff] [blame] | 3439 | |
| 3440 | /** Sets the keyboard focus to the given surface |
| 3441 | * |
| 3442 | * \param seat The seat to query |
| 3443 | */ |
| 3444 | WL_EXPORT void |
| 3445 | weston_seat_set_keyboard_focus(struct weston_seat *seat, |
| 3446 | struct weston_surface *surface) |
| 3447 | { |
| 3448 | struct weston_compositor *compositor = seat->compositor; |
| 3449 | struct weston_keyboard *keyboard = weston_seat_get_keyboard(seat); |
Jonas Ådahl | f7deb6a | 2016-07-22 17:50:26 +0800 | [diff] [blame] | 3450 | struct weston_surface_activation_data activation_data; |
Bryce Harrington | 24f917e | 2016-06-29 19:04:07 -0700 | [diff] [blame] | 3451 | |
Jonas Ådahl | ef8e1c3 | 2016-03-15 20:28:51 +0800 | [diff] [blame] | 3452 | if (keyboard && keyboard->focus != surface) { |
Bryce Harrington | 24f917e | 2016-06-29 19:04:07 -0700 | [diff] [blame] | 3453 | weston_keyboard_set_focus(keyboard, surface); |
| 3454 | wl_data_device_set_keyboard_focus(seat); |
| 3455 | } |
| 3456 | |
Jonas Ådahl | 94e2e2d | 2014-10-18 18:42:19 +0200 | [diff] [blame] | 3457 | inc_activate_serial(compositor); |
Jonas Ådahl | f7deb6a | 2016-07-22 17:50:26 +0800 | [diff] [blame] | 3458 | |
| 3459 | activation_data = (struct weston_surface_activation_data) { |
| 3460 | .surface = surface, |
| 3461 | .seat = seat, |
| 3462 | }; |
| 3463 | wl_signal_emit(&compositor->activate_signal, &activation_data); |
Bryce Harrington | 24f917e | 2016-06-29 19:04:07 -0700 | [diff] [blame] | 3464 | } |
Jonas Ådahl | 30d61d8 | 2014-10-22 21:21:17 +0200 | [diff] [blame] | 3465 | |
Jonas Ådahl | d3414f2 | 2016-07-22 17:56:31 +0800 | [diff] [blame] | 3466 | static void |
| 3467 | enable_pointer_constraint(struct weston_pointer_constraint *constraint, |
| 3468 | struct weston_view *view) |
| 3469 | { |
| 3470 | assert(constraint->view == NULL); |
| 3471 | constraint->view = view; |
| 3472 | pointer_constraint_notify_activated(constraint); |
| 3473 | weston_pointer_start_grab(constraint->pointer, &constraint->grab); |
| 3474 | wl_list_remove(&constraint->surface_destroy_listener.link); |
| 3475 | wl_list_init(&constraint->surface_destroy_listener.link); |
| 3476 | } |
| 3477 | |
| 3478 | static bool |
| 3479 | is_pointer_constraint_enabled(struct weston_pointer_constraint *constraint) |
| 3480 | { |
| 3481 | return constraint->view != NULL; |
| 3482 | } |
| 3483 | |
| 3484 | static void |
| 3485 | weston_pointer_constraint_disable(struct weston_pointer_constraint *constraint) |
| 3486 | { |
| 3487 | constraint->view = NULL; |
| 3488 | pointer_constraint_notify_deactivated(constraint); |
| 3489 | weston_pointer_end_grab(constraint->grab.pointer); |
| 3490 | } |
| 3491 | |
| 3492 | void |
| 3493 | weston_pointer_constraint_destroy(struct weston_pointer_constraint *constraint) |
| 3494 | { |
| 3495 | if (is_pointer_constraint_enabled(constraint)) |
| 3496 | weston_pointer_constraint_disable(constraint); |
| 3497 | |
| 3498 | wl_list_remove(&constraint->pointer_destroy_listener.link); |
| 3499 | wl_list_remove(&constraint->surface_destroy_listener.link); |
| 3500 | wl_list_remove(&constraint->surface_commit_listener.link); |
| 3501 | wl_list_remove(&constraint->surface_activate_listener.link); |
| 3502 | |
| 3503 | wl_resource_set_user_data(constraint->resource, NULL); |
| 3504 | pixman_region32_fini(&constraint->region); |
| 3505 | wl_list_remove(&constraint->link); |
| 3506 | free(constraint); |
| 3507 | } |
| 3508 | |
| 3509 | static void |
| 3510 | disable_pointer_constraint(struct weston_pointer_constraint *constraint) |
| 3511 | { |
| 3512 | switch (constraint->lifetime) { |
| 3513 | case ZWP_POINTER_CONSTRAINTS_V1_LIFETIME_ONESHOT: |
| 3514 | weston_pointer_constraint_destroy(constraint); |
| 3515 | break; |
| 3516 | case ZWP_POINTER_CONSTRAINTS_V1_LIFETIME_PERSISTENT: |
| 3517 | weston_pointer_constraint_disable(constraint); |
| 3518 | break; |
| 3519 | } |
| 3520 | } |
| 3521 | |
| 3522 | static bool |
| 3523 | is_within_constraint_region(struct weston_pointer_constraint *constraint, |
| 3524 | wl_fixed_t sx, wl_fixed_t sy) |
| 3525 | { |
| 3526 | struct weston_surface *surface = constraint->surface; |
| 3527 | pixman_region32_t constraint_region; |
| 3528 | bool result; |
| 3529 | |
| 3530 | pixman_region32_init(&constraint_region); |
| 3531 | pixman_region32_intersect(&constraint_region, |
| 3532 | &surface->input, |
| 3533 | &constraint->region); |
| 3534 | result = pixman_region32_contains_point(&constraint_region, |
| 3535 | wl_fixed_to_int(sx), |
| 3536 | wl_fixed_to_int(sy), |
| 3537 | NULL); |
| 3538 | pixman_region32_fini(&constraint_region); |
| 3539 | |
| 3540 | return result; |
| 3541 | } |
| 3542 | |
| 3543 | static void |
| 3544 | maybe_enable_pointer_constraint(struct weston_pointer_constraint *constraint) |
| 3545 | { |
| 3546 | struct weston_surface *surface = constraint->surface; |
| 3547 | struct weston_view *vit; |
| 3548 | struct weston_view *view = NULL; |
| 3549 | struct weston_pointer *pointer = constraint->pointer; |
| 3550 | struct weston_keyboard *keyboard; |
| 3551 | struct weston_seat *seat = pointer->seat; |
| 3552 | int32_t x, y; |
| 3553 | |
| 3554 | /* Postpone if no view of the surface was most recently clicked. */ |
| 3555 | wl_list_for_each(vit, &surface->views, surface_link) { |
| 3556 | if (vit->click_to_activate_serial == |
| 3557 | surface->compositor->activate_serial) { |
| 3558 | view = vit; |
| 3559 | } |
| 3560 | } |
| 3561 | if (view == NULL) |
| 3562 | return; |
| 3563 | |
| 3564 | /* Postpone if surface doesn't have keyboard focus. */ |
| 3565 | keyboard = weston_seat_get_keyboard(seat); |
| 3566 | if (!keyboard || keyboard->focus != surface) |
| 3567 | return; |
| 3568 | |
| 3569 | /* Postpone constraint if the pointer is not within the |
| 3570 | * constraint region. |
| 3571 | */ |
| 3572 | weston_view_from_global(view, |
| 3573 | wl_fixed_to_int(pointer->x), |
| 3574 | wl_fixed_to_int(pointer->y), |
| 3575 | &x, &y); |
| 3576 | if (!is_within_constraint_region(constraint, |
| 3577 | wl_fixed_from_int(x), |
| 3578 | wl_fixed_from_int(y))) |
| 3579 | return; |
| 3580 | |
| 3581 | enable_pointer_constraint(constraint, view); |
| 3582 | } |
| 3583 | |
| 3584 | static void |
| 3585 | locked_pointer_grab_pointer_focus(struct weston_pointer_grab *grab) |
| 3586 | { |
| 3587 | } |
| 3588 | |
| 3589 | static void |
| 3590 | locked_pointer_grab_pointer_motion(struct weston_pointer_grab *grab, |
Alexandros Frantzis | 84b31f8 | 2017-11-24 18:01:46 +0200 | [diff] [blame] | 3591 | const struct timespec *time, |
Jonas Ådahl | d3414f2 | 2016-07-22 17:56:31 +0800 | [diff] [blame] | 3592 | struct weston_pointer_motion_event *event) |
| 3593 | { |
Quentin Glidic | cde1345 | 2016-08-12 10:41:32 +0200 | [diff] [blame] | 3594 | pointer_send_relative_motion(grab->pointer, time, event); |
Jonas Ådahl | d3414f2 | 2016-07-22 17:56:31 +0800 | [diff] [blame] | 3595 | } |
| 3596 | |
| 3597 | static void |
| 3598 | locked_pointer_grab_pointer_button(struct weston_pointer_grab *grab, |
Alexandros Frantzis | 215bedc | 2017-11-16 18:20:55 +0200 | [diff] [blame] | 3599 | const struct timespec *time, |
Jonas Ådahl | d3414f2 | 2016-07-22 17:56:31 +0800 | [diff] [blame] | 3600 | uint32_t button, |
| 3601 | uint32_t state_w) |
| 3602 | { |
| 3603 | weston_pointer_send_button(grab->pointer, time, button, state_w); |
| 3604 | } |
| 3605 | |
| 3606 | static void |
| 3607 | locked_pointer_grab_pointer_axis(struct weston_pointer_grab *grab, |
Alexandros Frantzis | 8032194 | 2017-11-16 18:20:56 +0200 | [diff] [blame] | 3608 | const struct timespec *time, |
Jonas Ådahl | d3414f2 | 2016-07-22 17:56:31 +0800 | [diff] [blame] | 3609 | struct weston_pointer_axis_event *event) |
| 3610 | { |
| 3611 | weston_pointer_send_axis(grab->pointer, time, event); |
| 3612 | } |
| 3613 | |
| 3614 | static void |
| 3615 | locked_pointer_grab_pointer_axis_source(struct weston_pointer_grab *grab, |
| 3616 | uint32_t source) |
| 3617 | { |
| 3618 | weston_pointer_send_axis_source(grab->pointer, source); |
| 3619 | } |
| 3620 | |
| 3621 | static void |
| 3622 | locked_pointer_grab_pointer_frame(struct weston_pointer_grab *grab) |
| 3623 | { |
| 3624 | weston_pointer_send_frame(grab->pointer); |
| 3625 | } |
| 3626 | |
| 3627 | static void |
| 3628 | locked_pointer_grab_pointer_cancel(struct weston_pointer_grab *grab) |
| 3629 | { |
| 3630 | struct weston_pointer_constraint *constraint = |
| 3631 | container_of(grab, struct weston_pointer_constraint, grab); |
| 3632 | |
| 3633 | disable_pointer_constraint(constraint); |
| 3634 | } |
| 3635 | |
| 3636 | static const struct weston_pointer_grab_interface |
| 3637 | locked_pointer_grab_interface = { |
| 3638 | locked_pointer_grab_pointer_focus, |
| 3639 | locked_pointer_grab_pointer_motion, |
| 3640 | locked_pointer_grab_pointer_button, |
| 3641 | locked_pointer_grab_pointer_axis, |
| 3642 | locked_pointer_grab_pointer_axis_source, |
| 3643 | locked_pointer_grab_pointer_frame, |
| 3644 | locked_pointer_grab_pointer_cancel, |
| 3645 | }; |
| 3646 | |
| 3647 | static void |
| 3648 | pointer_constraint_constrain_resource_destroyed(struct wl_resource *resource) |
| 3649 | { |
| 3650 | struct weston_pointer_constraint *constraint = |
| 3651 | wl_resource_get_user_data(resource); |
| 3652 | |
| 3653 | if (!constraint) |
| 3654 | return; |
| 3655 | |
| 3656 | weston_pointer_constraint_destroy(constraint); |
| 3657 | } |
| 3658 | |
| 3659 | static void |
| 3660 | pointer_constraint_surface_activate(struct wl_listener *listener, void *data) |
| 3661 | { |
| 3662 | struct weston_surface_activation_data *activation = data; |
| 3663 | struct weston_pointer *pointer; |
| 3664 | struct weston_surface *focus = activation->surface; |
| 3665 | struct weston_pointer_constraint *constraint = |
| 3666 | container_of(listener, struct weston_pointer_constraint, |
| 3667 | surface_activate_listener); |
| 3668 | bool is_constraint_surface; |
| 3669 | |
| 3670 | pointer = weston_seat_get_pointer(activation->seat); |
| 3671 | if (!pointer) |
| 3672 | return; |
| 3673 | |
| 3674 | is_constraint_surface = |
| 3675 | get_pointer_constraint_for_pointer(focus, pointer) == constraint; |
| 3676 | |
| 3677 | if (is_constraint_surface && |
| 3678 | !is_pointer_constraint_enabled(constraint)) |
| 3679 | maybe_enable_pointer_constraint(constraint); |
| 3680 | else if (!is_constraint_surface && |
| 3681 | is_pointer_constraint_enabled(constraint)) |
| 3682 | disable_pointer_constraint(constraint); |
| 3683 | } |
| 3684 | |
| 3685 | static void |
| 3686 | pointer_constraint_pointer_destroyed(struct wl_listener *listener, void *data) |
| 3687 | { |
| 3688 | struct weston_pointer_constraint *constraint = |
| 3689 | container_of(listener, struct weston_pointer_constraint, |
| 3690 | pointer_destroy_listener); |
| 3691 | |
| 3692 | weston_pointer_constraint_destroy(constraint); |
| 3693 | } |
| 3694 | |
| 3695 | static void |
| 3696 | pointer_constraint_surface_destroyed(struct wl_listener *listener, void *data) |
| 3697 | { |
| 3698 | struct weston_pointer_constraint *constraint = |
| 3699 | container_of(listener, struct weston_pointer_constraint, |
| 3700 | surface_destroy_listener); |
| 3701 | |
| 3702 | weston_pointer_constraint_destroy(constraint); |
| 3703 | } |
| 3704 | |
| 3705 | static void |
| 3706 | pointer_constraint_surface_committed(struct wl_listener *listener, void *data) |
| 3707 | { |
| 3708 | struct weston_pointer_constraint *constraint = |
| 3709 | container_of(listener, struct weston_pointer_constraint, |
| 3710 | surface_commit_listener); |
| 3711 | |
| 3712 | if (constraint->region_is_pending) { |
| 3713 | constraint->region_is_pending = false; |
| 3714 | pixman_region32_copy(&constraint->region, |
| 3715 | &constraint->region_pending); |
| 3716 | pixman_region32_fini(&constraint->region_pending); |
| 3717 | pixman_region32_init(&constraint->region_pending); |
| 3718 | } |
| 3719 | |
| 3720 | if (constraint->hint_is_pending) { |
| 3721 | constraint->hint_is_pending = false; |
| 3722 | |
| 3723 | constraint->hint_is_pending = true; |
| 3724 | constraint->hint_x = constraint->hint_x_pending; |
| 3725 | constraint->hint_y = constraint->hint_y_pending; |
| 3726 | } |
| 3727 | |
| 3728 | if (pointer_constraint_get_type(constraint) == |
| 3729 | POINTER_CONSTRAINT_TYPE_CONFINE && |
| 3730 | is_pointer_constraint_enabled(constraint)) |
| 3731 | maybe_warp_confined_pointer(constraint); |
| 3732 | } |
| 3733 | |
| 3734 | static struct weston_pointer_constraint * |
| 3735 | weston_pointer_constraint_create(struct weston_surface *surface, |
| 3736 | struct weston_pointer *pointer, |
| 3737 | struct weston_region *region, |
| 3738 | enum zwp_pointer_constraints_v1_lifetime lifetime, |
| 3739 | struct wl_resource *cr, |
| 3740 | const struct weston_pointer_grab_interface *grab_interface) |
| 3741 | { |
| 3742 | struct weston_pointer_constraint *constraint; |
| 3743 | |
| 3744 | constraint = zalloc(sizeof *constraint); |
| 3745 | if (!constraint) |
| 3746 | return NULL; |
| 3747 | |
| 3748 | constraint->lifetime = lifetime; |
| 3749 | pixman_region32_init(&constraint->region); |
| 3750 | pixman_region32_init(&constraint->region_pending); |
| 3751 | wl_list_insert(&surface->pointer_constraints, &constraint->link); |
| 3752 | constraint->surface = surface; |
| 3753 | constraint->pointer = pointer; |
| 3754 | constraint->resource = cr; |
| 3755 | constraint->grab.interface = grab_interface; |
| 3756 | if (region) { |
| 3757 | pixman_region32_copy(&constraint->region, |
| 3758 | ®ion->region); |
| 3759 | } else { |
| 3760 | pixman_region32_fini(&constraint->region); |
| 3761 | region_init_infinite(&constraint->region); |
| 3762 | } |
| 3763 | |
| 3764 | constraint->surface_activate_listener.notify = |
| 3765 | pointer_constraint_surface_activate; |
| 3766 | constraint->surface_destroy_listener.notify = |
| 3767 | pointer_constraint_surface_destroyed; |
| 3768 | constraint->surface_commit_listener.notify = |
| 3769 | pointer_constraint_surface_committed; |
| 3770 | constraint->pointer_destroy_listener.notify = |
| 3771 | pointer_constraint_pointer_destroyed; |
| 3772 | |
| 3773 | wl_signal_add(&surface->compositor->activate_signal, |
| 3774 | &constraint->surface_activate_listener); |
| 3775 | wl_signal_add(&pointer->destroy_signal, |
| 3776 | &constraint->pointer_destroy_listener); |
| 3777 | wl_signal_add(&surface->destroy_signal, |
| 3778 | &constraint->surface_destroy_listener); |
| 3779 | wl_signal_add(&surface->commit_signal, |
| 3780 | &constraint->surface_commit_listener); |
| 3781 | |
| 3782 | return constraint; |
| 3783 | } |
| 3784 | |
| 3785 | static void |
| 3786 | init_pointer_constraint(struct wl_resource *pointer_constraints_resource, |
| 3787 | uint32_t id, |
| 3788 | struct weston_surface *surface, |
| 3789 | struct weston_pointer *pointer, |
| 3790 | struct weston_region *region, |
| 3791 | enum zwp_pointer_constraints_v1_lifetime lifetime, |
| 3792 | const struct wl_interface *interface, |
| 3793 | const void *implementation, |
| 3794 | const struct weston_pointer_grab_interface *grab_interface) |
| 3795 | { |
| 3796 | struct wl_client *client = |
| 3797 | wl_resource_get_client(pointer_constraints_resource); |
| 3798 | struct wl_resource *cr; |
| 3799 | struct weston_pointer_constraint *constraint; |
| 3800 | |
Alexandros Frantzis | 0f14ae9 | 2018-02-08 15:37:52 +0200 | [diff] [blame] | 3801 | if (pointer && get_pointer_constraint_for_pointer(surface, pointer)) { |
Jonas Ådahl | d3414f2 | 2016-07-22 17:56:31 +0800 | [diff] [blame] | 3802 | wl_resource_post_error(pointer_constraints_resource, |
| 3803 | ZWP_POINTER_CONSTRAINTS_V1_ERROR_ALREADY_CONSTRAINED, |
| 3804 | "the pointer has a lock/confine request on this surface"); |
| 3805 | return; |
| 3806 | } |
| 3807 | |
| 3808 | cr = wl_resource_create(client, interface, |
| 3809 | wl_resource_get_version(pointer_constraints_resource), |
| 3810 | id); |
| 3811 | if (cr == NULL) { |
| 3812 | wl_client_post_no_memory(client); |
| 3813 | return; |
| 3814 | } |
| 3815 | |
Alexandros Frantzis | 0f14ae9 | 2018-02-08 15:37:52 +0200 | [diff] [blame] | 3816 | if (pointer) { |
| 3817 | constraint = weston_pointer_constraint_create(surface, pointer, |
| 3818 | region, lifetime, |
| 3819 | cr, grab_interface); |
| 3820 | if (constraint == NULL) { |
| 3821 | wl_client_post_no_memory(client); |
| 3822 | return; |
| 3823 | } |
| 3824 | } else { |
| 3825 | constraint = NULL; |
Jonas Ådahl | d3414f2 | 2016-07-22 17:56:31 +0800 | [diff] [blame] | 3826 | } |
| 3827 | |
| 3828 | wl_resource_set_implementation(cr, implementation, constraint, |
| 3829 | pointer_constraint_constrain_resource_destroyed); |
| 3830 | |
Alexandros Frantzis | 0f14ae9 | 2018-02-08 15:37:52 +0200 | [diff] [blame] | 3831 | if (constraint) |
| 3832 | maybe_enable_pointer_constraint(constraint); |
Jonas Ådahl | d3414f2 | 2016-07-22 17:56:31 +0800 | [diff] [blame] | 3833 | } |
| 3834 | |
| 3835 | static void |
| 3836 | pointer_constraints_destroy(struct wl_client *client, |
| 3837 | struct wl_resource *resource) |
| 3838 | { |
| 3839 | wl_resource_destroy(resource); |
| 3840 | } |
| 3841 | |
| 3842 | static void |
| 3843 | locked_pointer_destroy(struct wl_client *client, |
| 3844 | struct wl_resource *resource) |
| 3845 | { |
| 3846 | struct weston_pointer_constraint *constraint = |
| 3847 | wl_resource_get_user_data(resource); |
| 3848 | wl_fixed_t x, y; |
| 3849 | |
| 3850 | if (constraint && constraint->view && constraint->hint_is_pending && |
| 3851 | is_within_constraint_region(constraint, |
| 3852 | constraint->hint_x, |
| 3853 | constraint->hint_y)) { |
| 3854 | weston_view_to_global_fixed(constraint->view, |
| 3855 | constraint->hint_x, |
| 3856 | constraint->hint_y, |
| 3857 | &x, &y); |
| 3858 | weston_pointer_move_to(constraint->pointer, x, y); |
| 3859 | } |
| 3860 | wl_resource_destroy(resource); |
| 3861 | } |
| 3862 | |
| 3863 | static void |
| 3864 | locked_pointer_set_cursor_position_hint(struct wl_client *client, |
| 3865 | struct wl_resource *resource, |
| 3866 | wl_fixed_t surface_x, |
| 3867 | wl_fixed_t surface_y) |
| 3868 | { |
| 3869 | struct weston_pointer_constraint *constraint = |
| 3870 | wl_resource_get_user_data(resource); |
| 3871 | |
| 3872 | /* Ignore a set cursor hint that was sent after the lock was cancelled. |
| 3873 | */ |
| 3874 | if (!constraint || |
| 3875 | !constraint->resource || |
| 3876 | constraint->resource != resource) |
| 3877 | return; |
| 3878 | |
| 3879 | constraint->hint_is_pending = true; |
| 3880 | constraint->hint_x_pending = surface_x; |
| 3881 | constraint->hint_y_pending = surface_y; |
| 3882 | } |
| 3883 | |
| 3884 | static void |
| 3885 | locked_pointer_set_region(struct wl_client *client, |
| 3886 | struct wl_resource *resource, |
| 3887 | struct wl_resource *region_resource) |
| 3888 | { |
| 3889 | struct weston_pointer_constraint *constraint = |
| 3890 | wl_resource_get_user_data(resource); |
| 3891 | struct weston_region *region = region_resource ? |
| 3892 | wl_resource_get_user_data(region_resource) : NULL; |
| 3893 | |
| 3894 | if (!constraint) |
| 3895 | return; |
| 3896 | |
| 3897 | if (region) { |
| 3898 | pixman_region32_copy(&constraint->region_pending, |
| 3899 | ®ion->region); |
| 3900 | } else { |
| 3901 | pixman_region32_fini(&constraint->region_pending); |
| 3902 | region_init_infinite(&constraint->region_pending); |
| 3903 | } |
| 3904 | constraint->region_is_pending = true; |
| 3905 | } |
| 3906 | |
| 3907 | |
| 3908 | static const struct zwp_locked_pointer_v1_interface locked_pointer_interface = { |
| 3909 | locked_pointer_destroy, |
| 3910 | locked_pointer_set_cursor_position_hint, |
| 3911 | locked_pointer_set_region, |
| 3912 | }; |
| 3913 | |
| 3914 | static void |
| 3915 | pointer_constraints_lock_pointer(struct wl_client *client, |
| 3916 | struct wl_resource *resource, |
| 3917 | uint32_t id, |
| 3918 | struct wl_resource *surface_resource, |
| 3919 | struct wl_resource *pointer_resource, |
| 3920 | struct wl_resource *region_resource, |
| 3921 | uint32_t lifetime) |
| 3922 | { |
| 3923 | struct weston_surface *surface = |
| 3924 | wl_resource_get_user_data(surface_resource); |
| 3925 | struct weston_pointer *pointer = wl_resource_get_user_data(pointer_resource); |
| 3926 | struct weston_region *region = region_resource ? |
| 3927 | wl_resource_get_user_data(region_resource) : NULL; |
| 3928 | |
| 3929 | init_pointer_constraint(resource, id, surface, pointer, region, lifetime, |
| 3930 | &zwp_locked_pointer_v1_interface, |
| 3931 | &locked_pointer_interface, |
| 3932 | &locked_pointer_grab_interface); |
| 3933 | } |
| 3934 | |
| 3935 | static void |
| 3936 | confined_pointer_grab_pointer_focus(struct weston_pointer_grab *grab) |
| 3937 | { |
| 3938 | } |
| 3939 | |
Jonas Ådahl | d0be2bb | 2015-04-30 17:56:37 +0800 | [diff] [blame] | 3940 | static double |
| 3941 | vec2d_cross_product(struct vec2d a, struct vec2d b) |
| 3942 | { |
| 3943 | return a.x * b.y - a.y * b.x; |
| 3944 | } |
| 3945 | |
| 3946 | static struct vec2d |
| 3947 | vec2d_add(struct vec2d a, struct vec2d b) |
| 3948 | { |
| 3949 | return (struct vec2d) { |
| 3950 | .x = a.x + b.x, |
| 3951 | .y = a.y + b.y, |
| 3952 | }; |
| 3953 | } |
| 3954 | |
| 3955 | static struct vec2d |
| 3956 | vec2d_subtract(struct vec2d a, struct vec2d b) |
| 3957 | { |
| 3958 | return (struct vec2d) { |
| 3959 | .x = a.x - b.x, |
| 3960 | .y = a.y - b.y, |
| 3961 | }; |
| 3962 | } |
| 3963 | |
| 3964 | static struct vec2d |
| 3965 | vec2d_multiply_constant(double c, struct vec2d a) |
| 3966 | { |
| 3967 | return (struct vec2d) { |
| 3968 | .x = c * a.x, |
| 3969 | .y = c * a.y, |
| 3970 | }; |
| 3971 | } |
| 3972 | |
| 3973 | static bool |
| 3974 | lines_intersect(struct line *line1, struct line *line2, |
| 3975 | struct vec2d *intersection) |
| 3976 | { |
| 3977 | struct vec2d p = line1->a; |
| 3978 | struct vec2d r = vec2d_subtract(line1->b, line1->a); |
| 3979 | struct vec2d q = line2->a; |
| 3980 | struct vec2d s = vec2d_subtract(line2->b, line2->a); |
| 3981 | double rxs; |
| 3982 | double sxr; |
| 3983 | double t; |
| 3984 | double u; |
| 3985 | |
| 3986 | /* |
| 3987 | * The line (p, r) and (q, s) intersects where |
| 3988 | * |
| 3989 | * p + t r = q + u s |
| 3990 | * |
| 3991 | * Calculate t: |
| 3992 | * |
| 3993 | * (p + t r) × s = (q + u s) × s |
| 3994 | * p × s + t (r × s) = q × s + u (s × s) |
| 3995 | * p × s + t (r × s) = q × s |
| 3996 | * t (r × s) = q × s - p × s |
| 3997 | * t (r × s) = (q - p) × s |
| 3998 | * t = ((q - p) × s) / (r × s) |
| 3999 | * |
| 4000 | * Using the same method, for u we get: |
| 4001 | * |
| 4002 | * u = ((p - q) × r) / (s × r) |
| 4003 | */ |
| 4004 | |
| 4005 | rxs = vec2d_cross_product(r, s); |
| 4006 | sxr = vec2d_cross_product(s, r); |
| 4007 | |
| 4008 | /* If r × s = 0 then the lines are either parallel or collinear. */ |
| 4009 | if (fabs(rxs) < DBL_MIN) |
| 4010 | return false; |
| 4011 | |
| 4012 | t = vec2d_cross_product(vec2d_subtract(q, p), s) / rxs; |
| 4013 | u = vec2d_cross_product(vec2d_subtract(p, q), r) / sxr; |
| 4014 | |
| 4015 | /* The lines only intersect if 0 ≤ t ≤ 1 and 0 ≤ u ≤ 1. */ |
| 4016 | if (t < 0.0 || t > 1.0 || u < 0.0 || u > 1.0) |
| 4017 | return false; |
| 4018 | |
| 4019 | *intersection = vec2d_add(p, vec2d_multiply_constant(t, r)); |
| 4020 | return true; |
| 4021 | } |
| 4022 | |
| 4023 | static struct border * |
| 4024 | add_border(struct wl_array *array, |
| 4025 | double x1, double y1, |
| 4026 | double x2, double y2, |
| 4027 | enum motion_direction blocking_dir) |
| 4028 | { |
| 4029 | struct border *border = wl_array_add(array, sizeof *border); |
| 4030 | |
| 4031 | *border = (struct border) { |
| 4032 | .line = (struct line) { |
| 4033 | .a = (struct vec2d) { |
| 4034 | .x = x1, |
| 4035 | .y = y1, |
| 4036 | }, |
| 4037 | .b = (struct vec2d) { |
| 4038 | .x = x2, |
| 4039 | .y = y2, |
| 4040 | }, |
| 4041 | }, |
| 4042 | .blocking_dir = blocking_dir, |
| 4043 | }; |
| 4044 | |
| 4045 | return border; |
| 4046 | } |
| 4047 | |
| 4048 | static int |
| 4049 | compare_lines_x(const void *a, const void *b) |
| 4050 | { |
| 4051 | const struct border *border_a = a; |
| 4052 | const struct border *border_b = b; |
| 4053 | |
| 4054 | |
| 4055 | if (border_a->line.a.x == border_b->line.a.x) |
| 4056 | return border_a->line.b.x < border_b->line.b.x; |
| 4057 | else |
| 4058 | return border_a->line.a.x > border_b->line.a.x; |
| 4059 | } |
| 4060 | |
| 4061 | static void |
| 4062 | add_non_overlapping_edges(pixman_box32_t *boxes, |
| 4063 | int band_above_start, |
| 4064 | int band_below_start, |
| 4065 | int band_below_end, |
| 4066 | struct wl_array *borders) |
| 4067 | { |
| 4068 | int i; |
| 4069 | struct wl_array band_merge; |
| 4070 | struct border *border; |
| 4071 | struct border *prev_border; |
| 4072 | struct border *new_border; |
| 4073 | |
| 4074 | wl_array_init(&band_merge); |
| 4075 | |
| 4076 | /* Add bottom band of previous row, and top band of current row, and |
| 4077 | * sort them so lower left x coordinate comes first. If there are two |
| 4078 | * borders with the same left x coordinate, the wider one comes first. |
| 4079 | */ |
| 4080 | for (i = band_above_start; i < band_below_start; i++) { |
| 4081 | pixman_box32_t *box = &boxes[i]; |
| 4082 | add_border(&band_merge, box->x1, box->y2, box->x2, box->y2, |
| 4083 | MOTION_DIRECTION_POSITIVE_Y); |
| 4084 | } |
| 4085 | for (i = band_below_start; i < band_below_end; i++) { |
| 4086 | pixman_box32_t *box= &boxes[i]; |
| 4087 | add_border(&band_merge, box->x1, box->y1, box->x2, box->y1, |
| 4088 | MOTION_DIRECTION_NEGATIVE_Y); |
| 4089 | } |
| 4090 | qsort(band_merge.data, |
| 4091 | band_merge.size / sizeof *border, |
| 4092 | sizeof *border, |
| 4093 | compare_lines_x); |
| 4094 | |
| 4095 | /* Combine the two combined bands so that any overlapping border is |
| 4096 | * eliminated. */ |
| 4097 | prev_border = NULL; |
| 4098 | wl_array_for_each(border, &band_merge) { |
| 4099 | assert(border->line.a.y == border->line.b.y); |
| 4100 | assert(!prev_border || |
| 4101 | prev_border->line.a.y == border->line.a.y); |
| 4102 | assert(!prev_border || |
| 4103 | (prev_border->line.a.x != border->line.a.x || |
| 4104 | prev_border->line.b.x != border->line.b.x)); |
| 4105 | assert(!prev_border || |
| 4106 | prev_border->line.a.x <= border->line.a.x); |
| 4107 | |
| 4108 | if (prev_border && |
| 4109 | prev_border->line.a.x == border->line.a.x) { |
| 4110 | /* |
| 4111 | * ------------ + |
| 4112 | * ------- = |
| 4113 | * [ ]----- |
| 4114 | */ |
| 4115 | prev_border->line.a.x = border->line.b.x; |
| 4116 | } else if (prev_border && |
| 4117 | prev_border->line.b.x == border->line.b.x) { |
| 4118 | /* |
| 4119 | * ------------ + |
| 4120 | * ------ = |
| 4121 | * ------[ ] |
| 4122 | */ |
| 4123 | prev_border->line.b.x = border->line.a.x; |
| 4124 | } else if (prev_border && |
| 4125 | prev_border->line.b.x == border->line.a.x) { |
| 4126 | /* |
| 4127 | * -------- + |
| 4128 | * ------ = |
| 4129 | * -------------- |
| 4130 | */ |
| 4131 | prev_border->line.b.x = border->line.b.x; |
| 4132 | } else if (prev_border && |
| 4133 | prev_border->line.b.x >= border->line.a.x) { |
| 4134 | /* |
| 4135 | * --------------- + |
| 4136 | * ------ = |
| 4137 | * -----[ ]---- |
| 4138 | */ |
| 4139 | new_border = add_border(borders, |
| 4140 | border->line.b.x, |
| 4141 | border->line.b.y, |
| 4142 | prev_border->line.b.x, |
| 4143 | prev_border->line.b.y, |
| 4144 | prev_border->blocking_dir); |
| 4145 | prev_border->line.b.x = border->line.a.x; |
| 4146 | prev_border = new_border; |
| 4147 | } else { |
| 4148 | assert(!prev_border || |
| 4149 | prev_border->line.b.x < border->line.a.x); |
| 4150 | /* |
| 4151 | * First border or non-overlapping. |
| 4152 | * |
| 4153 | * ----- + |
| 4154 | * ----- = |
| 4155 | * ----- ----- |
| 4156 | */ |
| 4157 | new_border = wl_array_add(borders, sizeof *border); |
| 4158 | *new_border = *border; |
| 4159 | prev_border = new_border; |
| 4160 | } |
| 4161 | } |
| 4162 | |
| 4163 | wl_array_release(&band_merge); |
| 4164 | } |
| 4165 | |
| 4166 | static void |
| 4167 | add_band_bottom_edges(pixman_box32_t *boxes, |
| 4168 | int band_start, |
| 4169 | int band_end, |
| 4170 | struct wl_array *borders) |
| 4171 | { |
| 4172 | int i; |
| 4173 | |
| 4174 | for (i = band_start; i < band_end; i++) { |
| 4175 | add_border(borders, |
| 4176 | boxes[i].x1, boxes[i].y2, |
| 4177 | boxes[i].x2, boxes[i].y2, |
| 4178 | MOTION_DIRECTION_POSITIVE_Y); |
| 4179 | } |
| 4180 | } |
| 4181 | |
| 4182 | static void |
| 4183 | region_to_outline(pixman_region32_t *region, struct wl_array *borders) |
| 4184 | { |
| 4185 | pixman_box32_t *boxes; |
| 4186 | int num_boxes; |
| 4187 | int i; |
| 4188 | int top_most, bottom_most; |
| 4189 | int current_roof; |
| 4190 | int prev_top; |
| 4191 | int band_start, prev_band_start; |
| 4192 | |
| 4193 | /* |
| 4194 | * Remove any overlapping lines from the set of rectangles. Note that |
| 4195 | * pixman regions are grouped as rows of rectangles, where rectangles |
| 4196 | * in one row never touch or overlap and are all of the same height. |
| 4197 | * |
| 4198 | * -------- --- -------- --- |
| 4199 | * | | | | | | | | |
| 4200 | * ----------====---- --- ----------- ----- --- |
| 4201 | * | | => | | |
| 4202 | * ----==========--------- ----- ---------- |
| 4203 | * | | | | |
| 4204 | * ------------------- ------------------- |
| 4205 | * |
| 4206 | */ |
| 4207 | |
| 4208 | boxes = pixman_region32_rectangles(region, &num_boxes); |
| 4209 | prev_top = 0; |
| 4210 | top_most = boxes[0].y1; |
| 4211 | current_roof = top_most; |
| 4212 | bottom_most = boxes[num_boxes - 1].y2; |
| 4213 | band_start = 0; |
| 4214 | prev_band_start = 0; |
| 4215 | for (i = 0; i < num_boxes; i++) { |
| 4216 | /* Detect if there is a vertical empty space, and add the lower |
| 4217 | * level of the previous band if so was the case. */ |
| 4218 | if (i > 0 && |
| 4219 | boxes[i].y1 != prev_top && |
| 4220 | boxes[i].y1 != boxes[i - 1].y2) { |
| 4221 | current_roof = boxes[i].y1; |
| 4222 | add_band_bottom_edges(boxes, |
| 4223 | band_start, |
| 4224 | i, |
| 4225 | borders); |
| 4226 | } |
| 4227 | |
| 4228 | /* Special case adding the last band, since it won't be handled |
| 4229 | * by the band change detection below. */ |
| 4230 | if (boxes[i].y1 != current_roof && i == num_boxes - 1) { |
| 4231 | if (boxes[i].y1 != prev_top) { |
| 4232 | /* The last band is a single box, so we don't |
| 4233 | * have a prev_band_start to tell us when the |
| 4234 | * previous band started. */ |
| 4235 | add_non_overlapping_edges(boxes, |
| 4236 | band_start, |
| 4237 | i, |
| 4238 | i + 1, |
| 4239 | borders); |
| 4240 | } else { |
| 4241 | add_non_overlapping_edges(boxes, |
| 4242 | prev_band_start, |
| 4243 | band_start, |
| 4244 | i + 1, |
| 4245 | borders); |
| 4246 | } |
| 4247 | } |
| 4248 | |
| 4249 | /* Detect when passing a band and combine the top border of the |
| 4250 | * just passed band with the bottom band of the previous band. |
| 4251 | */ |
| 4252 | if (boxes[i].y1 != top_most && boxes[i].y1 != prev_top) { |
| 4253 | /* Combine the two passed bands. */ |
| 4254 | if (prev_top != current_roof) { |
| 4255 | add_non_overlapping_edges(boxes, |
| 4256 | prev_band_start, |
| 4257 | band_start, |
| 4258 | i, |
| 4259 | borders); |
| 4260 | } |
| 4261 | |
| 4262 | prev_band_start = band_start; |
| 4263 | band_start = i; |
| 4264 | } |
| 4265 | |
| 4266 | /* Add the top border if the box is part of the current roof. */ |
| 4267 | if (boxes[i].y1 == current_roof) { |
| 4268 | add_border(borders, |
| 4269 | boxes[i].x1, boxes[i].y1, |
| 4270 | boxes[i].x2, boxes[i].y1, |
| 4271 | MOTION_DIRECTION_NEGATIVE_Y); |
| 4272 | } |
| 4273 | |
| 4274 | /* Add the bottom border of the last band. */ |
| 4275 | if (boxes[i].y2 == bottom_most) { |
| 4276 | add_border(borders, |
| 4277 | boxes[i].x1, boxes[i].y2, |
| 4278 | boxes[i].x2, boxes[i].y2, |
| 4279 | MOTION_DIRECTION_POSITIVE_Y); |
| 4280 | } |
| 4281 | |
| 4282 | /* Always add the left border. */ |
| 4283 | add_border(borders, |
| 4284 | boxes[i].x1, boxes[i].y1, |
| 4285 | boxes[i].x1, boxes[i].y2, |
| 4286 | MOTION_DIRECTION_NEGATIVE_X); |
| 4287 | |
| 4288 | /* Always add the right border. */ |
| 4289 | add_border(borders, |
| 4290 | boxes[i].x2, boxes[i].y1, |
| 4291 | boxes[i].x2, boxes[i].y2, |
| 4292 | MOTION_DIRECTION_POSITIVE_X); |
| 4293 | |
| 4294 | prev_top = boxes[i].y1; |
| 4295 | } |
| 4296 | } |
| 4297 | |
| 4298 | static bool |
| 4299 | is_border_horizontal (struct border *border) |
| 4300 | { |
| 4301 | return border->line.a.y == border->line.b.y; |
| 4302 | } |
| 4303 | |
| 4304 | static bool |
| 4305 | is_border_blocking_directions(struct border *border, |
| 4306 | uint32_t directions) |
| 4307 | { |
| 4308 | /* Don't block parallel motions. */ |
| 4309 | if (is_border_horizontal(border)) { |
| 4310 | if ((directions & (MOTION_DIRECTION_POSITIVE_Y | |
| 4311 | MOTION_DIRECTION_NEGATIVE_Y)) == 0) |
| 4312 | return false; |
| 4313 | } else { |
| 4314 | if ((directions & (MOTION_DIRECTION_POSITIVE_X | |
| 4315 | MOTION_DIRECTION_NEGATIVE_X)) == 0) |
| 4316 | return false; |
| 4317 | } |
| 4318 | |
| 4319 | return (~border->blocking_dir & directions) != directions; |
| 4320 | } |
| 4321 | |
| 4322 | static struct border * |
| 4323 | get_closest_border(struct wl_array *borders, |
| 4324 | struct line *motion, |
| 4325 | uint32_t directions) |
| 4326 | { |
| 4327 | struct border *border; |
| 4328 | struct vec2d intersection; |
| 4329 | struct vec2d delta; |
| 4330 | double distance_2; |
| 4331 | struct border *closest_border = NULL; |
| 4332 | double closest_distance_2 = DBL_MAX; |
| 4333 | |
| 4334 | wl_array_for_each(border, borders) { |
| 4335 | if (!is_border_blocking_directions(border, directions)) |
| 4336 | continue; |
| 4337 | |
| 4338 | if (!lines_intersect(&border->line, motion, &intersection)) |
| 4339 | continue; |
| 4340 | |
| 4341 | delta = vec2d_subtract(intersection, motion->a); |
| 4342 | distance_2 = delta.x*delta.x + delta.y*delta.y; |
| 4343 | if (distance_2 < closest_distance_2) { |
| 4344 | closest_border = border; |
| 4345 | closest_distance_2 = distance_2; |
| 4346 | } |
| 4347 | } |
| 4348 | |
| 4349 | return closest_border; |
| 4350 | } |
| 4351 | |
| 4352 | static void |
| 4353 | clamp_to_border(struct border *border, |
| 4354 | struct line *motion, |
| 4355 | uint32_t *motion_dir) |
| 4356 | { |
| 4357 | /* |
| 4358 | * When clamping either rightward or downward motions, the motion needs |
| 4359 | * to be clamped so that the destination coordinate does not end up on |
| 4360 | * the border (see weston_pointer_clamp_event_to_region). Do this by |
| 4361 | * clamping such motions to the border minus the smallest possible |
| 4362 | * wl_fixed_t value. |
| 4363 | */ |
| 4364 | if (is_border_horizontal(border)) { |
| 4365 | if (*motion_dir & MOTION_DIRECTION_POSITIVE_Y) |
| 4366 | motion->b.y = border->line.a.y - wl_fixed_to_double(1); |
| 4367 | else |
| 4368 | motion->b.y = border->line.a.y; |
| 4369 | *motion_dir &= ~(MOTION_DIRECTION_POSITIVE_Y | |
| 4370 | MOTION_DIRECTION_NEGATIVE_Y); |
| 4371 | } else { |
| 4372 | if (*motion_dir & MOTION_DIRECTION_POSITIVE_X) |
| 4373 | motion->b.x = border->line.a.x - wl_fixed_to_double(1); |
| 4374 | else |
| 4375 | motion->b.x = border->line.a.x; |
| 4376 | *motion_dir &= ~(MOTION_DIRECTION_POSITIVE_X | |
| 4377 | MOTION_DIRECTION_NEGATIVE_X); |
| 4378 | } |
| 4379 | } |
| 4380 | |
| 4381 | static uint32_t |
| 4382 | get_motion_directions(struct line *motion) |
| 4383 | { |
| 4384 | uint32_t directions = 0; |
| 4385 | |
| 4386 | if (motion->a.x < motion->b.x) |
| 4387 | directions |= MOTION_DIRECTION_POSITIVE_X; |
| 4388 | else if (motion->a.x > motion->b.x) |
| 4389 | directions |= MOTION_DIRECTION_NEGATIVE_X; |
| 4390 | if (motion->a.y < motion->b.y) |
| 4391 | directions |= MOTION_DIRECTION_POSITIVE_Y; |
| 4392 | else if (motion->a.y > motion->b.y) |
| 4393 | directions |= MOTION_DIRECTION_NEGATIVE_Y; |
| 4394 | |
| 4395 | return directions; |
| 4396 | } |
| 4397 | |
Jonas Ådahl | d3414f2 | 2016-07-22 17:56:31 +0800 | [diff] [blame] | 4398 | static void |
| 4399 | weston_pointer_clamp_event_to_region(struct weston_pointer *pointer, |
| 4400 | struct weston_pointer_motion_event *event, |
| 4401 | pixman_region32_t *region, |
| 4402 | wl_fixed_t *clamped_x, |
| 4403 | wl_fixed_t *clamped_y) |
| 4404 | { |
| 4405 | wl_fixed_t x, y; |
| 4406 | wl_fixed_t sx, sy; |
Jonas Ådahl | d0be2bb | 2015-04-30 17:56:37 +0800 | [diff] [blame] | 4407 | wl_fixed_t old_sx = pointer->sx; |
| 4408 | wl_fixed_t old_sy = pointer->sy; |
| 4409 | struct wl_array borders; |
| 4410 | struct line motion; |
| 4411 | struct border *closest_border; |
| 4412 | float new_x_f, new_y_f; |
| 4413 | uint32_t directions; |
Jonas Ådahl | d3414f2 | 2016-07-22 17:56:31 +0800 | [diff] [blame] | 4414 | |
| 4415 | weston_pointer_motion_to_abs(pointer, event, &x, &y); |
| 4416 | weston_view_from_global_fixed(pointer->focus, x, y, &sx, &sy); |
| 4417 | |
Jonas Ådahl | d0be2bb | 2015-04-30 17:56:37 +0800 | [diff] [blame] | 4418 | wl_array_init(&borders); |
Jonas Ådahl | d3414f2 | 2016-07-22 17:56:31 +0800 | [diff] [blame] | 4419 | |
Jonas Ådahl | d0be2bb | 2015-04-30 17:56:37 +0800 | [diff] [blame] | 4420 | /* |
| 4421 | * Generate borders given the confine region we are to use. The borders |
| 4422 | * are defined to be the outer region of the allowed area. This means |
| 4423 | * top/left borders are "within" the allowed area, while bottom/right |
| 4424 | * borders are outside. This needs to be considered when clamping |
| 4425 | * confined motion vectors. |
| 4426 | */ |
| 4427 | region_to_outline(region, &borders); |
Jonas Ådahl | d3414f2 | 2016-07-22 17:56:31 +0800 | [diff] [blame] | 4428 | |
Jonas Ådahl | d0be2bb | 2015-04-30 17:56:37 +0800 | [diff] [blame] | 4429 | motion = (struct line) { |
| 4430 | .a = (struct vec2d) { |
| 4431 | .x = wl_fixed_to_double(old_sx), |
| 4432 | .y = wl_fixed_to_double(old_sy), |
| 4433 | }, |
| 4434 | .b = (struct vec2d) { |
| 4435 | .x = wl_fixed_to_double(sx), |
| 4436 | .y = wl_fixed_to_double(sy), |
| 4437 | }, |
| 4438 | }; |
| 4439 | directions = get_motion_directions(&motion); |
| 4440 | |
| 4441 | while (directions) { |
| 4442 | closest_border = get_closest_border(&borders, |
| 4443 | &motion, |
| 4444 | directions); |
| 4445 | if (closest_border) |
| 4446 | clamp_to_border(closest_border, &motion, &directions); |
| 4447 | else |
| 4448 | break; |
| 4449 | } |
| 4450 | |
| 4451 | weston_view_to_global_float(pointer->focus, |
| 4452 | (float) motion.b.x, (float) motion.b.y, |
| 4453 | &new_x_f, &new_y_f); |
| 4454 | *clamped_x = wl_fixed_from_double(new_x_f); |
| 4455 | *clamped_y = wl_fixed_from_double(new_y_f); |
| 4456 | |
| 4457 | wl_array_release(&borders); |
| 4458 | } |
| 4459 | |
| 4460 | static double |
| 4461 | point_to_border_distance_2(struct border *border, double x, double y) |
| 4462 | { |
| 4463 | double orig_x, orig_y; |
| 4464 | double dx, dy; |
| 4465 | |
| 4466 | if (is_border_horizontal(border)) { |
| 4467 | if (x < border->line.a.x) |
| 4468 | orig_x = border->line.a.x; |
| 4469 | else if (x > border->line.b.x) |
| 4470 | orig_x = border->line.b.x; |
| 4471 | else |
| 4472 | orig_x = x; |
| 4473 | orig_y = border->line.a.y; |
| 4474 | } else { |
| 4475 | if (y < border->line.a.y) |
| 4476 | orig_y = border->line.a.y; |
| 4477 | else if (y > border->line.b.y) |
| 4478 | orig_y = border->line.b.y; |
| 4479 | else |
| 4480 | orig_y = y; |
| 4481 | orig_x = border->line.a.x; |
| 4482 | } |
| 4483 | |
| 4484 | |
| 4485 | dx = fabs(orig_x - x); |
| 4486 | dy = fabs(orig_y - y); |
| 4487 | return dx*dx + dy*dy; |
| 4488 | } |
| 4489 | |
| 4490 | static void |
| 4491 | warp_to_behind_border(struct border *border, wl_fixed_t *sx, wl_fixed_t *sy) |
| 4492 | { |
| 4493 | switch (border->blocking_dir) { |
| 4494 | case MOTION_DIRECTION_POSITIVE_X: |
| 4495 | case MOTION_DIRECTION_NEGATIVE_X: |
| 4496 | if (border->blocking_dir == MOTION_DIRECTION_POSITIVE_X) |
| 4497 | *sx = wl_fixed_from_double(border->line.a.x) - 1; |
| 4498 | else |
| 4499 | *sx = wl_fixed_from_double(border->line.a.x) + 1; |
| 4500 | if (*sy < wl_fixed_from_double(border->line.a.y)) |
| 4501 | *sy = wl_fixed_from_double(border->line.a.y) + 1; |
| 4502 | else if (*sy > wl_fixed_from_double(border->line.b.y)) |
| 4503 | *sy = wl_fixed_from_double(border->line.b.y) - 1; |
| 4504 | break; |
| 4505 | case MOTION_DIRECTION_POSITIVE_Y: |
| 4506 | case MOTION_DIRECTION_NEGATIVE_Y: |
| 4507 | if (border->blocking_dir == MOTION_DIRECTION_POSITIVE_Y) |
| 4508 | *sy = wl_fixed_from_double(border->line.a.y) - 1; |
| 4509 | else |
| 4510 | *sy = wl_fixed_from_double(border->line.a.y) + 1; |
| 4511 | if (*sx < wl_fixed_from_double(border->line.a.x)) |
| 4512 | *sx = wl_fixed_from_double(border->line.a.x) + 1; |
| 4513 | else if (*sx > wl_fixed_from_double(border->line.b.x)) |
| 4514 | *sx = wl_fixed_from_double(border->line.b.x) - 1; |
| 4515 | break; |
| 4516 | } |
Jonas Ådahl | d3414f2 | 2016-07-22 17:56:31 +0800 | [diff] [blame] | 4517 | } |
| 4518 | |
| 4519 | static void |
| 4520 | maybe_warp_confined_pointer(struct weston_pointer_constraint *constraint) |
| 4521 | { |
| 4522 | wl_fixed_t x; |
| 4523 | wl_fixed_t y; |
| 4524 | wl_fixed_t sx; |
| 4525 | wl_fixed_t sy; |
| 4526 | |
| 4527 | weston_view_from_global_fixed(constraint->view, |
| 4528 | constraint->pointer->x, |
| 4529 | constraint->pointer->y, |
| 4530 | &sx, |
| 4531 | &sy); |
| 4532 | |
| 4533 | if (!is_within_constraint_region(constraint, sx, sy)) { |
Jonas Ådahl | d0be2bb | 2015-04-30 17:56:37 +0800 | [diff] [blame] | 4534 | double xf = wl_fixed_to_double(sx); |
| 4535 | double yf = wl_fixed_to_double(sy); |
| 4536 | pixman_region32_t confine_region; |
| 4537 | struct wl_array borders; |
| 4538 | struct border *border; |
| 4539 | double closest_distance_2 = DBL_MAX; |
| 4540 | struct border *closest_border = NULL; |
Jonas Ådahl | d3414f2 | 2016-07-22 17:56:31 +0800 | [diff] [blame] | 4541 | |
Jonas Ådahl | d0be2bb | 2015-04-30 17:56:37 +0800 | [diff] [blame] | 4542 | wl_array_init(&borders); |
Jonas Ådahl | d3414f2 | 2016-07-22 17:56:31 +0800 | [diff] [blame] | 4543 | |
Jonas Ådahl | d0be2bb | 2015-04-30 17:56:37 +0800 | [diff] [blame] | 4544 | pixman_region32_init(&confine_region); |
| 4545 | pixman_region32_intersect(&confine_region, |
| 4546 | &constraint->view->surface->input, |
| 4547 | &constraint->region); |
| 4548 | region_to_outline(&confine_region, &borders); |
| 4549 | pixman_region32_fini(&confine_region); |
| 4550 | |
| 4551 | wl_array_for_each(border, &borders) { |
| 4552 | double distance_2; |
| 4553 | |
| 4554 | distance_2 = point_to_border_distance_2(border, xf, yf); |
| 4555 | if (distance_2 < closest_distance_2) { |
| 4556 | closest_border = border; |
| 4557 | closest_distance_2 = distance_2; |
| 4558 | } |
| 4559 | } |
| 4560 | assert(closest_border); |
| 4561 | |
| 4562 | warp_to_behind_border(closest_border, &sx, &sy); |
| 4563 | |
| 4564 | wl_array_release(&borders); |
Jonas Ådahl | d3414f2 | 2016-07-22 17:56:31 +0800 | [diff] [blame] | 4565 | |
| 4566 | weston_view_to_global_fixed(constraint->view, sx, sy, &x, &y); |
| 4567 | weston_pointer_move_to(constraint->pointer, x, y); |
| 4568 | } |
| 4569 | } |
| 4570 | |
| 4571 | static void |
| 4572 | confined_pointer_grab_pointer_motion(struct weston_pointer_grab *grab, |
Alexandros Frantzis | 84b31f8 | 2017-11-24 18:01:46 +0200 | [diff] [blame] | 4573 | const struct timespec *time, |
Jonas Ådahl | d3414f2 | 2016-07-22 17:56:31 +0800 | [diff] [blame] | 4574 | struct weston_pointer_motion_event *event) |
| 4575 | { |
| 4576 | struct weston_pointer_constraint *constraint = |
| 4577 | container_of(grab, struct weston_pointer_constraint, grab); |
| 4578 | struct weston_pointer *pointer = grab->pointer; |
| 4579 | struct weston_surface *surface; |
| 4580 | wl_fixed_t x, y; |
| 4581 | wl_fixed_t old_sx = pointer->sx; |
| 4582 | wl_fixed_t old_sy = pointer->sy; |
| 4583 | pixman_region32_t confine_region; |
| 4584 | |
| 4585 | assert(pointer->focus); |
| 4586 | assert(pointer->focus->surface == constraint->surface); |
| 4587 | |
| 4588 | surface = pointer->focus->surface; |
| 4589 | |
| 4590 | pixman_region32_init(&confine_region); |
| 4591 | pixman_region32_intersect(&confine_region, |
| 4592 | &surface->input, |
| 4593 | &constraint->region); |
| 4594 | weston_pointer_clamp_event_to_region(pointer, event, |
| 4595 | &confine_region, &x, &y); |
| 4596 | weston_pointer_move_to(pointer, x, y); |
| 4597 | pixman_region32_fini(&confine_region); |
| 4598 | |
| 4599 | weston_view_from_global_fixed(pointer->focus, x, y, |
| 4600 | &pointer->sx, &pointer->sy); |
| 4601 | |
| 4602 | if (old_sx != pointer->sx || old_sy != pointer->sy) { |
Quentin Glidic | cde1345 | 2016-08-12 10:41:32 +0200 | [diff] [blame] | 4603 | pointer_send_motion(pointer, time, |
| 4604 | pointer->sx, pointer->sy); |
Jonas Ådahl | d3414f2 | 2016-07-22 17:56:31 +0800 | [diff] [blame] | 4605 | } |
| 4606 | |
Quentin Glidic | cde1345 | 2016-08-12 10:41:32 +0200 | [diff] [blame] | 4607 | pointer_send_relative_motion(pointer, time, event); |
Jonas Ådahl | d3414f2 | 2016-07-22 17:56:31 +0800 | [diff] [blame] | 4608 | } |
| 4609 | |
| 4610 | static void |
| 4611 | confined_pointer_grab_pointer_button(struct weston_pointer_grab *grab, |
Alexandros Frantzis | 215bedc | 2017-11-16 18:20:55 +0200 | [diff] [blame] | 4612 | const struct timespec *time, |
Jonas Ådahl | d3414f2 | 2016-07-22 17:56:31 +0800 | [diff] [blame] | 4613 | uint32_t button, |
| 4614 | uint32_t state_w) |
| 4615 | { |
| 4616 | weston_pointer_send_button(grab->pointer, time, button, state_w); |
| 4617 | } |
| 4618 | |
| 4619 | static void |
| 4620 | confined_pointer_grab_pointer_axis(struct weston_pointer_grab *grab, |
Alexandros Frantzis | 8032194 | 2017-11-16 18:20:56 +0200 | [diff] [blame] | 4621 | const struct timespec *time, |
Jonas Ådahl | d3414f2 | 2016-07-22 17:56:31 +0800 | [diff] [blame] | 4622 | struct weston_pointer_axis_event *event) |
| 4623 | { |
| 4624 | weston_pointer_send_axis(grab->pointer, time, event); |
| 4625 | } |
| 4626 | |
| 4627 | static void |
| 4628 | confined_pointer_grab_pointer_axis_source(struct weston_pointer_grab *grab, |
| 4629 | uint32_t source) |
| 4630 | { |
| 4631 | weston_pointer_send_axis_source(grab->pointer, source); |
| 4632 | } |
| 4633 | |
| 4634 | static void |
| 4635 | confined_pointer_grab_pointer_frame(struct weston_pointer_grab *grab) |
| 4636 | { |
| 4637 | weston_pointer_send_frame(grab->pointer); |
| 4638 | } |
| 4639 | |
| 4640 | static void |
| 4641 | confined_pointer_grab_pointer_cancel(struct weston_pointer_grab *grab) |
| 4642 | { |
| 4643 | struct weston_pointer_constraint *constraint = |
| 4644 | container_of(grab, struct weston_pointer_constraint, grab); |
| 4645 | |
| 4646 | disable_pointer_constraint(constraint); |
Jonas Ådahl | d3414f2 | 2016-07-22 17:56:31 +0800 | [diff] [blame] | 4647 | } |
| 4648 | |
| 4649 | static const struct weston_pointer_grab_interface |
| 4650 | confined_pointer_grab_interface = { |
| 4651 | confined_pointer_grab_pointer_focus, |
| 4652 | confined_pointer_grab_pointer_motion, |
| 4653 | confined_pointer_grab_pointer_button, |
| 4654 | confined_pointer_grab_pointer_axis, |
| 4655 | confined_pointer_grab_pointer_axis_source, |
| 4656 | confined_pointer_grab_pointer_frame, |
| 4657 | confined_pointer_grab_pointer_cancel, |
| 4658 | }; |
| 4659 | |
| 4660 | static void |
| 4661 | confined_pointer_destroy(struct wl_client *client, |
| 4662 | struct wl_resource *resource) |
| 4663 | { |
| 4664 | wl_resource_destroy(resource); |
| 4665 | } |
| 4666 | |
| 4667 | static void |
| 4668 | confined_pointer_set_region(struct wl_client *client, |
| 4669 | struct wl_resource *resource, |
| 4670 | struct wl_resource *region_resource) |
| 4671 | { |
| 4672 | struct weston_pointer_constraint *constraint = |
| 4673 | wl_resource_get_user_data(resource); |
| 4674 | struct weston_region *region = region_resource ? |
| 4675 | wl_resource_get_user_data(region_resource) : NULL; |
| 4676 | |
| 4677 | if (!constraint) |
| 4678 | return; |
| 4679 | |
| 4680 | if (region) { |
| 4681 | pixman_region32_copy(&constraint->region_pending, |
| 4682 | ®ion->region); |
| 4683 | } else { |
| 4684 | pixman_region32_fini(&constraint->region_pending); |
| 4685 | region_init_infinite(&constraint->region_pending); |
| 4686 | } |
| 4687 | constraint->region_is_pending = true; |
| 4688 | } |
| 4689 | |
| 4690 | static const struct zwp_confined_pointer_v1_interface confined_pointer_interface = { |
| 4691 | confined_pointer_destroy, |
| 4692 | confined_pointer_set_region, |
| 4693 | }; |
| 4694 | |
| 4695 | static void |
| 4696 | pointer_constraints_confine_pointer(struct wl_client *client, |
| 4697 | struct wl_resource *resource, |
| 4698 | uint32_t id, |
| 4699 | struct wl_resource *surface_resource, |
| 4700 | struct wl_resource *pointer_resource, |
| 4701 | struct wl_resource *region_resource, |
| 4702 | uint32_t lifetime) |
| 4703 | { |
| 4704 | struct weston_surface *surface = |
| 4705 | wl_resource_get_user_data(surface_resource); |
| 4706 | struct weston_pointer *pointer = wl_resource_get_user_data(pointer_resource); |
| 4707 | struct weston_region *region = region_resource ? |
| 4708 | wl_resource_get_user_data(region_resource) : NULL; |
| 4709 | |
| 4710 | init_pointer_constraint(resource, id, surface, pointer, region, lifetime, |
| 4711 | &zwp_confined_pointer_v1_interface, |
| 4712 | &confined_pointer_interface, |
| 4713 | &confined_pointer_grab_interface); |
| 4714 | } |
| 4715 | |
| 4716 | static const struct zwp_pointer_constraints_v1_interface pointer_constraints_interface = { |
| 4717 | pointer_constraints_destroy, |
| 4718 | pointer_constraints_lock_pointer, |
| 4719 | pointer_constraints_confine_pointer, |
| 4720 | }; |
| 4721 | |
| 4722 | static void |
| 4723 | bind_pointer_constraints(struct wl_client *client, void *data, |
| 4724 | uint32_t version, uint32_t id) |
| 4725 | { |
| 4726 | struct wl_resource *resource; |
| 4727 | |
| 4728 | resource = wl_resource_create(client, |
| 4729 | &zwp_pointer_constraints_v1_interface, |
| 4730 | 1, id); |
| 4731 | |
| 4732 | wl_resource_set_implementation(resource, &pointer_constraints_interface, |
| 4733 | NULL, NULL); |
| 4734 | } |
| 4735 | |
Alexandros Frantzis | 538749d | 2018-02-16 18:44:16 +0200 | [diff] [blame] | 4736 | static void |
Alexandros Frantzis | 2b44248 | 2018-02-20 14:05:50 +0200 | [diff] [blame] | 4737 | input_timestamps_destroy(struct wl_client *client, |
| 4738 | struct wl_resource *resource) |
| 4739 | { |
| 4740 | wl_resource_destroy(resource); |
| 4741 | } |
| 4742 | |
| 4743 | static const struct zwp_input_timestamps_v1_interface |
| 4744 | input_timestamps_interface = { |
| 4745 | input_timestamps_destroy, |
| 4746 | }; |
| 4747 | |
| 4748 | static void |
Alexandros Frantzis | 538749d | 2018-02-16 18:44:16 +0200 | [diff] [blame] | 4749 | input_timestamps_manager_destroy(struct wl_client *client, |
| 4750 | struct wl_resource *resource) |
| 4751 | { |
| 4752 | wl_resource_destroy(resource); |
| 4753 | } |
| 4754 | |
| 4755 | static void |
| 4756 | input_timestamps_manager_get_keyboard_timestamps(struct wl_client *client, |
| 4757 | struct wl_resource *resource, |
| 4758 | uint32_t id, |
| 4759 | struct wl_resource *keyboard_resource) |
| 4760 | { |
Alexandros Frantzis | 2b44248 | 2018-02-20 14:05:50 +0200 | [diff] [blame] | 4761 | struct weston_keyboard *keyboard = |
| 4762 | wl_resource_get_user_data(keyboard_resource); |
| 4763 | struct wl_resource *input_ts; |
| 4764 | |
| 4765 | input_ts = wl_resource_create(client, |
| 4766 | &zwp_input_timestamps_v1_interface, |
| 4767 | 1, id); |
| 4768 | if (!input_ts) { |
| 4769 | wl_client_post_no_memory(client); |
| 4770 | return; |
| 4771 | } |
| 4772 | |
| 4773 | if (keyboard) { |
| 4774 | wl_list_insert(&keyboard->timestamps_list, |
| 4775 | wl_resource_get_link(input_ts)); |
| 4776 | } else { |
| 4777 | wl_list_init(wl_resource_get_link(input_ts)); |
| 4778 | } |
| 4779 | |
| 4780 | wl_resource_set_implementation(input_ts, |
| 4781 | &input_timestamps_interface, |
| 4782 | keyboard_resource, |
| 4783 | unbind_resource); |
Alexandros Frantzis | 538749d | 2018-02-16 18:44:16 +0200 | [diff] [blame] | 4784 | } |
| 4785 | |
| 4786 | static void |
| 4787 | input_timestamps_manager_get_pointer_timestamps(struct wl_client *client, |
| 4788 | struct wl_resource *resource, |
| 4789 | uint32_t id, |
| 4790 | struct wl_resource *pointer_resource) |
| 4791 | { |
Alexandros Frantzis | db907b7 | 2018-02-20 14:06:26 +0200 | [diff] [blame] | 4792 | struct weston_pointer *pointer = |
| 4793 | wl_resource_get_user_data(pointer_resource); |
| 4794 | struct wl_resource *input_ts; |
| 4795 | |
| 4796 | input_ts = wl_resource_create(client, |
| 4797 | &zwp_input_timestamps_v1_interface, |
| 4798 | 1, id); |
| 4799 | if (!input_ts) { |
| 4800 | wl_client_post_no_memory(client); |
| 4801 | return; |
| 4802 | } |
| 4803 | |
| 4804 | if (pointer) { |
| 4805 | wl_list_insert(&pointer->timestamps_list, |
| 4806 | wl_resource_get_link(input_ts)); |
| 4807 | } else { |
| 4808 | wl_list_init(wl_resource_get_link(input_ts)); |
| 4809 | } |
| 4810 | |
| 4811 | wl_resource_set_implementation(input_ts, |
| 4812 | &input_timestamps_interface, |
| 4813 | pointer_resource, |
| 4814 | unbind_resource); |
Alexandros Frantzis | 538749d | 2018-02-16 18:44:16 +0200 | [diff] [blame] | 4815 | } |
| 4816 | |
| 4817 | static void |
| 4818 | input_timestamps_manager_get_touch_timestamps(struct wl_client *client, |
| 4819 | struct wl_resource *resource, |
| 4820 | uint32_t id, |
| 4821 | struct wl_resource *touch_resource) |
| 4822 | { |
Alexandros Frantzis | d715784 | 2018-02-20 14:07:03 +0200 | [diff] [blame] | 4823 | struct weston_touch *touch = wl_resource_get_user_data(touch_resource); |
| 4824 | struct wl_resource *input_ts; |
| 4825 | |
| 4826 | input_ts = wl_resource_create(client, |
| 4827 | &zwp_input_timestamps_v1_interface, |
| 4828 | 1, id); |
| 4829 | if (!input_ts) { |
| 4830 | wl_client_post_no_memory(client); |
| 4831 | return; |
| 4832 | } |
| 4833 | |
| 4834 | if (touch) { |
| 4835 | wl_list_insert(&touch->timestamps_list, |
| 4836 | wl_resource_get_link(input_ts)); |
| 4837 | } else { |
| 4838 | wl_list_init(wl_resource_get_link(input_ts)); |
| 4839 | } |
| 4840 | |
| 4841 | wl_resource_set_implementation(input_ts, |
| 4842 | &input_timestamps_interface, |
| 4843 | touch_resource, |
| 4844 | unbind_resource); |
Alexandros Frantzis | 538749d | 2018-02-16 18:44:16 +0200 | [diff] [blame] | 4845 | } |
| 4846 | |
| 4847 | static const struct zwp_input_timestamps_manager_v1_interface |
| 4848 | input_timestamps_manager_interface = { |
| 4849 | input_timestamps_manager_destroy, |
| 4850 | input_timestamps_manager_get_keyboard_timestamps, |
| 4851 | input_timestamps_manager_get_pointer_timestamps, |
| 4852 | input_timestamps_manager_get_touch_timestamps, |
| 4853 | }; |
| 4854 | |
| 4855 | static void |
| 4856 | bind_input_timestamps_manager(struct wl_client *client, void *data, |
| 4857 | uint32_t version, uint32_t id) |
| 4858 | { |
| 4859 | struct wl_resource *resource = |
| 4860 | wl_resource_create(client, |
| 4861 | &zwp_input_timestamps_manager_v1_interface, |
| 4862 | 1, id); |
| 4863 | |
| 4864 | if (resource == NULL) { |
| 4865 | wl_client_post_no_memory(client); |
| 4866 | return; |
| 4867 | } |
| 4868 | |
| 4869 | wl_resource_set_implementation(resource, |
| 4870 | &input_timestamps_manager_interface, |
| 4871 | NULL, NULL); |
| 4872 | } |
| 4873 | |
Jonas Ådahl | 30d61d8 | 2014-10-22 21:21:17 +0200 | [diff] [blame] | 4874 | int |
| 4875 | weston_input_init(struct weston_compositor *compositor) |
| 4876 | { |
| 4877 | if (!wl_global_create(compositor->wl_display, |
| 4878 | &zwp_relative_pointer_manager_v1_interface, 1, |
| 4879 | compositor, bind_relative_pointer_manager)) |
| 4880 | return -1; |
| 4881 | |
Jonas Ådahl | d3414f2 | 2016-07-22 17:56:31 +0800 | [diff] [blame] | 4882 | if (!wl_global_create(compositor->wl_display, |
| 4883 | &zwp_pointer_constraints_v1_interface, 1, |
| 4884 | NULL, bind_pointer_constraints)) |
| 4885 | return -1; |
| 4886 | |
Alexandros Frantzis | 538749d | 2018-02-16 18:44:16 +0200 | [diff] [blame] | 4887 | if (!wl_global_create(compositor->wl_display, |
| 4888 | &zwp_input_timestamps_manager_v1_interface, 1, |
| 4889 | NULL, bind_input_timestamps_manager)) |
| 4890 | return -1; |
| 4891 | |
Jonas Ådahl | 30d61d8 | 2014-10-22 21:21:17 +0200 | [diff] [blame] | 4892 | return 0; |
| 4893 | } |