From 1d9965c972625318bc885afc97d7e443c6619eef Mon Sep 17 00:00:00 2001 From: Simon Schampijer Date: Thu, 25 Oct 2012 08:17:42 +0200 Subject: [PATCH] SugarLongPress gesture controller: remove animation We found out that the animation does not solve the issue of visually indicating the long-press gesture to our satisfaction. This is because you do not know upfront which icon does have a primary action and more options that can be revealed with the long-press gesture and the animation itself. We would need to theme the gesture better first as well. That the animation is a separate window does raise several side effects as well which we would need to solve first. Signed-off-by: Simon Schampijer Reviewed-by: Carlos Garnacho --- .../sugar-long-press-controller.c | 159 ------------------ 1 file changed, 159 deletions(-) diff --git a/src/sugar3/event-controller/sugar-long-press-controller.c b/src/sugar3/event-controller/sugar-long-press-controller.c index eee70dbe..64c41bf5 100644 --- a/src/sugar3/event-controller/sugar-long-press-controller.c +++ b/src/sugar3/event-controller/sugar-long-press-controller.c @@ -23,8 +23,6 @@ #define DEFAULT_THRESHOLD 32 #define DEFAULT_TRIGGER_DELAY 800 -#define ANIM_WINDOW_WIDTH 100 -#define ARC_LINE_WIDTH 10 typedef struct _SugarLongPressControllerPriv SugarLongPressControllerPriv; @@ -43,13 +41,11 @@ struct _SugarLongPressControllerPriv { GdkDevice *device; GdkEventSequence *sequence; - GtkWidget *anim_window; gint64 start_time; gint x; gint y; gint root_x; gint root_y; - guint anim_id; guint timeout_id; guint threshold; guint delay; @@ -99,16 +95,6 @@ _sugar_long_press_controller_cancel (SugarLongPressController *controller) { SugarLongPressControllerPriv *priv = controller->_priv; - if (priv->anim_id) - { - g_source_remove (priv->anim_id); - priv->anim_id = 0; - } - - if (priv->anim_window && - gtk_widget_get_visible (priv->anim_window)) - gtk_widget_hide (priv->anim_window); - if (priv->timeout_id) { g_source_remove (priv->timeout_id); @@ -177,147 +163,6 @@ sugar_long_press_controller_finalize (GObject *object) G_OBJECT_CLASS (sugar_long_press_controller_parent_class)->finalize (object); } -static void -_stroke_progress_notification (cairo_t *cr, - gdouble progress) -{ - cairo_set_line_width (cr, ARC_LINE_WIDTH); - cairo_arc (cr, - ANIM_WINDOW_WIDTH / 2, - ANIM_WINDOW_WIDTH / 2, - ANIM_WINDOW_WIDTH / 2 - ARC_LINE_WIDTH / 2, - - G_PI_2, (2 * G_PI * progress) - G_PI_2); - cairo_stroke (cr); -} - -static gboolean -_sugar_long_press_anim_draw (GtkWidget *widget, - cairo_t *cr, - SugarLongPressController *controller) -{ - SugarLongPressControllerPriv *priv = controller->_priv; - GtkStyleContext *context; - gdouble progress; - gint64 diff_msec; - GdkRGBA color; - - diff_msec = (g_get_monotonic_time () - priv->start_time) / 1000; - progress = (gdouble) diff_msec / priv->delay; - - context = gtk_widget_get_style_context (widget); - gtk_style_context_save (context); - cairo_save (cr); - - gtk_style_context_add_class (context, "long-press-notification"); - gtk_style_context_get_color (context, GTK_STATE_FLAG_NORMAL, &color); - - gdk_cairo_set_source_rgba (cr, &color); - _stroke_progress_notification (cr, progress); - - gtk_style_context_restore (context); - cairo_restore (cr); - - return TRUE; -} - -static void -_sugar_long_press_controller_update_shape (GtkWidget *widget, - SugarLongPressController *controller) -{ - cairo_surface_t *surface; - cairo_region_t *region; - cairo_t *cr; - - surface = cairo_image_surface_create (CAIRO_FORMAT_A1, - ANIM_WINDOW_WIDTH, - ANIM_WINDOW_WIDTH); - cr = cairo_create (surface); - _stroke_progress_notification (cr, 1.0); - cairo_destroy (cr); - - region = gdk_cairo_region_create_from_surface (surface); - cairo_surface_destroy (surface); - - gtk_widget_shape_combine_region (widget, region); - cairo_region_destroy (region); -} - -static gboolean -_sugar_long_press_anim_timeout (gpointer user_data) -{ - SugarLongPressController *controller = user_data; - SugarLongPressControllerPriv *priv = controller->_priv; - GtkWidget *widget; - - g_object_get (controller, "widget", &widget, NULL); - - if (!widget) - { - priv->anim_id = 0; - return FALSE; - } - - if (priv->anim_window && - gtk_widget_get_screen (widget) != - gtk_widget_get_screen (priv->anim_window)) - { - gtk_widget_destroy (priv->anim_window); - priv->anim_window = NULL; - } - - if (!priv->anim_window) - { - GdkScreen *screen; - GdkVisual *rgba_visual; - - priv->anim_window = gtk_window_new (GTK_WINDOW_POPUP); - gtk_widget_set_app_paintable (priv->anim_window, TRUE); - gtk_widget_input_shape_combine_region (priv->anim_window, NULL); - gtk_window_set_type_hint (GTK_WINDOW (priv->anim_window), - GDK_WINDOW_TYPE_HINT_UTILITY); - - screen = gtk_widget_get_screen (widget); - rgba_visual = gdk_screen_get_rgba_visual (screen); - - gtk_window_set_screen (GTK_WINDOW (priv->anim_window), screen); - - if (rgba_visual && gdk_screen_is_composited (screen)) - { - GdkRGBA bg = { 0, 0, 0, 0 }; - - gtk_widget_set_visual (priv->anim_window, rgba_visual); - gtk_widget_override_background_color (priv->anim_window, 0, &bg); - } - else - _sugar_long_press_controller_update_shape (priv->anim_window, - controller); - - g_signal_connect (priv->anim_window, "draw", - G_CALLBACK (_sugar_long_press_anim_draw), - controller); - } - - if (!gtk_widget_get_visible (priv->anim_window)) - { - gtk_window_move (GTK_WINDOW (priv->anim_window), - priv->root_x - (ANIM_WINDOW_WIDTH / 2), - priv->root_y - (ANIM_WINDOW_WIDTH / 2)); - gtk_window_resize (GTK_WINDOW (priv->anim_window), - ANIM_WINDOW_WIDTH, ANIM_WINDOW_WIDTH); - gtk_widget_show (priv->anim_window); - - priv->anim_id = - gdk_threads_add_timeout (20, _sugar_long_press_anim_timeout, - controller); - return FALSE; - } - else - { - gtk_widget_queue_draw (priv->anim_window); - return TRUE; - } -} - static gboolean _sugar_long_press_controller_timeout (gpointer user_data) { @@ -408,10 +253,6 @@ sugar_long_press_controller_handle_event (SugarEventController *controller, priv->root_y = event->touch.y_root; priv->sequence = sequence; - priv->anim_id = - gdk_threads_add_timeout (100, - _sugar_long_press_anim_timeout, - controller); priv->timeout_id = gdk_threads_add_timeout (priv->delay, _sugar_long_press_controller_timeout,