2 * Copyright © 2008 Kristian Høgsberg
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.
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
23 #ifndef LIBINPUT_UTIL_H
24 #define LIBINPUT_UTIL_H
29 set_logging_enabled(int enabled);
32 log_info(const char *format, ...);
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.
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);
50 #define container_of(ptr, sample, member) \
51 (__typeof__(sample))((char *)(ptr) - \
52 ((char *)&(sample)->member - (char *)(sample)))
54 #define container_of(ptr, sample, member) \
55 (void *)((char *)(ptr) - \
56 ((char *)&(sample)->member - (char *)(sample)))
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))
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); \
70 tmp = container_of(pos->member.next, tmp, member))
72 #define ARRAY_LENGTH(a) (sizeof (a) / sizeof (a)[0])
75 * This fixed point implementation is a verbatim copy from wayland-util.h from
76 * the Wayland project, with the wl_ prefix renamed li_.
79 static inline li_fixed_t li_fixed_from_int(int i)
84 static inline li_fixed_t
85 li_fixed_from_double(double d)
92 u.d = d + (3LL << (51 - 8));
97 #define LIBINPUT_EXPORT __attribute__ ((visibility("default")))
99 #endif /* LIBINPUT_UTIL_H */