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