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 if (source->display->event_pause_count > 0)
43 /* We have to add/remove the GPollFD if we want to update our
44 * poll event mask dynamically. Instead, let's just flush all
45 * write on idle instead, which is what this amounts to. */
47 if (_gdk_event_queue_find_first (source->display) != NULL)
50 wl_display_flush(display->wl_display);
56 gdk_event_source_check(GSource *base)
58 GdkWaylandEventSource *source = (GdkWaylandEventSource *) base;
60 if (source->pfd.revents & (G_IO_ERR | G_IO_HUP))
61 g_error ("Lost connection to wayland compositor");
63 if (source->display->event_pause_count > 0)
66 return _gdk_event_queue_find_first (source->display) != NULL ||
71 gdk_event_source_dispatch(GSource *base,
75 GdkWaylandEventSource *source = (GdkWaylandEventSource *) base;
76 GdkDisplay *display = source->display;
81 event = gdk_display_get_event (display);
85 _gdk_event_emit (event);
87 gdk_event_free (event);
96 gdk_event_source_finalize (GSource *source)
98 event_sources = g_list_remove (event_sources, source);
101 static GSourceFuncs wl_glib_source_funcs = {
102 gdk_event_source_prepare,
103 gdk_event_source_check,
104 gdk_event_source_dispatch,
105 gdk_event_source_finalize
109 _gdk_wayland_display_deliver_event (GdkDisplay *display, GdkEvent *event)
113 node = _gdk_event_queue_append (display, event);
114 _gdk_windowing_got_event (display, node, event,
115 _gdk_display_get_next_serial (display));
119 _gdk_wayland_display_event_source_new (GdkDisplay *display)
122 GdkWaylandEventSource *wl_source;
123 GdkWaylandDisplay *display_wayland;
126 source = g_source_new (&wl_glib_source_funcs,
127 sizeof (GdkWaylandEventSource));
128 name = g_strdup_printf ("GDK Wayland Event source (%s)", "display name");
129 g_source_set_name (source, name);
131 wl_source = (GdkWaylandEventSource *) source;
133 display_wayland = GDK_WAYLAND_DISPLAY (display);
134 wl_source->display = display;
135 wl_source->pfd.fd = wl_display_get_fd(display_wayland->wl_display);
136 wl_source->pfd.events = G_IO_IN | G_IO_ERR | G_IO_HUP;
137 g_source_add_poll(source, &wl_source->pfd);
139 g_source_set_priority (source, GDK_PRIORITY_EVENTS);
140 g_source_set_can_recurse (source, TRUE);
141 g_source_attach (source, NULL);
143 event_sources = g_list_prepend (event_sources, source);
149 _gdk_wayland_display_queue_events (GdkDisplay *display)
151 GdkWaylandDisplay *display_wayland;
152 GdkWaylandEventSource *source;
154 display_wayland = GDK_WAYLAND_DISPLAY (display);
155 source = (GdkWaylandEventSource *) display_wayland->event_source;
156 if (source->pfd.revents)
158 wl_display_dispatch(display_wayland->wl_display);
159 source->pfd.revents = 0;