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 | |
| 26 | #include <linux/input.h> |
| 27 | #include <wayland-util.h> |
Pekka Paalanen | cfa1f67 | 2012-08-03 14:38:59 +0300 | [diff] [blame] | 28 | |
| 29 | #define MAX_SLOTS 16 |
| 30 | |
| 31 | enum evdev_event_type { |
| 32 | EVDEV_ABSOLUTE_MOTION = (1 << 0), |
| 33 | EVDEV_ABSOLUTE_MT_DOWN = (1 << 1), |
| 34 | EVDEV_ABSOLUTE_MT_MOTION = (1 << 2), |
| 35 | EVDEV_ABSOLUTE_MT_UP = (1 << 3), |
| 36 | EVDEV_RELATIVE_MOTION = (1 << 4), |
| 37 | }; |
| 38 | |
| 39 | enum evdev_device_capability { |
| 40 | EVDEV_KEYBOARD = (1 << 0), |
| 41 | EVDEV_BUTTON = (1 << 1), |
| 42 | EVDEV_MOTION_ABS = (1 << 2), |
| 43 | EVDEV_MOTION_REL = (1 << 3), |
| 44 | EVDEV_TOUCH = (1 << 4), |
| 45 | }; |
| 46 | |
Pekka Paalanen | 3eb4761 | 2012-08-06 14:57:08 +0300 | [diff] [blame^] | 47 | struct evdev_device { |
Pekka Paalanen | 5618d6f | 2012-08-03 14:39:00 +0300 | [diff] [blame] | 48 | struct weston_seat *seat; |
Pekka Paalanen | cfa1f67 | 2012-08-03 14:38:59 +0300 | [diff] [blame] | 49 | struct wl_list link; |
| 50 | struct wl_event_source *source; |
| 51 | struct weston_output *output; |
| 52 | struct evdev_dispatch *dispatch; |
| 53 | char *devnode; |
Pekka Paalanen | bf639ab | 2012-08-03 14:39:07 +0300 | [diff] [blame] | 54 | char *devname; |
Pekka Paalanen | cfa1f67 | 2012-08-03 14:38:59 +0300 | [diff] [blame] | 55 | int fd; |
| 56 | struct { |
| 57 | int min_x, max_x, min_y, max_y; |
| 58 | int32_t x, y; |
| 59 | } abs; |
| 60 | |
| 61 | struct { |
| 62 | int slot; |
| 63 | int32_t x[MAX_SLOTS]; |
| 64 | int32_t y[MAX_SLOTS]; |
| 65 | } mt; |
| 66 | struct mtdev *mtdev; |
| 67 | |
| 68 | struct { |
| 69 | wl_fixed_t dx, dy; |
| 70 | } rel; |
| 71 | |
| 72 | enum evdev_event_type pending_events; |
| 73 | enum evdev_device_capability caps; |
| 74 | |
| 75 | int is_mt; |
| 76 | }; |
| 77 | |
| 78 | /* copied from udev/extras/input_id/input_id.c */ |
| 79 | /* we must use this kernel-compatible implementation */ |
| 80 | #define BITS_PER_LONG (sizeof(unsigned long) * 8) |
| 81 | #define NBITS(x) ((((x)-1)/BITS_PER_LONG)+1) |
| 82 | #define OFF(x) ((x)%BITS_PER_LONG) |
| 83 | #define BIT(x) (1UL<<OFF(x)) |
| 84 | #define LONG(x) ((x)/BITS_PER_LONG) |
| 85 | #define TEST_BIT(array, bit) ((array[LONG(bit)] >> OFF(bit)) & 1) |
| 86 | /* end copied */ |
| 87 | |
| 88 | struct evdev_dispatch; |
| 89 | |
| 90 | struct evdev_dispatch_interface { |
| 91 | /* Process an evdev input event. */ |
| 92 | void (*process)(struct evdev_dispatch *dispatch, |
Pekka Paalanen | 3eb4761 | 2012-08-06 14:57:08 +0300 | [diff] [blame^] | 93 | struct evdev_device *device, |
Pekka Paalanen | cfa1f67 | 2012-08-03 14:38:59 +0300 | [diff] [blame] | 94 | struct input_event *event, |
| 95 | uint32_t time); |
| 96 | |
| 97 | /* Destroy an event dispatch handler and free all its resources. */ |
| 98 | void (*destroy)(struct evdev_dispatch *dispatch); |
| 99 | }; |
| 100 | |
| 101 | struct evdev_dispatch { |
| 102 | struct evdev_dispatch_interface *interface; |
| 103 | }; |
| 104 | |
| 105 | struct evdev_dispatch * |
Pekka Paalanen | 3eb4761 | 2012-08-06 14:57:08 +0300 | [diff] [blame^] | 106 | evdev_touchpad_create(struct evdev_device *device); |
Pekka Paalanen | cfa1f67 | 2012-08-03 14:38:59 +0300 | [diff] [blame] | 107 | |
Tiago Vignatti | ce03ec3 | 2011-12-19 01:14:03 +0200 | [diff] [blame] | 108 | void |
Pekka Paalanen | 3eb4761 | 2012-08-06 14:57:08 +0300 | [diff] [blame^] | 109 | evdev_led_update(struct evdev_device *device, enum weston_led leds); |
Pekka Paalanen | 88594b6 | 2012-08-03 14:39:05 +0300 | [diff] [blame] | 110 | |
Pekka Paalanen | 3eb4761 | 2012-08-06 14:57:08 +0300 | [diff] [blame^] | 111 | struct evdev_device * |
| 112 | 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] | 113 | |
| 114 | void |
Pekka Paalanen | 3eb4761 | 2012-08-06 14:57:08 +0300 | [diff] [blame^] | 115 | evdev_device_destroy(struct evdev_device *device); |
Pekka Paalanen | 88594b6 | 2012-08-03 14:39:05 +0300 | [diff] [blame] | 116 | |
| 117 | void |
| 118 | evdev_notify_keyboard_focus(struct weston_seat *seat, |
| 119 | struct wl_list *evdev_devices); |
| 120 | |
Pekka Paalanen | cfa1f67 | 2012-08-03 14:38:59 +0300 | [diff] [blame] | 121 | #endif /* EVDEV_H */ |