[gtk+/gestures: 85/140] colorswatch: Replace GtkPressAndHold
- From: Carlos Garnacho <carlosg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+/gestures: 85/140] colorswatch: Replace GtkPressAndHold
- Date: Tue, 6 May 2014 16:48:04 +0000 (UTC)
commit 8690fd7e8529cf716407a9d369b1aad21bd9f975
Author: Carlos Garnacho <carlosg gnome org>
Date: Tue Apr 8 21:18:38 2014 +0200
colorswatch: Replace GtkPressAndHold
GtkGestureLongPress and GtkGestureMultiPress are both used
to replace it.
gtk/gtkcolorswatch.c | 91 ++++++++++++++++++++++++-------------------------
1 files changed, 45 insertions(+), 46 deletions(-)
---
diff --git a/gtk/gtkcolorswatch.c b/gtk/gtkcolorswatch.c
index e2017a9..ed61f85 100644
--- a/gtk/gtkcolorswatch.c
+++ b/gtk/gtkcolorswatch.c
@@ -28,7 +28,6 @@
#include "gtkmenu.h"
#include "gtkmenuitem.h"
#include "gtkmenushell.h"
-#include "gtkpressandholdprivate.h"
#include "gtkprivate.h"
#include "gtkintl.h"
#include "a11y/gtkcolorswatchaccessibleprivate.h"
@@ -46,7 +45,8 @@ struct _GtkColorSwatchPrivate
GdkWindow *event_window;
- GtkPressAndHold *press_and_hold;
+ GtkGesture *long_press_gesture;
+ GtkGesture *multipress_gesture;
};
enum
@@ -65,6 +65,16 @@ enum
static guint signals[LAST_SIGNAL];
+static void hold_action (GtkGestureLongPress *gesture,
+ gdouble x,
+ gdouble y,
+ GtkColorSwatch *swatch);
+static void tap_action (GtkGestureMultiPress *gesture,
+ gint n_press,
+ gdouble x,
+ gdouble y,
+ GtkColorSwatch *swatch);
+
G_DEFINE_TYPE_WITH_PRIVATE (GtkColorSwatch, gtk_color_swatch, GTK_TYPE_WIDGET)
static void
@@ -76,6 +86,18 @@ gtk_color_swatch_init (GtkColorSwatch *swatch)
gtk_widget_set_can_focus (GTK_WIDGET (swatch), TRUE);
gtk_widget_set_has_window (GTK_WIDGET (swatch), FALSE);
+
+ swatch->priv->long_press_gesture = gtk_gesture_long_press_new (GTK_WIDGET (swatch));
+ g_signal_connect (swatch->priv->long_press_gesture, "pressed",
+ G_CALLBACK (hold_action), swatch);
+ gtk_widget_add_controller (GTK_WIDGET (swatch),
+ GTK_EVENT_CONTROLLER (swatch->priv->long_press_gesture));
+
+ swatch->priv->multipress_gesture = gtk_gesture_multi_press_new (GTK_WIDGET (swatch));
+ g_signal_connect (swatch->priv->multipress_gesture, "pressed",
+ G_CALLBACK (tap_action), swatch);
+ gtk_widget_add_controller (GTK_WIDGET (swatch),
+ GTK_EVENT_CONTROLLER (swatch->priv->multipress_gesture));
}
#define INTENSITY(r, g, b) ((r) * 0.30 + (g) * 0.59 + (b) * 0.11)
@@ -527,53 +549,24 @@ swatch_button_release (GtkWidget *widget,
}
static void
-hold_action (GtkPressAndHold *pah,
- gint x,
- gint y,
- GtkColorSwatch *swatch)
+hold_action (GtkGestureLongPress *gesture,
+ gdouble x,
+ gdouble y,
+ GtkColorSwatch *swatch)
{
emit_customize (swatch);
+ gtk_gesture_set_state (GTK_GESTURE (gesture), GTK_EVENT_SEQUENCE_CLAIMED);
}
static void
-tap_action (GtkPressAndHold *pah,
- gint x,
- gint y,
- GtkColorSwatch *swatch)
-{
- swatch_primary_action (swatch);
-}
-
-static gboolean
-swatch_touch (GtkWidget *widget,
- GdkEventTouch *event)
+tap_action (GtkGestureMultiPress *gesture,
+ gint n_press,
+ gdouble x,
+ gdouble y,
+ GtkColorSwatch *swatch)
{
- GtkColorSwatch *swatch = GTK_COLOR_SWATCH (widget);
-
- if (!swatch->priv->press_and_hold)
- {
- gint drag_threshold;
-
- g_object_get (gtk_widget_get_settings (widget),
- "gtk-dnd-drag-threshold", &drag_threshold,
- NULL);
-
- swatch->priv->press_and_hold = gtk_press_and_hold_new ();
-
- g_object_set (swatch->priv->press_and_hold,
- "drag-threshold", drag_threshold,
- "hold-time", 1000,
- NULL);
-
- g_signal_connect (swatch->priv->press_and_hold, "hold",
- G_CALLBACK (hold_action), swatch);
- g_signal_connect (swatch->priv->press_and_hold, "tap",
- G_CALLBACK (tap_action), swatch);
- }
-
- gtk_press_and_hold_process_event (swatch->priv->press_and_hold, (GdkEvent *)event);
-
- return TRUE;
+ if (n_press == 1)
+ swatch_primary_action (swatch);
}
static void
@@ -727,7 +720,14 @@ swatch_finalize (GObject *object)
GtkColorSwatch *swatch = GTK_COLOR_SWATCH (object);
g_free (swatch->priv->icon);
- g_clear_object (&swatch->priv->press_and_hold);
+
+ gtk_widget_remove_controller (GTK_WIDGET (object),
+ GTK_EVENT_CONTROLLER (swatch->priv->long_press_gesture));
+ g_object_unref (swatch->priv->long_press_gesture);
+
+ gtk_widget_remove_controller (GTK_WIDGET (object),
+ GTK_EVENT_CONTROLLER (swatch->priv->multipress_gesture));
+ g_object_unref (swatch->priv->multipress_gesture);
G_OBJECT_CLASS (gtk_color_swatch_parent_class)->finalize (object);
}
@@ -759,7 +759,6 @@ gtk_color_swatch_class_init (GtkColorSwatchClass *class)
widget_class->map = swatch_map;
widget_class->unmap = swatch_unmap;
widget_class->size_allocate = swatch_size_allocate;
- widget_class->touch_event = swatch_touch;
signals[ACTIVATE] =
g_signal_new ("activate",
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]