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