2 * Copyright © 2013 Jonas Ådahl
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.
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.
23 #ifndef LIBINPUT_PRIVATE_H
24 #define LIBINPUT_PRIVATE_H
28 #include "linux/input.h"
31 #include "libinput-util.h"
33 struct libinput_source;
35 struct libinput_interface_backend {
36 int (*resume)(struct libinput *libinput);
37 void (*suspend)(struct libinput *libinput);
38 void (*destroy)(struct libinput *libinput);
43 struct list source_destroy_list;
45 struct list seat_list;
49 struct libinput_source *source;
53 struct libinput_event **events;
59 const struct libinput_interface *interface;
60 const struct libinput_interface_backend *interface_backend;
62 libinput_log_handler log_handler;
63 enum libinput_log_priority log_priority;
68 typedef void (*libinput_seat_destroy_func) (struct libinput_seat *seat);
70 struct libinput_seat {
71 struct libinput *libinput;
73 struct list devices_list;
76 libinput_seat_destroy_func destroy;
83 uint32_t button_count[KEY_CNT];
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);
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,
100 int (*get_default_matrix)(struct libinput_device *device,
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);
112 struct libinput_device_config_accel {
113 int (*available)(struct libinput_device *device);
114 enum libinput_config_status (*set_speed)(struct libinput_device *device,
116 double (*get_speed)(struct libinput_device *device);
117 double (*get_default_speed)(struct libinput_device *device);
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,
124 int (*get_enabled)(struct libinput_device *device);
125 int (*get_default_enabled)(struct libinput_device *device);
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);
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;
144 struct libinput_device {
145 struct libinput_seat *seat;
150 struct libinput_device_config config;
153 typedef void (*libinput_source_dispatch_t)(void *data);
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__)
164 log_msg(struct libinput *libinput,
165 enum libinput_log_priority priority,
166 const char *format, ...);
169 log_msg_va(struct libinput *libinput,
170 enum libinput_log_priority priority,
175 libinput_init(struct libinput *libinput,
176 const struct libinput_interface *interface,
177 const struct libinput_interface_backend *interface_backend,
180 struct libinput_source *
181 libinput_add_fd(struct libinput *libinput,
183 libinput_source_dispatch_t dispatch,
187 libinput_remove_source(struct libinput *libinput,
188 struct libinput_source *source);
191 open_restricted(struct libinput *libinput,
192 const char *path, int flags);
195 close_restricted(struct libinput *libinput, int fd);
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);
205 libinput_device_init(struct libinput_device *device,
206 struct libinput_seat *seat);
209 notify_added_device(struct libinput_device *device);
212 notify_removed_device(struct libinput_device *device);
215 keyboard_notify_key(struct libinput_device *device,
218 enum libinput_key_state state);
221 pointer_notify_motion(struct libinput_device *device,
227 pointer_notify_motion_absolute(struct libinput_device *device,
233 pointer_notify_button(struct libinput_device *device,
236 enum libinput_button_state state);
239 pointer_notify_axis(struct libinput_device *device,
241 enum libinput_pointer_axis axis,
245 touch_notify_touch_down(struct libinput_device *device,
253 touch_notify_touch_motion(struct libinput_device *device,
261 touch_notify_touch_up(struct libinput_device *device,
267 touch_notify_frame(struct libinput_device *device,
270 static inline uint64_t
271 libinput_now(struct libinput *libinput)
273 struct timespec ts = { 0, 0 };
275 if (clock_gettime(CLOCK_MONOTONIC, &ts) != 0) {
276 log_error(libinput, "clock_gettime failed: %s\n", strerror(errno));
280 return ts.tv_sec * 1000ULL + ts.tv_nsec / 1000000;
282 #endif /* LIBINPUT_PRIVATE_H */