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, see <http://www.gnu.org/licenses/>.
20 #include "gdkinternals.h"
21 #include "gdkprivate-wayland.h"
23 typedef struct _GdkWaylandEventSource {
28 } GdkWaylandEventSource;
30 static GList *event_sources = NULL;
33 gdk_event_source_prepare(GSource *base, gint *timeout)
35 GdkWaylandEventSource *source = (GdkWaylandEventSource *) base;
36 GdkWaylandDisplay *display = (GdkWaylandDisplay *) source->display;
40 /* We have to add/remove the GPollFD if we want to update our
41 * poll event mask dynamically. Instead, let's just flush all
42 * write on idle instead, which is what this amounts to. */
44 if (_gdk_event_queue_find_first (source->display) != NULL)
47 while (source->mask & WL_DISPLAY_WRITABLE)
48 wl_display_iterate(display->wl_display, WL_DISPLAY_WRITABLE);
54 gdk_event_source_check(GSource *base)
56 GdkWaylandEventSource *source = (GdkWaylandEventSource *) base;
58 return _gdk_event_queue_find_first (source->display) != NULL ||
63 gdk_event_source_dispatch(GSource *base,
67 GdkWaylandEventSource *source = (GdkWaylandEventSource *) base;
68 GdkDisplay *display = source->display;
73 event = gdk_display_get_event (display);
77 _gdk_event_emit (event);
79 gdk_event_free (event);
88 gdk_event_source_finalize (GSource *source)
90 event_sources = g_list_remove (event_sources, source);
93 static GSourceFuncs wl_glib_source_funcs = {
94 gdk_event_source_prepare,
95 gdk_event_source_check,
96 gdk_event_source_dispatch,
97 gdk_event_source_finalize
101 gdk_event_source_update(uint32_t mask, void *data)
103 GdkWaylandEventSource *source = data;
111 _gdk_wayland_display_deliver_event (GdkDisplay *display, GdkEvent *event)
115 node = _gdk_event_queue_append (display, event);
116 _gdk_windowing_got_event (display, node, event,
117 _gdk_display_get_next_serial (display));
121 _gdk_wayland_display_event_source_new (GdkDisplay *display)
124 GdkWaylandEventSource *wl_source;
125 GdkWaylandDisplay *display_wayland;
128 source = g_source_new (&wl_glib_source_funcs,
129 sizeof (GdkWaylandEventSource));
130 name = g_strdup_printf ("GDK Wayland Event source (%s)", "display name");
131 g_source_set_name (source, name);
133 wl_source = (GdkWaylandEventSource *) source;
135 display_wayland = GDK_WAYLAND_DISPLAY (display);
136 wl_source->display = display;
137 wl_source->pfd.fd = wl_display_get_fd(display_wayland->wl_display,
138 gdk_event_source_update, source);
139 wl_source->pfd.events = G_IO_IN | G_IO_ERR;
140 g_source_add_poll(source, &wl_source->pfd);
142 g_source_set_priority (source, GDK_PRIORITY_EVENTS);
143 g_source_set_can_recurse (source, TRUE);
144 g_source_attach (source, NULL);
146 event_sources = g_list_prepend (event_sources, source);
152 _gdk_wayland_display_flush (GdkDisplay *display, GSource *source)
154 GdkWaylandEventSource *wayland_source = (GdkWaylandEventSource *) source;
156 while (wayland_source->mask & WL_DISPLAY_WRITABLE)
157 wl_display_iterate(GDK_WAYLAND_DISPLAY (display)->wl_display,
158 WL_DISPLAY_WRITABLE);
162 _gdk_wayland_display_queue_events (GdkDisplay *display)
164 GdkWaylandDisplay *display_wayland;
165 GdkWaylandEventSource *source;
167 display_wayland = GDK_WAYLAND_DISPLAY (display);
168 source = (GdkWaylandEventSource *) display_wayland->event_source;
170 if (source->pfd.revents)
172 wl_display_iterate(display_wayland->wl_display, WL_DISPLAY_READABLE);
173 source->pfd.revents = 0;