mirror of
https://gitlab.gnome.org/GNOME/gtk.git
synced 2024-11-10 10:50:10 +00:00
gdk: Make events hold an axis array matching GdkAxisUse
Instead of doing device-specific translations of array positions, use GdkAxisUse as an array index right away.
This commit is contained in:
parent
7629f6d533
commit
4a2bbed157
@ -732,25 +732,24 @@ gdk_motion_event_push_history (GdkEvent *event,
|
||||
GdkEvent *history_event)
|
||||
{
|
||||
GdkMotionEvent *self = (GdkMotionEvent *) event;
|
||||
GdkDeviceTool *tool;
|
||||
GdkTimeCoord hist;
|
||||
GdkDevice *device;
|
||||
int i, n_axes;
|
||||
int i;
|
||||
|
||||
g_assert (GDK_IS_EVENT_TYPE (event, GDK_MOTION_NOTIFY));
|
||||
g_assert (GDK_IS_EVENT_TYPE (history_event, GDK_MOTION_NOTIFY));
|
||||
|
||||
device = gdk_event_get_device (history_event);
|
||||
n_axes = gdk_device_get_n_axes (device);
|
||||
if (!self->tool)
|
||||
return;
|
||||
|
||||
tool = gdk_event_get_device_tool (history_event);
|
||||
|
||||
memset (&hist, 0, sizeof (GdkTimeCoord));
|
||||
hist.time = gdk_event_get_time (history_event);
|
||||
hist.flags = gdk_device_get_axes (device);
|
||||
hist.flags = gdk_device_tool_get_axes (tool);
|
||||
|
||||
for (i = 0; i < n_axes; i++)
|
||||
{
|
||||
GdkAxisUse use = gdk_device_get_axis_use (device, i);
|
||||
gdk_event_get_axis (history_event, use, &hist.axes[use]);
|
||||
}
|
||||
for (i = GDK_AXIS_X; i < GDK_AXIS_LAST; i++)
|
||||
gdk_event_get_axis (history_event, i, &hist.axes[i]);
|
||||
|
||||
if (G_UNLIKELY (!self->history))
|
||||
self->history = g_array_new (FALSE, TRUE, sizeof (GdkTimeCoord));
|
||||
@ -952,10 +951,8 @@ gdk_event_get_axis (GdkEvent *event,
|
||||
if (!gdk_event_get_axes (event, &axes, &n_axes))
|
||||
return FALSE;
|
||||
|
||||
if (axis_use >= gdk_device_get_n_axes (event->device))
|
||||
return FALSE;
|
||||
|
||||
return gdk_device_get_axis (event->device, axes, axis_use, value);
|
||||
*value = axes[axis_use];
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1408,7 +1405,7 @@ gdk_button_event_get_axes (GdkEvent *event,
|
||||
return FALSE;
|
||||
|
||||
*axes = self->axes;
|
||||
*n_axes = gdk_device_get_n_axes (source_device);
|
||||
*n_axes = GDK_AXIS_LAST;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
@ -1985,7 +1982,7 @@ gdk_touch_event_get_axes (GdkEvent *event,
|
||||
return FALSE;
|
||||
|
||||
*axes = self->axes;
|
||||
*n_axes = gdk_device_get_n_axes (source_device);
|
||||
*n_axes = GDK_AXIS_LAST;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
@ -2865,7 +2862,7 @@ gdk_motion_event_get_axes (GdkEvent *event,
|
||||
return FALSE;
|
||||
|
||||
*axes = self->axes;
|
||||
*n_axes = gdk_device_get_n_axes (source_device);
|
||||
*n_axes = GDK_AXIS_LAST;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
@ -186,7 +186,7 @@ struct _GdkWaylandTabletData
|
||||
GdkWaylandTabletToolData *current_tool;
|
||||
|
||||
int axis_indices[GDK_AXIS_LAST];
|
||||
double *axes;
|
||||
double axes[GDK_AXIS_LAST];
|
||||
};
|
||||
|
||||
struct _GdkWaylandSeat
|
||||
@ -2755,9 +2755,6 @@ _gdk_wayland_seat_remove_tablet (GdkWaylandSeat *seat,
|
||||
if (tablet->pointer_info.focus)
|
||||
g_object_unref (tablet->pointer_info.focus);
|
||||
|
||||
if (tablet->axes)
|
||||
g_free (tablet->axes);
|
||||
|
||||
wl_surface_destroy (tablet->pointer_info.pointer_surface);
|
||||
g_object_unref (tablet->logical_device);
|
||||
g_object_unref (tablet->stylus_device);
|
||||
@ -3371,12 +3368,6 @@ gdk_wayland_device_tablet_clone_tool_axes (GdkWaylandTabletData *tablet,
|
||||
tablet->axis_indices[GDK_AXIS_SLIDER] = axis_pos;
|
||||
}
|
||||
|
||||
if (tablet->axes)
|
||||
g_free (tablet->axes);
|
||||
|
||||
tablet->axes =
|
||||
g_new0 (double, gdk_device_get_n_axes (tablet->stylus_device));
|
||||
|
||||
g_object_thaw_notify (G_OBJECT (tablet->stylus_device));
|
||||
}
|
||||
|
||||
@ -3492,7 +3483,7 @@ static double *
|
||||
tablet_copy_axes (GdkWaylandTabletData *tablet)
|
||||
{
|
||||
return g_memdup (tablet->axes,
|
||||
sizeof (double) * gdk_device_get_n_axes (tablet->stylus_device));
|
||||
sizeof (double) * GDK_AXIS_LAST);
|
||||
}
|
||||
|
||||
static void
|
||||
@ -3592,7 +3583,7 @@ tablet_tool_handle_pressure (void *data,
|
||||
int axis_index = tablet->axis_indices[GDK_AXIS_PRESSURE];
|
||||
|
||||
_gdk_device_translate_axis (tablet->stylus_device, axis_index,
|
||||
pressure, &tablet->axes[axis_index]);
|
||||
pressure, &tablet->axes[GDK_AXIS_PRESSURE]);
|
||||
|
||||
GDK_SEAT_NOTE (tool->seat, EVENTS,
|
||||
g_message ("tablet tool %d pressure %d",
|
||||
@ -3609,7 +3600,7 @@ tablet_tool_handle_distance (void *data,
|
||||
int axis_index = tablet->axis_indices[GDK_AXIS_DISTANCE];
|
||||
|
||||
_gdk_device_translate_axis (tablet->stylus_device, axis_index,
|
||||
distance, &tablet->axes[axis_index]);
|
||||
distance, &tablet->axes[GDK_AXIS_DISTANCE]);
|
||||
|
||||
GDK_SEAT_NOTE (tool->seat, EVENTS,
|
||||
g_message ("tablet tool %d distance %d",
|
||||
@ -3629,10 +3620,10 @@ tablet_tool_handle_tilt (void *data,
|
||||
|
||||
_gdk_device_translate_axis (tablet->stylus_device, xtilt_axis_index,
|
||||
wl_fixed_to_double (xtilt),
|
||||
&tablet->axes[xtilt_axis_index]);
|
||||
&tablet->axes[GDK_AXIS_XTILT]);
|
||||
_gdk_device_translate_axis (tablet->stylus_device, ytilt_axis_index,
|
||||
wl_fixed_to_double (ytilt),
|
||||
&tablet->axes[ytilt_axis_index]);
|
||||
&tablet->axes[GDK_AXIS_YTILT]);
|
||||
|
||||
GDK_SEAT_NOTE (tool->seat, EVENTS,
|
||||
g_message ("tablet tool %d tilt %f/%f",
|
||||
@ -3687,7 +3678,7 @@ tablet_tool_handle_rotation (void *data,
|
||||
|
||||
_gdk_device_translate_axis (tablet->stylus_device, axis_index,
|
||||
wl_fixed_to_double (degrees),
|
||||
&tablet->axes[axis_index]);
|
||||
&tablet->axes[GDK_AXIS_ROTATION]);
|
||||
|
||||
GDK_SEAT_NOTE (tool->seat, EVENTS,
|
||||
g_message ("tablet tool %d rotation %f",
|
||||
@ -3705,7 +3696,7 @@ tablet_tool_handle_slider (void *data,
|
||||
int axis_index = tablet->axis_indices[GDK_AXIS_SLIDER];
|
||||
|
||||
_gdk_device_translate_axis (tablet->stylus_device, axis_index,
|
||||
position, &tablet->axes[axis_index]);
|
||||
position, &tablet->axes[GDK_AXIS_SLIDER]);
|
||||
|
||||
GDK_SEAT_NOTE (tool->seat, EVENTS,
|
||||
g_message ("tablet tool %d slider %d",
|
||||
|
@ -201,18 +201,18 @@ _gdk_device_wintab_translate_axes (GdkDeviceWintab *device_wintab,
|
||||
minfo.rcWork.bottom - minfo.rcWork.top,
|
||||
i,
|
||||
device_wintab->last_axis_data[i],
|
||||
&axes[i]);
|
||||
&axes[use]);
|
||||
}
|
||||
if (use == GDK_AXIS_X)
|
||||
temp_x = axes[i];
|
||||
temp_x = axes[use];
|
||||
else if (use == GDK_AXIS_Y)
|
||||
temp_y = axes[i];
|
||||
temp_y = axes[use];
|
||||
|
||||
break;
|
||||
default:
|
||||
_gdk_device_translate_axis (device, i,
|
||||
device_wintab->last_axis_data[i],
|
||||
&axes[i]);
|
||||
&axes[use]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -1044,7 +1044,7 @@ gdk_input_other_event (GdkDisplay *display,
|
||||
if (event_type == GDK_BUTTON_PRESS ||
|
||||
event_type == GDK_BUTTON_RELEASE)
|
||||
{
|
||||
axes = g_new (double, num_axes);
|
||||
axes = g_new (double, GDK_AXIS_LAST);
|
||||
|
||||
_gdk_device_wintab_translate_axes (source_device,
|
||||
window,
|
||||
@ -1080,7 +1080,7 @@ gdk_input_other_event (GdkDisplay *display,
|
||||
}
|
||||
else
|
||||
{
|
||||
axes = g_new (double, num_axes);
|
||||
axes = g_new (double, GDK_AXIS_LAST);
|
||||
_gdk_device_wintab_translate_axes (source_device,
|
||||
window,
|
||||
axes,
|
||||
|
@ -1197,7 +1197,7 @@ translate_axes (GdkDevice *device,
|
||||
double *vals;
|
||||
|
||||
n_axes = gdk_device_get_n_axes (device);
|
||||
axes = g_new0 (double, n_axes);
|
||||
axes = g_new0 (double, GDK_AXIS_LAST);
|
||||
vals = valuators->values;
|
||||
|
||||
for (i = 0; i < MIN (valuators->mask_len * 8, n_axes); i++)
|
||||
@ -1206,10 +1206,7 @@ translate_axes (GdkDevice *device,
|
||||
double val;
|
||||
|
||||
if (!XIMaskIsSet (valuators->mask, i))
|
||||
{
|
||||
axes[i] = gdk_x11_device_xi2_get_last_axis_value (GDK_X11_DEVICE_XI2 (device), i);
|
||||
continue;
|
||||
}
|
||||
continue;
|
||||
|
||||
use = gdk_device_get_axis_use (device, i);
|
||||
val = *vals++;
|
||||
@ -1220,13 +1217,13 @@ translate_axes (GdkDevice *device,
|
||||
case GDK_AXIS_Y:
|
||||
{
|
||||
if (use == GDK_AXIS_X)
|
||||
axes[i] = x;
|
||||
axes[use] = x;
|
||||
else
|
||||
axes[i] = y;
|
||||
axes[use] = y;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
_gdk_device_translate_axis (device, i, val, &axes[i]);
|
||||
_gdk_device_translate_axis (device, i, val, &axes[use]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user