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