evdev: Add middle button scrolling for trackpoints
[platform/upstream/libinput.git] / src / evdev.h
1 /*
2  * Copyright © 2011, 2012 Intel Corporation
3  * Copyright © 2013 Jonas Ådahl
4  *
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.
14  *
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.
22  */
23
24 #ifndef EVDEV_H
25 #define EVDEV_H
26
27 #include "config.h"
28
29 #include <stdbool.h>
30 #include "linux/input.h"
31 #include <libevdev/libevdev.h>
32
33 #include "libinput-private.h"
34 #include "timer.h"
35
36 enum evdev_event_type {
37         EVDEV_NONE,
38         EVDEV_ABSOLUTE_TOUCH_DOWN,
39         EVDEV_ABSOLUTE_MOTION,
40         EVDEV_ABSOLUTE_TOUCH_UP,
41         EVDEV_ABSOLUTE_MT_DOWN,
42         EVDEV_ABSOLUTE_MT_MOTION,
43         EVDEV_ABSOLUTE_MT_UP,
44         EVDEV_RELATIVE_MOTION,
45 };
46
47 enum evdev_device_seat_capability {
48         EVDEV_DEVICE_POINTER = (1 << 0),
49         EVDEV_DEVICE_KEYBOARD = (1 << 1),
50         EVDEV_DEVICE_TOUCH = (1 << 2)
51 };
52
53 enum evdev_device_tags {
54         EVDEV_TAG_EXTERNAL_MOUSE = (1 << 0),
55         EVDEV_TAG_INTERNAL_TOUCHPAD = (1 << 1),
56 };
57
58 struct mt_slot {
59         int32_t seat_slot;
60         int32_t x, y;
61 };
62
63 struct evdev_device {
64         struct libinput_device base;
65
66         struct libinput_source *source;
67
68         struct evdev_dispatch *dispatch;
69         struct libevdev *evdev;
70         char *output_name;
71         char *devnode;
72         char *sysname;
73         char *syspath;
74         const char *devname;
75         int fd;
76         struct {
77                 const struct input_absinfo *absinfo_x, *absinfo_y;
78                 int fake_resolution;
79
80                 int32_t x, y;
81                 int32_t seat_slot;
82
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 */
87         } abs;
88
89         struct {
90                 int slot;
91                 struct mt_slot *slots;
92                 size_t slots_len;
93         } mt;
94         struct mtdev *mtdev;
95
96         struct {
97                 int dx, dy;
98         } rel;
99
100         struct {
101                 struct libinput_timer timer;
102                 bool has_middle_button_scroll;
103                 bool middle_button_scroll_active;
104                 double threshold;
105                 uint32_t direction;
106         } scroll;
107
108         enum evdev_event_type pending_event;
109         enum evdev_device_seat_capability seat_caps;
110         enum evdev_device_tags tags;
111
112         int is_mt;
113
114         struct {
115                 struct motion_filter *filter;
116         } pointer;
117
118         /* Bitmask of pressed keys used to ignore initial release events from
119          * the kernel. */
120         unsigned long hw_key_mask[NLONGS(KEY_CNT)];
121         /* Key counter used for multiplexing button events internally in
122          * libinput. */
123         uint8_t key_count[KEY_CNT];
124 };
125
126 #define EVDEV_UNHANDLED_DEVICE ((struct evdev_device *) 1)
127
128 struct evdev_dispatch;
129
130 struct evdev_dispatch_interface {
131         /* Process an evdev input event. */
132         void (*process)(struct evdev_dispatch *dispatch,
133                         struct evdev_device *device,
134                         struct input_event *event,
135                         uint64_t time);
136
137         /* Destroy an event dispatch handler and free all its resources. */
138         void (*destroy)(struct evdev_dispatch *dispatch);
139
140         /* A new device was added */
141         void (*device_added)(struct evdev_device *device,
142                              struct evdev_device *added_device);
143
144         /* A device was removed */
145         void (*device_removed)(struct evdev_device *device,
146                                struct evdev_device *removed_device);
147
148         /* Tag device with one of EVDEV_TAG */
149         void (*tag_device)(struct evdev_device *device,
150                            struct udev_device *udev_device);
151 };
152
153 struct evdev_dispatch {
154         struct evdev_dispatch_interface *interface;
155         struct libinput_device_config_calibration calibration;
156
157         struct {
158                 struct libinput_device_config_send_events config;
159                 enum libinput_config_send_events_mode current_mode;
160         } sendevents;
161 };
162
163 struct evdev_device *
164 evdev_device_create(struct libinput_seat *seat,
165                     const char *devnode,
166                     const char *sysname,
167                     const char *syspath);
168
169 struct evdev_dispatch *
170 evdev_touchpad_create(struct evdev_device *device);
171
172 struct evdev_dispatch *
173 evdev_mt_touchpad_create(struct evdev_device *device);
174
175 void
176 evdev_device_proces_event(struct libinput_event *event);
177
178 void
179 evdev_device_led_update(struct evdev_device *device, enum libinput_led leds);
180
181 int
182 evdev_device_get_keys(struct evdev_device *device, char *keys, size_t size);
183
184 const char *
185 evdev_device_get_output(struct evdev_device *device);
186
187 const char *
188 evdev_device_get_sysname(struct evdev_device *device);
189
190 const char *
191 evdev_device_get_name(struct evdev_device *device);
192
193 unsigned int
194 evdev_device_get_id_product(struct evdev_device *device);
195
196 unsigned int
197 evdev_device_get_id_vendor(struct evdev_device *device);
198
199 void
200 evdev_device_set_default_calibration(struct evdev_device *device,
201                                      const float calibration[6]);
202 void
203 evdev_device_calibrate(struct evdev_device *device,
204                        const float calibration[6]);
205
206 int
207 evdev_device_has_capability(struct evdev_device *device,
208                             enum libinput_device_capability capability);
209
210 int
211 evdev_device_get_size(struct evdev_device *device,
212                       double *w,
213                       double *h);
214
215 double
216 evdev_device_transform_x(struct evdev_device *device,
217                          double x,
218                          uint32_t width);
219
220 double
221 evdev_device_transform_y(struct evdev_device *device,
222                          double y,
223                          uint32_t height);
224 int
225 evdev_device_suspend(struct evdev_device *device);
226
227 int
228 evdev_device_resume(struct evdev_device *device);
229
230 void
231 evdev_keyboard_notify_key(struct evdev_device *device,
232                           uint32_t time,
233                           int key,
234                           enum libinput_key_state state);
235
236 void
237 evdev_pointer_notify_button(struct evdev_device *device,
238                             uint32_t time,
239                             int button,
240                             enum libinput_button_state state);
241
242 void
243 evdev_post_scroll(struct evdev_device *device,
244                   uint64_t time,
245                   double dx,
246                   double dy);
247
248
249 void
250 evdev_stop_scroll(struct evdev_device *device, uint64_t time);
251
252 void
253 evdev_device_remove(struct evdev_device *device);
254
255 void
256 evdev_device_destroy(struct evdev_device *device);
257
258 static inline double
259 evdev_convert_to_mm(const struct input_absinfo *absinfo, double v)
260 {
261         double value = v - absinfo->minimum;
262         return value/absinfo->resolution;
263 }
264
265 #endif /* EVDEV_H */