]> Pileus Git - ~andy/gtk/blobdiff - gdk/wayland/gdkeventsource.c
wayland: don't attempt to unqueue events when events are paused
[~andy/gtk] / gdk / wayland / gdkeventsource.c
index b48e88010766bb9b97e0baf691d2cc074074e086..93f68dc3b67b145bfd0b424a12ecc913ab386156 100644 (file)
@@ -12,9 +12,7 @@
  * Lesser General Public License for more details.
  *
  * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
  */
 
 #include "config.h"
@@ -35,10 +33,13 @@ static gboolean
 gdk_event_source_prepare(GSource *base, gint *timeout)
 {
   GdkWaylandEventSource *source = (GdkWaylandEventSource *) base;
-  GdkDisplayWayland *display = (GdkDisplayWayland *) source->display;
+  GdkWaylandDisplay *display = (GdkWaylandDisplay *) source->display;
 
   *timeout = -1;
 
+  if (source->display->event_pause_count > 0)
+    return FALSE;
+
   /* 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. */
@@ -46,8 +47,7 @@ gdk_event_source_prepare(GSource *base, gint *timeout)
   if (_gdk_event_queue_find_first (source->display) != NULL)
     return TRUE;
 
-  while (source->mask & WL_DISPLAY_WRITABLE)
-    wl_display_iterate(display->wl_display, WL_DISPLAY_WRITABLE);
+  wl_display_flush(display->wl_display);
 
   return FALSE;
 }
@@ -57,6 +57,12 @@ gdk_event_source_check(GSource *base)
 {
   GdkWaylandEventSource *source = (GdkWaylandEventSource *) base;
 
+  if (source->pfd.revents & (G_IO_ERR | G_IO_HUP))
+    g_error ("Lost connection to wayland compositor");
+
+  if (source->display->event_pause_count > 0)
+    return FALSE;
+
   return _gdk_event_queue_find_first (source->display) != NULL ||
     source->pfd.revents;
 }
@@ -70,7 +76,7 @@ gdk_event_source_dispatch(GSource *base,
   GdkDisplay *display = source->display;
   GdkEvent *event;
 
-  GDK_THREADS_ENTER ();
+  gdk_threads_enter ();
 
   event = gdk_display_get_event (display);
 
@@ -81,7 +87,7 @@ gdk_event_source_dispatch(GSource *base,
       gdk_event_free (event);
     }
 
-  GDK_THREADS_LEAVE ();
+  gdk_threads_leave ();
 
   return TRUE;
 }
@@ -99,24 +105,14 @@ static GSourceFuncs wl_glib_source_funcs = {
   gdk_event_source_finalize
 };
 
-static int
-gdk_event_source_update(uint32_t mask, void *data)
-{
-  GdkWaylandEventSource *source = data;
-
-  source->mask = mask;
-
-  return 0;
-}
-
 void
 _gdk_wayland_display_deliver_event (GdkDisplay *display, GdkEvent *event)
 {
   GList *node;
-  static int serial;
 
   node = _gdk_event_queue_append (display, event);
-  _gdk_windowing_got_event (display, node, event, serial++);
+  _gdk_windowing_got_event (display, node, event,
+                            _gdk_display_get_next_serial (display));
 }
 
 GSource *
@@ -124,7 +120,7 @@ _gdk_wayland_display_event_source_new (GdkDisplay *display)
 {
   GSource *source;
   GdkWaylandEventSource *wl_source;
-  GdkDisplayWayland *display_wayland;
+  GdkWaylandDisplay *display_wayland;
   char *name;
 
   source = g_source_new (&wl_glib_source_funcs,
@@ -134,11 +130,10 @@ _gdk_wayland_display_event_source_new (GdkDisplay *display)
   g_free (name);
   wl_source = (GdkWaylandEventSource *) source;
 
-  display_wayland = GDK_DISPLAY_WAYLAND (display);
+  display_wayland = GDK_WAYLAND_DISPLAY (display);
   wl_source->display = display;
-  wl_source->pfd.fd = wl_display_get_fd(display_wayland->wl_display,
-                                       gdk_event_source_update, source);
-  wl_source->pfd.events = G_IO_IN | G_IO_ERR;
+  wl_source->pfd.fd = wl_display_get_fd(display_wayland->wl_display);
+  wl_source->pfd.events = G_IO_IN | G_IO_ERR | G_IO_HUP;
   g_source_add_poll(source, &wl_source->pfd);
 
   g_source_set_priority (source, GDK_PRIORITY_EVENTS);
@@ -150,28 +145,17 @@ _gdk_wayland_display_event_source_new (GdkDisplay *display)
   return source;
 }
 
-void
-_gdk_wayland_display_flush (GdkDisplay *display, GSource *source)
-{
-  GdkWaylandEventSource *wayland_source = (GdkWaylandEventSource *) source;
-
-  while (wayland_source->mask & WL_DISPLAY_WRITABLE)
-    wl_display_iterate(GDK_DISPLAY_WAYLAND (display)->wl_display,
-                      WL_DISPLAY_WRITABLE);
-}
-
 void
 _gdk_wayland_display_queue_events (GdkDisplay *display)
 {
-  GdkDisplayWayland *display_wayland;
+  GdkWaylandDisplay *display_wayland;
   GdkWaylandEventSource *source;
 
-  display_wayland = GDK_DISPLAY_WAYLAND (display);
+  display_wayland = GDK_WAYLAND_DISPLAY (display);
   source = (GdkWaylandEventSource *) display_wayland->event_source;
-
   if (source->pfd.revents)
     {
-      wl_display_iterate(display_wayland->wl_display, WL_DISPLAY_READABLE);
-      source->pfd.revents = 0;
+       wl_display_dispatch(display_wayland->wl_display);
+       source->pfd.revents = 0;
     }
 }