Move zalloc() up to libinput-util.h
[platform/upstream/libinput.git] / src / evdev.h
1 /*
2  * Copyright © 2011, 2012 Intel Corporation
3  * Copyright © 2013 Jonas Ådahl
4  *
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.
14  *
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.
22  */
23
24 #ifndef EVDEV_H
25 #define EVDEV_H
26
27 #include "config.h"
28
29 #include <linux/input.h>
30
31 #include "libinput-private.h"
32
33 #define MAX_SLOTS 16
34
35 enum evdev_event_type {
36         EVDEV_NONE,
37         EVDEV_ABSOLUTE_TOUCH_DOWN,
38         EVDEV_ABSOLUTE_MOTION,
39         EVDEV_ABSOLUTE_TOUCH_UP,
40         EVDEV_ABSOLUTE_MT_DOWN,
41         EVDEV_ABSOLUTE_MT_MOTION,
42         EVDEV_ABSOLUTE_MT_UP,
43         EVDEV_RELATIVE_MOTION,
44 };
45
46 enum evdev_device_capability {
47         EVDEV_KEYBOARD = (1 << 0),
48         EVDEV_BUTTON = (1 << 1),
49         EVDEV_MOTION_ABS = (1 << 2),
50         EVDEV_MOTION_REL = (1 << 3),
51         EVDEV_TOUCH = (1 << 4),
52 };
53
54 enum evdev_device_seat_capability {
55         EVDEV_DEVICE_POINTER = (1 << 0),
56         EVDEV_DEVICE_KEYBOARD = (1 << 1),
57         EVDEV_DEVICE_TOUCH = (1 << 2)
58 };
59
60 struct evdev_device {
61         struct libinput_device base;
62
63         struct libinput_source *source;
64
65         struct evdev_dispatch *dispatch;
66         char *output_name;
67         char *devnode;
68         char *sysname;
69         char *devname;
70         int fd;
71         struct {
72                 int min_x, max_x, min_y, max_y;
73                 int32_t x, y;
74
75                 int apply_calibration;
76                 float calibration[6];
77         } abs;
78
79         struct {
80                 int slot;
81                 struct {
82                         int32_t x, y;
83                 } slots[MAX_SLOTS];
84         } mt;
85         struct mtdev *mtdev;
86
87         struct {
88                 li_fixed_t dx, dy;
89         } rel;
90
91         enum evdev_event_type pending_event;
92         enum evdev_device_capability caps;
93         enum evdev_device_seat_capability seat_caps;
94
95         int is_mt;
96 };
97
98 /* copied from udev/extras/input_id/input_id.c */
99 /* we must use this kernel-compatible implementation */
100 #define BITS_PER_LONG (sizeof(unsigned long) * 8)
101 #define NBITS(x) ((((x)-1)/BITS_PER_LONG)+1)
102 #define OFF(x)  ((x)%BITS_PER_LONG)
103 #define BIT(x)  (1UL<<OFF(x))
104 #define LONG(x) ((x)/BITS_PER_LONG)
105 #define TEST_BIT(array, bit)    ((array[LONG(bit)] >> OFF(bit)) & 1)
106 /* end copied */
107
108 #define EVDEV_UNHANDLED_DEVICE ((struct evdev_device *) 1)
109
110 struct evdev_dispatch;
111
112 struct evdev_dispatch_interface {
113         /* Process an evdev input event. */
114         void (*process)(struct evdev_dispatch *dispatch,
115                         struct evdev_device *device,
116                         struct input_event *event,
117                         uint32_t time);
118
119         /* Destroy an event dispatch handler and free all its resources. */
120         void (*destroy)(struct evdev_dispatch *dispatch);
121 };
122
123 struct evdev_dispatch {
124         struct evdev_dispatch_interface *interface;
125 };
126
127 struct evdev_device *
128 evdev_device_create(struct libinput_seat *seat,
129                     const char *devnode,
130                     const char *sysname,
131                     int fd);
132
133 struct evdev_dispatch *
134 evdev_touchpad_create(struct evdev_device *device);
135
136 void
137 evdev_device_proces_event(struct libinput_event *event);
138
139 void
140 evdev_device_led_update(struct evdev_device *device, enum libinput_led leds);
141
142 int
143 evdev_device_get_keys(struct evdev_device *device, char *keys, size_t size);
144
145 const char *
146 evdev_device_get_output(struct evdev_device *device);
147
148 const char *
149 evdev_device_get_sysname(struct evdev_device *device);
150
151 void
152 evdev_device_calibrate(struct evdev_device *device, float calibration[6]);
153
154 int
155 evdev_device_has_capability(struct evdev_device *device,
156                             enum libinput_device_capability capability);
157
158 void
159 evdev_device_remove(struct evdev_device *device);
160
161 void
162 evdev_device_destroy(struct evdev_device *device);
163
164 #endif /* EVDEV_H */