Commit 6c257040 authored by Matthias Clasen's avatar Matthias Clasen

gtk: translate unhandled touch events to button events

We don't want to fallback for 'random' touch sequences, since
that could lead to all kinds of pairedness and other violations.
Since the X server already tells us what touch events it would
have used for emulating pointer events, we just use that information
here.
parent 68087281
......@@ -588,6 +588,8 @@ static gboolean gtk_widget_real_focus_in_event (GtkWidget *widget,
GdkEventFocus *event);
static gboolean gtk_widget_real_focus_out_event (GtkWidget *widget,
GdkEventFocus *event);
static gboolean gtk_widget_real_touch_event (GtkWidget *widget,
GdkEventTouch *event);
static gboolean gtk_widget_real_focus (GtkWidget *widget,
GtkDirectionType direction);
static void gtk_widget_real_move_focus (GtkWidget *widget,
......@@ -903,6 +905,7 @@ gtk_widget_class_init (GtkWidgetClass *klass)
klass->button_press_event = NULL;
klass->button_release_event = NULL;
klass->motion_notify_event = NULL;
klass->touch_event = gtk_widget_real_touch_event;
klass->delete_event = NULL;
klass->destroy_event = NULL;
klass->key_press_event = gtk_widget_real_key_press_event;
......@@ -5840,6 +5843,76 @@ gtk_widget_real_focus_out_event (GtkWidget *widget,
return FALSE;
}
static gboolean
gtk_widget_real_touch_event (GtkWidget *widget,
GdkEventTouch *event)
{
GdkEvent *bevent;
gboolean return_val;
gint signum;
if (!event->emulating_pointer)
return FALSE;
if (event->type == GDK_TOUCH_BEGIN ||
event->type == GDK_TOUCH_END)
{
GdkEventType type;
if (event->type == GDK_TOUCH_BEGIN)
{
type = GDK_BUTTON_PRESS;
signum = BUTTON_PRESS_EVENT;
}
else
{
type = GDK_BUTTON_RELEASE;
signum = BUTTON_RELEASE_EVENT;
}
bevent = gdk_event_new (type);
bevent->any.window = g_object_ref (event->window);
bevent->any.send_event = FALSE;
bevent->button.time = event->time;
bevent->button.state = event->state;
bevent->button.button = 1;
bevent->button.x_root = event->x_root;
bevent->button.y_root = event->y_root;
bevent->button.x = event->x;
bevent->button.y = event->y;
bevent->button.device = event->device;
bevent->button.axes = g_memdup (event->axes,
sizeof (gdouble) * gdk_device_get_n_axes (event->device));
gdk_event_set_source_device (bevent, gdk_event_get_source_device ((GdkEvent*)event));
}
else if (event->type == GDK_TOUCH_UPDATE)
{
signum = MOTION_NOTIFY_EVENT;
bevent = gdk_event_new (GDK_MOTION_NOTIFY);
bevent->any.window = g_object_ref (event->window);
bevent->any.send_event = FALSE;
bevent->motion.time = event->time;
bevent->motion.state = event->state;
bevent->motion.x_root = event->x_root;
bevent->motion.y_root = event->y_root;
bevent->motion.x = event->x;
bevent->motion.y = event->y;
bevent->motion.device = event->device;
bevent->motion.is_hint = FALSE;
bevent->motion.axes = g_memdup (event->axes,
sizeof (gdouble) * gdk_device_get_n_axes (event->device));
gdk_event_set_source_device (bevent, gdk_event_get_source_device ((GdkEvent*)event));
}
else
return FALSE;
g_signal_emit (widget, widget_signals[signum], 0, bevent, &return_val);
gdk_event_free (bevent);
return return_val;
}
#define WIDGET_REALIZED_FOR_EVENT(widget, event) \
(event->type == GDK_FOCUS_CHANGE || gtk_widget_get_realized(widget))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment