[gtk+/xi2: 1222/1239] GdkDeviceXI: Implement get_history().



commit 31186dddebaf6f89b5a9305ae343c55c99f4d2fd
Author: Carlos Garnacho <carlos gnome org>
Date:   Sat Sep 26 15:23:55 2009 +0200

    GdkDeviceXI: Implement get_history().

 gdk/x11/gdkdevice-xi.c |   83 ++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 83 insertions(+), 0 deletions(-)
---
diff --git a/gdk/x11/gdkdevice-xi.c b/gdk/x11/gdkdevice-xi.c
index 43c56b4..11743da 100644
--- a/gdk/x11/gdkdevice-xi.c
+++ b/gdk/x11/gdkdevice-xi.c
@@ -18,6 +18,7 @@
  */
 
 #include <gdk/gdkwindow.h>
+#include "gdkdeviceprivate.h"
 #include "gdkdevice-xi.h"
 #include "gdkprivate-x11.h"
 #include "gdkintl.h"
@@ -33,6 +34,13 @@ static void gdk_device_xi_get_property (GObject      *object,
                                         GValue       *value,
                                         GParamSpec   *pspec);
 
+static gboolean gdk_device_xi_get_history (GdkDevice      *device,
+                                           GdkWindow      *window,
+                                           guint32         start,
+                                           guint32         stop,
+                                           GdkTimeCoord ***events,
+                                           guint          *n_events);
+
 
 G_DEFINE_TYPE (GdkDeviceXI, gdk_device_xi, GDK_TYPE_DEVICE)
 
@@ -45,11 +53,14 @@ static void
 gdk_device_xi_class_init (GdkDeviceXIClass *klass)
 {
   GObjectClass *object_class = G_OBJECT_CLASS (klass);
+  GdkDeviceClass *device_class = GDK_DEVICE_CLASS (klass);
 
   object_class->constructed = gdk_device_xi_constructed;
   object_class->set_property = gdk_device_xi_set_property;
   object_class->get_property = gdk_device_xi_get_property;
 
+  device_class->get_history = gdk_device_xi_get_history;
+
   g_object_class_install_property (object_class,
 				   PROP_DEVICE_ID,
 				   g_param_spec_int ("device-id",
@@ -121,3 +132,75 @@ gdk_device_xi_get_property (GObject    *object,
       break;
     }
 }
+
+static GdkTimeCoord **
+allocate_history (GdkDevice *device,
+                  gint       n_events)
+{
+  GdkTimeCoord **result = g_new (GdkTimeCoord *, n_events);
+  gint i;
+
+  for (i = 0; i < n_events; i++)
+    result[i] = g_malloc (sizeof (GdkTimeCoord) -
+			  sizeof (double) * (GDK_MAX_TIMECOORD_AXES - device->num_axes));
+  return result;
+}
+
+static gboolean
+gdk_device_xi_get_history (GdkDevice      *device,
+                           GdkWindow      *window,
+                           guint32         start,
+                           guint32         stop,
+                           GdkTimeCoord ***events,
+                           guint          *n_events)
+{
+  GdkTimeCoord **coords;
+  XDeviceTimeCoord *device_coords;
+  GdkWindow *impl_window;
+  GdkDeviceXI *device_xi;
+  gint n_events_return;
+  gint mode_return;
+  gint axis_count_return;
+  gint n_axes, i, j;
+  gint width, height;
+
+  device_xi = GDK_DEVICE_XI (device);
+  impl_window = _gdk_window_get_impl_window (window);
+  g_object_get (device, "n-axes", &n_axes, NULL);
+
+  gdk_drawable_get_size (GDK_DRAWABLE (window), &width, &height);
+
+  device_coords = XGetDeviceMotionEvents (GDK_WINDOW_XDISPLAY (impl_window),
+					  device_xi->xdevice,
+					  start, stop,
+					  &n_events_return,
+                                          &mode_return,
+					  &axis_count_return);
+
+  if (!device_coords)
+    return FALSE;
+
+  coords = allocate_history (device, *n_events);
+
+  for (i = 0; i < *n_events; i++)
+    {
+      coords[i]->time = device_coords[i].time;
+
+      for (j = 0; j < n_axes; j++)
+        {
+          _gdk_device_translate_axis (device,
+                                      width, height,
+                                      0, 0,
+                                      j,
+                                      (gdouble) device_coords[i].data[j],
+                                      &coords[i]->axes[j]);
+        }
+    }
+
+  XFreeDeviceMotionEvents (device_coords);
+
+  *events = coords;
+  *n_events = (guint) n_events_return;
+
+  return TRUE;
+}



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