Remove old touchpad code
[platform/upstream/libinput.git] / src / libinput-util.h
1 /*
2  * Copyright © 2008 Kristian Høgsberg
3  *
4  * Permission to use, copy, modify, distribute, and sell this software and its
5  * documentation for any purpose is hereby granted without fee, provided that
6  * the above copyright notice appear in all copies and that both that copyright
7  * notice and this permission notice appear in supporting documentation, and
8  * that the name of the copyright holders not be used in advertising or
9  * publicity pertaining to distribution of the software without specific,
10  * written prior permission.  The copyright holders make no representations
11  * about the suitability of this software for any purpose.  It is provided "as
12  * is" without express or implied warranty.
13  *
14  * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
15  * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
16  * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
17  * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
18  * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
19  * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
20  * OF THIS SOFTWARE.
21  */
22
23 #ifndef LIBINPUT_UTIL_H
24 #define LIBINPUT_UTIL_H
25
26 #include "libinput.h"
27
28 void
29 set_logging_enabled(int enabled);
30
31 void
32 log_info(const char *format, ...);
33
34 /*
35  * This list data structure is a verbatim copy from wayland-util.h from the
36  * Wayland project; except that wl_ prefix has been removed.
37  */
38
39 struct list {
40         struct list *prev;
41         struct list *next;
42 };
43
44 void list_init(struct list *list);
45 void list_insert(struct list *list, struct list *elm);
46 void list_remove(struct list *elm);
47 int list_empty(const struct list *list);
48
49 #ifdef __GNUC__
50 #define container_of(ptr, sample, member)                               \
51         (__typeof__(sample))((char *)(ptr)      -                       \
52                  ((char *)&(sample)->member - (char *)(sample)))
53 #else
54 #define container_of(ptr, sample, member)                               \
55         (void *)((char *)(ptr)  -                                       \
56                  ((char *)&(sample)->member - (char *)(sample)))
57 #endif
58
59 #define list_for_each(pos, head, member)                                \
60         for (pos = 0, pos = container_of((head)->next, pos, member);    \
61              &pos->member != (head);                                    \
62              pos = container_of(pos->member.next, pos, member))
63
64 #define list_for_each_safe(pos, tmp, head, member)                      \
65         for (pos = 0, tmp = 0,                                          \
66              pos = container_of((head)->next, pos, member),             \
67              tmp = container_of((pos)->member.next, tmp, member);       \
68              &pos->member != (head);                                    \
69              pos = tmp,                                                 \
70              tmp = container_of(pos->member.next, tmp, member))
71
72 #define ARRAY_LENGTH(a) (sizeof (a) / sizeof (a)[0])
73 #define ARRAY_FOR_EACH(_arr, _elem) \
74         for (size_t _i = 0; (_elem = &_arr[_i]) && _i < ARRAY_LENGTH(_arr); _i++)
75
76 #define min(a, b) (((a) < (b)) ? (a) : (b))
77 #define max(a, b) (((a) > (b)) ? (a) : (b))
78
79 /*
80  * This fixed point implementation is a verbatim copy from wayland-util.h from
81  * the Wayland project, with the wl_ prefix renamed li_.
82  */
83
84 static inline li_fixed_t li_fixed_from_int(int i)
85 {
86         return i * 256;
87 }
88
89 static inline li_fixed_t
90 li_fixed_from_double(double d)
91 {
92         union {
93                 double d;
94                 int64_t i;
95         } u;
96
97         u.d = d + (3LL << (51 - 8));
98
99         return u.i;
100 }
101
102 #define LIBINPUT_EXPORT __attribute__ ((visibility("default")))
103
104 static inline void *
105 zalloc(size_t size)
106 {
107         return calloc(1, size);
108 }
109
110 #endif /* LIBINPUT_UTIL_H */