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 | 9bc1a4e | 2012-03-30 15:20:23 +0300 | [diff] [blame] | 28 | #include <libudev.h> |
| 29 | |
Pekka Paalanen | cfa1f67 | 2012-08-03 14:38:59 +0300 | [diff] [blame^] | 30 | struct evdev_seat { |
| 31 | struct weston_seat base; |
| 32 | struct wl_list devices_list; |
| 33 | struct udev_monitor *udev_monitor; |
| 34 | struct wl_event_source *udev_monitor_source; |
| 35 | char *seat_id; |
| 36 | }; |
| 37 | |
| 38 | #define MAX_SLOTS 16 |
| 39 | |
| 40 | enum evdev_event_type { |
| 41 | EVDEV_ABSOLUTE_MOTION = (1 << 0), |
| 42 | EVDEV_ABSOLUTE_MT_DOWN = (1 << 1), |
| 43 | EVDEV_ABSOLUTE_MT_MOTION = (1 << 2), |
| 44 | EVDEV_ABSOLUTE_MT_UP = (1 << 3), |
| 45 | EVDEV_RELATIVE_MOTION = (1 << 4), |
| 46 | }; |
| 47 | |
| 48 | enum evdev_device_capability { |
| 49 | EVDEV_KEYBOARD = (1 << 0), |
| 50 | EVDEV_BUTTON = (1 << 1), |
| 51 | EVDEV_MOTION_ABS = (1 << 2), |
| 52 | EVDEV_MOTION_REL = (1 << 3), |
| 53 | EVDEV_TOUCH = (1 << 4), |
| 54 | }; |
| 55 | |
| 56 | struct evdev_input_device { |
| 57 | struct evdev_seat *master; |
| 58 | struct wl_list link; |
| 59 | struct wl_event_source *source; |
| 60 | struct weston_output *output; |
| 61 | struct evdev_dispatch *dispatch; |
| 62 | char *devnode; |
| 63 | int fd; |
| 64 | struct { |
| 65 | int min_x, max_x, min_y, max_y; |
| 66 | int32_t x, y; |
| 67 | } abs; |
| 68 | |
| 69 | struct { |
| 70 | int slot; |
| 71 | int32_t x[MAX_SLOTS]; |
| 72 | int32_t y[MAX_SLOTS]; |
| 73 | } mt; |
| 74 | struct mtdev *mtdev; |
| 75 | |
| 76 | struct { |
| 77 | wl_fixed_t dx, dy; |
| 78 | } rel; |
| 79 | |
| 80 | enum evdev_event_type pending_events; |
| 81 | enum evdev_device_capability caps; |
| 82 | |
| 83 | int is_mt; |
| 84 | }; |
| 85 | |
| 86 | /* copied from udev/extras/input_id/input_id.c */ |
| 87 | /* we must use this kernel-compatible implementation */ |
| 88 | #define BITS_PER_LONG (sizeof(unsigned long) * 8) |
| 89 | #define NBITS(x) ((((x)-1)/BITS_PER_LONG)+1) |
| 90 | #define OFF(x) ((x)%BITS_PER_LONG) |
| 91 | #define BIT(x) (1UL<<OFF(x)) |
| 92 | #define LONG(x) ((x)/BITS_PER_LONG) |
| 93 | #define TEST_BIT(array, bit) ((array[LONG(bit)] >> OFF(bit)) & 1) |
| 94 | /* end copied */ |
| 95 | |
| 96 | struct evdev_dispatch; |
| 97 | |
| 98 | struct evdev_dispatch_interface { |
| 99 | /* Process an evdev input event. */ |
| 100 | void (*process)(struct evdev_dispatch *dispatch, |
| 101 | struct evdev_input_device *device, |
| 102 | struct input_event *event, |
| 103 | uint32_t time); |
| 104 | |
| 105 | /* Destroy an event dispatch handler and free all its resources. */ |
| 106 | void (*destroy)(struct evdev_dispatch *dispatch); |
| 107 | }; |
| 108 | |
| 109 | struct evdev_dispatch { |
| 110 | struct evdev_dispatch_interface *interface; |
| 111 | }; |
| 112 | |
| 113 | struct evdev_dispatch * |
| 114 | evdev_touchpad_create(struct evdev_input_device *device); |
| 115 | |
Tiago Vignatti | ce03ec3 | 2011-12-19 01:14:03 +0200 | [diff] [blame] | 116 | void |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 117 | evdev_add_devices(struct udev *udev, struct weston_seat *seat_base); |
Tiago Vignatti | ce03ec3 | 2011-12-19 01:14:03 +0200 | [diff] [blame] | 118 | |
| 119 | void |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 120 | evdev_remove_devices(struct weston_seat *seat_base); |
Tiago Vignatti | ce03ec3 | 2011-12-19 01:14:03 +0200 | [diff] [blame] | 121 | |
| 122 | void |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 123 | evdev_input_create(struct weston_compositor *c, struct udev *udev, |
Tiago Vignatti | ce03ec3 | 2011-12-19 01:14:03 +0200 | [diff] [blame] | 124 | const char *seat); |
| 125 | |
| 126 | void |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 127 | evdev_input_destroy(struct weston_seat *seat); |
Benjamin Franzke | 78d3afe | 2012-04-09 18:14:58 +0200 | [diff] [blame] | 128 | |
| 129 | int |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 130 | evdev_enable_udev_monitor(struct udev *udev, struct weston_seat *seat_base); |
Benjamin Franzke | 78d3afe | 2012-04-09 18:14:58 +0200 | [diff] [blame] | 131 | |
| 132 | void |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 133 | evdev_disable_udev_monitor(struct weston_seat *seat_base); |
Pekka Paalanen | cfa1f67 | 2012-08-03 14:38:59 +0300 | [diff] [blame^] | 134 | |
| 135 | #endif /* EVDEV_H */ |