summaryrefslogtreecommitdiffstats
path: root/wayland-glib.c
diff options
context:
space:
mode:
authorKristian Høgsberg <krh@redhat.com>2008-11-07 14:27:23 -0500
committerKristian Høgsberg <krh@redhat.com>2008-11-07 14:27:23 -0500
commitfb59084fbf03b738276579e121defcc6a586301d (patch)
treec61fd19f2c181a0c00c4c3e2619a29f7f69ff2dc /wayland-glib.c
parent7f77bd8fbedee8a8a1fbb26776084ccaffc2a087 (diff)
downloadwayland-fb59084fbf03b738276579e121defcc6a586301d.tar.gz
wayland-fb59084fbf03b738276579e121defcc6a586301d.tar.xz
wayland-fb59084fbf03b738276579e121defcc6a586301d.zip
Add glib main loop integration, use it in flower client.
Diffstat (limited to 'wayland-glib.c')
-rw-r--r--wayland-glib.c83
1 files changed, 83 insertions, 0 deletions
diff --git a/wayland-glib.c b/wayland-glib.c
new file mode 100644
index 0000000..10bcfea
--- /dev/null
+++ b/wayland-glib.c
@@ -0,0 +1,83 @@
+#include <stdint.h>
+#include <glib/giochannel.h>
+#include "wayland-client.h"
+#include "wayland-glib.h"
+
+struct _WaylandSource {
+ GSource source;
+ GPollFD pfd;
+ uint32_t mask;
+ struct wl_display *display;
+};
+
+static gboolean
+wayland_source_prepare(GSource *base, gint *timeout)
+{
+ WaylandSource *source = (WaylandSource *) base;
+
+ *timeout = -1;
+
+ /* We have to add/remove the GPollFD if we want to update our
+ * poll event mask dynamically. Instead, let's just flush all
+ * write on idle instead, which is what this amounts to. */
+
+ while (source->mask & WL_DISPLAY_WRITABLE)
+ wl_display_iterate(source->display,
+ WL_DISPLAY_WRITABLE);
+
+ return FALSE;
+}
+
+static gboolean
+wayland_source_check(GSource *base)
+{
+ WaylandSource *source = (WaylandSource *) base;
+
+ return source->pfd.revents;
+}
+
+static gboolean
+wayland_source_dispatch(GSource *base,
+ GSourceFunc callback,
+ gpointer data)
+{
+ WaylandSource *source = (WaylandSource *) base;
+
+ wl_display_iterate(source->display,
+ WL_DISPLAY_READABLE | WL_DISPLAY_WRITABLE);
+
+ return TRUE;
+}
+
+static GSourceFuncs wayland_source_funcs = {
+ wayland_source_prepare,
+ wayland_source_check,
+ wayland_source_dispatch,
+ NULL
+};
+
+static int
+wayland_source_update(uint32_t mask, void *data)
+{
+ WaylandSource *source = data;
+
+ source->mask = mask;
+
+ return 0;
+}
+
+GSource *
+wayland_source_new(struct wl_display *display)
+{
+ WaylandSource *source;
+
+ source = (WaylandSource *) g_source_new(&wayland_source_funcs,
+ sizeof (WaylandSource));
+ source->display = display;
+ source->pfd.fd = wl_display_get_fd(display,
+ wayland_source_update, source);
+ source->pfd.events = G_IO_IN | G_IO_ERR;
+ g_source_add_poll(&source->source, &source->pfd);
+
+ return &source->source;
+}