[gtk+/gtk-3-14] x11: Store last axes from device



commit 5c17e0b027700be3e0e15565d68ecc8e319fbb3a
Author: Carlos Garnacho <carlosg gnome org>
Date:   Mon Mar 2 18:19:16 2015 +0100

    x11: Store last axes from device
    
    And use these for the missing axes if the valuator mask is incomplete.
    This used to work fine on tablets because the Wacom driver ensures all
    valuators are sent, which is not true if using the evdev driver.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=703610

 gdk/x11/gdkdevice-xi2.c        |   28 ++++++++++++++++++++++++++++
 gdk/x11/gdkdevicemanager-xi2.c |   10 ++++++++--
 gdk/x11/gdkprivate-x11.h       |    6 ++++++
 3 files changed, 42 insertions(+), 2 deletions(-)
---
diff --git a/gdk/x11/gdkdevice-xi2.c b/gdk/x11/gdkdevice-xi2.c
index b3289c0..fad8671 100644
--- a/gdk/x11/gdkdevice-xi2.c
+++ b/gdk/x11/gdkdevice-xi2.c
@@ -51,6 +51,7 @@ struct _GdkX11DeviceXI2
 
   gint device_id;
   GArray *scroll_valuators;
+  gdouble *last_axes;
 };
 
 struct _GdkX11DeviceXI2Class
@@ -157,6 +158,7 @@ gdk_x11_device_xi2_finalize (GObject *object)
   GdkX11DeviceXI2 *device = GDK_X11_DEVICE_XI2 (object);
 
   g_array_free (device->scroll_valuators, TRUE);
+  g_free (device->last_axes);
 
   G_OBJECT_CLASS (gdk_x11_device_xi2_parent_class)->finalize (object);
 }
@@ -891,3 +893,29 @@ _gdk_x11_device_xi2_get_id (GdkX11DeviceXI2 *device)
 
   return device->device_id;
 }
+
+gdouble
+gdk_x11_device_xi2_get_last_axis_value (GdkX11DeviceXI2 *device,
+                                        gint             n_axis)
+{
+  if (n_axis >= gdk_device_get_n_axes (GDK_DEVICE (device)))
+    return 0;
+
+  if (!device->last_axes)
+    return 0;
+
+  return device->last_axes[n_axis];
+}
+
+void
+gdk_x11_device_xi2_store_axes (GdkX11DeviceXI2 *device,
+                               gdouble         *axes,
+                               gint             n_axes)
+{
+  g_free (device->last_axes);
+
+  if (axes && n_axes)
+    device->last_axes = g_memdup (axes, sizeof (gdouble) * n_axes);
+  else
+    device->last_axes = NULL;
+}
diff --git a/gdk/x11/gdkdevicemanager-xi2.c b/gdk/x11/gdkdevicemanager-xi2.c
index 49d6987..0ce2e1c 100644
--- a/gdk/x11/gdkdevicemanager-xi2.c
+++ b/gdk/x11/gdkdevicemanager-xi2.c
@@ -766,6 +766,7 @@ handle_device_changed (GdkX11DeviceManagerXI2 *device_manager,
     {
       _gdk_device_reset_axes (device);
       _gdk_device_xi2_unset_scroll_valuators ((GdkX11DeviceXI2 *) device);
+      gdk_x11_device_xi2_store_axes (GDK_X11_DEVICE_XI2 (device), NULL, 0);
       translate_device_classes (display, device, ev->classes, ev->num_classes);
 
       g_signal_emit_by_name (G_OBJECT (device), "changed");
@@ -868,13 +869,16 @@ translate_axes (GdkDevice       *device,
   axes = g_new0 (gdouble, n_axes);
   vals = valuators->values;
 
-  for (i = 0; i < valuators->mask_len * 8; i++)
+  for (i = 0; i < MIN (valuators->mask_len * 8, n_axes); i++)
     {
       GdkAxisUse use;
       gdouble val;
 
       if (!XIMaskIsSet (valuators->mask, i))
-        continue;
+        {
+          axes[i] = gdk_x11_device_xi2_get_last_axis_value (GDK_X11_DEVICE_XI2 (device), i);
+          continue;
+        }
 
       use = gdk_device_get_axis_use (device, i);
       val = *vals++;
@@ -899,6 +903,8 @@ translate_axes (GdkDevice       *device,
         }
     }
 
+  gdk_x11_device_xi2_store_axes (GDK_X11_DEVICE_XI2 (device), axes, n_axes);
+
   return axes;
 }
 
diff --git a/gdk/x11/gdkprivate-x11.h b/gdk/x11/gdkprivate-x11.h
index d5f3e1d..c2afecf 100644
--- a/gdk/x11/gdkprivate-x11.h
+++ b/gdk/x11/gdkprivate-x11.h
@@ -247,6 +247,12 @@ gboolean  _gdk_x11_device_xi2_get_scroll_delta    (GdkX11DeviceXI2    *device,
                                                    gdouble            *delta_ret);
 void     _gdk_device_xi2_reset_scroll_valuators   (GdkX11DeviceXI2    *device);
 
+gdouble  gdk_x11_device_xi2_get_last_axis_value (GdkX11DeviceXI2 *device,
+                                                 gint             n_axis);
+
+void     gdk_x11_device_xi2_store_axes          (GdkX11DeviceXI2 *device,
+                                                 gdouble         *axes,
+                                                 gint             n_axes);
 #endif
 
 void     _gdk_x11_event_translate_keyboard_string (GdkEventKey *event);


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