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