[gtk+/touchscreens: 26/67] scrolledwindow: add another shortcut to bypass event capture



commit 10774d735cbed2ec410c33d51e7c4d0c0f074cae
Author: Carlos Garnacho <carlosg gnome org>
Date:   Tue Nov 1 12:55:06 2011 +0100

    scrolledwindow: add another shortcut to bypass event capture
    
    When clicked again close to the previous button press location
    (assuming it had ~0 movement), the scrolled window wil allow
    the child to handle the events immediately.
    
    This is so the user doesn't have to wait to the p-a-h timeout
    in order to operate on the scrolledwindow child.

 gtk/gtkscrolledwindow.c |   29 +++++++++++++++++++++++++++++
 1 files changed, 29 insertions(+), 0 deletions(-)
---
diff --git a/gtk/gtkscrolledwindow.c b/gtk/gtkscrolledwindow.c
index d491548..f99a266 100644
--- a/gtk/gtkscrolledwindow.c
+++ b/gtk/gtkscrolledwindow.c
@@ -125,6 +125,7 @@
 
 #define DEFAULT_SCROLLBAR_SPACING  3
 #define AUTO_HIDE_SCROLLBARS_TIMEOUT 1000
+#define TOUCH_BYPASS_CAPTURED_THRESHOLD 30
 
 /* Kinetic scrolling */
 #define FPS 60
@@ -184,6 +185,9 @@ struct _GtkScrolledWindowPrivate
   gdouble                deceleration_rate;
   gdouble                overshoot;
   guint                  accumulated_delta;
+
+  gdouble                last_button_event_x_root;
+  gdouble                last_button_event_y_root;
 };
 
 enum {
@@ -607,6 +611,8 @@ gtk_scrolled_window_init (GtkScrolledWindow *scrolled_window)
   priv->min_content_width = -1;
   priv->min_content_height = -1;
   priv->deceleration_rate = 1.1f;
+  priv->last_button_event_x_root = -TOUCH_BYPASS_CAPTURED_THRESHOLD;
+  priv->last_button_event_y_root = -TOUCH_BYPASS_CAPTURED_THRESHOLD;
 }
 
 /**
@@ -2953,6 +2959,12 @@ gtk_scrolled_window_button_release_event (GtkWidget *widget,
   distance = gtk_scrolled_window_get_deceleration_distance (scrolled_window, event->x_root, event->y_root);
   gtk_scrolled_window_start_deceleration (scrolled_window, distance);
 
+  if (distance == 0)
+    {
+      priv->last_button_event_x_root = event->x_root;
+      priv->last_button_event_y_root = event->y_root;
+    }
+
   /* Reset motion event buffer */
   motion_event_list_reset (&priv->motion_events);
 
@@ -2994,6 +3006,9 @@ gtk_scrolled_window_motion_notify_event (GtkWidget *widget,
         return FALSE;
     }
 
+  priv->last_button_event_x_root = -TOUCH_BYPASS_CAPTURED_THRESHOLD;
+  priv->last_button_event_y_root = -TOUCH_BYPASS_CAPTURED_THRESHOLD;
+
   if (priv->button_press_event)
     {
       gdk_event_free (priv->button_press_event);
@@ -3052,6 +3067,20 @@ gtk_scrolled_window_button_press_event (GtkWidget *widget,
 
   event = (GdkEventButton *)_event;
 
+  /* Check whether the button press is close to the previous one,
+   * take that as a shortcut to get the child widget handle events
+   */
+  if (ABS (event->x_root - priv->last_button_event_x_root) < TOUCH_BYPASS_CAPTURED_THRESHOLD &&
+      ABS (event->y_root - priv->last_button_event_y_root) < TOUCH_BYPASS_CAPTURED_THRESHOLD)
+    {
+      priv->last_button_event_x_root = -TOUCH_BYPASS_CAPTURED_THRESHOLD;
+      priv->last_button_event_y_root = -TOUCH_BYPASS_CAPTURED_THRESHOLD;
+      return FALSE;
+    }
+
+  priv->last_button_event_x_root = event->x_root;
+  priv->last_button_event_y_root = event->y_root;
+
   if (event->button != 1)
     return FALSE;
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]