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
27 * This list data structure is a verbatim copy from wayland-util.h from the
28 * Wayland project; except that wl_ prefix has been removed.
36 void list_init(struct list *list);
37 void list_insert(struct list *list, struct list *elm);
38 void list_remove(struct list *elm);
39 int list_empty(const struct list *list);
42 #define container_of(ptr, sample, member) \
43 (__typeof__(sample))((char *)(ptr) - \
44 ((char *)&(sample)->member - (char *)(sample)))
46 #define container_of(ptr, sample, member) \
47 (void *)((char *)(ptr) - \
48 ((char *)&(sample)->member - (char *)(sample)))
51 #define list_for_each(pos, head, member) \
52 for (pos = 0, pos = container_of((head)->next, pos, member); \
53 &pos->member != (head); \
54 pos = container_of(pos->member.next, pos, member))
56 #define list_for_each_safe(pos, tmp, head, member) \
57 for (pos = 0, tmp = 0, \
58 pos = container_of((head)->next, pos, member), \
59 tmp = container_of((pos)->member.next, tmp, member); \
60 &pos->member != (head); \
62 tmp = container_of(pos->member.next, tmp, member))
64 #define ARRAY_LENGTH(a) (sizeof (a) / sizeof (a)[0])
67 * This fixed point implementation is a verbatim copy from wayland-util.h from
68 * the Wayland project, with the wl_ prefix renamed li_.
71 static inline li_fixed_t li_fixed_from_int(int i)
76 static inline li_fixed_t
77 li_fixed_from_double(double d)
84 u.d = d + (3LL << (51 - 8));
89 #define LIBINPUT_EXPORT __attribute__ ((visibility("default")))
91 #endif /* LIBINPUT_UTIL_H */