Change API from using listeners to using an event queue
[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
68         LIBINPUT_EVENT_KEYBOARD_KEY = 300,
69
70         LIBINPUT_EVENT_POINTER_MOTION = 400,
71         LIBINPUT_EVENT_POINTER_MOTION_ABSOLUTE,
72         LIBINPUT_EVENT_POINTER_BUTTON,
73         LIBINPUT_EVENT_POINTER_AXIS,
74
75         LIBINPUT_EVENT_TOUCH_TOUCH = 500,
76 };
77
78 struct libinput_event {
79         enum libinput_event_type type;
80 };
81
82 struct libinput_event_keyboard_key {
83         struct libinput_event base;
84         uint32_t time;
85         uint32_t key;
86         enum libinput_keyboard_key_state state;
87 };
88
89 struct libinput_event_pointer_motion {
90         struct libinput_event base;
91         uint32_t time;
92         li_fixed_t dx;
93         li_fixed_t dy;
94 };
95
96 struct libinput_event_pointer_motion_absolute {
97         struct libinput_event base;
98         uint32_t time;
99         li_fixed_t x;
100         li_fixed_t y;
101 };
102
103 struct libinput_event_pointer_button {
104         struct libinput_event base;
105         uint32_t time;
106         int32_t button;
107         enum libinput_pointer_button_state state;
108 };
109
110 struct libinput_event_pointer_axis {
111         struct libinput_event base;
112         uint32_t time;
113         enum libinput_pointer_axis axis;
114         li_fixed_t value;
115 };
116
117 struct libinput_event_touch_touch {
118         struct libinput_event base;
119         uint32_t time;
120         int32_t slot;
121         li_fixed_t x;
122         li_fixed_t y;
123         enum libinput_touch_type touch_type;
124 };
125
126 struct libinput_fd_handle;
127
128 typedef void (*libinput_fd_callback)(int fd, void *data);
129
130 struct libinput_device_interface {
131         /* */
132         void (*register_capability)(enum libinput_device_capability capability,
133                                     void *data);
134         void (*unregister_capability)(enum libinput_device_capability capability,
135                                       void *data);
136
137         /* */
138         void (*get_current_screen_dimensions)(int *width,
139                                               int *height,
140                                               void *data);
141
142         /* */
143         struct libinput_fd_handle * (*add_fd)(int fd,
144                                               libinput_fd_callback callback,
145                                               void *data);
146         void (*remove_fd)(struct libinput_fd_handle *fd_container,
147                           void *data);
148
149         /* */
150         void (*device_lost)(void *data);
151 };
152
153 struct libinput_seat;
154 struct libinput_device;
155
156 struct libinput_device *
157 libinput_device_create_evdev(const char *devnode,
158                              int fd,
159                              const struct libinput_device_interface *interface,
160                              void *user_data);
161
162 int
163 libinput_device_dispatch(struct libinput_device *device);
164
165 struct libinput_event *
166 libinput_device_get_event(struct libinput_device *device);
167
168 void
169 libinput_device_destroy(struct libinput_device *device);
170
171 void
172 libinput_device_led_update(struct libinput_device *device,
173                            enum libinput_led leds);
174
175 int
176 libinput_device_get_keys(struct libinput_device *device,
177                          char *keys, size_t size);
178
179 void
180 libinput_device_calibrate(struct libinput_device *device,
181                           float calibration[6]);
182
183 #endif /* LIBINPUT_H */