Jonas Ådahl | e0de3c2 | 2014-03-12 22:08:42 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright © 2010 Intel Corporation |
| 3 | * Copyright © 2013 Jonas Ådahl |
| 4 | * |
Bryce Harrington | a0bbfea | 2015-06-11 15:35:43 -0700 | [diff] [blame] | 5 | * Permission is hereby granted, free of charge, to any person obtaining |
| 6 | * a copy of this software and associated documentation files (the |
| 7 | * "Software"), to deal in the Software without restriction, including |
| 8 | * without limitation the rights to use, copy, modify, merge, publish, |
| 9 | * distribute, sublicense, and/or sell copies of the Software, and to |
| 10 | * permit persons to whom the Software is furnished to do so, subject to |
| 11 | * the following conditions: |
Jonas Ådahl | e0de3c2 | 2014-03-12 22:08:42 +0100 | [diff] [blame] | 12 | * |
Bryce Harrington | a0bbfea | 2015-06-11 15:35:43 -0700 | [diff] [blame] | 13 | * The above copyright notice and this permission notice (including the |
| 14 | * next paragraph) shall be included in all copies or substantial |
| 15 | * portions of the Software. |
| 16 | * |
| 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
| 18 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| 19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
| 20 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS |
| 21 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN |
| 22 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN |
| 23 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 24 | * SOFTWARE. |
Jonas Ådahl | e0de3c2 | 2014-03-12 22:08:42 +0100 | [diff] [blame] | 25 | */ |
| 26 | |
| 27 | #include "config.h" |
| 28 | |
| 29 | #include <errno.h> |
| 30 | #include <stdlib.h> |
| 31 | #include <string.h> |
| 32 | #include <linux/input.h> |
| 33 | #include <unistd.h> |
| 34 | #include <fcntl.h> |
| 35 | #include <mtdev.h> |
| 36 | #include <assert.h> |
| 37 | #include <libinput.h> |
| 38 | |
| 39 | #include "compositor.h" |
| 40 | #include "libinput-device.h" |
| 41 | |
| 42 | #define DEFAULT_AXIS_STEP_DISTANCE wl_fixed_from_int(10) |
| 43 | |
| 44 | void |
| 45 | evdev_led_update(struct evdev_device *device, enum weston_led weston_leds) |
| 46 | { |
| 47 | enum libinput_led leds = 0; |
| 48 | |
| 49 | if (weston_leds & LED_NUM_LOCK) |
| 50 | leds |= LIBINPUT_LED_NUM_LOCK; |
| 51 | if (weston_leds & LED_CAPS_LOCK) |
| 52 | leds |= LIBINPUT_LED_CAPS_LOCK; |
| 53 | if (weston_leds & LED_SCROLL_LOCK) |
| 54 | leds |= LIBINPUT_LED_SCROLL_LOCK; |
| 55 | |
| 56 | libinput_device_led_update(device->device, leds); |
| 57 | } |
| 58 | |
| 59 | static void |
| 60 | handle_keyboard_key(struct libinput_device *libinput_device, |
| 61 | struct libinput_event_keyboard *keyboard_event) |
| 62 | { |
| 63 | struct evdev_device *device = |
| 64 | libinput_device_get_user_data(libinput_device); |
Jonas Ådahl | 90d1ac8 | 2015-01-30 12:23:00 +0800 | [diff] [blame] | 65 | int key_state = |
| 66 | libinput_event_keyboard_get_key_state(keyboard_event); |
| 67 | int seat_key_count = |
| 68 | libinput_event_keyboard_get_seat_key_count(keyboard_event); |
| 69 | |
| 70 | /* Ignore key events that are not seat wide state changes. */ |
| 71 | if ((key_state == LIBINPUT_KEY_STATE_PRESSED && |
| 72 | seat_key_count != 1) || |
| 73 | (key_state == LIBINPUT_KEY_STATE_RELEASED && |
| 74 | seat_key_count != 0)) |
| 75 | return; |
Jonas Ådahl | e0de3c2 | 2014-03-12 22:08:42 +0100 | [diff] [blame] | 76 | |
| 77 | notify_key(device->seat, |
| 78 | libinput_event_keyboard_get_time(keyboard_event), |
| 79 | libinput_event_keyboard_get_key(keyboard_event), |
| 80 | libinput_event_keyboard_get_key_state(keyboard_event), |
| 81 | STATE_UPDATE_AUTOMATIC); |
| 82 | } |
| 83 | |
| 84 | static void |
| 85 | handle_pointer_motion(struct libinput_device *libinput_device, |
| 86 | struct libinput_event_pointer *pointer_event) |
| 87 | { |
| 88 | struct evdev_device *device = |
| 89 | libinput_device_get_user_data(libinput_device); |
Jonas Ådahl | 26714b4 | 2014-06-02 23:15:48 +0200 | [diff] [blame] | 90 | wl_fixed_t dx, dy; |
Jonas Ådahl | e0de3c2 | 2014-03-12 22:08:42 +0100 | [diff] [blame] | 91 | |
Jonas Ådahl | 26714b4 | 2014-06-02 23:15:48 +0200 | [diff] [blame] | 92 | dx = wl_fixed_from_double(libinput_event_pointer_get_dx(pointer_event)); |
| 93 | dy = wl_fixed_from_double(libinput_event_pointer_get_dy(pointer_event)); |
Jonas Ådahl | e0de3c2 | 2014-03-12 22:08:42 +0100 | [diff] [blame] | 94 | notify_motion(device->seat, |
| 95 | libinput_event_pointer_get_time(pointer_event), |
Jonas Ådahl | 26714b4 | 2014-06-02 23:15:48 +0200 | [diff] [blame] | 96 | dx, |
| 97 | dy); |
Jonas Ådahl | e0de3c2 | 2014-03-12 22:08:42 +0100 | [diff] [blame] | 98 | } |
| 99 | |
| 100 | static void |
| 101 | handle_pointer_motion_absolute( |
| 102 | struct libinput_device *libinput_device, |
| 103 | struct libinput_event_pointer *pointer_event) |
| 104 | { |
| 105 | struct evdev_device *device = |
| 106 | libinput_device_get_user_data(libinput_device); |
| 107 | struct weston_output *output = device->output; |
| 108 | uint32_t time; |
| 109 | wl_fixed_t x, y; |
| 110 | uint32_t width, height; |
| 111 | |
| 112 | if (!output) |
| 113 | return; |
| 114 | |
| 115 | time = libinput_event_pointer_get_time(pointer_event); |
| 116 | width = device->output->current_mode->width; |
| 117 | height = device->output->current_mode->height; |
| 118 | |
Jonas Ådahl | 26714b4 | 2014-06-02 23:15:48 +0200 | [diff] [blame] | 119 | x = wl_fixed_from_double( |
| 120 | libinput_event_pointer_get_absolute_x_transformed(pointer_event, |
| 121 | width)); |
| 122 | y = wl_fixed_from_double( |
| 123 | libinput_event_pointer_get_absolute_y_transformed(pointer_event, |
| 124 | height)); |
Jonas Ådahl | e0de3c2 | 2014-03-12 22:08:42 +0100 | [diff] [blame] | 125 | |
| 126 | weston_output_transform_coordinate(device->output, x, y, &x, &y); |
| 127 | notify_motion_absolute(device->seat, time, x, y); |
| 128 | } |
| 129 | |
| 130 | static void |
| 131 | handle_pointer_button(struct libinput_device *libinput_device, |
| 132 | struct libinput_event_pointer *pointer_event) |
| 133 | { |
| 134 | struct evdev_device *device = |
| 135 | libinput_device_get_user_data(libinput_device); |
Jonas Ådahl | e90b9e9 | 2015-01-30 12:22:59 +0800 | [diff] [blame] | 136 | int button_state = |
| 137 | libinput_event_pointer_get_button_state(pointer_event); |
| 138 | int seat_button_count = |
| 139 | libinput_event_pointer_get_seat_button_count(pointer_event); |
| 140 | |
| 141 | /* Ignore button events that are not seat wide state changes. */ |
| 142 | if ((button_state == LIBINPUT_BUTTON_STATE_PRESSED && |
| 143 | seat_button_count != 1) || |
| 144 | (button_state == LIBINPUT_BUTTON_STATE_RELEASED && |
| 145 | seat_button_count != 0)) |
| 146 | return; |
Jonas Ådahl | e0de3c2 | 2014-03-12 22:08:42 +0100 | [diff] [blame] | 147 | |
| 148 | notify_button(device->seat, |
| 149 | libinput_event_pointer_get_time(pointer_event), |
| 150 | libinput_event_pointer_get_button(pointer_event), |
| 151 | libinput_event_pointer_get_button_state(pointer_event)); |
| 152 | } |
| 153 | |
Peter Hutterer | 5dddd41 | 2015-01-15 13:14:43 +1000 | [diff] [blame] | 154 | static double |
| 155 | normalize_scroll(struct libinput_event_pointer *pointer_event, |
| 156 | enum libinput_pointer_axis axis) |
| 157 | { |
| 158 | static int warned; |
| 159 | enum libinput_pointer_axis_source source; |
| 160 | double value; |
| 161 | |
| 162 | source = libinput_event_pointer_get_axis_source(pointer_event); |
| 163 | /* libinput < 0.8 sent wheel click events with value 10. Since 0.8 |
| 164 | the value is the angle of the click in degrees. To keep |
| 165 | backwards-compat with existing clients, we just send multiples of |
| 166 | the click count. |
| 167 | */ |
| 168 | switch (source) { |
| 169 | case LIBINPUT_POINTER_AXIS_SOURCE_WHEEL: |
| 170 | value = 10 * libinput_event_pointer_get_axis_value_discrete( |
| 171 | pointer_event, |
| 172 | axis); |
| 173 | break; |
| 174 | case LIBINPUT_POINTER_AXIS_SOURCE_FINGER: |
| 175 | case LIBINPUT_POINTER_AXIS_SOURCE_CONTINUOUS: |
| 176 | value = libinput_event_pointer_get_axis_value(pointer_event, |
| 177 | axis); |
| 178 | break; |
| 179 | default: |
| 180 | value = 0; |
| 181 | if (warned < 5) { |
| 182 | weston_log("Unknown scroll source %d. Event discarded\n", |
| 183 | source); |
| 184 | warned++; |
| 185 | } |
| 186 | break; |
| 187 | } |
| 188 | |
| 189 | return value; |
| 190 | } |
| 191 | |
Jonas Ådahl | e0de3c2 | 2014-03-12 22:08:42 +0100 | [diff] [blame] | 192 | static void |
| 193 | handle_pointer_axis(struct libinput_device *libinput_device, |
| 194 | struct libinput_event_pointer *pointer_event) |
| 195 | { |
| 196 | struct evdev_device *device = |
| 197 | libinput_device_get_user_data(libinput_device); |
Jonas Ådahl | 26714b4 | 2014-06-02 23:15:48 +0200 | [diff] [blame] | 198 | double value; |
Peter Hutterer | c54f23d | 2015-01-13 11:55:37 +1000 | [diff] [blame] | 199 | enum libinput_pointer_axis axis; |
Jonas Ådahl | e0de3c2 | 2014-03-12 22:08:42 +0100 | [diff] [blame] | 200 | |
Peter Hutterer | c54f23d | 2015-01-13 11:55:37 +1000 | [diff] [blame] | 201 | axis = LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL; |
| 202 | if (libinput_event_pointer_has_axis(pointer_event, axis)) { |
Peter Hutterer | 5dddd41 | 2015-01-15 13:14:43 +1000 | [diff] [blame] | 203 | value = normalize_scroll(pointer_event, axis); |
Peter Hutterer | c54f23d | 2015-01-13 11:55:37 +1000 | [diff] [blame] | 204 | notify_axis(device->seat, |
| 205 | libinput_event_pointer_get_time(pointer_event), |
| 206 | WL_POINTER_AXIS_VERTICAL_SCROLL, |
| 207 | wl_fixed_from_double(value)); |
| 208 | } |
| 209 | |
| 210 | axis = LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL; |
| 211 | if (libinput_event_pointer_has_axis(pointer_event, axis)) { |
Peter Hutterer | 5dddd41 | 2015-01-15 13:14:43 +1000 | [diff] [blame] | 212 | value = normalize_scroll(pointer_event, axis); |
Peter Hutterer | c54f23d | 2015-01-13 11:55:37 +1000 | [diff] [blame] | 213 | notify_axis(device->seat, |
| 214 | libinput_event_pointer_get_time(pointer_event), |
| 215 | WL_POINTER_AXIS_HORIZONTAL_SCROLL, |
| 216 | wl_fixed_from_double(value)); |
| 217 | } |
Jonas Ådahl | e0de3c2 | 2014-03-12 22:08:42 +0100 | [diff] [blame] | 218 | } |
| 219 | |
| 220 | static void |
| 221 | handle_touch_with_coords(struct libinput_device *libinput_device, |
| 222 | struct libinput_event_touch *touch_event, |
| 223 | int touch_type) |
| 224 | { |
| 225 | struct evdev_device *device = |
| 226 | libinput_device_get_user_data(libinput_device); |
| 227 | wl_fixed_t x; |
| 228 | wl_fixed_t y; |
| 229 | uint32_t width, height; |
| 230 | uint32_t time; |
| 231 | int32_t slot; |
| 232 | |
Ander Conselvan de Oliveira | f957dfb | 2014-04-24 15:11:14 +0300 | [diff] [blame] | 233 | if (!device->output) |
| 234 | return; |
| 235 | |
Jonas Ådahl | e0de3c2 | 2014-03-12 22:08:42 +0100 | [diff] [blame] | 236 | time = libinput_event_touch_get_time(touch_event); |
| 237 | slot = libinput_event_touch_get_seat_slot(touch_event); |
| 238 | |
| 239 | width = device->output->current_mode->width; |
| 240 | height = device->output->current_mode->height; |
Jonas Ådahl | 26714b4 | 2014-06-02 23:15:48 +0200 | [diff] [blame] | 241 | x = wl_fixed_from_double( |
| 242 | libinput_event_touch_get_x_transformed(touch_event, width)); |
| 243 | y = wl_fixed_from_double( |
| 244 | libinput_event_touch_get_y_transformed(touch_event, height)); |
Jonas Ådahl | e0de3c2 | 2014-03-12 22:08:42 +0100 | [diff] [blame] | 245 | |
| 246 | weston_output_transform_coordinate(device->output, |
| 247 | x, y, &x, &y); |
| 248 | |
| 249 | notify_touch(device->seat, time, slot, x, y, touch_type); |
| 250 | } |
| 251 | |
| 252 | static void |
| 253 | handle_touch_down(struct libinput_device *device, |
| 254 | struct libinput_event_touch *touch_event) |
| 255 | { |
| 256 | handle_touch_with_coords(device, touch_event, WL_TOUCH_DOWN); |
| 257 | } |
| 258 | |
| 259 | static void |
| 260 | handle_touch_motion(struct libinput_device *device, |
| 261 | struct libinput_event_touch *touch_event) |
| 262 | { |
| 263 | handle_touch_with_coords(device, touch_event, WL_TOUCH_MOTION); |
| 264 | } |
| 265 | |
| 266 | static void |
| 267 | handle_touch_up(struct libinput_device *libinput_device, |
| 268 | struct libinput_event_touch *touch_event) |
| 269 | { |
| 270 | struct evdev_device *device = |
| 271 | libinput_device_get_user_data(libinput_device); |
| 272 | uint32_t time = libinput_event_touch_get_time(touch_event); |
| 273 | int32_t slot = libinput_event_touch_get_seat_slot(touch_event); |
| 274 | |
| 275 | notify_touch(device->seat, time, slot, 0, 0, WL_TOUCH_UP); |
| 276 | } |
| 277 | |
Jonas Ådahl | 1679f23 | 2014-04-12 09:39:51 +0200 | [diff] [blame] | 278 | static void |
| 279 | handle_touch_frame(struct libinput_device *libinput_device, |
| 280 | struct libinput_event_touch *touch_event) |
| 281 | { |
| 282 | struct evdev_device *device = |
| 283 | libinput_device_get_user_data(libinput_device); |
| 284 | struct weston_seat *seat = device->seat; |
| 285 | |
| 286 | notify_touch_frame(seat); |
| 287 | } |
| 288 | |
Jonas Ådahl | e0de3c2 | 2014-03-12 22:08:42 +0100 | [diff] [blame] | 289 | int |
| 290 | evdev_device_process_event(struct libinput_event *event) |
| 291 | { |
| 292 | struct libinput_device *libinput_device = |
| 293 | libinput_event_get_device(event); |
| 294 | int handled = 1; |
| 295 | |
| 296 | switch (libinput_event_get_type(event)) { |
| 297 | case LIBINPUT_EVENT_KEYBOARD_KEY: |
| 298 | handle_keyboard_key(libinput_device, |
| 299 | libinput_event_get_keyboard_event(event)); |
| 300 | break; |
| 301 | case LIBINPUT_EVENT_POINTER_MOTION: |
| 302 | handle_pointer_motion(libinput_device, |
| 303 | libinput_event_get_pointer_event(event)); |
| 304 | break; |
| 305 | case LIBINPUT_EVENT_POINTER_MOTION_ABSOLUTE: |
| 306 | handle_pointer_motion_absolute( |
| 307 | libinput_device, |
| 308 | libinput_event_get_pointer_event(event)); |
| 309 | break; |
| 310 | case LIBINPUT_EVENT_POINTER_BUTTON: |
| 311 | handle_pointer_button(libinput_device, |
| 312 | libinput_event_get_pointer_event(event)); |
| 313 | break; |
| 314 | case LIBINPUT_EVENT_POINTER_AXIS: |
| 315 | handle_pointer_axis(libinput_device, |
| 316 | libinput_event_get_pointer_event(event)); |
| 317 | break; |
| 318 | case LIBINPUT_EVENT_TOUCH_DOWN: |
| 319 | handle_touch_down(libinput_device, |
| 320 | libinput_event_get_touch_event(event)); |
| 321 | break; |
| 322 | case LIBINPUT_EVENT_TOUCH_MOTION: |
| 323 | handle_touch_motion(libinput_device, |
| 324 | libinput_event_get_touch_event(event)); |
| 325 | break; |
| 326 | case LIBINPUT_EVENT_TOUCH_UP: |
| 327 | handle_touch_up(libinput_device, |
| 328 | libinput_event_get_touch_event(event)); |
U. Artie Eoff | cd9e545 | 2014-04-17 07:53:24 -0700 | [diff] [blame] | 329 | break; |
Jonas Ådahl | 1679f23 | 2014-04-12 09:39:51 +0200 | [diff] [blame] | 330 | case LIBINPUT_EVENT_TOUCH_FRAME: |
| 331 | handle_touch_frame(libinput_device, |
| 332 | libinput_event_get_touch_event(event)); |
| 333 | break; |
Jonas Ådahl | e0de3c2 | 2014-03-12 22:08:42 +0100 | [diff] [blame] | 334 | default: |
| 335 | handled = 0; |
| 336 | weston_log("unknown libinput event %d\n", |
| 337 | libinput_event_get_type(event)); |
| 338 | } |
| 339 | |
| 340 | return handled; |
| 341 | } |
| 342 | |
| 343 | static void |
| 344 | notify_output_destroy(struct wl_listener *listener, void *data) |
| 345 | { |
| 346 | struct evdev_device *device = |
| 347 | container_of(listener, |
| 348 | struct evdev_device, output_destroy_listener); |
| 349 | struct weston_compositor *c = device->seat->compositor; |
| 350 | struct weston_output *output; |
| 351 | |
Ander Conselvan de Oliveira | a7caef9 | 2014-04-24 15:11:17 +0300 | [diff] [blame] | 352 | if (!device->output_name && !wl_list_empty(&c->output_list)) { |
Jonas Ådahl | e0de3c2 | 2014-03-12 22:08:42 +0100 | [diff] [blame] | 353 | output = container_of(c->output_list.next, |
| 354 | struct weston_output, link); |
| 355 | evdev_device_set_output(device, output); |
| 356 | } else { |
| 357 | device->output = NULL; |
| 358 | } |
| 359 | } |
| 360 | |
Peter Hutterer | 3fbba49 | 2014-09-09 13:02:25 +1000 | [diff] [blame] | 361 | /** |
| 362 | * The WL_CALIBRATION property requires a pixel-specific matrix to be |
| 363 | * applied after scaling device coordinates to screen coordinates. libinput |
| 364 | * can't do that, so we need to convert the calibration to the normalized |
| 365 | * format libinput expects. |
| 366 | */ |
| 367 | static void |
| 368 | evdev_device_set_calibration(struct evdev_device *device) |
| 369 | { |
| 370 | struct udev *udev; |
| 371 | struct udev_device *udev_device = NULL; |
| 372 | const char *sysname = libinput_device_get_sysname(device->device); |
| 373 | const char *calibration_values; |
| 374 | uint32_t width, height; |
| 375 | float calibration[6]; |
| 376 | enum libinput_config_status status; |
| 377 | |
| 378 | if (!device->output) |
| 379 | return; |
| 380 | |
| 381 | width = device->output->width; |
| 382 | height = device->output->height; |
| 383 | if (width == 0 || height == 0) |
| 384 | return; |
| 385 | |
| 386 | /* If libinput has a pre-set calibration matrix, don't override it */ |
| 387 | if (!libinput_device_config_calibration_has_matrix(device->device) || |
| 388 | libinput_device_config_calibration_get_default_matrix( |
| 389 | device->device, |
| 390 | calibration) != 0) |
| 391 | return; |
| 392 | |
| 393 | udev = udev_new(); |
| 394 | if (!udev) |
| 395 | return; |
| 396 | |
| 397 | udev_device = udev_device_new_from_subsystem_sysname(udev, |
| 398 | "input", |
| 399 | sysname); |
| 400 | if (!udev_device) |
| 401 | goto out; |
| 402 | |
| 403 | calibration_values = |
| 404 | udev_device_get_property_value(udev_device, |
| 405 | "WL_CALIBRATION"); |
| 406 | |
| 407 | if (!calibration_values || sscanf(calibration_values, |
| 408 | "%f %f %f %f %f %f", |
| 409 | &calibration[0], |
| 410 | &calibration[1], |
| 411 | &calibration[2], |
| 412 | &calibration[3], |
| 413 | &calibration[4], |
| 414 | &calibration[5]) != 6) |
| 415 | goto out; |
| 416 | |
| 417 | weston_log("Applying calibration: %f %f %f %f %f %f " |
| 418 | "(normalized %f %f)\n", |
| 419 | calibration[0], |
| 420 | calibration[1], |
| 421 | calibration[2], |
| 422 | calibration[3], |
| 423 | calibration[4], |
| 424 | calibration[5], |
| 425 | calibration[2] / width, |
| 426 | calibration[5] / height); |
| 427 | |
| 428 | /* normalize to a format libinput can use. There is a chance of |
| 429 | this being wrong if the width/height don't match the device |
| 430 | width/height but I'm not sure how to fix that */ |
| 431 | calibration[2] /= width; |
| 432 | calibration[5] /= height; |
| 433 | |
| 434 | status = libinput_device_config_calibration_set_matrix(device->device, |
| 435 | calibration); |
| 436 | if (status != LIBINPUT_CONFIG_STATUS_SUCCESS) |
| 437 | weston_log("Failed to apply calibration.\n"); |
| 438 | |
| 439 | out: |
| 440 | if (udev_device) |
| 441 | udev_device_unref(udev_device); |
| 442 | udev_unref(udev); |
| 443 | } |
| 444 | |
Jonas Ådahl | e0de3c2 | 2014-03-12 22:08:42 +0100 | [diff] [blame] | 445 | void |
| 446 | evdev_device_set_output(struct evdev_device *device, |
| 447 | struct weston_output *output) |
| 448 | { |
U. Artie Eoff | 161c6c5 | 2014-04-17 07:53:25 -0700 | [diff] [blame] | 449 | if (device->output_destroy_listener.notify) { |
| 450 | wl_list_remove(&device->output_destroy_listener.link); |
| 451 | device->output_destroy_listener.notify = NULL; |
| 452 | } |
| 453 | |
Jonas Ådahl | e0de3c2 | 2014-03-12 22:08:42 +0100 | [diff] [blame] | 454 | device->output = output; |
| 455 | device->output_destroy_listener.notify = notify_output_destroy; |
| 456 | wl_signal_add(&output->destroy_signal, |
| 457 | &device->output_destroy_listener); |
Peter Hutterer | 3fbba49 | 2014-09-09 13:02:25 +1000 | [diff] [blame] | 458 | evdev_device_set_calibration(device); |
Jonas Ådahl | e0de3c2 | 2014-03-12 22:08:42 +0100 | [diff] [blame] | 459 | } |
| 460 | |
Jonas Ådahl | 05e4a1f | 2014-07-22 22:49:41 +0200 | [diff] [blame] | 461 | static void |
| 462 | configure_device(struct evdev_device *device) |
| 463 | { |
| 464 | struct weston_compositor *compositor = device->seat->compositor; |
| 465 | struct weston_config_section *s; |
| 466 | int enable_tap; |
| 467 | int enable_tap_default; |
| 468 | |
| 469 | s = weston_config_get_section(compositor->config, |
| 470 | "libinput", NULL, NULL); |
| 471 | |
| 472 | if (libinput_device_config_tap_get_finger_count(device->device) > 0) { |
| 473 | enable_tap_default = |
| 474 | libinput_device_config_tap_get_default_enabled( |
| 475 | device->device); |
| 476 | weston_config_section_get_bool(s, "enable_tap", |
| 477 | &enable_tap, |
| 478 | enable_tap_default); |
| 479 | libinput_device_config_tap_set_enabled(device->device, |
| 480 | enable_tap); |
| 481 | } |
Peter Hutterer | 3fbba49 | 2014-09-09 13:02:25 +1000 | [diff] [blame] | 482 | |
| 483 | evdev_device_set_calibration(device); |
Jonas Ådahl | 05e4a1f | 2014-07-22 22:49:41 +0200 | [diff] [blame] | 484 | } |
| 485 | |
Jonas Ådahl | e0de3c2 | 2014-03-12 22:08:42 +0100 | [diff] [blame] | 486 | struct evdev_device * |
| 487 | evdev_device_create(struct libinput_device *libinput_device, |
| 488 | struct weston_seat *seat) |
| 489 | { |
| 490 | struct evdev_device *device; |
| 491 | |
| 492 | device = zalloc(sizeof *device); |
| 493 | if (device == NULL) |
| 494 | return NULL; |
| 495 | |
| 496 | device->seat = seat; |
| 497 | wl_list_init(&device->link); |
| 498 | device->device = libinput_device; |
| 499 | |
| 500 | if (libinput_device_has_capability(libinput_device, |
| 501 | LIBINPUT_DEVICE_CAP_KEYBOARD)) { |
| 502 | weston_seat_init_keyboard(seat, NULL); |
| 503 | device->seat_caps |= EVDEV_SEAT_KEYBOARD; |
| 504 | } |
| 505 | if (libinput_device_has_capability(libinput_device, |
| 506 | LIBINPUT_DEVICE_CAP_POINTER)) { |
| 507 | weston_seat_init_pointer(seat); |
| 508 | device->seat_caps |= EVDEV_SEAT_POINTER; |
| 509 | } |
| 510 | if (libinput_device_has_capability(libinput_device, |
| 511 | LIBINPUT_DEVICE_CAP_TOUCH)) { |
| 512 | weston_seat_init_touch(seat); |
| 513 | device->seat_caps |= EVDEV_SEAT_TOUCH; |
| 514 | } |
| 515 | |
| 516 | libinput_device_set_user_data(libinput_device, device); |
| 517 | libinput_device_ref(libinput_device); |
| 518 | |
Jonas Ådahl | 05e4a1f | 2014-07-22 22:49:41 +0200 | [diff] [blame] | 519 | configure_device(device); |
| 520 | |
Jonas Ådahl | e0de3c2 | 2014-03-12 22:08:42 +0100 | [diff] [blame] | 521 | return device; |
| 522 | } |
| 523 | |
| 524 | void |
| 525 | evdev_device_destroy(struct evdev_device *device) |
| 526 | { |
| 527 | if (device->seat_caps & EVDEV_SEAT_POINTER) |
| 528 | weston_seat_release_pointer(device->seat); |
| 529 | if (device->seat_caps & EVDEV_SEAT_KEYBOARD) |
| 530 | weston_seat_release_keyboard(device->seat); |
| 531 | if (device->seat_caps & EVDEV_SEAT_TOUCH) |
| 532 | weston_seat_release_touch(device->seat); |
| 533 | |
| 534 | if (device->output) |
| 535 | wl_list_remove(&device->output_destroy_listener.link); |
| 536 | wl_list_remove(&device->link); |
| 537 | libinput_device_unref(device->device); |
| 538 | free(device->devnode); |
| 539 | free(device->output_name); |
| 540 | free(device); |
| 541 | } |
| 542 | |
| 543 | void |
| 544 | evdev_notify_keyboard_focus(struct weston_seat *seat, |
| 545 | struct wl_list *evdev_devices) |
| 546 | { |
Jonas Ådahl | e0de3c2 | 2014-03-12 22:08:42 +0100 | [diff] [blame] | 547 | struct wl_array keys; |
Jonas Ådahl | e0de3c2 | 2014-03-12 22:08:42 +0100 | [diff] [blame] | 548 | |
Derek Foreman | d621df2 | 2014-11-19 11:04:12 -0600 | [diff] [blame] | 549 | if (seat->keyboard_device_count == 0) |
Jonas Ådahl | e0de3c2 | 2014-03-12 22:08:42 +0100 | [diff] [blame] | 550 | return; |
| 551 | |
Jonas Ådahl | e0de3c2 | 2014-03-12 22:08:42 +0100 | [diff] [blame] | 552 | wl_array_init(&keys); |
Jonas Ådahl | e0de3c2 | 2014-03-12 22:08:42 +0100 | [diff] [blame] | 553 | notify_keyboard_focus_in(seat, &keys, STATE_UPDATE_AUTOMATIC); |
Jonas Ådahl | e0de3c2 | 2014-03-12 22:08:42 +0100 | [diff] [blame] | 554 | wl_array_release(&keys); |
| 555 | } |