Make the slots unsigned, the kernel guarantees a base of 0
[platform/upstream/libinput.git] / src / libinput.h
1 /*
2  * Copyright © 2013 Jonas Ådahl
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
23 #ifndef LIBINPUT_H
24 #define LIBINPUT_H
25
26 #include <stdlib.h>
27 #include <stdint.h>
28 #include <libudev.h>
29
30 typedef int32_t li_fixed_t;
31
32 enum libinput_device_capability {
33         LIBINPUT_DEVICE_CAP_KEYBOARD = 0,
34         LIBINPUT_DEVICE_CAP_POINTER = 1,
35         LIBINPUT_DEVICE_CAP_TOUCH = 2,
36 };
37
38 enum libinput_keyboard_key_state {
39         LIBINPUT_KEYBOARD_KEY_STATE_RELEASED = 0,
40         LIBINPUT_KEYBOARD_KEY_STATE_PRESSED = 1,
41 };
42
43 enum libinput_led {
44         LIBINPUT_LED_NUM_LOCK = (1 << 0),
45         LIBINPUT_LED_CAPS_LOCK = (1 << 1),
46         LIBINPUT_LED_SCROLL_LOCK = (1 << 2),
47 };
48
49 enum libinput_pointer_button_state {
50         LIBINPUT_POINTER_BUTTON_STATE_RELEASED = 0,
51         LIBINPUT_POINTER_BUTTON_STATE_PRESSED = 1,
52 };
53
54 enum libinput_pointer_axis {
55         LIBINPUT_POINTER_AXIS_VERTICAL_SCROLL = 0,
56         LIBINPUT_POINTER_AXIS_HORIZONTAL_SCROLL = 1,
57 };
58
59 enum libinput_touch_type {
60         LIBINPUT_TOUCH_TYPE_DOWN = 0,
61         LIBINPUT_TOUCH_TYPE_UP = 1,
62         LIBINPUT_TOUCH_TYPE_MOTION = 2,
63         LIBINPUT_TOUCH_TYPE_FRAME = 3,
64         LIBINPUT_TOUCH_TYPE_CANCEL = 4,
65 };
66
67 enum libinput_event_type {
68         LIBINPUT_EVENT_ADDED_SEAT = 0,
69         LIBINPUT_EVENT_REMOVED_SEAT,
70         LIBINPUT_EVENT_ADDED_DEVICE,
71         LIBINPUT_EVENT_REMOVED_DEVICE,
72
73         LIBINPUT_EVENT_DEVICE_REGISTER_CAPABILITY = 200,
74         LIBINPUT_EVENT_DEVICE_UNREGISTER_CAPABILITY,
75
76         LIBINPUT_EVENT_KEYBOARD_KEY = 300,
77
78         LIBINPUT_EVENT_POINTER_MOTION = 400,
79         LIBINPUT_EVENT_POINTER_MOTION_ABSOLUTE,
80         LIBINPUT_EVENT_POINTER_BUTTON,
81         LIBINPUT_EVENT_POINTER_AXIS,
82
83         LIBINPUT_EVENT_TOUCH_TOUCH = 500,
84 };
85
86 union libinput_event_target {
87         struct libinput *libinput;
88         struct libinput_seat *seat;
89         struct libinput_device *device;
90 };
91
92 struct libinput_event {
93         enum libinput_event_type type;
94         union libinput_event_target target;
95 };
96
97 struct libinput_event_added_seat {
98         struct libinput_event base;
99         struct libinput_seat *seat;
100 };
101
102 struct libinput_event_removed_seat {
103         struct libinput_event base;
104         struct libinput_seat *seat;
105 };
106
107 struct libinput_event_added_device {
108         struct libinput_event base;
109         struct libinput_device *device;
110 };
111
112 struct libinput_event_removed_device {
113         struct libinput_event base;
114         struct libinput_device *device;
115 };
116
117 struct libinput_event_device_register_capability {
118         struct libinput_event base;
119         enum libinput_device_capability capability;
120 };
121
122 struct libinput_event_device_unregister_capability {
123         struct libinput_event base;
124         enum libinput_device_capability capability;
125 };
126
127 struct libinput_event_keyboard_key {
128         struct libinput_event base;
129         uint32_t time;
130         uint32_t key;
131         enum libinput_keyboard_key_state state;
132 };
133
134 struct libinput_event_pointer_motion {
135         struct libinput_event base;
136         uint32_t time;
137         li_fixed_t dx;
138         li_fixed_t dy;
139 };
140
141 struct libinput_event_pointer_motion_absolute {
142         struct libinput_event base;
143         uint32_t time;
144         li_fixed_t x;
145         li_fixed_t y;
146 };
147
148 struct libinput_event_pointer_button {
149         struct libinput_event base;
150         uint32_t time;
151         uint32_t button;
152         enum libinput_pointer_button_state state;
153 };
154
155 struct libinput_event_pointer_axis {
156         struct libinput_event base;
157         uint32_t time;
158         enum libinput_pointer_axis axis;
159         li_fixed_t value;
160 };
161
162 struct libinput_event_touch_touch {
163         struct libinput_event base;
164         uint32_t time;
165         uint32_t slot;
166         li_fixed_t x;
167         li_fixed_t y;
168         enum libinput_touch_type touch_type;
169 };
170
171 struct libinput_fd_handle;
172
173 typedef void (*libinput_fd_callback)(int fd, void *data);
174
175 struct libinput_interface {
176         int (*open_restricted)(const char *path, int flags, void *user_data);
177         void (*close_restricted)(int fd, void *user_data);
178
179         void (*get_current_screen_dimensions)(struct libinput_device *device,
180                                               int *width,
181                                               int *height,
182                                               void *user_data);
183 };
184
185 struct libinput;
186 struct libinput_device;
187
188 /*
189  * Base
190  */
191
192 struct libinput *
193 libinput_create_udev(const struct libinput_interface *interface,
194                      void *user_data,
195                      struct udev *udev,
196                      const char *seat_id);
197
198 int
199 libinput_get_fd(struct libinput *libinput);
200
201 int
202 libinput_dispatch(struct libinput *libinput);
203
204 struct libinput_event *
205 libinput_get_event(struct libinput *libinput);
206
207 void *
208 libinput_get_user_data(struct libinput *libinput);
209
210 int
211 libinput_resume(struct libinput *libinput);
212
213 void
214 libinput_suspend(struct libinput *libinput);
215
216 void
217 libinput_destroy(struct libinput *libinput);
218
219 /*
220  * Seat
221  */
222
223 void
224 libinput_seat_ref(struct libinput_seat *seat);
225
226 void
227 libinput_seat_unref(struct libinput_seat *seat);
228
229 void
230 libinput_seat_set_user_data(struct libinput_seat *seat, void *user_data);
231
232 void *
233 libinput_seat_get_user_data(struct libinput_seat *seat);
234
235 const char *
236 libinput_seat_get_name(struct libinput_seat *seat);
237
238 /*
239  * Device
240  */
241
242 void
243 libinput_device_ref(struct libinput_device *device);
244
245 void
246 libinput_device_unref(struct libinput_device *device);
247
248 void
249 libinput_device_set_user_data(struct libinput_device *device, void *user_data);
250
251 void *
252 libinput_device_get_user_data(struct libinput_device *device);
253
254 const char *
255 libinput_device_get_output_name(struct libinput_device *device);
256
257 struct libinput_seat *
258 libinput_device_get_seat(struct libinput_device *device);
259
260 void
261 libinput_device_led_update(struct libinput_device *device,
262                            enum libinput_led leds);
263
264 int
265 libinput_device_get_keys(struct libinput_device *device,
266                          char *keys, size_t size);
267
268 void
269 libinput_device_calibrate(struct libinput_device *device,
270                           float calibration[6]);
271
272 #endif /* LIBINPUT_H */