accel_profile_smooth_simple: Fix jump in acceleration curve
[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 <unistd.h>
27
28 #include "libinput.h"
29
30 void
31 set_logging_enabled(int enabled);
32
33 void
34 log_info(const char *format, ...);
35
36 /*
37  * This list data structure is a verbatim copy from wayland-util.h from the
38  * Wayland project; except that wl_ prefix has been removed.
39  */
40
41 struct list {
42         struct list *prev;
43         struct list *next;
44 };
45
46 void list_init(struct list *list);
47 void list_insert(struct list *list, struct list *elm);
48 void list_remove(struct list *elm);
49 int list_empty(const struct list *list);
50
51 #ifdef __GNUC__
52 #define container_of(ptr, sample, member)                               \
53         (__typeof__(sample))((char *)(ptr)      -                       \
54                  ((char *)&(sample)->member - (char *)(sample)))
55 #else
56 #define container_of(ptr, sample, member)                               \
57         (void *)((char *)(ptr)  -                                       \
58                  ((char *)&(sample)->member - (char *)(sample)))
59 #endif
60
61 #define list_for_each(pos, head, member)                                \
62         for (pos = 0, pos = container_of((head)->next, pos, member);    \
63              &pos->member != (head);                                    \
64              pos = container_of(pos->member.next, pos, member))
65
66 #define list_for_each_safe(pos, tmp, head, member)                      \
67         for (pos = 0, tmp = 0,                                          \
68              pos = container_of((head)->next, pos, member),             \
69              tmp = container_of((pos)->member.next, tmp, member);       \
70              &pos->member != (head);                                    \
71              pos = tmp,                                                 \
72              tmp = container_of(pos->member.next, tmp, member))
73
74 #define ARRAY_LENGTH(a) (sizeof (a) / sizeof (a)[0])
75 #define ARRAY_FOR_EACH(_arr, _elem) \
76         for (size_t _i = 0; (_elem = &_arr[_i]) && _i < ARRAY_LENGTH(_arr); _i++)
77
78 #define min(a, b) (((a) < (b)) ? (a) : (b))
79 #define max(a, b) (((a) > (b)) ? (a) : (b))
80
81 #define LIBINPUT_EXPORT __attribute__ ((visibility("default")))
82
83 static inline void *
84 zalloc(size_t size)
85 {
86         return calloc(1, size);
87 }
88
89 static inline void
90 msleep(unsigned int ms)
91 {
92         usleep(ms * 1000);
93 }
94
95 #endif /* LIBINPUT_UTIL_H */