Commit 0106099f authored by Matthias Clasen's avatar Matthias Clasen Committed by Carlos Garnacho

GtkButton: Port to GtkGesture

Quick-and-dirty patch to use a GtkGestureSingle for both
button press/release and touch event handling.
parent f73f4d82
......@@ -119,12 +119,6 @@ static void gtk_button_style_updated (GtkWidget * widget);
static void gtk_button_size_allocate (GtkWidget * widget,
GtkAllocation * allocation);
static gint gtk_button_draw (GtkWidget * widget, cairo_t *cr);
static gint gtk_button_button_press (GtkWidget * widget,
GdkEventButton * event);
static gint gtk_button_button_release (GtkWidget * widget,
GdkEventButton * event);
static gboolean gtk_button_touch (GtkWidget *widget,
GdkEventTouch *event);
static gint gtk_button_grab_broken (GtkWidget * widget,
GdkEventGrabBroken * event);
static gint gtk_button_key_release (GtkWidget * widget, GdkEventKey * event);
......@@ -225,9 +219,6 @@ gtk_button_class_init (GtkButtonClass *klass)
widget_class->style_updated = gtk_button_style_updated;
widget_class->size_allocate = gtk_button_size_allocate;
widget_class->draw = gtk_button_draw;
widget_class->button_press_event = gtk_button_button_press;
widget_class->button_release_event = gtk_button_button_release;
widget_class->touch_event = gtk_button_touch;
widget_class->grab_broken_event = gtk_button_grab_broken;
widget_class->key_release_event = gtk_button_key_release;
widget_class->enter_notify_event = gtk_button_enter_notify;
......@@ -593,6 +584,30 @@ gtk_button_class_init (GtkButtonClass *klass)
gtk_widget_class_set_accessible_type (widget_class, GTK_TYPE_BUTTON_ACCESSIBLE);
}
static void
gesture_begin_cb (GtkGesture *gesture,
gpointer sequence,
GtkWidget *widget)
{
GtkButton *button = GTK_BUTTON (widget);
GtkButtonPrivate *priv = button->priv;
if (priv->focus_on_click && !gtk_widget_has_focus (widget))
gtk_widget_grab_focus (widget);
g_signal_emit (button, button_signals[PRESSED], 0);
}
static void
gesture_end_cb (GtkGesture *gesture,
gpointer sequence,
GtkWidget *widget)
{
GtkButton *button = GTK_BUTTON (widget);
g_signal_emit (button, button_signals[RELEASED], 0);
}
static void
gtk_button_init (GtkButton *button)
{
......@@ -627,6 +642,14 @@ gtk_button_init (GtkButton *button)
context = gtk_widget_get_style_context (GTK_WIDGET (button));
gtk_style_context_add_class (context, GTK_STYLE_CLASS_BUTTON);
priv->gesture = GTK_GESTURE (g_object_new (GTK_TYPE_GESTURE_SINGLE, "widget", button, NULL));
gtk_gesture_single_set_touch_only (GTK_GESTURE_SINGLE (priv->gesture), FALSE);
gtk_gesture_single_set_button (GTK_GESTURE_SINGLE (priv->gesture), GDK_BUTTON_PRIMARY);
g_signal_connect (priv->gesture, "begin", G_CALLBACK (gesture_begin_cb), button);
g_signal_connect (priv->gesture, "end", G_CALLBACK (gesture_end_cb), button);
gtk_widget_add_controller (GTK_WIDGET (button),
GTK_EVENT_CONTROLLER (priv->gesture));
}
static void
......@@ -1849,75 +1872,6 @@ gtk_button_draw (GtkWidget *widget,
return FALSE;
}
static gboolean
gtk_button_button_press (GtkWidget *widget,
GdkEventButton *event)
{
GtkButton *button;
GtkButtonPrivate *priv;
if (event->type == GDK_BUTTON_PRESS)
{
button = GTK_BUTTON (widget);
priv = button->priv;
if (priv->focus_on_click && !gtk_widget_has_focus (widget))
gtk_widget_grab_focus (widget);
if (event->button == GDK_BUTTON_PRIMARY)
{
g_signal_emit (button, button_signals[PRESSED], 0);
return GDK_EVENT_STOP;
}
}
else if (event->type == GDK_2BUTTON_PRESS)
{
return GDK_EVENT_STOP;
}
return GDK_EVENT_PROPAGATE;
}
static gboolean
gtk_button_button_release (GtkWidget *widget,
GdkEventButton *event)
{
GtkButton *button;
if (event->button == GDK_BUTTON_PRIMARY)
{
button = GTK_BUTTON (widget);
g_signal_emit (button, button_signals[RELEASED], 0);
return GDK_EVENT_STOP;
}
return GDK_EVENT_PROPAGATE;
}
static gboolean
gtk_button_touch (GtkWidget *widget,
GdkEventTouch *event)
{
GtkButton *button = GTK_BUTTON (widget);
GtkButtonPrivate *priv = button->priv;
if (event->type == GDK_TOUCH_BEGIN)
{
if (priv->focus_on_click && !gtk_widget_has_focus (widget))
gtk_widget_grab_focus (widget);
g_signal_emit (button, button_signals[PRESSED], 0);
return GDK_EVENT_STOP;
}
else if (event->type == GDK_TOUCH_END)
{
g_signal_emit (button, button_signals[RELEASED], 0);
return GDK_EVENT_STOP;
}
return GDK_EVENT_PROPAGATE;
}
static void
gtk_button_do_release (GtkButton *button,
gboolean emit_clicked)
......
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