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
24 #include <glib/giochannel.h>
25 #include "wayland-client.h"
26 #include "wayland-glib.h"
28 typedef struct _WlSource {
32 struct wl_display *display;
36 wl_glib_source_prepare(GSource *base, gint *timeout)
38 WlSource *source = (WlSource *) base;
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. */
46 while (source->mask & WL_DISPLAY_WRITABLE)
47 wl_display_iterate(source->display,
54 wl_glib_source_check(GSource *base)
56 WlSource *source = (WlSource *) base;
58 return source->pfd.revents;
62 wl_glib_source_dispatch(GSource *base,
66 WlSource *source = (WlSource *) base;
68 wl_display_iterate(source->display,
74 static GSourceFuncs wl_glib_source_funcs = {
75 wl_glib_source_prepare,
77 wl_glib_source_dispatch,
82 wl_glib_source_update(uint32_t mask, void *data)
84 WlSource *source = data;
92 wl_glib_source_new(struct wl_display *display)
96 source = (WlSource *) g_source_new(&wl_glib_source_funcs,
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);
104 return &source->source;