]> Pileus Git - ~andy/gtk/commitdiff
xi2: Normalize scroll deltas
authorMatthias Clasen <mclasen@redhat.com>
Mon, 5 Mar 2012 00:12:27 +0000 (19:12 -0500)
committerMatthias Clasen <mclasen@redhat.com>
Mon, 5 Mar 2012 00:12:27 +0000 (19:12 -0500)
XI2 provides us with an increment for each scroll valuator,
and by dividing the delta by the increment, we obtain normalized
values in some abstract 'scroll unit'.

For mouse wheels, the evdev driver reports an increment of -1,
so doing this division fixes the inverted scrolling with wheels
that we've seen recently.

gdk/x11/gdkdevice-xi2.c
gdk/x11/gdkdevicemanager-xi2.c
gdk/x11/gdkprivate-x11.h

index 6e496261ebbe6ca3792dfb5e630b3e6c79950ea2..263b3f3a676898ca6cffc2b6d03b6a94f94a644c 100644 (file)
@@ -38,6 +38,7 @@ struct _ScrollValuator
   guint direction        : 4;
   guint last_value_valid : 1;
   gdouble last_value;
+  gdouble increment;
 };
 
 struct _GdkX11DeviceXI2
@@ -791,7 +792,8 @@ _gdk_x11_device_xi2_translate_state (XIModifierState *mods_state,
 void
 _gdk_x11_device_xi2_add_scroll_valuator (GdkX11DeviceXI2    *device,
                                          guint               n_valuator,
-                                         GdkScrollDirection  direction)
+                                         GdkScrollDirection  direction,
+                                         gdouble             increment)
 {
   ScrollValuator scroll;
 
@@ -801,6 +803,7 @@ _gdk_x11_device_xi2_add_scroll_valuator (GdkX11DeviceXI2    *device,
   scroll.n_valuator = n_valuator;
   scroll.direction = direction;
   scroll.last_value_valid = FALSE;
+  scroll.increment = increment;
 
   g_array_append_val (device->scroll_valuators, scroll);
 }
@@ -834,7 +837,7 @@ _gdk_x11_device_xi2_get_scroll_delta (GdkX11DeviceXI2    *device,
           if (scroll->last_value_valid)
             {
               if (delta_ret)
-                *delta_ret = valuator_value - scroll->last_value;
+                *delta_ret = (valuator_value - scroll->last_value) / scroll->increment;
 
               scroll->last_value = valuator_value;
             }
index b4a02565637ba98318d870bf92e0100cb168dcb7..6f93fd21b23af7dc271710076b71498fef033990 100644 (file)
@@ -247,15 +247,17 @@ translate_device_classes (GdkDisplay      *display,
               direction = GDK_SCROLL_RIGHT;
 
             GDK_NOTE (INPUT,
-                      g_message ("\n\tscroll valuator %d: %s",
+                      g_message ("\n\tscroll valuator %d: %s, increment %f",
                                  scroll_info->number,
                                  scroll_info->scroll_type == XIScrollTypeVertical
                                                 ? "vertical"
-                                                : "horizontal"));
+                                                : "horizontal",
+                                 scroll_info->increment));
 
             _gdk_x11_device_xi2_add_scroll_valuator (GDK_X11_DEVICE_XI2 (device),
                                                      scroll_info->number,
-                                                     direction);
+                                                     direction,
+                                                     scroll_info->increment);
           }
 #endif /* XINPUT_2_2 */
         default:
index 14ab2fd3911c38760001da8c7c659e9955a6f088..d17d4fd3dfa281e103827376eee030abb743e558 100644 (file)
@@ -239,7 +239,8 @@ GdkDevice * _gdk_x11_device_manager_xi2_lookup    (GdkX11DeviceManagerXI2 *devic
                                                    gint                    device_id);
 void     _gdk_x11_device_xi2_add_scroll_valuator  (GdkX11DeviceXI2    *device,
                                                    guint               n_valuator,
-                                                   GdkScrollDirection  direction);
+                                                   GdkScrollDirection  direction,
+                                                   gdouble             increment);
 gboolean  _gdk_x11_device_xi2_get_scroll_delta    (GdkX11DeviceXI2    *device,
                                                    guint               n_valuator,
                                                    gdouble             valuator_value,