evdev: Add event process dispatching
[platform/upstream/libinput.git] / src / evdev-private.h
1 /*
2  * Copyright © 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_PRIVATE_H
24 #define EVDEV_PRIVATE_H
25
26 #include <linux/input.h>
27 #include <wayland-util.h>
28
29 struct evdev_seat {
30         struct weston_seat base;
31         struct wl_list devices_list;
32         struct udev_monitor *udev_monitor;
33         struct wl_event_source *udev_monitor_source;
34         char *seat_id;
35 };
36
37 #define MAX_SLOTS 16
38
39 struct evdev_input_device {
40         struct evdev_seat *master;
41         struct wl_list link;
42         struct wl_event_source *source;
43         struct weston_output *output;
44         struct evdev_dispatch *dispatch;
45         char *devnode;
46         int fd;
47         struct {
48                 int min_x, max_x, min_y, max_y;
49                 int old_x, old_y, reset_x, reset_y;
50                 int32_t x, y;
51         } abs;
52
53         struct {
54                 int slot;
55                 int32_t x[MAX_SLOTS];
56                 int32_t y[MAX_SLOTS];
57         } mt;
58         struct mtdev *mtdev;
59
60         struct {
61                 wl_fixed_t dx, dy;
62         } rel;
63
64         int type; /* event type flags */
65
66         int is_touchpad, is_mt;
67 };
68
69 /* event type flags */
70 #define EVDEV_ABSOLUTE_MOTION           (1 << 0)
71 #define EVDEV_ABSOLUTE_MT_DOWN          (1 << 1)
72 #define EVDEV_ABSOLUTE_MT_MOTION        (1 << 2)
73 #define EVDEV_ABSOLUTE_MT_UP            (1 << 3)
74 #define EVDEV_RELATIVE_MOTION           (1 << 4)
75
76 /* copied from udev/extras/input_id/input_id.c */
77 /* we must use this kernel-compatible implementation */
78 #define BITS_PER_LONG (sizeof(unsigned long) * 8)
79 #define NBITS(x) ((((x)-1)/BITS_PER_LONG)+1)
80 #define OFF(x)  ((x)%BITS_PER_LONG)
81 #define BIT(x)  (1UL<<OFF(x))
82 #define LONG(x) ((x)/BITS_PER_LONG)
83 #define TEST_BIT(array, bit)    ((array[LONG(bit)] >> OFF(bit)) & 1)
84 /* end copied */
85
86 struct evdev_dispatch;
87
88 struct evdev_dispatch_interface {
89         /* Process an evdev input event. */
90         void (*process)(struct evdev_dispatch *dispatch,
91                         struct evdev_input_device *device,
92                         struct input_event *event,
93                         uint32_t time);
94
95         /* Destroy an event dispatch handler and free all its resources. */
96         void (*destroy)(struct evdev_dispatch *dispatch);
97 };
98
99 struct evdev_dispatch {
100         struct evdev_dispatch_interface *interface;
101 };
102
103 #endif /* EVDEV_PRIVATE_H */