Use events instead of callbacks for capability registration
[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
29 typedef int32_t li_fixed_t;
30
31 enum libinput_device_capability {
32         LIBINPUT_DEVICE_CAP_KEYBOARD = 0,
33         LIBINPUT_DEVICE_CAP_POINTER = 1,
34         LIBINPUT_DEVICE_CAP_TOUCH = 2,
35 };
36
37 enum libinput_keyboard_key_state {
38         LIBINPUT_KEYBOARD_KEY_STATE_RELEASED = 0,
39         LIBINPUT_KEYBOARD_KEY_STATE_PRESSED = 1,
40 };
41
42 enum libinput_led {
43         LIBINPUT_LED_NUM_LOCK = (1 << 0),
44         LIBINPUT_LED_CAPS_LOCK = (1 << 1),
45         LIBINPUT_LED_SCROLL_LOCK = (1 << 2),
46 };
47
48 enum libinput_pointer_button_state {
49         LIBINPUT_POINTER_BUTTON_STATE_RELEASED = 0,
50         LIBINPUT_POINTER_BUTTON_STATE_PRESSED = 1,
51 };
52
53 enum libinput_pointer_axis {
54         LIBINPUT_POINTER_AXIS_VERTICAL_SCROLL = 0,
55         LIBINPUT_POINTER_AXIS_HORIZONTAL_SCROLL = 1,
56 };
57
58 enum libinput_touch_type {
59         LIBINPUT_TOUCH_TYPE_DOWN = 0,
60         LIBINPUT_TOUCH_TYPE_UP = 1,
61         LIBINPUT_TOUCH_TYPE_MOTION = 2,
62         LIBINPUT_TOUCH_TYPE_FRAME = 3,
63         LIBINPUT_TOUCH_TYPE_CANCEL = 4,
64 };
65
66 enum libinput_event_type {
67         LIBINPUT_EVENT_DEVICE_REGISTER_CAPABILITY = 200,
68         LIBINPUT_EVENT_DEVICE_UNREGISTER_CAPABILITY,
69
70         LIBINPUT_EVENT_KEYBOARD_KEY = 300,
71
72         LIBINPUT_EVENT_POINTER_MOTION = 400,
73         LIBINPUT_EVENT_POINTER_MOTION_ABSOLUTE,
74         LIBINPUT_EVENT_POINTER_BUTTON,
75         LIBINPUT_EVENT_POINTER_AXIS,
76
77         LIBINPUT_EVENT_TOUCH_TOUCH = 500,
78 };
79
80 struct libinput_event {
81         enum libinput_event_type type;
82         struct libinput_device *device;
83 };
84
85 struct libinput_event_device_register_capability {
86         struct libinput_event base;
87         enum libinput_device_capability capability;
88 };
89
90 struct libinput_event_device_unregister_capability {
91         struct libinput_event base;
92         enum libinput_device_capability capability;
93 };
94
95 struct libinput_event_keyboard_key {
96         struct libinput_event base;
97         uint32_t time;
98         uint32_t key;
99         enum libinput_keyboard_key_state state;
100 };
101
102 struct libinput_event_pointer_motion {
103         struct libinput_event base;
104         uint32_t time;
105         li_fixed_t dx;
106         li_fixed_t dy;
107 };
108
109 struct libinput_event_pointer_motion_absolute {
110         struct libinput_event base;
111         uint32_t time;
112         li_fixed_t x;
113         li_fixed_t y;
114 };
115
116 struct libinput_event_pointer_button {
117         struct libinput_event base;
118         uint32_t time;
119         int32_t button;
120         enum libinput_pointer_button_state state;
121 };
122
123 struct libinput_event_pointer_axis {
124         struct libinput_event base;
125         uint32_t time;
126         enum libinput_pointer_axis axis;
127         li_fixed_t value;
128 };
129
130 struct libinput_event_touch_touch {
131         struct libinput_event base;
132         uint32_t time;
133         int32_t slot;
134         li_fixed_t x;
135         li_fixed_t y;
136         enum libinput_touch_type touch_type;
137 };
138
139 struct libinput_fd_handle;
140
141 typedef void (*libinput_fd_callback)(int fd, void *data);
142
143 struct libinput_device_interface {
144         void (*get_current_screen_dimensions)(int *width,
145                                               int *height,
146                                               void *data);
147 };
148
149 struct libinput;
150 struct libinput_device;
151
152 struct libinput *
153 libinput_create(void);
154
155 int
156 libinput_get_fd(struct libinput *libinput);
157
158 int
159 libinput_dispatch(struct libinput *libinput);
160
161 struct libinput_event *
162 libinput_get_event(struct libinput *libinput);
163
164 void
165 libinput_destroy(struct libinput *libinput);
166
167 struct libinput_device *
168 libinput_device_create_evdev(struct libinput *libinput,
169                              const char *devnode,
170                              int fd,
171                              const struct libinput_device_interface *interface,
172                              void *user_data);
173
174 void
175 libinput_device_terminate(struct libinput_device *device);
176
177 void
178 libinput_device_destroy(struct libinput_device *device);
179
180 void *
181 libinput_device_get_user_data(struct libinput_device *device);
182
183 void
184 libinput_device_led_update(struct libinput_device *device,
185                            enum libinput_led leds);
186
187 int
188 libinput_device_get_keys(struct libinput_device *device,
189                          char *keys, size_t size);
190
191 void
192 libinput_device_calibrate(struct libinput_device *device,
193                           float calibration[6]);
194
195 #endif /* LIBINPUT_H */