xi2: Normalize scroll deltas

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.
This commit is contained in:
Matthias Clasen 2012-03-04 19:12:27 -05:00
parent 47c190a1b7
commit 3dd5e88c07
3 changed files with 12 additions and 6 deletions

View 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;
}

View 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:

View 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,