[gtk+/xi2] GdkDeviceCore: Implement get_history().



commit 374a62bbfc106d08582e8ff8718e6bf4b2628227
Author: Carlos Garnacho <carlos gnome org>
Date:   Fri Oct 16 02:50:05 2009 +0200

    GdkDeviceCore: Implement get_history().
    
    This code lived previously in gdk/x11/gdkinput.c

 gdk/x11/gdkdevice-core.c |   89 ++++++++++++++++++++++++++++++++++
 gdk/x11/gdkinput.c       |  120 ----------------------------------------------
 2 files changed, 89 insertions(+), 120 deletions(-)
---
diff --git a/gdk/x11/gdkdevice-core.c b/gdk/x11/gdkdevice-core.c
index fa5e640..c2506ff 100644
--- a/gdk/x11/gdkdevice-core.c
+++ b/gdk/x11/gdkdevice-core.c
@@ -22,6 +22,12 @@
 #include "gdkprivate-x11.h"
 #include "gdkx.h"
 
+static gboolean gdk_device_core_get_history (GdkDevice      *device,
+                                             GdkWindow      *window,
+                                             guint32         start,
+                                             guint32         stop,
+                                             GdkTimeCoord ***events,
+                                             guint          *n_events);
 static void gdk_device_core_get_state (GdkDevice       *device,
                                        GdkWindow       *window,
                                        gdouble         *axes,
@@ -67,6 +73,7 @@ gdk_device_core_class_init (GdkDeviceCoreClass *klass)
 {
   GdkDeviceClass *device_class = GDK_DEVICE_CLASS (klass);
 
+  device_class->get_history = gdk_device_core_get_history;
   device_class->get_state = gdk_device_core_get_state;
   device_class->set_window_cursor = gdk_device_core_set_window_cursor;
   device_class->warp = gdk_device_core_warp;
@@ -88,6 +95,88 @@ gdk_device_core_init (GdkDeviceCore *device_core)
   _gdk_device_add_axis (device, GDK_NONE, GDK_AXIS_Y, 0, 0, 1);
 }
 
+static gboolean
+impl_coord_in_window (GdkWindow *window,
+		      int        impl_x,
+		      int        impl_y)
+{
+  GdkWindowObject *priv = (GdkWindowObject *) window;
+
+  if (impl_x < priv->abs_x ||
+      impl_x > priv->abs_x + priv->width)
+    return FALSE;
+
+  if (impl_y < priv->abs_y ||
+      impl_y > priv->abs_y + priv->height)
+    return FALSE;
+
+  return TRUE;
+}
+
+static gboolean
+gdk_device_core_get_history (GdkDevice      *device,
+                             GdkWindow      *window,
+                             guint32         start,
+                             guint32         stop,
+                             GdkTimeCoord ***events,
+                             guint          *n_events)
+{
+  GdkWindowObject *priv;
+  XTimeCoord *xcoords;
+  GdkTimeCoord **coords;
+  GdkWindow *impl_window;
+  int tmp_n_events;
+  int i, j;
+
+  impl_window = _gdk_window_get_impl_window (window);
+  xcoords = XGetMotionEvents (GDK_DRAWABLE_XDISPLAY (window),
+                              GDK_DRAWABLE_XID (impl_window),
+                              start, stop, &tmp_n_events);
+  if (!xcoords)
+    return FALSE;
+
+  priv = (GdkWindowObject *) window;
+  coords = _gdk_device_allocate_history (device, tmp_n_events);
+
+  for (i = 0, j = 0; i < tmp_n_events; i++)
+    {
+      if (impl_coord_in_window (window, xcoords[i].x, xcoords[i].y))
+        {
+          coords[j]->time = xcoords[i].time;
+          coords[j]->axes[0] = xcoords[i].x - priv->abs_x;
+          coords[j]->axes[1] = xcoords[i].y - priv->abs_y;
+          j++;
+        }
+    }
+
+  XFree (xcoords);
+
+  /* free the events we allocated too much */
+  for (i = j; i < tmp_n_events; i++)
+    {
+      g_free (coords[i]);
+      coords[i] = NULL;
+    }
+
+  tmp_n_events = j;
+
+  if (tmp_n_events == 0)
+    {
+      gdk_device_free_history (coords, tmp_n_events);
+      return FALSE;
+    }
+
+  if (n_events)
+    *n_events = tmp_n_events;
+
+  if (events)
+    *events = coords;
+  else if (coords)
+    gdk_device_free_history (coords, tmp_n_events);
+
+  return TRUE;
+}
+
 static void
 gdk_device_core_get_state (GdkDevice       *device,
                            GdkWindow       *window,
diff --git a/gdk/x11/gdkinput.c b/gdk/x11/gdkinput.c
index 7f25266..cb6cd7d 100644
--- a/gdk/x11/gdkinput.c
+++ b/gdk/x11/gdkinput.c
@@ -59,126 +59,6 @@ gdk_devices_list (void)
   return gdk_display_list_devices (gdk_display_get_default ());
 }
 
-#if 0
-
-static gboolean
-impl_coord_in_window (GdkWindow *window,
-		      int impl_x,
-		      int impl_y)
-{
-  GdkWindowObject *priv = (GdkWindowObject *)window;
-
-  if (impl_x < priv->abs_x ||
-      impl_x > priv->abs_x + priv->width)
-    return FALSE;
-  if (impl_y < priv->abs_y ||
-      impl_y > priv->abs_y + priv->height)
-    return FALSE;
-  return TRUE;
-}
-
-/**
- * gdk_device_get_history:
- * @device: a #GdkDevice
- * @window: the window with respect to which which the event coordinates will be reported
- * @start: starting timestamp for range of events to return
- * @stop: ending timestamp for the range of events to return
- * @events: location to store a newly-allocated array of #GdkTimeCoord, or %NULL
- * @n_events: location to store the length of @events, or %NULL
- *
- * Obtains the motion history for a device; given a starting and
- * ending timestamp, return all events in the motion history for
- * the device in the given range of time. Some windowing systems
- * do not support motion history, in which case, %FALSE will
- * be returned. (This is not distinguishable from the case where
- * motion history is supported and no events were found.)
- *
- * Return value: %TRUE if the windowing system supports motion history and
- *  at least one event was found.
- **/
-gboolean
-gdk_device_get_history  (GdkDevice         *device,
-			 GdkWindow         *window,
-			 guint32            start,
-			 guint32            stop,
-			 GdkTimeCoord    ***events,
-			 gint              *n_events)
-{
-  GdkTimeCoord **coords = NULL;
-  GdkWindow *impl_window;
-  gboolean result = FALSE;
-  int tmp_n_events = 0;
-
-  g_return_val_if_fail (GDK_WINDOW_IS_X11 (window), FALSE);
-
-  impl_window = _gdk_window_get_impl_window (window);
-
-  if (GDK_WINDOW_DESTROYED (window))
-    /* Nothing */ ;
-  else if (GDK_IS_CORE (device))
-    {
-      XTimeCoord *xcoords;
-
-      xcoords = XGetMotionEvents (GDK_DRAWABLE_XDISPLAY (window),
-				  GDK_DRAWABLE_XID (impl_window),
-				  start, stop, &tmp_n_events);
-      if (xcoords)
-	{
-	  GdkWindowObject *priv = (GdkWindowObject *)window;
-          int i, j;
-
-	  coords = _gdk_device_allocate_history (device, tmp_n_events);
-	  j = 0;
-
-	  for (i = 0; i < tmp_n_events; i++)
-	    {
-	      if (impl_coord_in_window (window, xcoords[i].x, xcoords[i].y))
-		{
-		  coords[j]->time = xcoords[i].time;
-		  coords[j]->axes[0] = xcoords[i].x - priv->abs_x;
-		  coords[j]->axes[1] = xcoords[i].y - priv->abs_y;
-		  j++;
-		}
-	    }
-
-	  XFree (xcoords);
-
-          /* free the events we allocated too much */
-          for (i = j; i < tmp_n_events; i++)
-            {
-              g_free (coords[i]);
-              coords[i] = NULL;
-            }
-
-          tmp_n_events = j;
-
-          if (tmp_n_events > 0)
-            {
-              result = TRUE;
-            }
-          else
-            {
-              gdk_device_free_history (coords, tmp_n_events);
-              coords = NULL;
-            }
-	}
-    }
-  else
-    result = _gdk_device_get_history (device, window, start, stop, &coords, &tmp_n_events);
-
-  if (n_events)
-    *n_events = tmp_n_events;
-
-  if (events)
-    *events = coords;
-  else if (coords)
-    gdk_device_free_history (coords, tmp_n_events);
-
-  return result;
-}
-
-#endif
-
 static void
 _gdk_input_select_device_events (GdkWindow *impl_window,
                                  GdkDevice *device)



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]