evdev: Process touch up events of single-touch devices
[platform/upstream/libinput.git] / src / evdev.h
1 /*
2  * Copyright © 2011, 2012 Intel Corporation
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 EVDEV_H
24 #define EVDEV_H
25
26 #include "config.h"
27
28 #include <linux/input.h>
29 #include <wayland-util.h>
30
31 #define MAX_SLOTS 16
32
33 enum evdev_event_type {
34         EVDEV_NONE,
35         EVDEV_ABSOLUTE_TOUCH_DOWN,
36         EVDEV_ABSOLUTE_MOTION,
37         EVDEV_ABSOLUTE_TOUCH_UP,
38         EVDEV_ABSOLUTE_MT_DOWN,
39         EVDEV_ABSOLUTE_MT_MOTION,
40         EVDEV_ABSOLUTE_MT_UP,
41         EVDEV_RELATIVE_MOTION,
42 };
43
44 enum evdev_device_capability {
45         EVDEV_KEYBOARD = (1 << 0),
46         EVDEV_BUTTON = (1 << 1),
47         EVDEV_MOTION_ABS = (1 << 2),
48         EVDEV_MOTION_REL = (1 << 3),
49         EVDEV_TOUCH = (1 << 4),
50 };
51
52 struct evdev_device {
53         struct weston_seat *seat;
54         struct wl_list link;
55         struct wl_event_source *source;
56         struct weston_output *output;
57         struct evdev_dispatch *dispatch;
58         char *devnode;
59         char *devname;
60         int fd;
61         struct {
62                 int min_x, max_x, min_y, max_y;
63                 int32_t x, y;
64
65                 int apply_calibration;
66                 float calibration[6];
67         } abs;
68
69         struct {
70                 int slot;
71                 struct {
72                         int32_t x, y;
73                 } slots[MAX_SLOTS];
74         } mt;
75         struct mtdev *mtdev;
76
77         struct {
78                 wl_fixed_t dx, dy;
79         } rel;
80
81         enum evdev_event_type pending_event;
82         enum evdev_device_capability caps;
83
84         int is_mt;
85 };
86
87 /* copied from udev/extras/input_id/input_id.c */
88 /* we must use this kernel-compatible implementation */
89 #define BITS_PER_LONG (sizeof(unsigned long) * 8)
90 #define NBITS(x) ((((x)-1)/BITS_PER_LONG)+1)
91 #define OFF(x)  ((x)%BITS_PER_LONG)
92 #define BIT(x)  (1UL<<OFF(x))
93 #define LONG(x) ((x)/BITS_PER_LONG)
94 #define TEST_BIT(array, bit)    ((array[LONG(bit)] >> OFF(bit)) & 1)
95 /* end copied */
96
97 #define EVDEV_UNHANDLED_DEVICE ((struct evdev_device *) 1)
98
99 struct evdev_dispatch;
100
101 struct evdev_dispatch_interface {
102         /* Process an evdev input event. */
103         void (*process)(struct evdev_dispatch *dispatch,
104                         struct evdev_device *device,
105                         struct input_event *event,
106                         uint32_t time);
107
108         /* Destroy an event dispatch handler and free all its resources. */
109         void (*destroy)(struct evdev_dispatch *dispatch);
110 };
111
112 struct evdev_dispatch {
113         struct evdev_dispatch_interface *interface;
114 };
115
116 struct evdev_dispatch *
117 evdev_touchpad_create(struct evdev_device *device);
118
119 void
120 evdev_led_update(struct evdev_device *device, enum weston_led leds);
121
122 struct evdev_device *
123 evdev_device_create(struct weston_seat *seat, const char *path, int device_fd);
124
125 void
126 evdev_device_destroy(struct evdev_device *device);
127
128 void
129 evdev_notify_keyboard_focus(struct weston_seat *seat,
130                             struct wl_list *evdev_devices);
131
132 #endif /* EVDEV_H */