touchpad: hook up natural scrolling configuration
[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 {
129         struct libinput_device_config_tap *tap;
130         struct libinput_device_config_calibration *calibration;
131         struct libinput_device_config_send_events *sendevents;
132         struct libinput_device_config_accel *accel;
133         struct libinput_device_config_natural_scroll *natural_scroll;
134 };
135
136 struct libinput_device {
137         struct libinput_seat *seat;
138         struct list link;
139         void *user_data;
140         int terminated;
141         int refcount;
142         struct libinput_device_config config;
143 };
144
145 typedef void (*libinput_source_dispatch_t)(void *data);
146
147
148 #define log_debug(li_, ...) log_msg((li_), LIBINPUT_LOG_PRIORITY_DEBUG, __VA_ARGS__)
149 #define log_info(li_, ...) log_msg((li_), LIBINPUT_LOG_PRIORITY_INFO, __VA_ARGS__)
150 #define log_error(li_, ...) log_msg((li_), LIBINPUT_LOG_PRIORITY_ERROR, __VA_ARGS__)
151 #define log_bug_kernel(li_, ...) log_msg((li_), LIBINPUT_LOG_PRIORITY_ERROR, "kernel bug: " __VA_ARGS__)
152 #define log_bug_libinput(li_, ...) log_msg((li_), LIBINPUT_LOG_PRIORITY_ERROR, "libinput bug: " __VA_ARGS__)
153 #define log_bug_client(li_, ...) log_msg((li_), LIBINPUT_LOG_PRIORITY_ERROR, "client bug: " __VA_ARGS__)
154
155 void
156 log_msg(struct libinput *libinput,
157         enum libinput_log_priority priority,
158         const char *format, ...);
159
160 void
161 log_msg_va(struct libinput *libinput,
162            enum libinput_log_priority priority,
163            const char *format,
164            va_list args);
165
166 int
167 libinput_init(struct libinput *libinput,
168               const struct libinput_interface *interface,
169               const struct libinput_interface_backend *interface_backend,
170               void *user_data);
171
172 struct libinput_source *
173 libinput_add_fd(struct libinput *libinput,
174                 int fd,
175                 libinput_source_dispatch_t dispatch,
176                 void *data);
177
178 void
179 libinput_remove_source(struct libinput *libinput,
180                        struct libinput_source *source);
181
182 int
183 open_restricted(struct libinput *libinput,
184                 const char *path, int flags);
185
186 void
187 close_restricted(struct libinput *libinput, int fd);
188
189 void
190 libinput_seat_init(struct libinput_seat *seat,
191                    struct libinput *libinput,
192                    const char *physical_name,
193                    const char *logical_name,
194                    libinput_seat_destroy_func destroy);
195
196 void
197 libinput_device_init(struct libinput_device *device,
198                      struct libinput_seat *seat);
199
200 void
201 notify_added_device(struct libinput_device *device);
202
203 void
204 notify_removed_device(struct libinput_device *device);
205
206 void
207 keyboard_notify_key(struct libinput_device *device,
208                     uint32_t time,
209                     uint32_t key,
210                     enum libinput_key_state state);
211
212 void
213 pointer_notify_motion(struct libinput_device *device,
214                       uint32_t time,
215                       double dx,
216                       double dy);
217
218 void
219 pointer_notify_motion_absolute(struct libinput_device *device,
220                                uint32_t time,
221                                double x,
222                                double y);
223
224 void
225 pointer_notify_button(struct libinput_device *device,
226                       uint32_t time,
227                       int32_t button,
228                       enum libinput_button_state state);
229
230 void
231 pointer_notify_axis(struct libinput_device *device,
232                     uint32_t time,
233                     enum libinput_pointer_axis axis,
234                     double value);
235
236 void
237 touch_notify_touch_down(struct libinput_device *device,
238                         uint32_t time,
239                         int32_t slot,
240                         int32_t seat_slot,
241                         double x,
242                         double y);
243
244 void
245 touch_notify_touch_motion(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_up(struct libinput_device *device,
254                       uint32_t time,
255                       int32_t slot,
256                       int32_t seat_slot);
257
258 void
259 touch_notify_frame(struct libinput_device *device,
260                    uint32_t time);
261
262 static inline uint64_t
263 libinput_now(struct libinput *libinput)
264 {
265         struct timespec ts = { 0, 0 };
266
267         if (clock_gettime(CLOCK_MONOTONIC, &ts) != 0) {
268                 log_error(libinput, "clock_gettime failed: %s\n", strerror(errno));
269                 return 0;
270         }
271
272         return ts.tv_sec * 1000ULL + ts.tv_nsec / 1000000;
273 }
274 #endif /* LIBINPUT_PRIVATE_H */