1 /* GDK - The GIMP Drawing Kit
2 * Copyright (C) 2009 Carlos Garnacho <carlosg@gnome.org>
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
22 #include "gdkinternals.h"
23 #include "gdkprivate-wayland.h"
25 typedef struct _GdkWaylandEventSource {
30 } GdkWaylandEventSource;
32 static GList *event_sources = NULL;
35 gdk_event_source_prepare(GSource *base, gint *timeout)
37 GdkWaylandEventSource *source = (GdkWaylandEventSource *) base;
38 GdkDisplayWayland *display = (GdkDisplayWayland *) source->display;
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 if (_gdk_event_queue_find_first (source->display) != NULL)
49 while (source->mask & WL_DISPLAY_WRITABLE)
50 wl_display_iterate(display->wl_display, WL_DISPLAY_WRITABLE);
56 gdk_event_source_check(GSource *base)
58 GdkWaylandEventSource *source = (GdkWaylandEventSource *) base;
60 return _gdk_event_queue_find_first (source->display) != NULL ||
65 gdk_event_source_dispatch(GSource *base,
69 GdkWaylandEventSource *source = (GdkWaylandEventSource *) base;
70 GdkDisplay *display = source->display;
75 event = gdk_display_get_event (display);
79 _gdk_event_emit (event);
81 gdk_event_free (event);
90 gdk_event_source_finalize (GSource *source)
92 event_sources = g_list_remove (event_sources, source);
95 static GSourceFuncs wl_glib_source_funcs = {
96 gdk_event_source_prepare,
97 gdk_event_source_check,
98 gdk_event_source_dispatch,
99 gdk_event_source_finalize
103 gdk_event_source_update(uint32_t mask, void *data)
105 GdkWaylandEventSource *source = data;
113 _gdk_wayland_display_deliver_event (GdkDisplay *display, GdkEvent *event)
117 node = _gdk_event_queue_append (display, event);
118 _gdk_windowing_got_event (display, node, event,
119 _gdk_display_get_next_serial (display));
123 _gdk_wayland_display_event_source_new (GdkDisplay *display)
126 GdkWaylandEventSource *wl_source;
127 GdkDisplayWayland *display_wayland;
130 source = g_source_new (&wl_glib_source_funcs,
131 sizeof (GdkWaylandEventSource));
132 name = g_strdup_printf ("GDK Wayland Event source (%s)", "display name");
133 g_source_set_name (source, name);
135 wl_source = (GdkWaylandEventSource *) source;
137 display_wayland = GDK_DISPLAY_WAYLAND (display);
138 wl_source->display = display;
139 wl_source->pfd.fd = wl_display_get_fd(display_wayland->wl_display,
140 gdk_event_source_update, source);
141 wl_source->pfd.events = G_IO_IN | G_IO_ERR;
142 g_source_add_poll(source, &wl_source->pfd);
144 g_source_set_priority (source, GDK_PRIORITY_EVENTS);
145 g_source_set_can_recurse (source, TRUE);
146 g_source_attach (source, NULL);
148 event_sources = g_list_prepend (event_sources, source);
154 _gdk_wayland_display_flush (GdkDisplay *display, GSource *source)
156 GdkWaylandEventSource *wayland_source = (GdkWaylandEventSource *) source;
158 while (wayland_source->mask & WL_DISPLAY_WRITABLE)
159 wl_display_iterate(GDK_DISPLAY_WAYLAND (display)->wl_display,
160 WL_DISPLAY_WRITABLE);
164 _gdk_wayland_display_queue_events (GdkDisplay *display)
166 GdkDisplayWayland *display_wayland;
167 GdkWaylandEventSource *source;
169 display_wayland = GDK_DISPLAY_WAYLAND (display);
170 source = (GdkWaylandEventSource *) display_wayland->event_source;
172 if (source->pfd.revents)
174 wl_display_iterate(display_wayland->wl_display, WL_DISPLAY_READABLE);
175 source->pfd.revents = 0;