]> Pileus Git - ~andy/gtk/blobdiff - gdk/gdkevents.c
win32: Request higher precision timers during animations
[~andy/gtk] / gdk / gdkevents.c
index 688fec24d6de4d24585bfe943b5aac551522fd0a..4a9d0b965a0e73543985559673c3ea7ac9c9ff9f 100644 (file)
@@ -85,13 +85,27 @@ _gdk_event_emit (GdkEvent *event)
 GList*
 _gdk_event_queue_find_first (GdkDisplay *display)
 {
-  GList *tmp_list = display->queued_events;
+  GList *tmp_list;
+  GList *pending_motion = NULL;
+
+  if (display->event_pause_count > 0)
+    return NULL;
 
+  tmp_list = display->queued_events;
   while (tmp_list)
     {
       GdkEventPrivate *event = tmp_list->data;
-      if (!(event->flags & GDK_EVENT_PENDING))
-       return tmp_list;
+
+      if (event->flags & GDK_EVENT_PENDING)
+        continue;
+
+      if (pending_motion)
+        return pending_motion;
+
+      if (event->event.type == GDK_MOTION_NOTIFY && !display->flushing_events)
+        pending_motion = tmp_list;
+      else
+        return tmp_list;
 
       tmp_list = g_list_next (tmp_list);
     }
@@ -170,15 +184,15 @@ _gdk_event_queue_insert_after (GdkDisplay *display,
 }
 
 /**
- * _gdk_event_queue_insert_after:
+ * _gdk_event_queue_insert_before:
  * @display: a #GdkDisplay
- * @sibling: Append after this event.
- * @event: Event to append.
+ * @sibling: Append before this event
+ * @event: Event to prepend
  *
- * Appends an event before the specified event, or if it isn't in
- * the queue, onto the tail of the event queue.
+ * Prepends an event before the specified event, or if it isn't in
+ * the queue, onto the head of the event queue.
  *
- * Returns: the newly appended list node.
+ * Returns: the newly prepended list node.
  *
  * Since: 2.16
  */
@@ -248,6 +262,61 @@ _gdk_event_unqueue (GdkDisplay *display)
   return event;
 }
 
+void
+_gdk_event_queue_handle_motion_compression (GdkDisplay *display)
+{
+  GList *tmp_list;
+  GList *pending_motions = NULL;
+  GdkWindow *pending_motion_window = NULL;
+  GdkDevice *pending_motion_device = NULL;
+
+  /* If the last N events in the event queue are motion notify
+   * events for the same window, drop all but the last */
+
+  tmp_list = display->queued_tail;
+
+  while (tmp_list)
+    {
+      GdkEventPrivate *event = tmp_list->data;
+
+      if (event->flags & GDK_EVENT_PENDING)
+        break;
+
+      if (event->event.type != GDK_MOTION_NOTIFY)
+        break;
+
+      if (pending_motion_window != NULL &&
+          pending_motion_window != event->event.motion.window)
+        break;
+
+      if (pending_motion_device != NULL &&
+          pending_motion_device != event->event.motion.device)
+        break;
+
+      pending_motion_window = event->event.motion.window;
+      pending_motion_device = event->event.motion.device;
+      pending_motions = tmp_list;
+
+      tmp_list = tmp_list->prev;
+    }
+
+  while (pending_motions && pending_motions->next != NULL)
+    {
+      GList *next = pending_motions->next;
+      display->queued_events = g_list_delete_link (display->queued_events,
+                                                   pending_motions);
+      pending_motions = next;
+    }
+
+  if (pending_motions &&
+      pending_motions == display->queued_events &&
+      pending_motions == display->queued_tail)
+    {
+      GdkFrameClock *clock = gdk_window_get_frame_clock (pending_motion_window);
+      gdk_frame_clock_request_phase (clock, GDK_FRAME_CLOCK_PHASE_FLUSH_EVENTS);
+    }
+}
+
 /**
  * gdk_event_handler_set:
  * @func: the function to call to handle events from GDK.
@@ -471,6 +540,8 @@ gdk_event_new (GdkEventType type)
       new_event->scroll.y = 0.;
       new_event->scroll.x_root = 0.;
       new_event->scroll.y_root = 0.;
+      new_event->scroll.delta_x = 0.;
+      new_event->scroll.delta_y = 0.;
       break;
     case GDK_ENTER_NOTIFY:
     case GDK_LEAVE_NOTIFY:
@@ -1194,7 +1265,10 @@ gdk_event_get_scroll_direction (const GdkEvent *event,
   switch (event->type)
     {
     case GDK_SCROLL:
-      dir = event->scroll.direction;
+      if (event->scroll.direction == GDK_SCROLL_SMOOTH)
+        fetched = FALSE;
+      else
+        dir = event->scroll.direction;
       break;
     default:
       fetched = FALSE;
@@ -1207,6 +1281,52 @@ gdk_event_get_scroll_direction (const GdkEvent *event,
   return fetched;
 }
 
+/**
+ * gdk_event_get_scroll_deltas:
+ * @event: a #GdkEvent
+ * @delta_x: (out): return location for X delta
+ * @delta_y: (out): return location for Y delta
+ *
+ * Retrieves the scroll deltas from a #GdkEvent
+ *
+ * Returns: %TRUE if the event contains smooth scroll information
+ *
+ * Since: 3.4
+ **/
+gboolean
+gdk_event_get_scroll_deltas (const GdkEvent *event,
+                             gdouble        *delta_x,
+                             gdouble        *delta_y)
+{
+  gboolean fetched = TRUE;
+  gdouble dx = 0.0;
+  gdouble dy = 0.0;
+
+  switch (event->type)
+    {
+    case GDK_SCROLL:
+      if (event->scroll.direction == GDK_SCROLL_SMOOTH)
+        {
+          dx = event->scroll.delta_x;
+          dy = event->scroll.delta_y;
+        }
+      else
+        fetched = FALSE;
+      break;
+    default:
+      fetched = FALSE;
+      break;
+    }
+
+  if (delta_x)
+    *delta_x = dx;
+
+  if (delta_y)
+    *delta_y = dy;
+
+  return fetched;
+}
+
 /**
  * gdk_event_get_axis:
  * @event: a #GdkEvent