evdev: Drop EVDEV_MOTION_REL flag
[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_TOUCH = (1 << 3),
51 };
52
53 enum evdev_device_seat_capability {
54         EVDEV_DEVICE_POINTER = (1 << 0),
55         EVDEV_DEVICE_KEYBOARD = (1 << 1),
56         EVDEV_DEVICE_TOUCH = (1 << 2)
57 };
58
59 struct evdev_device {
60         struct libinput_device base;
61
62         struct libinput_source *source;
63
64         struct evdev_dispatch *dispatch;
65         char *output_name;
66         char *devnode;
67         char *sysname;
68         char *devname;
69         int fd;
70         struct {
71                 int min_x, max_x, min_y, max_y;
72                 int32_t x, y;
73
74                 int apply_calibration;
75                 float calibration[6];
76         } abs;
77
78         struct {
79                 int slot;
80                 struct {
81                         int32_t x, y;
82                 } slots[MAX_SLOTS];
83         } mt;
84         struct mtdev *mtdev;
85
86         struct {
87                 li_fixed_t dx, dy;
88         } rel;
89
90         enum evdev_event_type pending_event;
91         enum evdev_device_capability caps;
92         enum evdev_device_seat_capability seat_caps;
93
94         int is_mt;
95 };
96
97 /* copied from udev/extras/input_id/input_id.c */
98 /* we must use this kernel-compatible implementation */
99 #define BITS_PER_LONG (sizeof(unsigned long) * 8)
100 #define NBITS(x) ((((x)-1)/BITS_PER_LONG)+1)
101 #define OFF(x)  ((x)%BITS_PER_LONG)
102 #define BIT(x)  (1UL<<OFF(x))
103 #define LONG(x) ((x)/BITS_PER_LONG)
104 #define TEST_BIT(array, bit)    ((array[LONG(bit)] >> OFF(bit)) & 1)
105 /* end copied */
106
107 #define EVDEV_UNHANDLED_DEVICE ((struct evdev_device *) 1)
108
109 struct evdev_dispatch;
110
111 struct evdev_dispatch_interface {
112         /* Process an evdev input event. */
113         void (*process)(struct evdev_dispatch *dispatch,
114                         struct evdev_device *device,
115                         struct input_event *event,
116                         uint32_t time);
117
118         /* Destroy an event dispatch handler and free all its resources. */
119         void (*destroy)(struct evdev_dispatch *dispatch);
120 };
121
122 struct evdev_dispatch {
123         struct evdev_dispatch_interface *interface;
124 };
125
126 struct evdev_device *
127 evdev_device_create(struct libinput_seat *seat,
128                     const char *devnode,
129                     const char *sysname,
130                     int fd);
131
132 struct evdev_dispatch *
133 evdev_touchpad_create(struct evdev_device *device);
134
135 void
136 evdev_device_proces_event(struct libinput_event *event);
137
138 void
139 evdev_device_led_update(struct evdev_device *device, enum libinput_led leds);
140
141 int
142 evdev_device_get_keys(struct evdev_device *device, char *keys, size_t size);
143
144 const char *
145 evdev_device_get_output(struct evdev_device *device);
146
147 const char *
148 evdev_device_get_sysname(struct evdev_device *device);
149
150 void
151 evdev_device_calibrate(struct evdev_device *device, float calibration[6]);
152
153 int
154 evdev_device_has_capability(struct evdev_device *device,
155                             enum libinput_device_capability capability);
156
157 void
158 evdev_device_remove(struct evdev_device *device);
159
160 void
161 evdev_device_destroy(struct evdev_device *device);
162
163 #endif /* EVDEV_H */