Drop libdrm CFLAGS where no longer necessary.
[profile/ivi/wayland.git] / wayland-glib.c
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 #include <stdint.h>
24 #include <glib/giochannel.h>
25 #include "wayland-client.h"
26 #include "wayland-glib.h"
27
28 typedef struct _WlSource {
29         GSource source;
30         GPollFD pfd;
31         uint32_t mask;
32         struct wl_display *display;
33 } WlSource;
34
35 static gboolean
36 wl_glib_source_prepare(GSource *base, gint *timeout)
37 {
38         WlSource *source = (WlSource *) base;
39
40         *timeout = -1;
41
42         /* We have to add/remove the GPollFD if we want to update our
43          * poll event mask dynamically.  Instead, let's just flush all
44          * write on idle instead, which is what this amounts to. */
45
46         while (source->mask & WL_DISPLAY_WRITABLE)
47                 wl_display_iterate(source->display,
48                                    WL_DISPLAY_WRITABLE);
49
50         return FALSE;
51 }
52
53 static gboolean
54 wl_glib_source_check(GSource *base)
55 {
56         WlSource *source = (WlSource *) base;
57
58         return source->pfd.revents;
59 }
60
61 static gboolean
62 wl_glib_source_dispatch(GSource *base,
63                         GSourceFunc callback,
64                         gpointer data)
65 {
66         WlSource *source = (WlSource *) base;
67
68         wl_display_iterate(source->display,
69                            WL_DISPLAY_READABLE);
70
71         return TRUE;
72 }
73
74 static GSourceFuncs wl_glib_source_funcs = {
75         wl_glib_source_prepare,
76         wl_glib_source_check,
77         wl_glib_source_dispatch,
78         NULL
79 };
80
81 static int
82 wl_glib_source_update(uint32_t mask, void *data)
83 {
84         WlSource *source = data;
85
86         source->mask = mask;
87
88         return 0;
89 }
90
91 GSource *
92 wl_glib_source_new(struct wl_display *display)
93 {
94         WlSource *source;
95
96         source = (WlSource *) g_source_new(&wl_glib_source_funcs,
97                                            sizeof (WlSource));
98         source->display = display;
99         source->pfd.fd = wl_display_get_fd(display,
100                                            wl_glib_source_update, source);
101         source->pfd.events = G_IO_IN | G_IO_ERR;
102         g_source_add_poll(&source->source, &source->pfd);
103
104         return &source->source;
105 }