Merge branch 'master' of git+ssh://git.freedesktop.org/git/wayland/libinput
[platform/upstream/libinput.git] / src / libinput-private.h
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 #ifndef LIBINPUT_PRIVATE_H
24 #define LIBINPUT_PRIVATE_H
25
26 #include "linux/input.h"
27
28 #include "libinput.h"
29 #include "libinput-util.h"
30
31 struct libinput_source;
32
33 struct libinput_interface_backend {
34         int (*resume)(struct libinput *libinput);
35         void (*suspend)(struct libinput *libinput);
36         void (*destroy)(struct libinput *libinput);
37 };
38
39 struct libinput {
40         int epoll_fd;
41         struct list source_destroy_list;
42
43         struct list seat_list;
44
45         struct {
46                 struct list list;
47                 struct libinput_source *source;
48                 int fd;
49         } timer;
50
51         struct libinput_event **events;
52         size_t events_count;
53         size_t events_len;
54         size_t events_in;
55         size_t events_out;
56
57         const struct libinput_interface *interface;
58         const struct libinput_interface_backend *interface_backend;
59
60         libinput_log_handler log_handler;
61         enum libinput_log_priority log_priority;
62         void *user_data;
63         int refcount;
64 };
65
66 typedef void (*libinput_seat_destroy_func) (struct libinput_seat *seat);
67
68 struct libinput_seat {
69         struct libinput *libinput;
70         struct list link;
71         struct list devices_list;
72         void *user_data;
73         int refcount;
74         libinput_seat_destroy_func destroy;
75
76         char *physical_name;
77         char *logical_name;
78
79         uint32_t slot_map;
80
81         uint32_t button_count[KEY_CNT];
82 };
83
84 struct libinput_device {
85         struct libinput_seat *seat;
86         struct list link;
87         void *user_data;
88         int terminated;
89         int refcount;
90 };
91
92 typedef void (*libinput_source_dispatch_t)(void *data);
93
94
95 #define log_debug(li_, ...) log_msg((li_), LIBINPUT_LOG_PRIORITY_DEBUG, __VA_ARGS__)
96 #define log_info(li_, ...) log_msg((li_), LIBINPUT_LOG_PRIORITY_INFO, __VA_ARGS__)
97 #define log_error(li_, ...) log_msg((li_), LIBINPUT_LOG_PRIORITY_ERROR, __VA_ARGS__)
98 #define log_bug_kernel(li_, ...) log_msg((li_), LIBINPUT_LOG_PRIORITY_ERROR, "kernel bug: " __VA_ARGS__)
99 #define log_bug_libinput(li_, ...) log_msg((li_), LIBINPUT_LOG_PRIORITY_ERROR, "libinput bug: " __VA_ARGS__);
100 #define log_bug_client(li_, ...) log_msg((li_), LIBINPUT_LOG_PRIORITY_ERROR, "client bug: " __VA_ARGS__);
101
102 void
103 log_msg(struct libinput *libinput,
104         enum libinput_log_priority priority,
105         const char *format, ...);
106
107 void
108 log_msg_va(struct libinput *libinput,
109            enum libinput_log_priority priority,
110            const char *format,
111            va_list args);
112
113 int
114 libinput_init(struct libinput *libinput,
115               const struct libinput_interface *interface,
116               const struct libinput_interface_backend *interface_backend,
117               void *user_data);
118
119 struct libinput_source *
120 libinput_add_fd(struct libinput *libinput,
121                 int fd,
122                 libinput_source_dispatch_t dispatch,
123                 void *data);
124
125 void
126 libinput_remove_source(struct libinput *libinput,
127                        struct libinput_source *source);
128
129 int
130 open_restricted(struct libinput *libinput,
131                 const char *path, int flags);
132
133 void
134 close_restricted(struct libinput *libinput, int fd);
135
136 void
137 libinput_seat_init(struct libinput_seat *seat,
138                    struct libinput *libinput,
139                    const char *physical_name,
140                    const char *logical_name,
141                    libinput_seat_destroy_func destroy);
142
143 void
144 libinput_device_init(struct libinput_device *device,
145                      struct libinput_seat *seat);
146
147 void
148 notify_added_device(struct libinput_device *device);
149
150 void
151 notify_removed_device(struct libinput_device *device);
152
153 void
154 keyboard_notify_key(struct libinput_device *device,
155                     uint32_t time,
156                     uint32_t key,
157                     enum libinput_key_state state);
158
159 void
160 pointer_notify_motion(struct libinput_device *device,
161                       uint32_t time,
162                       double dx,
163                       double dy);
164
165 void
166 pointer_notify_motion_absolute(struct libinput_device *device,
167                                uint32_t time,
168                                double x,
169                                double y);
170
171 void
172 pointer_notify_button(struct libinput_device *device,
173                       uint32_t time,
174                       int32_t button,
175                       enum libinput_button_state state);
176
177 void
178 pointer_notify_axis(struct libinput_device *device,
179                     uint32_t time,
180                     enum libinput_pointer_axis axis,
181                     double value);
182
183 void
184 touch_notify_touch_down(struct libinput_device *device,
185                         uint32_t time,
186                         int32_t slot,
187                         int32_t seat_slot,
188                         double x,
189                         double y);
190
191 void
192 touch_notify_touch_motion(struct libinput_device *device,
193                           uint32_t time,
194                           int32_t slot,
195                           int32_t seat_slot,
196                           double x,
197                           double y);
198
199 void
200 touch_notify_touch_up(struct libinput_device *device,
201                       uint32_t time,
202                       int32_t slot,
203                       int32_t seat_slot);
204
205 void
206 touch_notify_frame(struct libinput_device *device,
207                    uint32_t time);
208 #endif /* LIBINPUT_PRIVATE_H */