Jonas Ådahl | e0de3c2 | 2014-03-12 22:08:42 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright © 2010 Intel Corporation |
| 3 | * Copyright © 2013 Jonas Ådahl |
Louis-Francis Ratté-Boulianne | 6ef59c9 | 2017-11-28 20:42:47 -0500 | [diff] [blame] | 4 | * Copyright 2017-2018 Collabora, Ltd. |
| 5 | * Copyright 2017-2018 General Electric Company |
Jonas Ådahl | e0de3c2 | 2014-03-12 22:08:42 +0100 | [diff] [blame] | 6 | * |
Bryce Harrington | a0bbfea | 2015-06-11 15:35:43 -0700 | [diff] [blame] | 7 | * Permission is hereby granted, free of charge, to any person obtaining |
| 8 | * a copy of this software and associated documentation files (the |
| 9 | * "Software"), to deal in the Software without restriction, including |
| 10 | * without limitation the rights to use, copy, modify, merge, publish, |
| 11 | * distribute, sublicense, and/or sell copies of the Software, and to |
| 12 | * permit persons to whom the Software is furnished to do so, subject to |
| 13 | * the following conditions: |
Jonas Ådahl | e0de3c2 | 2014-03-12 22:08:42 +0100 | [diff] [blame] | 14 | * |
Bryce Harrington | a0bbfea | 2015-06-11 15:35:43 -0700 | [diff] [blame] | 15 | * The above copyright notice and this permission notice (including the |
| 16 | * next paragraph) shall be included in all copies or substantial |
| 17 | * portions of the Software. |
| 18 | * |
| 19 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
| 20 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| 21 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
| 22 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS |
| 23 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN |
| 24 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN |
| 25 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 26 | * SOFTWARE. |
Jonas Ådahl | e0de3c2 | 2014-03-12 22:08:42 +0100 | [diff] [blame] | 27 | */ |
| 28 | |
| 29 | #include "config.h" |
| 30 | |
| 31 | #include <errno.h> |
Jussi Kukkonen | 649bbce | 2016-07-19 14:16:27 +0300 | [diff] [blame] | 32 | #include <stdint.h> |
Jonas Ådahl | e0de3c2 | 2014-03-12 22:08:42 +0100 | [diff] [blame] | 33 | #include <stdlib.h> |
| 34 | #include <string.h> |
| 35 | #include <linux/input.h> |
| 36 | #include <unistd.h> |
| 37 | #include <fcntl.h> |
Jonas Ådahl | e0de3c2 | 2014-03-12 22:08:42 +0100 | [diff] [blame] | 38 | #include <assert.h> |
| 39 | #include <libinput.h> |
| 40 | |
Pekka Paalanen | 3d5d947 | 2019-03-28 16:28:47 +0200 | [diff] [blame] | 41 | #include <libweston/libweston.h> |
Marius Vlad | 9eb2064 | 2019-07-10 18:23:43 +0300 | [diff] [blame^] | 42 | #include "libweston-internal.h" |
Jonas Ådahl | e0de3c2 | 2014-03-12 22:08:42 +0100 | [diff] [blame] | 43 | #include "libinput-device.h" |
Jon Cruz | 867d50e | 2015-06-15 15:37:10 -0700 | [diff] [blame] | 44 | #include "shared/helpers.h" |
Alexandros Frantzis | 84b31f8 | 2017-11-24 18:01:46 +0200 | [diff] [blame] | 45 | #include "shared/timespec-util.h" |
Jonas Ådahl | e0de3c2 | 2014-03-12 22:08:42 +0100 | [diff] [blame] | 46 | |
Jonas Ådahl | e0de3c2 | 2014-03-12 22:08:42 +0100 | [diff] [blame] | 47 | void |
| 48 | evdev_led_update(struct evdev_device *device, enum weston_led weston_leds) |
| 49 | { |
| 50 | enum libinput_led leds = 0; |
| 51 | |
| 52 | if (weston_leds & LED_NUM_LOCK) |
| 53 | leds |= LIBINPUT_LED_NUM_LOCK; |
| 54 | if (weston_leds & LED_CAPS_LOCK) |
| 55 | leds |= LIBINPUT_LED_CAPS_LOCK; |
| 56 | if (weston_leds & LED_SCROLL_LOCK) |
| 57 | leds |= LIBINPUT_LED_SCROLL_LOCK; |
| 58 | |
| 59 | libinput_device_led_update(device->device, leds); |
| 60 | } |
| 61 | |
| 62 | static void |
| 63 | handle_keyboard_key(struct libinput_device *libinput_device, |
| 64 | struct libinput_event_keyboard *keyboard_event) |
| 65 | { |
| 66 | struct evdev_device *device = |
| 67 | libinput_device_get_user_data(libinput_device); |
Jonas Ådahl | 90d1ac8 | 2015-01-30 12:23:00 +0800 | [diff] [blame] | 68 | int key_state = |
| 69 | libinput_event_keyboard_get_key_state(keyboard_event); |
| 70 | int seat_key_count = |
| 71 | libinput_event_keyboard_get_seat_key_count(keyboard_event); |
Alexandros Frantzis | 47e79c8 | 2017-11-16 18:20:57 +0200 | [diff] [blame] | 72 | struct timespec time; |
Jonas Ådahl | 90d1ac8 | 2015-01-30 12:23:00 +0800 | [diff] [blame] | 73 | |
| 74 | /* Ignore key events that are not seat wide state changes. */ |
| 75 | if ((key_state == LIBINPUT_KEY_STATE_PRESSED && |
| 76 | seat_key_count != 1) || |
| 77 | (key_state == LIBINPUT_KEY_STATE_RELEASED && |
| 78 | seat_key_count != 0)) |
| 79 | return; |
Jonas Ådahl | e0de3c2 | 2014-03-12 22:08:42 +0100 | [diff] [blame] | 80 | |
Alexandros Frantzis | 47e79c8 | 2017-11-16 18:20:57 +0200 | [diff] [blame] | 81 | timespec_from_usec(&time, |
| 82 | libinput_event_keyboard_get_time_usec(keyboard_event)); |
| 83 | |
| 84 | notify_key(device->seat, &time, |
Jonas Ådahl | e0de3c2 | 2014-03-12 22:08:42 +0100 | [diff] [blame] | 85 | libinput_event_keyboard_get_key(keyboard_event), |
Chris Michael | 7e7f793 | 2016-02-22 08:47:24 -0500 | [diff] [blame] | 86 | key_state, STATE_UPDATE_AUTOMATIC); |
Jonas Ådahl | e0de3c2 | 2014-03-12 22:08:42 +0100 | [diff] [blame] | 87 | } |
| 88 | |
Peter Hutterer | 87743e9 | 2016-01-18 16:38:22 +1000 | [diff] [blame] | 89 | static bool |
Jonas Ådahl | e0de3c2 | 2014-03-12 22:08:42 +0100 | [diff] [blame] | 90 | handle_pointer_motion(struct libinput_device *libinput_device, |
| 91 | struct libinput_event_pointer *pointer_event) |
| 92 | { |
| 93 | struct evdev_device *device = |
| 94 | libinput_device_get_user_data(libinput_device); |
Jonas Ådahl | d251010 | 2014-10-05 21:39:14 +0200 | [diff] [blame] | 95 | struct weston_pointer_motion_event event = { 0 }; |
Alexandros Frantzis | 84b31f8 | 2017-11-24 18:01:46 +0200 | [diff] [blame] | 96 | struct timespec time; |
Jonas Ådahl | 3845b32 | 2014-10-21 23:51:29 +0200 | [diff] [blame] | 97 | double dx_unaccel, dy_unaccel; |
| 98 | |
Alexandros Frantzis | 84b31f8 | 2017-11-24 18:01:46 +0200 | [diff] [blame] | 99 | timespec_from_usec(&time, |
| 100 | libinput_event_pointer_get_time_usec(pointer_event)); |
Jonas Ådahl | 3845b32 | 2014-10-21 23:51:29 +0200 | [diff] [blame] | 101 | dx_unaccel = libinput_event_pointer_get_dx_unaccelerated(pointer_event); |
| 102 | dy_unaccel = libinput_event_pointer_get_dy_unaccelerated(pointer_event); |
Jonas Ådahl | e0de3c2 | 2014-03-12 22:08:42 +0100 | [diff] [blame] | 103 | |
Jonas Ådahl | d251010 | 2014-10-05 21:39:14 +0200 | [diff] [blame] | 104 | event = (struct weston_pointer_motion_event) { |
Jonas Ådahl | 3845b32 | 2014-10-21 23:51:29 +0200 | [diff] [blame] | 105 | .mask = WESTON_POINTER_MOTION_REL | |
| 106 | WESTON_POINTER_MOTION_REL_UNACCEL, |
Alexandros Frantzis | 84b31f8 | 2017-11-24 18:01:46 +0200 | [diff] [blame] | 107 | .time = time, |
Jonas Ådahl | d251010 | 2014-10-05 21:39:14 +0200 | [diff] [blame] | 108 | .dx = libinput_event_pointer_get_dx(pointer_event), |
| 109 | .dy = libinput_event_pointer_get_dy(pointer_event), |
Jonas Ådahl | 3845b32 | 2014-10-21 23:51:29 +0200 | [diff] [blame] | 110 | .dx_unaccel = dx_unaccel, |
| 111 | .dy_unaccel = dy_unaccel, |
Jonas Ådahl | d251010 | 2014-10-05 21:39:14 +0200 | [diff] [blame] | 112 | }; |
| 113 | |
Alexandros Frantzis | 84b31f8 | 2017-11-24 18:01:46 +0200 | [diff] [blame] | 114 | notify_motion(device->seat, &time, &event); |
Peter Hutterer | 87743e9 | 2016-01-18 16:38:22 +1000 | [diff] [blame] | 115 | |
| 116 | return true; |
Jonas Ådahl | e0de3c2 | 2014-03-12 22:08:42 +0100 | [diff] [blame] | 117 | } |
| 118 | |
Peter Hutterer | 87743e9 | 2016-01-18 16:38:22 +1000 | [diff] [blame] | 119 | static bool |
Jonas Ådahl | e0de3c2 | 2014-03-12 22:08:42 +0100 | [diff] [blame] | 120 | handle_pointer_motion_absolute( |
| 121 | struct libinput_device *libinput_device, |
| 122 | struct libinput_event_pointer *pointer_event) |
| 123 | { |
| 124 | struct evdev_device *device = |
| 125 | libinput_device_get_user_data(libinput_device); |
| 126 | struct weston_output *output = device->output; |
Alexandros Frantzis | 84b31f8 | 2017-11-24 18:01:46 +0200 | [diff] [blame] | 127 | struct timespec time; |
Giulio Camuffo | 90a6fc6 | 2016-03-22 17:44:54 +0200 | [diff] [blame] | 128 | double x, y; |
Jonas Ådahl | e0de3c2 | 2014-03-12 22:08:42 +0100 | [diff] [blame] | 129 | uint32_t width, height; |
| 130 | |
| 131 | if (!output) |
Peter Hutterer | 87743e9 | 2016-01-18 16:38:22 +1000 | [diff] [blame] | 132 | return false; |
Jonas Ådahl | e0de3c2 | 2014-03-12 22:08:42 +0100 | [diff] [blame] | 133 | |
Alexandros Frantzis | 84b31f8 | 2017-11-24 18:01:46 +0200 | [diff] [blame] | 134 | timespec_from_usec(&time, |
| 135 | libinput_event_pointer_get_time_usec(pointer_event)); |
Jonas Ådahl | e0de3c2 | 2014-03-12 22:08:42 +0100 | [diff] [blame] | 136 | width = device->output->current_mode->width; |
| 137 | height = device->output->current_mode->height; |
| 138 | |
Giulio Camuffo | 90a6fc6 | 2016-03-22 17:44:54 +0200 | [diff] [blame] | 139 | x = libinput_event_pointer_get_absolute_x_transformed(pointer_event, |
| 140 | width); |
| 141 | y = libinput_event_pointer_get_absolute_y_transformed(pointer_event, |
| 142 | height); |
Jonas Ådahl | e0de3c2 | 2014-03-12 22:08:42 +0100 | [diff] [blame] | 143 | |
| 144 | weston_output_transform_coordinate(device->output, x, y, &x, &y); |
Alexandros Frantzis | 84b31f8 | 2017-11-24 18:01:46 +0200 | [diff] [blame] | 145 | notify_motion_absolute(device->seat, &time, x, y); |
Peter Hutterer | 87743e9 | 2016-01-18 16:38:22 +1000 | [diff] [blame] | 146 | |
| 147 | return true; |
Jonas Ådahl | e0de3c2 | 2014-03-12 22:08:42 +0100 | [diff] [blame] | 148 | } |
| 149 | |
Peter Hutterer | 87743e9 | 2016-01-18 16:38:22 +1000 | [diff] [blame] | 150 | static bool |
Jonas Ådahl | e0de3c2 | 2014-03-12 22:08:42 +0100 | [diff] [blame] | 151 | handle_pointer_button(struct libinput_device *libinput_device, |
| 152 | struct libinput_event_pointer *pointer_event) |
| 153 | { |
| 154 | struct evdev_device *device = |
| 155 | libinput_device_get_user_data(libinput_device); |
Jonas Ådahl | e90b9e9 | 2015-01-30 12:22:59 +0800 | [diff] [blame] | 156 | int button_state = |
| 157 | libinput_event_pointer_get_button_state(pointer_event); |
| 158 | int seat_button_count = |
| 159 | libinput_event_pointer_get_seat_button_count(pointer_event); |
Alexandros Frantzis | 215bedc | 2017-11-16 18:20:55 +0200 | [diff] [blame] | 160 | struct timespec time; |
Jonas Ådahl | e90b9e9 | 2015-01-30 12:22:59 +0800 | [diff] [blame] | 161 | |
| 162 | /* Ignore button events that are not seat wide state changes. */ |
| 163 | if ((button_state == LIBINPUT_BUTTON_STATE_PRESSED && |
| 164 | seat_button_count != 1) || |
| 165 | (button_state == LIBINPUT_BUTTON_STATE_RELEASED && |
| 166 | seat_button_count != 0)) |
Peter Hutterer | 87743e9 | 2016-01-18 16:38:22 +1000 | [diff] [blame] | 167 | return false; |
Jonas Ådahl | e0de3c2 | 2014-03-12 22:08:42 +0100 | [diff] [blame] | 168 | |
Alexandros Frantzis | 215bedc | 2017-11-16 18:20:55 +0200 | [diff] [blame] | 169 | timespec_from_usec(&time, |
| 170 | libinput_event_pointer_get_time_usec(pointer_event)); |
| 171 | |
| 172 | notify_button(device->seat, &time, |
Jonas Ådahl | e0de3c2 | 2014-03-12 22:08:42 +0100 | [diff] [blame] | 173 | libinput_event_pointer_get_button(pointer_event), |
Christopher Michael | e1719c7 | 2016-02-19 11:07:00 -0500 | [diff] [blame] | 174 | button_state); |
| 175 | |
Peter Hutterer | 87743e9 | 2016-01-18 16:38:22 +1000 | [diff] [blame] | 176 | return true; |
Jonas Ådahl | e0de3c2 | 2014-03-12 22:08:42 +0100 | [diff] [blame] | 177 | } |
| 178 | |
Peter Hutterer | 5dddd41 | 2015-01-15 13:14:43 +1000 | [diff] [blame] | 179 | static double |
| 180 | normalize_scroll(struct libinput_event_pointer *pointer_event, |
| 181 | enum libinput_pointer_axis axis) |
| 182 | { |
Peter Hutterer | 5dddd41 | 2015-01-15 13:14:43 +1000 | [diff] [blame] | 183 | enum libinput_pointer_axis_source source; |
Peter Hutterer | 87743e9 | 2016-01-18 16:38:22 +1000 | [diff] [blame] | 184 | double value = 0.0; |
Peter Hutterer | 5dddd41 | 2015-01-15 13:14:43 +1000 | [diff] [blame] | 185 | |
| 186 | source = libinput_event_pointer_get_axis_source(pointer_event); |
| 187 | /* libinput < 0.8 sent wheel click events with value 10. Since 0.8 |
| 188 | the value is the angle of the click in degrees. To keep |
| 189 | backwards-compat with existing clients, we just send multiples of |
| 190 | the click count. |
| 191 | */ |
| 192 | switch (source) { |
| 193 | case LIBINPUT_POINTER_AXIS_SOURCE_WHEEL: |
| 194 | value = 10 * libinput_event_pointer_get_axis_value_discrete( |
| 195 | pointer_event, |
| 196 | axis); |
| 197 | break; |
| 198 | case LIBINPUT_POINTER_AXIS_SOURCE_FINGER: |
| 199 | case LIBINPUT_POINTER_AXIS_SOURCE_CONTINUOUS: |
| 200 | value = libinput_event_pointer_get_axis_value(pointer_event, |
| 201 | axis); |
| 202 | break; |
Daniel Stone | 4933ca5 | 2017-03-14 17:24:04 +0000 | [diff] [blame] | 203 | default: |
| 204 | assert(!"unhandled event source in normalize_scroll"); |
Peter Hutterer | 5dddd41 | 2015-01-15 13:14:43 +1000 | [diff] [blame] | 205 | } |
| 206 | |
| 207 | return value; |
| 208 | } |
| 209 | |
Peter Hutterer | 87743e9 | 2016-01-18 16:38:22 +1000 | [diff] [blame] | 210 | static int32_t |
| 211 | get_axis_discrete(struct libinput_event_pointer *pointer_event, |
| 212 | enum libinput_pointer_axis axis) |
| 213 | { |
| 214 | enum libinput_pointer_axis_source source; |
| 215 | |
| 216 | source = libinput_event_pointer_get_axis_source(pointer_event); |
| 217 | |
| 218 | if (source != LIBINPUT_POINTER_AXIS_SOURCE_WHEEL) |
| 219 | return 0; |
| 220 | |
| 221 | return libinput_event_pointer_get_axis_value_discrete(pointer_event, |
| 222 | axis); |
| 223 | } |
| 224 | |
| 225 | static bool |
Jonas Ådahl | e0de3c2 | 2014-03-12 22:08:42 +0100 | [diff] [blame] | 226 | handle_pointer_axis(struct libinput_device *libinput_device, |
| 227 | struct libinput_event_pointer *pointer_event) |
| 228 | { |
Peter Hutterer | 87743e9 | 2016-01-18 16:38:22 +1000 | [diff] [blame] | 229 | static int warned; |
Jonas Ådahl | e0de3c2 | 2014-03-12 22:08:42 +0100 | [diff] [blame] | 230 | struct evdev_device *device = |
| 231 | libinput_device_get_user_data(libinput_device); |
Peter Hutterer | 87743e9 | 2016-01-18 16:38:22 +1000 | [diff] [blame] | 232 | double vert, horiz; |
| 233 | int32_t vert_discrete, horiz_discrete; |
Peter Hutterer | c54f23d | 2015-01-13 11:55:37 +1000 | [diff] [blame] | 234 | enum libinput_pointer_axis axis; |
Peter Hutterer | 89b6a49 | 2016-01-18 15:58:17 +1000 | [diff] [blame] | 235 | struct weston_pointer_axis_event weston_event; |
Peter Hutterer | 87743e9 | 2016-01-18 16:38:22 +1000 | [diff] [blame] | 236 | enum libinput_pointer_axis_source source; |
| 237 | uint32_t wl_axis_source; |
| 238 | bool has_vert, has_horiz; |
Alexandros Frantzis | 8032194 | 2017-11-16 18:20:56 +0200 | [diff] [blame] | 239 | struct timespec time; |
Jonas Ådahl | e0de3c2 | 2014-03-12 22:08:42 +0100 | [diff] [blame] | 240 | |
Peter Hutterer | 87743e9 | 2016-01-18 16:38:22 +1000 | [diff] [blame] | 241 | has_vert = libinput_event_pointer_has_axis(pointer_event, |
| 242 | LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL); |
| 243 | has_horiz = libinput_event_pointer_has_axis(pointer_event, |
| 244 | LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL); |
| 245 | |
| 246 | if (!has_vert && !has_horiz) |
| 247 | return false; |
| 248 | |
| 249 | source = libinput_event_pointer_get_axis_source(pointer_event); |
| 250 | switch (source) { |
| 251 | case LIBINPUT_POINTER_AXIS_SOURCE_WHEEL: |
| 252 | wl_axis_source = WL_POINTER_AXIS_SOURCE_WHEEL; |
| 253 | break; |
| 254 | case LIBINPUT_POINTER_AXIS_SOURCE_FINGER: |
| 255 | wl_axis_source = WL_POINTER_AXIS_SOURCE_FINGER; |
| 256 | break; |
| 257 | case LIBINPUT_POINTER_AXIS_SOURCE_CONTINUOUS: |
| 258 | wl_axis_source = WL_POINTER_AXIS_SOURCE_CONTINUOUS; |
| 259 | break; |
| 260 | default: |
| 261 | if (warned < 5) { |
| 262 | weston_log("Unknown scroll source %d.\n", source); |
| 263 | warned++; |
| 264 | } |
| 265 | return false; |
| 266 | } |
| 267 | |
| 268 | notify_axis_source(device->seat, wl_axis_source); |
| 269 | |
Alexandros Frantzis | 8032194 | 2017-11-16 18:20:56 +0200 | [diff] [blame] | 270 | timespec_from_usec(&time, |
| 271 | libinput_event_pointer_get_time_usec(pointer_event)); |
| 272 | |
Peter Hutterer | 87743e9 | 2016-01-18 16:38:22 +1000 | [diff] [blame] | 273 | if (has_vert) { |
| 274 | axis = LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL; |
| 275 | vert_discrete = get_axis_discrete(pointer_event, axis); |
| 276 | vert = normalize_scroll(pointer_event, axis); |
| 277 | |
Peter Hutterer | 89b6a49 | 2016-01-18 15:58:17 +1000 | [diff] [blame] | 278 | weston_event.axis = WL_POINTER_AXIS_VERTICAL_SCROLL; |
Giulio Camuffo | 90a6fc6 | 2016-03-22 17:44:54 +0200 | [diff] [blame] | 279 | weston_event.value = vert; |
Peter Hutterer | 87743e9 | 2016-01-18 16:38:22 +1000 | [diff] [blame] | 280 | weston_event.discrete = vert_discrete; |
| 281 | weston_event.has_discrete = (vert_discrete != 0); |
| 282 | |
Alexandros Frantzis | 8032194 | 2017-11-16 18:20:56 +0200 | [diff] [blame] | 283 | notify_axis(device->seat, &time, &weston_event); |
Peter Hutterer | c54f23d | 2015-01-13 11:55:37 +1000 | [diff] [blame] | 284 | } |
| 285 | |
Peter Hutterer | 87743e9 | 2016-01-18 16:38:22 +1000 | [diff] [blame] | 286 | if (has_horiz) { |
| 287 | axis = LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL; |
| 288 | horiz_discrete = get_axis_discrete(pointer_event, axis); |
| 289 | horiz = normalize_scroll(pointer_event, axis); |
| 290 | |
Peter Hutterer | 89b6a49 | 2016-01-18 15:58:17 +1000 | [diff] [blame] | 291 | weston_event.axis = WL_POINTER_AXIS_HORIZONTAL_SCROLL; |
Giulio Camuffo | 90a6fc6 | 2016-03-22 17:44:54 +0200 | [diff] [blame] | 292 | weston_event.value = horiz; |
Peter Hutterer | 87743e9 | 2016-01-18 16:38:22 +1000 | [diff] [blame] | 293 | weston_event.discrete = horiz_discrete; |
| 294 | weston_event.has_discrete = (horiz_discrete != 0); |
| 295 | |
Alexandros Frantzis | 8032194 | 2017-11-16 18:20:56 +0200 | [diff] [blame] | 296 | notify_axis(device->seat, &time, &weston_event); |
Peter Hutterer | c54f23d | 2015-01-13 11:55:37 +1000 | [diff] [blame] | 297 | } |
Peter Hutterer | 87743e9 | 2016-01-18 16:38:22 +1000 | [diff] [blame] | 298 | |
| 299 | return true; |
Jonas Ådahl | e0de3c2 | 2014-03-12 22:08:42 +0100 | [diff] [blame] | 300 | } |
| 301 | |
Louis-Francis Ratté-Boulianne | 6ef59c9 | 2017-11-28 20:42:47 -0500 | [diff] [blame] | 302 | static struct weston_output * |
| 303 | touch_get_output(struct weston_touch_device *device) |
| 304 | { |
| 305 | struct evdev_device *evdev_device = device->backend_data; |
| 306 | |
| 307 | return evdev_device->output; |
| 308 | } |
| 309 | |
| 310 | static const char * |
| 311 | touch_get_calibration_head_name(struct weston_touch_device *device) |
| 312 | { |
| 313 | struct evdev_device *evdev_device = device->backend_data; |
| 314 | struct weston_output *output = evdev_device->output; |
| 315 | struct weston_head *head; |
| 316 | |
| 317 | if (!output) |
| 318 | return NULL; |
| 319 | |
| 320 | assert(output->enabled); |
| 321 | if (evdev_device->output_name) |
| 322 | return evdev_device->output_name; |
| 323 | |
| 324 | /* No specific head was configured, so the association was made by |
| 325 | * the default rule. Just grab whatever head's name. |
| 326 | */ |
| 327 | wl_list_for_each(head, &output->head_list, output_link) |
| 328 | return head->name; |
| 329 | |
| 330 | assert(0); |
| 331 | return NULL; |
| 332 | } |
| 333 | |
| 334 | static void |
| 335 | touch_get_calibration(struct weston_touch_device *device, |
| 336 | struct weston_touch_device_matrix *cal) |
| 337 | { |
| 338 | struct evdev_device *evdev_device = device->backend_data; |
| 339 | |
| 340 | libinput_device_config_calibration_get_matrix(evdev_device->device, |
| 341 | cal->m); |
| 342 | } |
| 343 | |
| 344 | static void |
| 345 | do_set_calibration(struct evdev_device *evdev_device, |
| 346 | const struct weston_touch_device_matrix *cal) |
| 347 | { |
| 348 | enum libinput_config_status status; |
| 349 | |
Pekka Paalanen | 09fbe14 | 2017-04-18 12:11:53 +0300 | [diff] [blame] | 350 | weston_log("input device %s: applying calibration:\n", |
| 351 | libinput_device_get_sysname(evdev_device->device)); |
| 352 | weston_log_continue(STAMP_SPACE " %f %f %f\n", |
| 353 | cal->m[0], cal->m[1], cal->m[2]); |
| 354 | weston_log_continue(STAMP_SPACE " %f %f %f\n", |
| 355 | cal->m[3], cal->m[4], cal->m[5]); |
| 356 | |
Louis-Francis Ratté-Boulianne | 6ef59c9 | 2017-11-28 20:42:47 -0500 | [diff] [blame] | 357 | status = libinput_device_config_calibration_set_matrix(evdev_device->device, |
| 358 | cal->m); |
| 359 | if (status != LIBINPUT_CONFIG_STATUS_SUCCESS) |
Pekka Paalanen | 09fbe14 | 2017-04-18 12:11:53 +0300 | [diff] [blame] | 360 | weston_log("Error: Failed to apply calibration.\n"); |
Louis-Francis Ratté-Boulianne | 6ef59c9 | 2017-11-28 20:42:47 -0500 | [diff] [blame] | 361 | } |
| 362 | |
| 363 | static void |
| 364 | touch_set_calibration(struct weston_touch_device *device, |
| 365 | const struct weston_touch_device_matrix *cal) |
| 366 | { |
| 367 | struct evdev_device *evdev_device = device->backend_data; |
| 368 | |
| 369 | /* Stop output hotplug from reloading the WL_CALIBRATION values. |
| 370 | * libinput will maintain the latest calibration for us. |
| 371 | */ |
| 372 | evdev_device->override_wl_calibration = true; |
| 373 | |
| 374 | do_set_calibration(evdev_device, cal); |
| 375 | } |
| 376 | |
| 377 | static const struct weston_touch_device_ops touch_calibration_ops = { |
| 378 | .get_output = touch_get_output, |
| 379 | .get_calibration_head_name = touch_get_calibration_head_name, |
| 380 | .get_calibration = touch_get_calibration, |
| 381 | .set_calibration = touch_set_calibration |
| 382 | }; |
| 383 | |
| 384 | static struct weston_touch_device * |
| 385 | create_touch_device(struct evdev_device *device) |
| 386 | { |
| 387 | const struct weston_touch_device_ops *ops = NULL; |
| 388 | struct weston_touch_device *touch_device; |
| 389 | struct udev_device *udev_device; |
| 390 | |
| 391 | if (libinput_device_config_calibration_has_matrix(device->device)) |
| 392 | ops = &touch_calibration_ops; |
| 393 | |
| 394 | udev_device = libinput_device_get_udev_device(device->device); |
| 395 | if (!udev_device) |
| 396 | return NULL; |
| 397 | |
| 398 | touch_device = weston_touch_create_touch_device(device->seat->touch_state, |
| 399 | udev_device_get_syspath(udev_device), |
| 400 | device, ops); |
| 401 | |
| 402 | udev_device_unref(udev_device); |
| 403 | |
| 404 | if (!touch_device) |
| 405 | return NULL; |
| 406 | |
| 407 | weston_log("Touchscreen - %s - %s\n", |
| 408 | libinput_device_get_name(device->device), |
| 409 | touch_device->syspath); |
| 410 | |
| 411 | return touch_device; |
| 412 | } |
| 413 | |
Jonas Ådahl | e0de3c2 | 2014-03-12 22:08:42 +0100 | [diff] [blame] | 414 | static void |
| 415 | handle_touch_with_coords(struct libinput_device *libinput_device, |
| 416 | struct libinput_event_touch *touch_event, |
| 417 | int touch_type) |
| 418 | { |
| 419 | struct evdev_device *device = |
| 420 | libinput_device_get_user_data(libinput_device); |
Giulio Camuffo | 90a6fc6 | 2016-03-22 17:44:54 +0200 | [diff] [blame] | 421 | double x; |
| 422 | double y; |
Pekka Paalanen | f406253 | 2018-02-26 16:18:29 +0200 | [diff] [blame] | 423 | struct weston_point2d_device_normalized norm; |
Jonas Ådahl | e0de3c2 | 2014-03-12 22:08:42 +0100 | [diff] [blame] | 424 | uint32_t width, height; |
Alexandros Frantzis | 9448deb | 2017-11-16 18:20:58 +0200 | [diff] [blame] | 425 | struct timespec time; |
Jonas Ådahl | e0de3c2 | 2014-03-12 22:08:42 +0100 | [diff] [blame] | 426 | int32_t slot; |
| 427 | |
Ander Conselvan de Oliveira | f957dfb | 2014-04-24 15:11:14 +0300 | [diff] [blame] | 428 | if (!device->output) |
| 429 | return; |
| 430 | |
Alexandros Frantzis | 9448deb | 2017-11-16 18:20:58 +0200 | [diff] [blame] | 431 | timespec_from_usec(&time, |
| 432 | libinput_event_touch_get_time_usec(touch_event)); |
Jonas Ådahl | e0de3c2 | 2014-03-12 22:08:42 +0100 | [diff] [blame] | 433 | slot = libinput_event_touch_get_seat_slot(touch_event); |
| 434 | |
| 435 | width = device->output->current_mode->width; |
| 436 | height = device->output->current_mode->height; |
Giulio Camuffo | 90a6fc6 | 2016-03-22 17:44:54 +0200 | [diff] [blame] | 437 | x = libinput_event_touch_get_x_transformed(touch_event, width); |
| 438 | y = libinput_event_touch_get_y_transformed(touch_event, height); |
Jonas Ådahl | e0de3c2 | 2014-03-12 22:08:42 +0100 | [diff] [blame] | 439 | |
| 440 | weston_output_transform_coordinate(device->output, |
| 441 | x, y, &x, &y); |
| 442 | |
Pekka Paalanen | f406253 | 2018-02-26 16:18:29 +0200 | [diff] [blame] | 443 | if (weston_touch_device_can_calibrate(device->touch_device)) { |
| 444 | norm.x = libinput_event_touch_get_x_transformed(touch_event, 1); |
| 445 | norm.y = libinput_event_touch_get_y_transformed(touch_event, 1); |
| 446 | notify_touch_normalized(device->touch_device, &time, slot, |
| 447 | x, y, &norm, touch_type); |
| 448 | } else { |
| 449 | notify_touch(device->touch_device, &time, slot, x, y, touch_type); |
| 450 | } |
Jonas Ådahl | e0de3c2 | 2014-03-12 22:08:42 +0100 | [diff] [blame] | 451 | } |
| 452 | |
| 453 | static void |
| 454 | handle_touch_down(struct libinput_device *device, |
| 455 | struct libinput_event_touch *touch_event) |
| 456 | { |
| 457 | handle_touch_with_coords(device, touch_event, WL_TOUCH_DOWN); |
| 458 | } |
| 459 | |
| 460 | static void |
| 461 | handle_touch_motion(struct libinput_device *device, |
| 462 | struct libinput_event_touch *touch_event) |
| 463 | { |
| 464 | handle_touch_with_coords(device, touch_event, WL_TOUCH_MOTION); |
| 465 | } |
| 466 | |
| 467 | static void |
| 468 | handle_touch_up(struct libinput_device *libinput_device, |
| 469 | struct libinput_event_touch *touch_event) |
| 470 | { |
| 471 | struct evdev_device *device = |
| 472 | libinput_device_get_user_data(libinput_device); |
Alexandros Frantzis | 9448deb | 2017-11-16 18:20:58 +0200 | [diff] [blame] | 473 | struct timespec time; |
Jonas Ådahl | e0de3c2 | 2014-03-12 22:08:42 +0100 | [diff] [blame] | 474 | int32_t slot = libinput_event_touch_get_seat_slot(touch_event); |
| 475 | |
Alexandros Frantzis | 9448deb | 2017-11-16 18:20:58 +0200 | [diff] [blame] | 476 | timespec_from_usec(&time, |
| 477 | libinput_event_touch_get_time_usec(touch_event)); |
| 478 | |
Pekka Paalanen | bcbce33 | 2018-02-26 14:43:00 +0200 | [diff] [blame] | 479 | notify_touch(device->touch_device, &time, slot, 0, 0, WL_TOUCH_UP); |
Jonas Ådahl | e0de3c2 | 2014-03-12 22:08:42 +0100 | [diff] [blame] | 480 | } |
| 481 | |
Jonas Ådahl | 1679f23 | 2014-04-12 09:39:51 +0200 | [diff] [blame] | 482 | static void |
| 483 | handle_touch_frame(struct libinput_device *libinput_device, |
| 484 | struct libinput_event_touch *touch_event) |
| 485 | { |
| 486 | struct evdev_device *device = |
| 487 | libinput_device_get_user_data(libinput_device); |
Jonas Ådahl | 1679f23 | 2014-04-12 09:39:51 +0200 | [diff] [blame] | 488 | |
Pekka Paalanen | bcbce33 | 2018-02-26 14:43:00 +0200 | [diff] [blame] | 489 | notify_touch_frame(device->touch_device); |
Jonas Ådahl | 1679f23 | 2014-04-12 09:39:51 +0200 | [diff] [blame] | 490 | } |
| 491 | |
Jonas Ådahl | e0de3c2 | 2014-03-12 22:08:42 +0100 | [diff] [blame] | 492 | int |
| 493 | evdev_device_process_event(struct libinput_event *event) |
| 494 | { |
| 495 | struct libinput_device *libinput_device = |
| 496 | libinput_event_get_device(event); |
Peter Hutterer | 87743e9 | 2016-01-18 16:38:22 +1000 | [diff] [blame] | 497 | struct evdev_device *device = |
| 498 | libinput_device_get_user_data(libinput_device); |
Jonas Ådahl | e0de3c2 | 2014-03-12 22:08:42 +0100 | [diff] [blame] | 499 | int handled = 1; |
Peter Hutterer | 87743e9 | 2016-01-18 16:38:22 +1000 | [diff] [blame] | 500 | bool need_frame = false; |
Jonas Ådahl | e0de3c2 | 2014-03-12 22:08:42 +0100 | [diff] [blame] | 501 | |
| 502 | switch (libinput_event_get_type(event)) { |
| 503 | case LIBINPUT_EVENT_KEYBOARD_KEY: |
| 504 | handle_keyboard_key(libinput_device, |
| 505 | libinput_event_get_keyboard_event(event)); |
| 506 | break; |
| 507 | case LIBINPUT_EVENT_POINTER_MOTION: |
Peter Hutterer | 87743e9 | 2016-01-18 16:38:22 +1000 | [diff] [blame] | 508 | need_frame = handle_pointer_motion(libinput_device, |
Jonas Ådahl | e0de3c2 | 2014-03-12 22:08:42 +0100 | [diff] [blame] | 509 | libinput_event_get_pointer_event(event)); |
| 510 | break; |
| 511 | case LIBINPUT_EVENT_POINTER_MOTION_ABSOLUTE: |
Peter Hutterer | 87743e9 | 2016-01-18 16:38:22 +1000 | [diff] [blame] | 512 | need_frame = handle_pointer_motion_absolute( |
| 513 | libinput_device, |
| 514 | libinput_event_get_pointer_event(event)); |
Jonas Ådahl | e0de3c2 | 2014-03-12 22:08:42 +0100 | [diff] [blame] | 515 | break; |
| 516 | case LIBINPUT_EVENT_POINTER_BUTTON: |
Peter Hutterer | 87743e9 | 2016-01-18 16:38:22 +1000 | [diff] [blame] | 517 | need_frame = handle_pointer_button(libinput_device, |
Jonas Ådahl | e0de3c2 | 2014-03-12 22:08:42 +0100 | [diff] [blame] | 518 | libinput_event_get_pointer_event(event)); |
| 519 | break; |
| 520 | case LIBINPUT_EVENT_POINTER_AXIS: |
Peter Hutterer | 87743e9 | 2016-01-18 16:38:22 +1000 | [diff] [blame] | 521 | need_frame = handle_pointer_axis( |
| 522 | libinput_device, |
| 523 | libinput_event_get_pointer_event(event)); |
Jonas Ådahl | e0de3c2 | 2014-03-12 22:08:42 +0100 | [diff] [blame] | 524 | break; |
| 525 | case LIBINPUT_EVENT_TOUCH_DOWN: |
| 526 | handle_touch_down(libinput_device, |
| 527 | libinput_event_get_touch_event(event)); |
| 528 | break; |
| 529 | case LIBINPUT_EVENT_TOUCH_MOTION: |
| 530 | handle_touch_motion(libinput_device, |
| 531 | libinput_event_get_touch_event(event)); |
| 532 | break; |
| 533 | case LIBINPUT_EVENT_TOUCH_UP: |
| 534 | handle_touch_up(libinput_device, |
| 535 | libinput_event_get_touch_event(event)); |
U. Artie Eoff | cd9e545 | 2014-04-17 07:53:24 -0700 | [diff] [blame] | 536 | break; |
Jonas Ådahl | 1679f23 | 2014-04-12 09:39:51 +0200 | [diff] [blame] | 537 | case LIBINPUT_EVENT_TOUCH_FRAME: |
| 538 | handle_touch_frame(libinput_device, |
| 539 | libinput_event_get_touch_event(event)); |
| 540 | break; |
Jonas Ådahl | e0de3c2 | 2014-03-12 22:08:42 +0100 | [diff] [blame] | 541 | default: |
| 542 | handled = 0; |
| 543 | weston_log("unknown libinput event %d\n", |
| 544 | libinput_event_get_type(event)); |
| 545 | } |
| 546 | |
Peter Hutterer | 87743e9 | 2016-01-18 16:38:22 +1000 | [diff] [blame] | 547 | if (need_frame) |
| 548 | notify_pointer_frame(device->seat); |
| 549 | |
Jonas Ådahl | e0de3c2 | 2014-03-12 22:08:42 +0100 | [diff] [blame] | 550 | return handled; |
| 551 | } |
| 552 | |
| 553 | static void |
| 554 | notify_output_destroy(struct wl_listener *listener, void *data) |
| 555 | { |
| 556 | struct evdev_device *device = |
| 557 | container_of(listener, |
| 558 | struct evdev_device, output_destroy_listener); |
Jonas Ådahl | e0de3c2 | 2014-03-12 22:08:42 +0100 | [diff] [blame] | 559 | |
Pekka Paalanen | 1bbf58f | 2018-03-20 14:45:36 +0200 | [diff] [blame] | 560 | evdev_device_set_output(device, NULL); |
Jonas Ådahl | e0de3c2 | 2014-03-12 22:08:42 +0100 | [diff] [blame] | 561 | } |
| 562 | |
Peter Hutterer | 3fbba49 | 2014-09-09 13:02:25 +1000 | [diff] [blame] | 563 | /** |
| 564 | * The WL_CALIBRATION property requires a pixel-specific matrix to be |
| 565 | * applied after scaling device coordinates to screen coordinates. libinput |
| 566 | * can't do that, so we need to convert the calibration to the normalized |
| 567 | * format libinput expects. |
| 568 | */ |
Giulio Camuffo | 8aedf7b | 2016-06-02 21:48:12 +0300 | [diff] [blame] | 569 | void |
Peter Hutterer | 3fbba49 | 2014-09-09 13:02:25 +1000 | [diff] [blame] | 570 | evdev_device_set_calibration(struct evdev_device *device) |
| 571 | { |
| 572 | struct udev *udev; |
| 573 | struct udev_device *udev_device = NULL; |
| 574 | const char *sysname = libinput_device_get_sysname(device->device); |
| 575 | const char *calibration_values; |
| 576 | uint32_t width, height; |
Pekka Paalanen | 09fbe14 | 2017-04-18 12:11:53 +0300 | [diff] [blame] | 577 | struct weston_touch_device_matrix calibration; |
Peter Hutterer | 3fbba49 | 2014-09-09 13:02:25 +1000 | [diff] [blame] | 578 | |
Pekka Paalanen | dfc9d3b | 2017-04-18 12:14:32 +0300 | [diff] [blame] | 579 | if (!libinput_device_config_calibration_has_matrix(device->device)) |
Peter Hutterer | 3fbba49 | 2014-09-09 13:02:25 +1000 | [diff] [blame] | 580 | return; |
| 581 | |
Pekka Paalanen | dfc9d3b | 2017-04-18 12:14:32 +0300 | [diff] [blame] | 582 | /* If LIBINPUT_CALIBRATION_MATRIX was set to non-identity, we will not |
| 583 | * override it with WL_CALIBRATION. It also means we don't need an |
| 584 | * output to load a calibration. */ |
| 585 | if (libinput_device_config_calibration_get_default_matrix( |
| 586 | device->device, |
Pekka Paalanen | 09fbe14 | 2017-04-18 12:11:53 +0300 | [diff] [blame] | 587 | calibration.m) != 0) |
Pekka Paalanen | dfc9d3b | 2017-04-18 12:14:32 +0300 | [diff] [blame] | 588 | return; |
| 589 | |
Louis-Francis Ratté-Boulianne | 6ef59c9 | 2017-11-28 20:42:47 -0500 | [diff] [blame] | 590 | /* touch_set_calibration() has updated the values, do not load old |
| 591 | * values from WL_CALIBRATION. |
| 592 | */ |
| 593 | if (device->override_wl_calibration) |
| 594 | return; |
| 595 | |
Pekka Paalanen | dfc9d3b | 2017-04-18 12:14:32 +0300 | [diff] [blame] | 596 | if (!device->output) { |
| 597 | weston_log("input device %s has no enabled output associated " |
| 598 | "(%s named), skipping calibration for now.\n", |
| 599 | sysname, device->output_name ?: "none"); |
| 600 | return; |
| 601 | } |
| 602 | |
Peter Hutterer | 3fbba49 | 2014-09-09 13:02:25 +1000 | [diff] [blame] | 603 | width = device->output->width; |
| 604 | height = device->output->height; |
| 605 | if (width == 0 || height == 0) |
| 606 | return; |
| 607 | |
Peter Hutterer | 3fbba49 | 2014-09-09 13:02:25 +1000 | [diff] [blame] | 608 | udev = udev_new(); |
| 609 | if (!udev) |
| 610 | return; |
| 611 | |
| 612 | udev_device = udev_device_new_from_subsystem_sysname(udev, |
| 613 | "input", |
| 614 | sysname); |
| 615 | if (!udev_device) |
| 616 | goto out; |
| 617 | |
| 618 | calibration_values = |
| 619 | udev_device_get_property_value(udev_device, |
| 620 | "WL_CALIBRATION"); |
| 621 | |
Pekka Paalanen | ed51b62 | 2018-03-21 14:30:04 +0200 | [diff] [blame] | 622 | if (calibration_values) { |
| 623 | weston_log("Warning: input device %s has WL_CALIBRATION property set. " |
| 624 | "Support for it will be removed in the future. " |
| 625 | "Please use LIBINPUT_CALIBRATION_MATRIX instead.\n", |
| 626 | sysname); |
| 627 | } |
| 628 | |
Peter Hutterer | 3fbba49 | 2014-09-09 13:02:25 +1000 | [diff] [blame] | 629 | if (!calibration_values || sscanf(calibration_values, |
| 630 | "%f %f %f %f %f %f", |
Pekka Paalanen | 09fbe14 | 2017-04-18 12:11:53 +0300 | [diff] [blame] | 631 | &calibration.m[0], |
| 632 | &calibration.m[1], |
| 633 | &calibration.m[2], |
| 634 | &calibration.m[3], |
| 635 | &calibration.m[4], |
| 636 | &calibration.m[5]) != 6) |
Peter Hutterer | 3fbba49 | 2014-09-09 13:02:25 +1000 | [diff] [blame] | 637 | goto out; |
| 638 | |
Peter Hutterer | 3fbba49 | 2014-09-09 13:02:25 +1000 | [diff] [blame] | 639 | /* normalize to a format libinput can use. There is a chance of |
| 640 | this being wrong if the width/height don't match the device |
| 641 | width/height but I'm not sure how to fix that */ |
Pekka Paalanen | 09fbe14 | 2017-04-18 12:11:53 +0300 | [diff] [blame] | 642 | calibration.m[2] /= width; |
| 643 | calibration.m[5] /= height; |
Peter Hutterer | 3fbba49 | 2014-09-09 13:02:25 +1000 | [diff] [blame] | 644 | |
Pekka Paalanen | 09fbe14 | 2017-04-18 12:11:53 +0300 | [diff] [blame] | 645 | do_set_calibration(device, &calibration); |
| 646 | |
| 647 | weston_log_continue(STAMP_SPACE " raw translation %f %f for output %s\n", |
| 648 | calibration.m[2] * width, |
| 649 | calibration.m[5] * height, |
| 650 | device->output->name); |
Peter Hutterer | 3fbba49 | 2014-09-09 13:02:25 +1000 | [diff] [blame] | 651 | |
| 652 | out: |
| 653 | if (udev_device) |
| 654 | udev_device_unref(udev_device); |
| 655 | udev_unref(udev); |
| 656 | } |
| 657 | |
Jonas Ådahl | e0de3c2 | 2014-03-12 22:08:42 +0100 | [diff] [blame] | 658 | void |
| 659 | evdev_device_set_output(struct evdev_device *device, |
| 660 | struct weston_output *output) |
| 661 | { |
Pekka Paalanen | 018e6ad | 2017-04-18 12:22:12 +0300 | [diff] [blame] | 662 | if (device->output == output) |
| 663 | return; |
| 664 | |
U. Artie Eoff | 161c6c5 | 2014-04-17 07:53:25 -0700 | [diff] [blame] | 665 | if (device->output_destroy_listener.notify) { |
| 666 | wl_list_remove(&device->output_destroy_listener.link); |
| 667 | device->output_destroy_listener.notify = NULL; |
| 668 | } |
| 669 | |
Pekka Paalanen | 98d50cc | 2017-04-20 11:38:06 +0300 | [diff] [blame] | 670 | if (!output) { |
| 671 | weston_log("output for input device %s removed\n", |
| 672 | libinput_device_get_sysname(device->device)); |
| 673 | |
| 674 | device->output = NULL; |
| 675 | return; |
| 676 | } |
| 677 | |
Pekka Paalanen | 6632b6d | 2017-04-18 12:22:12 +0300 | [diff] [blame] | 678 | weston_log("associating input device %s with output %s " |
| 679 | "(%s by udev)\n", |
| 680 | libinput_device_get_sysname(device->device), |
| 681 | output->name, |
| 682 | device->output_name ?: "none"); |
| 683 | |
Jonas Ådahl | e0de3c2 | 2014-03-12 22:08:42 +0100 | [diff] [blame] | 684 | device->output = output; |
| 685 | device->output_destroy_listener.notify = notify_output_destroy; |
| 686 | wl_signal_add(&output->destroy_signal, |
| 687 | &device->output_destroy_listener); |
Peter Hutterer | 3fbba49 | 2014-09-09 13:02:25 +1000 | [diff] [blame] | 688 | evdev_device_set_calibration(device); |
Jonas Ådahl | e0de3c2 | 2014-03-12 22:08:42 +0100 | [diff] [blame] | 689 | } |
| 690 | |
| 691 | struct evdev_device * |
| 692 | evdev_device_create(struct libinput_device *libinput_device, |
| 693 | struct weston_seat *seat) |
| 694 | { |
| 695 | struct evdev_device *device; |
| 696 | |
| 697 | device = zalloc(sizeof *device); |
| 698 | if (device == NULL) |
| 699 | return NULL; |
| 700 | |
| 701 | device->seat = seat; |
| 702 | wl_list_init(&device->link); |
| 703 | device->device = libinput_device; |
| 704 | |
| 705 | if (libinput_device_has_capability(libinput_device, |
| 706 | LIBINPUT_DEVICE_CAP_KEYBOARD)) { |
| 707 | weston_seat_init_keyboard(seat, NULL); |
| 708 | device->seat_caps |= EVDEV_SEAT_KEYBOARD; |
| 709 | } |
| 710 | if (libinput_device_has_capability(libinput_device, |
| 711 | LIBINPUT_DEVICE_CAP_POINTER)) { |
| 712 | weston_seat_init_pointer(seat); |
| 713 | device->seat_caps |= EVDEV_SEAT_POINTER; |
| 714 | } |
| 715 | if (libinput_device_has_capability(libinput_device, |
| 716 | LIBINPUT_DEVICE_CAP_TOUCH)) { |
| 717 | weston_seat_init_touch(seat); |
| 718 | device->seat_caps |= EVDEV_SEAT_TOUCH; |
Louis-Francis Ratté-Boulianne | 6ef59c9 | 2017-11-28 20:42:47 -0500 | [diff] [blame] | 719 | device->touch_device = create_touch_device(device); |
Jonas Ådahl | e0de3c2 | 2014-03-12 22:08:42 +0100 | [diff] [blame] | 720 | } |
| 721 | |
| 722 | libinput_device_set_user_data(libinput_device, device); |
| 723 | libinput_device_ref(libinput_device); |
| 724 | |
Jonas Ådahl | e0de3c2 | 2014-03-12 22:08:42 +0100 | [diff] [blame] | 725 | return device; |
| 726 | } |
| 727 | |
| 728 | void |
| 729 | evdev_device_destroy(struct evdev_device *device) |
| 730 | { |
| 731 | if (device->seat_caps & EVDEV_SEAT_POINTER) |
| 732 | weston_seat_release_pointer(device->seat); |
| 733 | if (device->seat_caps & EVDEV_SEAT_KEYBOARD) |
| 734 | weston_seat_release_keyboard(device->seat); |
Louis-Francis Ratté-Boulianne | 6ef59c9 | 2017-11-28 20:42:47 -0500 | [diff] [blame] | 735 | if (device->seat_caps & EVDEV_SEAT_TOUCH) { |
| 736 | weston_touch_device_destroy(device->touch_device); |
Jonas Ådahl | e0de3c2 | 2014-03-12 22:08:42 +0100 | [diff] [blame] | 737 | weston_seat_release_touch(device->seat); |
Louis-Francis Ratté-Boulianne | 6ef59c9 | 2017-11-28 20:42:47 -0500 | [diff] [blame] | 738 | } |
Jonas Ådahl | e0de3c2 | 2014-03-12 22:08:42 +0100 | [diff] [blame] | 739 | |
| 740 | if (device->output) |
| 741 | wl_list_remove(&device->output_destroy_listener.link); |
| 742 | wl_list_remove(&device->link); |
| 743 | libinput_device_unref(device->device); |
Jonas Ådahl | e0de3c2 | 2014-03-12 22:08:42 +0100 | [diff] [blame] | 744 | free(device->output_name); |
| 745 | free(device); |
| 746 | } |
| 747 | |
| 748 | void |
| 749 | evdev_notify_keyboard_focus(struct weston_seat *seat, |
| 750 | struct wl_list *evdev_devices) |
| 751 | { |
Jonas Ådahl | e0de3c2 | 2014-03-12 22:08:42 +0100 | [diff] [blame] | 752 | struct wl_array keys; |
Jonas Ådahl | e0de3c2 | 2014-03-12 22:08:42 +0100 | [diff] [blame] | 753 | |
Derek Foreman | d621df2 | 2014-11-19 11:04:12 -0600 | [diff] [blame] | 754 | if (seat->keyboard_device_count == 0) |
Jonas Ådahl | e0de3c2 | 2014-03-12 22:08:42 +0100 | [diff] [blame] | 755 | return; |
| 756 | |
Jonas Ådahl | e0de3c2 | 2014-03-12 22:08:42 +0100 | [diff] [blame] | 757 | wl_array_init(&keys); |
Jonas Ådahl | e0de3c2 | 2014-03-12 22:08:42 +0100 | [diff] [blame] | 758 | notify_keyboard_focus_in(seat, &keys, STATE_UPDATE_AUTOMATIC); |
Jonas Ådahl | e0de3c2 | 2014-03-12 22:08:42 +0100 | [diff] [blame] | 759 | wl_array_release(&keys); |
| 760 | } |