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 wl_display_flush(display->wl_display);
53 gdk_event_source_check(GSource *base)
55 GdkWaylandEventSource *source = (GdkWaylandEventSource *) base;
57 if (source->pfd.revents & (G_IO_ERR | G_IO_HUP))
58 g_error ("Lost connection to wayland compositor");
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_wayland_display_deliver_event (GdkDisplay *display, GdkEvent *event)
107 node = _gdk_event_queue_append (display, event);
108 _gdk_windowing_got_event (display, node, event,
109 _gdk_display_get_next_serial (display));
113 _gdk_wayland_display_event_source_new (GdkDisplay *display)
116 GdkWaylandEventSource *wl_source;
117 GdkWaylandDisplay *display_wayland;
120 source = g_source_new (&wl_glib_source_funcs,
121 sizeof (GdkWaylandEventSource));
122 name = g_strdup_printf ("GDK Wayland Event source (%s)", "display name");
123 g_source_set_name (source, name);
125 wl_source = (GdkWaylandEventSource *) source;
127 display_wayland = GDK_WAYLAND_DISPLAY (display);
128 wl_source->display = display;
129 wl_source->pfd.fd = wl_display_get_fd(display_wayland->wl_display);
130 wl_source->pfd.events = G_IO_IN | G_IO_ERR | G_IO_HUP;
131 g_source_add_poll(source, &wl_source->pfd);
133 g_source_set_priority (source, GDK_PRIORITY_EVENTS);
134 g_source_set_can_recurse (source, TRUE);
135 g_source_attach (source, NULL);
137 event_sources = g_list_prepend (event_sources, source);
143 _gdk_wayland_display_queue_events (GdkDisplay *display)
145 GdkWaylandDisplay *display_wayland;
146 GdkWaylandEventSource *source;
148 display_wayland = GDK_WAYLAND_DISPLAY (display);
149 source = (GdkWaylandEventSource *) display_wayland->event_source;
150 if (source->pfd.revents)
152 wl_display_dispatch(display_wayland->wl_display);
153 source->pfd.revents = 0;