app: fix a CRITICAL when physical device axis list changes.

After some investigation, I am a bit unsure of why this happens exactly,
but I have a case that the device's axis number listed is not right and
this only becomes apparent after the stylus gets close then further from
the tablet-display. This fixes it, though I think we should look more
closely and reorganize a bit this whole part of our code, which seems
unecessarily complicated and duplicating some data already in GTK/GDK,
like the list of axis, etc. (though maybe it was necessary back when
this was first implemented before more logics got moved to GDK?)
This commit is contained in:
Jehan 2022-03-26 16:27:54 +01:00
parent 7ca324fb2d
commit c799d5235e
1 changed files with 33 additions and 0 deletions

View File

@ -595,6 +595,39 @@ gimp_device_info_tool_changed (GdkDevice *device,
{
g_object_freeze_notify (G_OBJECT (info));
/* GDK docs says that the number of axes can change on "changed"
* signal for virtual devices only, but here, I encounter a change of
* number of axes on a physical device, the first time when a stylus
* approached then moved away from the active surface. When the tool
* became then a GDK_DEVICE_TOOL_TYPE_UNKNOWN, I had one more axis
* (which created criticals later).
* So let's check specifically for such case.
*/
if (info->priv->n_axes != gdk_device_get_n_axes (device))
{
gint n_axes = gdk_device_get_n_axes (device);
gint old_n_axes = info->priv->n_axes;
gint i;
for (i = n_axes; i < info->priv->n_axes; i++)
g_free (info->priv->axes_names[i]);
info->priv->axes_names = g_renew (gchar *, info->priv->axes_names, n_axes + 1);
for (i = info->priv->n_axes; i < n_axes + 1; i++)
info->priv->axes_names[i] = NULL;
info->priv->axes_uses = g_renew (GdkAxisUse, info->priv->axes_uses, n_axes);
info->priv->n_axes = n_axes;
for (i = old_n_axes; i < n_axes; i++)
{
GdkAxisUse axis_use;
axis_use = gdk_device_get_axis_use (info->priv->device, i);
gimp_device_info_set_axis_use (info, i, axis_use);
}
}
g_object_notify (G_OBJECT (info), "tool-type");
g_object_notify (G_OBJECT (info), "tool-serial");
g_object_notify (G_OBJECT (info), "tool-hardware-id");