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