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),
64 struct libinput_device base;
66 struct libinput_source *source;
68 struct evdev_dispatch *dispatch;
69 struct libevdev *evdev;
77 const struct input_absinfo *absinfo_x, *absinfo_y;
83 int apply_calibration;
84 struct matrix calibration;
85 struct matrix default_calibration; /* from LIBINPUT_CALIBRATION_MATRIX */
86 struct matrix usermatrix; /* as supplied by the caller */
91 struct mt_slot *slots;
101 struct libinput_timer timer;
102 bool has_middle_button_scroll;
103 bool middle_button_scroll_active;
108 enum evdev_event_type pending_event;
109 enum evdev_device_seat_capability seat_caps;
110 enum evdev_device_tags tags;
116 struct motion_filter *filter;
119 /* Bitmask of pressed keys used to ignore initial release events from
121 unsigned long hw_key_mask[NLONGS(KEY_CNT)];
122 /* Key counter used for multiplexing button events internally in
124 uint8_t key_count[KEY_CNT];
127 #define EVDEV_UNHANDLED_DEVICE ((struct evdev_device *) 1)
129 struct evdev_dispatch;
131 struct evdev_dispatch_interface {
132 /* Process an evdev input event. */
133 void (*process)(struct evdev_dispatch *dispatch,
134 struct evdev_device *device,
135 struct input_event *event,
138 /* Destroy an event dispatch handler and free all its resources. */
139 void (*destroy)(struct evdev_dispatch *dispatch);
141 /* A new device was added */
142 void (*device_added)(struct evdev_device *device,
143 struct evdev_device *added_device);
145 /* A device was removed */
146 void (*device_removed)(struct evdev_device *device,
147 struct evdev_device *removed_device);
149 /* A device was suspended */
150 void (*device_suspended)(struct evdev_device *device,
151 struct evdev_device *suspended_device);
153 /* A device was resumed */
154 void (*device_resumed)(struct evdev_device *device,
155 struct evdev_device *resumed_device);
157 /* Tag device with one of EVDEV_TAG */
158 void (*tag_device)(struct evdev_device *device,
159 struct udev_device *udev_device);
162 struct evdev_dispatch {
163 struct evdev_dispatch_interface *interface;
164 struct libinput_device_config_calibration calibration;
167 struct libinput_device_config_send_events config;
168 enum libinput_config_send_events_mode current_mode;
172 struct evdev_device *
173 evdev_device_create(struct libinput_seat *seat,
176 const char *syspath);
178 struct evdev_dispatch *
179 evdev_touchpad_create(struct evdev_device *device);
181 struct evdev_dispatch *
182 evdev_mt_touchpad_create(struct evdev_device *device);
185 evdev_device_proces_event(struct libinput_event *event);
188 evdev_device_led_update(struct evdev_device *device, enum libinput_led leds);
191 evdev_device_get_keys(struct evdev_device *device, char *keys, size_t size);
194 evdev_device_get_output(struct evdev_device *device);
197 evdev_device_get_sysname(struct evdev_device *device);
200 evdev_device_get_name(struct evdev_device *device);
203 evdev_device_get_id_product(struct evdev_device *device);
206 evdev_device_get_id_vendor(struct evdev_device *device);
209 evdev_device_set_default_calibration(struct evdev_device *device,
210 const float calibration[6]);
212 evdev_device_calibrate(struct evdev_device *device,
213 const float calibration[6]);
216 evdev_device_has_capability(struct evdev_device *device,
217 enum libinput_device_capability capability);
220 evdev_device_get_size(struct evdev_device *device,
225 evdev_device_transform_x(struct evdev_device *device,
230 evdev_device_transform_y(struct evdev_device *device,
234 evdev_device_suspend(struct evdev_device *device);
237 evdev_device_resume(struct evdev_device *device);
240 evdev_notify_suspended_device(struct evdev_device *device);
243 evdev_notify_resumed_device(struct evdev_device *device);
246 evdev_keyboard_notify_key(struct evdev_device *device,
249 enum libinput_key_state state);
252 evdev_pointer_notify_button(struct evdev_device *device,
255 enum libinput_button_state state);
258 evdev_post_scroll(struct evdev_device *device,
265 evdev_stop_scroll(struct evdev_device *device, uint64_t time);
268 evdev_device_remove(struct evdev_device *device);
271 evdev_device_destroy(struct evdev_device *device);
274 evdev_convert_to_mm(const struct input_absinfo *absinfo, double v)
276 double value = v - absinfo->minimum;
277 return value/absinfo->resolution;