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
This commit is contained in:
Carlos Garnacho 2015-03-02 18:19:16 +01:00
parent 3ccfcf5b9f
commit 4cae9bdd05
3 changed files with 42 additions and 2 deletions

View File

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

View File

@ -837,6 +837,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");
@ -939,13 +940,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++;
@ -970,6 +974,8 @@ translate_axes (GdkDevice *device,
}
}
gdk_x11_device_xi2_store_axes (GDK_X11_DEVICE_XI2 (device), axes, n_axes);
return axes;
}

View File

@ -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);