Port evdev code to be used as a shared library
[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_seat_capability {
32         LIBINPUT_SEAT_CAP_KEYBOARD = 0,
33         LIBINPUT_SEAT_CAP_POINTER = 1,
34         LIBINPUT_SEAT_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 struct libinput_fd_handle;
67
68 typedef void (*libinput_fd_callback)(int fd, void *data);
69
70 struct libinput_device_interface {
71         /* */
72         void (*register_capability)(enum libinput_seat_capability capability,
73                                     void *data);
74         void (*unregister_capability)(enum libinput_seat_capability capability,
75                                       void *data);
76
77         /* */
78         void (*get_current_screen_dimensions)(int *width,
79                                               int *height,
80                                               void *data);
81
82         /* */
83         struct libinput_fd_handle * (*add_fd)(int fd,
84                                               libinput_fd_callback callback,
85                                               void *data);
86         void (*remove_fd)(struct libinput_fd_handle *fd_container,
87                           void *data);
88
89         /* */
90         void (*device_lost)(void *data);
91 };
92
93 struct libinput_keyboard_listener {
94         void (*notify_key)(uint32_t time,
95                            uint32_t key,
96                            enum libinput_keyboard_key_state state,
97                            void *data);
98 };
99
100 struct libinput_pointer_listener {
101         void (*notify_motion)(uint32_t time,
102                               li_fixed_t dx,
103                               li_fixed_t dy,
104                               void *data);
105         void (*notify_motion_absolute)(uint32_t time,
106                                        li_fixed_t x,
107                                        li_fixed_t y,
108                                        void *data);
109         void (*notify_button)(uint32_t time,
110                               int32_t button,
111                               enum libinput_pointer_button_state state,
112                               void *data);
113         void (*notify_axis)(uint32_t time,
114                             enum libinput_pointer_axis axis,
115                             li_fixed_t value,
116                             void *data);
117 };
118
119 struct libinput_touch_listener {
120         void (*notify_touch)(uint32_t time,
121                              int32_t slot,
122                              li_fixed_t x,
123                              li_fixed_t y,
124                              enum libinput_touch_type touch_type,
125                              void *data);
126 };
127
128 struct libinput_seat;
129 struct libinput_device;
130
131 struct libinput_device *
132 libinput_device_create_evdev(const char *devnode,
133                              int fd,
134                              const struct libinput_device_interface *interface,
135                              void *user_data);
136
137 void
138 libinput_device_set_keyboard_listener(
139         struct libinput_device *device,
140         const struct libinput_keyboard_listener *listener,
141         void *data);
142
143 void
144 libinput_device_set_pointer_listener(
145         struct libinput_device *device,
146         const struct libinput_pointer_listener *listener,
147         void *data);
148
149 void
150 libinput_device_set_touch_listener(
151         struct libinput_device *device,
152         const struct libinput_touch_listener *listener,
153         void *data);
154
155 int
156 libinput_device_dispatch(struct libinput_device *device);
157
158 void
159 libinput_device_destroy(struct libinput_device *device);
160
161 void
162 libinput_device_led_update(struct libinput_device *device,
163                            enum libinput_led leds);
164
165 int
166 libinput_device_get_keys(struct libinput_device *device,
167                          char *keys, size_t size);
168
169 void
170 libinput_device_calibrate(struct libinput_device *device,
171                           float calibration[6]);
172
173 #endif /* LIBINPUT_H */