4a92fb95af8807ef5a4d248c663baee56d9a04aa
[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         void *user_data;
60 };
61
62 typedef void (*libinput_seat_destroy_func) (struct libinput_seat *seat);
63
64 struct libinput_seat {
65         struct libinput *libinput;
66         struct list link;
67         struct list devices_list;
68         void *user_data;
69         int refcount;
70         libinput_seat_destroy_func destroy;
71
72         char *physical_name;
73         char *logical_name;
74
75         uint32_t slot_map;
76
77         uint32_t button_count[KEY_CNT];
78 };
79
80 struct libinput_device {
81         struct libinput_seat *seat;
82         struct list link;
83         void *user_data;
84         int terminated;
85         int refcount;
86 };
87
88 typedef void (*libinput_source_dispatch_t)(void *data);
89
90
91 #define log_debug(...) log_msg(LIBINPUT_LOG_PRIORITY_DEBUG, __VA_ARGS__)
92 #define log_info(...) log_msg(LIBINPUT_LOG_PRIORITY_INFO, __VA_ARGS__)
93 #define log_error(...) log_msg(LIBINPUT_LOG_PRIORITY_ERROR, __VA_ARGS__)
94 #define log_bug_kernel(...) log_msg(LIBINPUT_LOG_PRIORITY_ERROR, "kernel bug: " __VA_ARGS__)
95 #define log_bug_libinput(...) log_msg(LIBINPUT_LOG_PRIORITY_ERROR, "libinput bug: " __VA_ARGS__);
96 #define log_bug_client(...) log_msg(LIBINPUT_LOG_PRIORITY_ERROR, "client bug: " __VA_ARGS__);
97
98 void
99 log_msg(enum libinput_log_priority priority, const char *format, ...);
100 void
101 log_msg_va(enum libinput_log_priority priority,
102            const char *format,
103            va_list args);
104
105 int
106 libinput_init(struct libinput *libinput,
107               const struct libinput_interface *interface,
108               const struct libinput_interface_backend *interface_backend,
109               void *user_data);
110
111 struct libinput_source *
112 libinput_add_fd(struct libinput *libinput,
113                 int fd,
114                 libinput_source_dispatch_t dispatch,
115                 void *data);
116
117 void
118 libinput_remove_source(struct libinput *libinput,
119                        struct libinput_source *source);
120
121 int
122 open_restricted(struct libinput *libinput,
123                 const char *path, int flags);
124
125 void
126 close_restricted(struct libinput *libinput, int fd);
127
128 void
129 libinput_seat_init(struct libinput_seat *seat,
130                    struct libinput *libinput,
131                    const char *physical_name,
132                    const char *logical_name,
133                    libinput_seat_destroy_func destroy);
134
135 void
136 libinput_device_init(struct libinput_device *device,
137                      struct libinput_seat *seat);
138
139 void
140 notify_added_device(struct libinput_device *device);
141
142 void
143 notify_removed_device(struct libinput_device *device);
144
145 void
146 keyboard_notify_key(struct libinput_device *device,
147                     uint32_t time,
148                     uint32_t key,
149                     enum libinput_key_state state);
150
151 void
152 pointer_notify_motion(struct libinput_device *device,
153                       uint32_t time,
154                       double dx,
155                       double dy);
156
157 void
158 pointer_notify_motion_absolute(struct libinput_device *device,
159                                uint32_t time,
160                                double x,
161                                double y);
162
163 void
164 pointer_notify_button(struct libinput_device *device,
165                       uint32_t time,
166                       int32_t button,
167                       enum libinput_button_state state);
168
169 void
170 pointer_notify_axis(struct libinput_device *device,
171                     uint32_t time,
172                     enum libinput_pointer_axis axis,
173                     double value);
174
175 void
176 touch_notify_touch_down(struct libinput_device *device,
177                         uint32_t time,
178                         int32_t slot,
179                         int32_t seat_slot,
180                         double x,
181                         double y);
182
183 void
184 touch_notify_touch_motion(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_up(struct libinput_device *device,
193                       uint32_t time,
194                       int32_t slot,
195                       int32_t seat_slot);
196
197 void
198 touch_notify_frame(struct libinput_device *device,
199                    uint32_t time);
200 #endif /* LIBINPUT_PRIVATE_H */