Port evdev code to be used as a shared library
[platform/upstream/libinput.git] / src / libinput.c
1 /*
2  * Copyright © 2013 Jonas Ådahl
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 #include "config.h"
24
25 #include <stdlib.h>
26
27 #include "libinput.h"
28 #include "evdev.h"
29 #include "libinput-private.h"
30
31 void
32 keyboard_notify_key(struct libinput_device *device,
33                     uint32_t time,
34                     uint32_t key,
35                     enum libinput_keyboard_key_state state)
36 {
37         if (device->keyboard_listener)
38                 device->keyboard_listener->notify_key(
39                         time, key, state,
40                         device->keyboard_listener_data);
41 }
42
43 void
44 pointer_notify_motion(struct libinput_device *device,
45                       uint32_t time,
46                       li_fixed_t dx,
47                       li_fixed_t dy)
48 {
49         if (device->pointer_listener)
50                 device->pointer_listener->notify_motion(
51                         time, dx, dy,
52                         device->pointer_listener_data);
53 }
54
55 void
56 pointer_notify_motion_absolute(struct libinput_device *device,
57                                uint32_t time,
58                                li_fixed_t x,
59                                li_fixed_t y)
60 {
61         if (device->pointer_listener)
62                 device->pointer_listener->notify_motion_absolute(
63                         time, x, y,
64                         device->pointer_listener_data);
65 }
66
67 void
68 pointer_notify_button(struct libinput_device *device,
69                       uint32_t time,
70                       int32_t button,
71                       enum libinput_pointer_button_state state)
72 {
73         if (device->pointer_listener)
74                 device->pointer_listener->notify_button(
75                         time, button, state,
76                         device->pointer_listener_data);
77 }
78
79 void
80 pointer_notify_axis(struct libinput_device *device,
81                     uint32_t time,
82                     enum libinput_pointer_axis axis,
83                     li_fixed_t value)
84 {
85         if (device->pointer_listener)
86                 device->pointer_listener->notify_axis(
87                         time, axis, value,
88                         device->pointer_listener_data);
89 }
90
91 void
92 touch_notify_touch(struct libinput_device *device,
93                    uint32_t time,
94                    int32_t slot,
95                    li_fixed_t x,
96                    li_fixed_t y,
97                    enum libinput_touch_type touch_type)
98 {
99         if (device->touch_listener)
100                 device->touch_listener->notify_touch(
101                         time, slot, x, y, touch_type,
102                         device->touch_listener_data);
103 }
104
105 LIBINPUT_EXPORT void
106 libinput_device_set_keyboard_listener(
107         struct libinput_device *device,
108         const struct libinput_keyboard_listener *listener,
109         void *data)
110 {
111         device->keyboard_listener = listener;
112         device->keyboard_listener_data = data;
113 }
114
115 LIBINPUT_EXPORT void
116 libinput_device_set_pointer_listener(
117         struct libinput_device *device,
118         const struct libinput_pointer_listener *listener,
119         void *data)
120 {
121         device->pointer_listener = listener;
122         device->pointer_listener_data = data;
123 }
124
125 LIBINPUT_EXPORT void
126 libinput_device_set_touch_listener(
127         struct libinput_device *device,
128         const struct libinput_touch_listener *listener,
129         void *data)
130 {
131         device->touch_listener = listener;
132         device->touch_listener_data = data;
133 }
134
135 LIBINPUT_EXPORT int
136 libinput_device_dispatch(struct libinput_device *device)
137 {
138         return evdev_device_dispatch((struct evdev_device *) device);
139 }
140
141 LIBINPUT_EXPORT void
142 libinput_device_destroy(struct libinput_device *device)
143 {
144         evdev_device_destroy((struct evdev_device *) device);
145 }
146
147 LIBINPUT_EXPORT void
148 libinput_device_led_update(struct libinput_device *device,
149                            enum libinput_led leds)
150 {
151         evdev_device_led_update((struct evdev_device *) device, leds);
152 }
153
154 LIBINPUT_EXPORT int
155 libinput_device_get_keys(struct libinput_device *device,
156                          char *keys, size_t size)
157 {
158         return evdev_device_get_keys((struct evdev_device *) device,
159                                      keys,
160                                      size);
161 }
162
163 LIBINPUT_EXPORT void
164 libinput_device_calibrate(struct libinput_device *device,
165                           float calibration[6])
166 {
167         evdev_device_calibrate((struct evdev_device *) device, calibration);
168 }