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