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