Tiago Vignatti | ce03ec3 | 2011-12-19 01:14:03 +0200 | [diff] [blame] | 1 | /* |
Pekka Paalanen | cfa1f67 | 2012-08-03 14:38:59 +0300 | [diff] [blame] | 2 | * Copyright © 2011, 2012 Intel Corporation |
Tiago Vignatti | ce03ec3 | 2011-12-19 01:14:03 +0200 | [diff] [blame] | 3 | * |
| 4 | * Permission to use, copy, modify, distribute, and sell this software and |
| 5 | * its documentation for any purpose is hereby granted without fee, provided |
| 6 | * that the above copyright notice appear in all copies and that both that |
| 7 | * copyright notice and this permission notice appear in supporting |
| 8 | * documentation, and that the name of the copyright holders not be used in |
| 9 | * advertising or publicity pertaining to distribution of the software |
| 10 | * without specific, written prior permission. The copyright holders make |
| 11 | * no representations about the suitability of this software for any |
| 12 | * purpose. It is provided "as is" without express or implied warranty. |
| 13 | * |
| 14 | * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS |
| 15 | * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND |
| 16 | * FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY |
| 17 | * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER |
| 18 | * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF |
| 19 | * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN |
| 20 | * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
| 21 | */ |
| 22 | |
Pekka Paalanen | cfa1f67 | 2012-08-03 14:38:59 +0300 | [diff] [blame] | 23 | #ifndef EVDEV_H |
| 24 | #define EVDEV_H |
| 25 | |
Daniel Stone | 8e7a8bd | 2013-08-15 01:10:24 +0100 | [diff] [blame] | 26 | #include "config.h" |
| 27 | |
Pekka Paalanen | cfa1f67 | 2012-08-03 14:38:59 +0300 | [diff] [blame] | 28 | #include <linux/input.h> |
| 29 | #include <wayland-util.h> |
Pekka Paalanen | cfa1f67 | 2012-08-03 14:38:59 +0300 | [diff] [blame] | 30 | |
| 31 | #define MAX_SLOTS 16 |
| 32 | |
| 33 | enum evdev_event_type { |
Neil Roberts | daf7d47 | 2013-09-24 12:09:03 +0100 | [diff] [blame] | 34 | EVDEV_NONE, |
Neil Roberts | be336c8 | 2013-09-24 20:05:07 +0100 | [diff] [blame] | 35 | EVDEV_ABSOLUTE_TOUCH_DOWN, |
Neil Roberts | daf7d47 | 2013-09-24 12:09:03 +0100 | [diff] [blame] | 36 | EVDEV_ABSOLUTE_MOTION, |
Neil Roberts | be336c8 | 2013-09-24 20:05:07 +0100 | [diff] [blame] | 37 | EVDEV_ABSOLUTE_TOUCH_UP, |
Neil Roberts | daf7d47 | 2013-09-24 12:09:03 +0100 | [diff] [blame] | 38 | EVDEV_ABSOLUTE_MT_DOWN, |
| 39 | EVDEV_ABSOLUTE_MT_MOTION, |
| 40 | EVDEV_ABSOLUTE_MT_UP, |
| 41 | EVDEV_RELATIVE_MOTION, |
Pekka Paalanen | cfa1f67 | 2012-08-03 14:38:59 +0300 | [diff] [blame] | 42 | }; |
| 43 | |
Jonas Ådahl | d6e1c34 | 2013-10-17 23:04:05 +0200 | [diff] [blame] | 44 | enum evdev_device_seat_capability { |
| 45 | EVDEV_SEAT_POINTER = (1 << 0), |
| 46 | EVDEV_SEAT_KEYBOARD = (1 << 1), |
| 47 | EVDEV_SEAT_TOUCH = (1 << 2) |
| 48 | }; |
| 49 | |
Pekka Paalanen | 3eb4761 | 2012-08-06 14:57:08 +0300 | [diff] [blame] | 50 | struct evdev_device { |
Pekka Paalanen | 5618d6f | 2012-08-03 14:39:00 +0300 | [diff] [blame] | 51 | struct weston_seat *seat; |
Pekka Paalanen | cfa1f67 | 2012-08-03 14:38:59 +0300 | [diff] [blame] | 52 | struct wl_list link; |
| 53 | struct wl_event_source *source; |
| 54 | struct weston_output *output; |
| 55 | struct evdev_dispatch *dispatch; |
Kristian Høgsberg | 17bccae | 2014-01-16 16:46:28 -0800 | [diff] [blame] | 56 | struct wl_listener output_destroy_listener; |
Pekka Paalanen | cfa1f67 | 2012-08-03 14:38:59 +0300 | [diff] [blame] | 57 | char *devnode; |
Pekka Paalanen | bf639ab | 2012-08-03 14:39:07 +0300 | [diff] [blame] | 58 | char *devname; |
Kristian Høgsberg | 8ca9544 | 2014-01-09 16:41:58 -0800 | [diff] [blame] | 59 | char *output_name; |
Pekka Paalanen | cfa1f67 | 2012-08-03 14:38:59 +0300 | [diff] [blame] | 60 | int fd; |
| 61 | struct { |
| 62 | int min_x, max_x, min_y, max_y; |
Kristian Høgsberg | 2fce480 | 2014-01-08 16:21:24 -0800 | [diff] [blame] | 63 | uint32_t seat_slot; |
Pekka Paalanen | cfa1f67 | 2012-08-03 14:38:59 +0300 | [diff] [blame] | 64 | int32_t x, y; |
Rob Bradford | ea23b28 | 2012-12-03 19:44:16 +0000 | [diff] [blame] | 65 | |
| 66 | int apply_calibration; |
| 67 | float calibration[6]; |
Pekka Paalanen | cfa1f67 | 2012-08-03 14:38:59 +0300 | [diff] [blame] | 68 | } abs; |
| 69 | |
| 70 | struct { |
| 71 | int slot; |
Neil Roberts | daf7d47 | 2013-09-24 12:09:03 +0100 | [diff] [blame] | 72 | struct { |
| 73 | int32_t x, y; |
Kristian Høgsberg | 2fce480 | 2014-01-08 16:21:24 -0800 | [diff] [blame] | 74 | uint32_t seat_slot; |
Neil Roberts | daf7d47 | 2013-09-24 12:09:03 +0100 | [diff] [blame] | 75 | } slots[MAX_SLOTS]; |
Pekka Paalanen | cfa1f67 | 2012-08-03 14:38:59 +0300 | [diff] [blame] | 76 | } mt; |
| 77 | struct mtdev *mtdev; |
| 78 | |
| 79 | struct { |
| 80 | wl_fixed_t dx, dy; |
| 81 | } rel; |
| 82 | |
Neil Roberts | daf7d47 | 2013-09-24 12:09:03 +0100 | [diff] [blame] | 83 | enum evdev_event_type pending_event; |
Jonas Ådahl | d6e1c34 | 2013-10-17 23:04:05 +0200 | [diff] [blame] | 84 | enum evdev_device_seat_capability seat_caps; |
Pekka Paalanen | cfa1f67 | 2012-08-03 14:38:59 +0300 | [diff] [blame] | 85 | |
| 86 | int is_mt; |
| 87 | }; |
| 88 | |
| 89 | /* copied from udev/extras/input_id/input_id.c */ |
| 90 | /* we must use this kernel-compatible implementation */ |
| 91 | #define BITS_PER_LONG (sizeof(unsigned long) * 8) |
| 92 | #define NBITS(x) ((((x)-1)/BITS_PER_LONG)+1) |
| 93 | #define OFF(x) ((x)%BITS_PER_LONG) |
| 94 | #define BIT(x) (1UL<<OFF(x)) |
| 95 | #define LONG(x) ((x)/BITS_PER_LONG) |
| 96 | #define TEST_BIT(array, bit) ((array[LONG(bit)] >> OFF(bit)) & 1) |
| 97 | /* end copied */ |
| 98 | |
Kristian Høgsberg | 2f07ef6 | 2013-02-16 14:29:24 -0500 | [diff] [blame] | 99 | #define EVDEV_UNHANDLED_DEVICE ((struct evdev_device *) 1) |
| 100 | |
Pekka Paalanen | cfa1f67 | 2012-08-03 14:38:59 +0300 | [diff] [blame] | 101 | struct evdev_dispatch; |
| 102 | |
| 103 | struct evdev_dispatch_interface { |
| 104 | /* Process an evdev input event. */ |
| 105 | void (*process)(struct evdev_dispatch *dispatch, |
Pekka Paalanen | 3eb4761 | 2012-08-06 14:57:08 +0300 | [diff] [blame] | 106 | struct evdev_device *device, |
Pekka Paalanen | cfa1f67 | 2012-08-03 14:38:59 +0300 | [diff] [blame] | 107 | struct input_event *event, |
| 108 | uint32_t time); |
| 109 | |
| 110 | /* Destroy an event dispatch handler and free all its resources. */ |
| 111 | void (*destroy)(struct evdev_dispatch *dispatch); |
| 112 | }; |
| 113 | |
| 114 | struct evdev_dispatch { |
| 115 | struct evdev_dispatch_interface *interface; |
| 116 | }; |
| 117 | |
| 118 | struct evdev_dispatch * |
Pekka Paalanen | 3eb4761 | 2012-08-06 14:57:08 +0300 | [diff] [blame] | 119 | evdev_touchpad_create(struct evdev_device *device); |
Pekka Paalanen | cfa1f67 | 2012-08-03 14:38:59 +0300 | [diff] [blame] | 120 | |
Tiago Vignatti | ce03ec3 | 2011-12-19 01:14:03 +0200 | [diff] [blame] | 121 | void |
Pekka Paalanen | 3eb4761 | 2012-08-06 14:57:08 +0300 | [diff] [blame] | 122 | evdev_led_update(struct evdev_device *device, enum weston_led leds); |
Pekka Paalanen | 88594b6 | 2012-08-03 14:39:05 +0300 | [diff] [blame] | 123 | |
Pekka Paalanen | 3eb4761 | 2012-08-06 14:57:08 +0300 | [diff] [blame] | 124 | struct evdev_device * |
| 125 | evdev_device_create(struct weston_seat *seat, const char *path, int device_fd); |
Pekka Paalanen | 88594b6 | 2012-08-03 14:39:05 +0300 | [diff] [blame] | 126 | |
| 127 | void |
Kristian Høgsberg | 17bccae | 2014-01-16 16:46:28 -0800 | [diff] [blame] | 128 | evdev_device_set_output(struct evdev_device *device, |
| 129 | struct weston_output *output); |
| 130 | void |
Pekka Paalanen | 3eb4761 | 2012-08-06 14:57:08 +0300 | [diff] [blame] | 131 | evdev_device_destroy(struct evdev_device *device); |
Pekka Paalanen | 88594b6 | 2012-08-03 14:39:05 +0300 | [diff] [blame] | 132 | |
| 133 | void |
| 134 | evdev_notify_keyboard_focus(struct weston_seat *seat, |
| 135 | struct wl_list *evdev_devices); |
| 136 | |
Pekka Paalanen | cfa1f67 | 2012-08-03 14:38:59 +0300 | [diff] [blame] | 137 | #endif /* EVDEV_H */ |