Fix documentation for libinput_log_set_handler
[platform/upstream/libinput.git] / src / libinput-private.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_PRIVATE_H
24 #define LIBINPUT_PRIVATE_H
25
26 #include <errno.h>
27
28 #include "linux/input.h"
29
30 #include "libinput.h"
31 #include "libinput-util.h"
32
33 struct libinput_source;
34
35 struct libinput_interface_backend {
36         int (*resume)(struct libinput *libinput);
37         void (*suspend)(struct libinput *libinput);
38         void (*destroy)(struct libinput *libinput);
39 };
40
41 struct libinput {
42         int epoll_fd;
43         struct list source_destroy_list;
44
45         struct list seat_list;
46
47         struct {
48                 struct list list;
49                 struct libinput_source *source;
50                 int fd;
51         } timer;
52
53         struct libinput_event **events;
54         size_t events_count;
55         size_t events_len;
56         size_t events_in;
57         size_t events_out;
58
59         const struct libinput_interface *interface;
60         const struct libinput_interface_backend *interface_backend;
61
62         libinput_log_handler log_handler;
63         enum libinput_log_priority log_priority;
64         void *user_data;
65         int refcount;
66 };
67
68 typedef void (*libinput_seat_destroy_func) (struct libinput_seat *seat);
69
70 struct libinput_seat {
71         struct libinput *libinput;
72         struct list link;
73         struct list devices_list;
74         void *user_data;
75         int refcount;
76         libinput_seat_destroy_func destroy;
77
78         char *physical_name;
79         char *logical_name;
80
81         uint32_t slot_map;
82
83         uint32_t button_count[KEY_CNT];
84 };
85
86 struct libinput_device_config_tap {
87         int (*count)(struct libinput_device *device);
88         enum libinput_config_status (*set_enabled)(struct libinput_device *device,
89                                                    enum libinput_config_tap_state enable);
90         enum libinput_config_tap_state (*get_enabled)(struct libinput_device *device);
91         enum libinput_config_tap_state (*get_default)(struct libinput_device *device);
92 };
93
94 struct libinput_device_config_calibration {
95         int (*has_matrix)(struct libinput_device *device);
96         enum libinput_config_status (*set_matrix)(struct libinput_device *device,
97                                                   const float matrix[6]);
98         int (*get_matrix)(struct libinput_device *device,
99                           float matrix[6]);
100         int (*get_default_matrix)(struct libinput_device *device,
101                                                           float matrix[6]);
102 };
103
104 struct libinput_device_config_send_events {
105         uint32_t (*get_modes)(struct libinput_device *device);
106         enum libinput_config_status (*set_mode)(struct libinput_device *device,
107                                                    enum libinput_config_send_events_mode mode);
108         enum libinput_config_send_events_mode (*get_mode)(struct libinput_device *device);
109         enum libinput_config_send_events_mode (*get_default_mode)(struct libinput_device *device);
110 };
111
112 struct libinput_device_config_accel {
113         int (*available)(struct libinput_device *device);
114         enum libinput_config_status (*set_speed)(struct libinput_device *device,
115                                                  double speed);
116         double (*get_speed)(struct libinput_device *device);
117         double (*get_default_speed)(struct libinput_device *device);
118 };
119
120 struct libinput_device_config_natural_scroll {
121         int (*has)(struct libinput_device *device);
122         enum libinput_config_status (*set_enabled)(struct libinput_device *device,
123                                                    int enabled);
124         int (*get_enabled)(struct libinput_device *device);
125         int (*get_default_enabled)(struct libinput_device *device);
126 };
127
128 struct libinput_device_config_left_handed {
129         int (*has)(struct libinput_device *device);
130         enum libinput_config_status (*set)(struct libinput_device *device, int left_handed);
131         int (*get)(struct libinput_device *device);
132         int (*get_default)(struct libinput_device *device);
133 };
134
135 struct libinput_device_config {
136         struct libinput_device_config_tap *tap;
137         struct libinput_device_config_calibration *calibration;
138         struct libinput_device_config_send_events *sendevents;
139         struct libinput_device_config_accel *accel;
140         struct libinput_device_config_natural_scroll *natural_scroll;
141         struct libinput_device_config_left_handed *left_handed;
142 };
143
144 struct libinput_device {
145         struct libinput_seat *seat;
146         struct list link;
147         void *user_data;
148         int terminated;
149         int refcount;
150         struct libinput_device_config config;
151 };
152
153 typedef void (*libinput_source_dispatch_t)(void *data);
154
155
156 #define log_debug(li_, ...) log_msg((li_), LIBINPUT_LOG_PRIORITY_DEBUG, __VA_ARGS__)
157 #define log_info(li_, ...) log_msg((li_), LIBINPUT_LOG_PRIORITY_INFO, __VA_ARGS__)
158 #define log_error(li_, ...) log_msg((li_), LIBINPUT_LOG_PRIORITY_ERROR, __VA_ARGS__)
159 #define log_bug_kernel(li_, ...) log_msg((li_), LIBINPUT_LOG_PRIORITY_ERROR, "kernel bug: " __VA_ARGS__)
160 #define log_bug_libinput(li_, ...) log_msg((li_), LIBINPUT_LOG_PRIORITY_ERROR, "libinput bug: " __VA_ARGS__)
161 #define log_bug_client(li_, ...) log_msg((li_), LIBINPUT_LOG_PRIORITY_ERROR, "client bug: " __VA_ARGS__)
162
163 void
164 log_msg(struct libinput *libinput,
165         enum libinput_log_priority priority,
166         const char *format, ...);
167
168 void
169 log_msg_va(struct libinput *libinput,
170            enum libinput_log_priority priority,
171            const char *format,
172            va_list args);
173
174 int
175 libinput_init(struct libinput *libinput,
176               const struct libinput_interface *interface,
177               const struct libinput_interface_backend *interface_backend,
178               void *user_data);
179
180 struct libinput_source *
181 libinput_add_fd(struct libinput *libinput,
182                 int fd,
183                 libinput_source_dispatch_t dispatch,
184                 void *data);
185
186 void
187 libinput_remove_source(struct libinput *libinput,
188                        struct libinput_source *source);
189
190 int
191 open_restricted(struct libinput *libinput,
192                 const char *path, int flags);
193
194 void
195 close_restricted(struct libinput *libinput, int fd);
196
197 void
198 libinput_seat_init(struct libinput_seat *seat,
199                    struct libinput *libinput,
200                    const char *physical_name,
201                    const char *logical_name,
202                    libinput_seat_destroy_func destroy);
203
204 void
205 libinput_device_init(struct libinput_device *device,
206                      struct libinput_seat *seat);
207
208 void
209 notify_added_device(struct libinput_device *device);
210
211 void
212 notify_removed_device(struct libinput_device *device);
213
214 void
215 keyboard_notify_key(struct libinput_device *device,
216                     uint32_t time,
217                     uint32_t key,
218                     enum libinput_key_state state);
219
220 void
221 pointer_notify_motion(struct libinput_device *device,
222                       uint32_t time,
223                       double dx,
224                       double dy);
225
226 void
227 pointer_notify_motion_absolute(struct libinput_device *device,
228                                uint32_t time,
229                                double x,
230                                double y);
231
232 void
233 pointer_notify_button(struct libinput_device *device,
234                       uint32_t time,
235                       int32_t button,
236                       enum libinput_button_state state);
237
238 void
239 pointer_notify_axis(struct libinput_device *device,
240                     uint32_t time,
241                     enum libinput_pointer_axis axis,
242                     double value);
243
244 void
245 touch_notify_touch_down(struct libinput_device *device,
246                         uint32_t time,
247                         int32_t slot,
248                         int32_t seat_slot,
249                         double x,
250                         double y);
251
252 void
253 touch_notify_touch_motion(struct libinput_device *device,
254                           uint32_t time,
255                           int32_t slot,
256                           int32_t seat_slot,
257                           double x,
258                           double y);
259
260 void
261 touch_notify_touch_up(struct libinput_device *device,
262                       uint32_t time,
263                       int32_t slot,
264                       int32_t seat_slot);
265
266 void
267 touch_notify_frame(struct libinput_device *device,
268                    uint32_t time);
269
270 static inline uint64_t
271 libinput_now(struct libinput *libinput)
272 {
273         struct timespec ts = { 0, 0 };
274
275         if (clock_gettime(CLOCK_MONOTONIC, &ts) != 0) {
276                 log_error(libinput, "clock_gettime failed: %s\n", strerror(errno));
277                 return 0;
278         }
279
280         return ts.tv_sec * 1000ULL + ts.tv_nsec / 1000000;
281 }
282 #endif /* LIBINPUT_PRIVATE_H */