2 * Copyright © 2011, 2012 Intel Corporation
3 * Copyright © 2013 Jonas Ådahl
5 * Permission to use, copy, modify, distribute, and sell this software and
6 * its documentation for any purpose is hereby granted without fee, provided
7 * that the above copyright notice appear in all copies and that both that
8 * copyright notice and this permission notice appear in supporting
9 * documentation, and that the name of the copyright holders not be used in
10 * advertising or publicity pertaining to distribution of the software
11 * without specific, written prior permission. The copyright holders make
12 * no representations about the suitability of this software for any
13 * purpose. It is provided "as is" without express or implied warranty.
15 * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
16 * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
17 * FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY
18 * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
19 * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
20 * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
21 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
30 #include "linux/input.h"
31 #include <libevdev/libevdev.h>
33 #include "libinput-private.h"
36 enum evdev_event_type {
38 EVDEV_ABSOLUTE_TOUCH_DOWN,
39 EVDEV_ABSOLUTE_MOTION,
40 EVDEV_ABSOLUTE_TOUCH_UP,
41 EVDEV_ABSOLUTE_MT_DOWN,
42 EVDEV_ABSOLUTE_MT_MOTION,
44 EVDEV_RELATIVE_MOTION,
47 enum evdev_device_seat_capability {
48 EVDEV_DEVICE_POINTER = (1 << 0),
49 EVDEV_DEVICE_KEYBOARD = (1 << 1),
50 EVDEV_DEVICE_TOUCH = (1 << 2)
53 enum evdev_device_tags {
54 EVDEV_TAG_EXTERNAL_MOUSE = (1 << 0),
55 EVDEV_TAG_INTERNAL_TOUCHPAD = (1 << 1),
56 EVDEV_TAG_TRACKPOINT = (1 << 2),
65 struct libinput_device base;
67 struct libinput_source *source;
69 struct evdev_dispatch *dispatch;
70 struct libevdev *evdev;
78 const struct input_absinfo *absinfo_x, *absinfo_y;
84 int apply_calibration;
85 struct matrix calibration;
86 struct matrix default_calibration; /* from LIBINPUT_CALIBRATION_MATRIX */
87 struct matrix usermatrix; /* as supplied by the caller */
92 struct mt_slot *slots;
102 struct libinput_timer timer;
103 struct libinput_device_config_scroll_method config;
104 /* Currently enabled method, button */
105 enum libinput_config_scroll_method method;
107 /* set during device init, used at runtime to delay changes
108 * until all buttons are up */
109 enum libinput_config_scroll_method want_method;
110 uint32_t want_button;
111 /* Checks if buttons are down and commits the setting */
112 void (*change_scroll_method)(struct evdev_device *device);
113 bool button_scroll_active;
116 double buildup_vertical;
117 double buildup_horizontal;
119 struct libinput_device_config_natural_scroll config_natural;
120 /* set during device init if we want natural scrolling,
121 * used at runtime to enable/disable the feature */
122 bool natural_scrolling_enabled;
125 enum evdev_event_type pending_event;
126 enum evdev_device_seat_capability seat_caps;
127 enum evdev_device_tags tags;
133 struct libinput_device_config_accel config;
134 struct motion_filter *filter;
137 /* Bitmask of pressed keys used to ignore initial release events from
139 unsigned long hw_key_mask[NLONGS(KEY_CNT)];
140 /* Key counter used for multiplexing button events internally in
142 uint8_t key_count[KEY_CNT];
145 struct libinput_device_config_left_handed config_left_handed;
146 /* left-handed currently enabled */
148 /* set during device init if we want left_handed config,
149 * used at runtime to delay the effect until buttons are up */
150 bool want_left_handed;
151 /* Checks if buttons are down and commits the setting */
152 void (*change_to_left_handed)(struct evdev_device *device);
155 int dpi; /* HW resolution */
156 struct ratelimit syn_drop_limit; /* ratelimit for SYN_DROPPED logging */
159 #define EVDEV_UNHANDLED_DEVICE ((struct evdev_device *) 1)
161 struct evdev_dispatch;
163 struct evdev_dispatch_interface {
164 /* Process an evdev input event. */
165 void (*process)(struct evdev_dispatch *dispatch,
166 struct evdev_device *device,
167 struct input_event *event,
170 /* Destroy an event dispatch handler and free all its resources. */
171 void (*destroy)(struct evdev_dispatch *dispatch);
173 /* A new device was added */
174 void (*device_added)(struct evdev_device *device,
175 struct evdev_device *added_device);
177 /* A device was removed */
178 void (*device_removed)(struct evdev_device *device,
179 struct evdev_device *removed_device);
181 /* A device was suspended */
182 void (*device_suspended)(struct evdev_device *device,
183 struct evdev_device *suspended_device);
185 /* A device was resumed */
186 void (*device_resumed)(struct evdev_device *device,
187 struct evdev_device *resumed_device);
189 /* Tag device with one of EVDEV_TAG */
190 void (*tag_device)(struct evdev_device *device,
191 struct udev_device *udev_device);
194 struct evdev_dispatch {
195 struct evdev_dispatch_interface *interface;
196 struct libinput_device_config_calibration calibration;
199 struct libinput_device_config_send_events config;
200 enum libinput_config_send_events_mode current_mode;
204 struct evdev_device *
205 evdev_device_create(struct libinput_seat *seat,
208 const char *syspath);
211 evdev_device_init_pointer_acceleration(struct evdev_device *device);
213 struct evdev_dispatch *
214 evdev_touchpad_create(struct evdev_device *device);
216 struct evdev_dispatch *
217 evdev_mt_touchpad_create(struct evdev_device *device);
220 evdev_device_led_update(struct evdev_device *device, enum libinput_led leds);
223 evdev_device_get_keys(struct evdev_device *device, char *keys, size_t size);
226 evdev_device_get_output(struct evdev_device *device);
229 evdev_device_get_sysname(struct evdev_device *device);
232 evdev_device_get_name(struct evdev_device *device);
235 evdev_device_get_id_product(struct evdev_device *device);
238 evdev_device_get_id_vendor(struct evdev_device *device);
241 evdev_device_set_default_calibration(struct evdev_device *device,
242 const float calibration[6]);
244 evdev_device_calibrate(struct evdev_device *device,
245 const float calibration[6]);
248 evdev_device_has_capability(struct evdev_device *device,
249 enum libinput_device_capability capability);
252 evdev_device_get_size(struct evdev_device *device,
257 evdev_device_has_button(struct evdev_device *device, uint32_t code);
260 evdev_device_transform_x(struct evdev_device *device,
265 evdev_device_transform_y(struct evdev_device *device,
269 evdev_device_suspend(struct evdev_device *device);
272 evdev_device_resume(struct evdev_device *device);
275 evdev_notify_suspended_device(struct evdev_device *device);
278 evdev_notify_resumed_device(struct evdev_device *device);
281 evdev_keyboard_notify_key(struct evdev_device *device,
284 enum libinput_key_state state);
287 evdev_pointer_notify_button(struct evdev_device *device,
290 enum libinput_button_state state);
293 evdev_init_natural_scroll(struct evdev_device *device);
296 evdev_post_scroll(struct evdev_device *device,
303 evdev_stop_scroll(struct evdev_device *device, uint64_t time);
306 evdev_device_remove(struct evdev_device *device);
309 evdev_device_destroy(struct evdev_device *device);
312 evdev_convert_to_mm(const struct input_absinfo *absinfo, double v)
314 double value = v - absinfo->minimum;
315 return value/absinfo->resolution;
319 evdev_init_left_handed(struct evdev_device *device,
320 void (*change_to_left_handed)(struct evdev_device *));
322 static inline uint32_t
323 evdev_to_left_handed(struct evdev_device *device,
326 if (device->buttons.left_handed) {
327 if (button == BTN_LEFT)
329 else if (button == BTN_RIGHT)