Replace output screen size callback with transform helpers
[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 <linux/input.h>
30
31 #include "libinput-private.h"
32
33 #define MAX_SLOTS 16
34
35 enum evdev_event_type {
36         EVDEV_NONE,
37         EVDEV_ABSOLUTE_TOUCH_DOWN,
38         EVDEV_ABSOLUTE_MOTION,
39         EVDEV_ABSOLUTE_TOUCH_UP,
40         EVDEV_ABSOLUTE_MT_DOWN,
41         EVDEV_ABSOLUTE_MT_MOTION,
42         EVDEV_ABSOLUTE_MT_UP,
43         EVDEV_RELATIVE_MOTION,
44 };
45
46 enum evdev_device_seat_capability {
47         EVDEV_DEVICE_POINTER = (1 << 0),
48         EVDEV_DEVICE_KEYBOARD = (1 << 1),
49         EVDEV_DEVICE_TOUCH = (1 << 2)
50 };
51
52 struct evdev_device {
53         struct libinput_device base;
54
55         struct libinput_source *source;
56
57         struct evdev_dispatch *dispatch;
58         char *output_name;
59         char *devnode;
60         char *sysname;
61         char *devname;
62         int fd;
63         struct {
64                 int min_x, max_x, min_y, max_y;
65                 int32_t x, y;
66
67                 int apply_calibration;
68                 float calibration[6];
69         } abs;
70
71         struct {
72                 int slot;
73                 struct {
74                         int32_t x, y;
75                 } slots[MAX_SLOTS];
76         } mt;
77         struct mtdev *mtdev;
78
79         struct {
80                 li_fixed_t dx, dy;
81         } rel;
82
83         enum evdev_event_type pending_event;
84         enum evdev_device_seat_capability seat_caps;
85
86         int is_mt;
87 };
88
89 /* copied from udev/extras/input_id/input_id.c */
90 /* we must use this kernel-compatible implementation */
91 #define BITS_PER_LONG (sizeof(unsigned long) * 8)
92 #define NBITS(x) ((((x)-1)/BITS_PER_LONG)+1)
93 #define OFF(x)  ((x)%BITS_PER_LONG)
94 #define BIT(x)  (1UL<<OFF(x))
95 #define LONG(x) ((x)/BITS_PER_LONG)
96 #define TEST_BIT(array, bit)    ((array[LONG(bit)] >> OFF(bit)) & 1)
97 /* end copied */
98
99 #define EVDEV_UNHANDLED_DEVICE ((struct evdev_device *) 1)
100
101 struct evdev_dispatch;
102
103 struct evdev_dispatch_interface {
104         /* Process an evdev input event. */
105         void (*process)(struct evdev_dispatch *dispatch,
106                         struct evdev_device *device,
107                         struct input_event *event,
108                         uint32_t time);
109
110         /* Destroy an event dispatch handler and free all its resources. */
111         void (*destroy)(struct evdev_dispatch *dispatch);
112 };
113
114 struct evdev_dispatch {
115         struct evdev_dispatch_interface *interface;
116 };
117
118 struct evdev_device *
119 evdev_device_create(struct libinput_seat *seat,
120                     const char *devnode,
121                     const char *sysname,
122                     int fd);
123
124 struct evdev_dispatch *
125 evdev_touchpad_create(struct evdev_device *device);
126
127 void
128 evdev_device_proces_event(struct libinput_event *event);
129
130 void
131 evdev_device_led_update(struct evdev_device *device, enum libinput_led leds);
132
133 int
134 evdev_device_get_keys(struct evdev_device *device, char *keys, size_t size);
135
136 const char *
137 evdev_device_get_output(struct evdev_device *device);
138
139 const char *
140 evdev_device_get_sysname(struct evdev_device *device);
141
142 void
143 evdev_device_calibrate(struct evdev_device *device, float calibration[6]);
144
145 int
146 evdev_device_has_capability(struct evdev_device *device,
147                             enum libinput_device_capability capability);
148
149 li_fixed_t
150 evdev_device_transform_x(struct evdev_device *device,
151                          li_fixed_t x,
152                          uint32_t width);
153
154 li_fixed_t
155 evdev_device_transform_y(struct evdev_device *device,
156                          li_fixed_t y,
157                          uint32_t height);
158
159 void
160 evdev_device_remove(struct evdev_device *device);
161
162 void
163 evdev_device_destroy(struct evdev_device *device);
164
165 #endif /* EVDEV_H */