2 * Copyright © 2011, 2012 Intel Corporation
3 * Copyright © 2013 Jonas Ådahl
5 * Permission to use, copy, modify, distribute, and sell this software and
6 * its documentation for any purpose is hereby granted without fee, provided
7 * that the above copyright notice appear in all copies and that both that
8 * copyright notice and this permission notice appear in supporting
9 * documentation, and that the name of the copyright holders not be used in
10 * advertising or publicity pertaining to distribution of the software
11 * without specific, written prior permission. The copyright holders make
12 * no representations about the suitability of this software for any
13 * purpose. It is provided "as is" without express or implied warranty.
15 * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
16 * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
17 * FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY
18 * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
19 * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
20 * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
21 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
29 #include <linux/input.h>
31 #include "libinput-private.h"
36 return calloc(1, size);
41 enum evdev_event_type {
43 EVDEV_ABSOLUTE_TOUCH_DOWN,
44 EVDEV_ABSOLUTE_MOTION,
45 EVDEV_ABSOLUTE_TOUCH_UP,
46 EVDEV_ABSOLUTE_MT_DOWN,
47 EVDEV_ABSOLUTE_MT_MOTION,
49 EVDEV_RELATIVE_MOTION,
52 enum evdev_device_capability {
53 EVDEV_KEYBOARD = (1 << 0),
54 EVDEV_BUTTON = (1 << 1),
55 EVDEV_MOTION_ABS = (1 << 2),
56 EVDEV_MOTION_REL = (1 << 3),
57 EVDEV_TOUCH = (1 << 4),
60 enum evdev_device_seat_capability {
61 EVDEV_DEVICE_POINTER = (1 << 0),
62 EVDEV_DEVICE_KEYBOARD = (1 << 1),
63 EVDEV_DEVICE_TOUCH = (1 << 2)
67 struct libinput_device base;
69 struct libinput_source *source;
71 struct evdev_dispatch *dispatch;
77 int min_x, max_x, min_y, max_y;
80 int apply_calibration;
96 enum evdev_event_type pending_event;
97 enum evdev_device_capability caps;
98 enum evdev_device_seat_capability seat_caps;
103 /* copied from udev/extras/input_id/input_id.c */
104 /* we must use this kernel-compatible implementation */
105 #define BITS_PER_LONG (sizeof(unsigned long) * 8)
106 #define NBITS(x) ((((x)-1)/BITS_PER_LONG)+1)
107 #define OFF(x) ((x)%BITS_PER_LONG)
108 #define BIT(x) (1UL<<OFF(x))
109 #define LONG(x) ((x)/BITS_PER_LONG)
110 #define TEST_BIT(array, bit) ((array[LONG(bit)] >> OFF(bit)) & 1)
113 #define EVDEV_UNHANDLED_DEVICE ((struct evdev_device *) 1)
115 struct evdev_dispatch;
117 struct evdev_dispatch_interface {
118 /* Process an evdev input event. */
119 void (*process)(struct evdev_dispatch *dispatch,
120 struct evdev_device *device,
121 struct input_event *event,
124 /* Destroy an event dispatch handler and free all its resources. */
125 void (*destroy)(struct evdev_dispatch *dispatch);
128 struct evdev_dispatch {
129 struct evdev_dispatch_interface *interface;
132 struct evdev_device *
133 evdev_device_create(struct libinput_seat *seat,
137 struct evdev_dispatch *
138 evdev_touchpad_create(struct evdev_device *device);
141 evdev_device_proces_event(struct libinput_event *event);
144 evdev_device_led_update(struct evdev_device *device, enum libinput_led leds);
147 evdev_device_get_keys(struct evdev_device *device, char *keys, size_t size);
150 evdev_device_get_output(struct evdev_device *device);
153 evdev_device_calibrate(struct evdev_device *device, float calibration[6]);
156 evdev_device_has_capability(struct evdev_device *device,
157 enum libinput_device_capability capability);
160 evdev_device_remove(struct evdev_device *device);
163 evdev_device_destroy(struct evdev_device *device);