[gtk/wip/otte/bitset: 23/23] listbase: Make rubberbanding a threshold drag



commit 20fcace0a2c77451957a887dce099d6f1988b178
Author: Benjamin Otte <otte redhat com>
Date:   Fri Jun 26 04:07:35 2020 +0200

    listbase: Make rubberbanding a threshold drag

 gtk/gtklistbase.c | 22 ++++++++++++----------
 1 file changed, 12 insertions(+), 10 deletions(-)
---
diff --git a/gtk/gtklistbase.c b/gtk/gtklistbase.c
index edd68833df..5a1a38e40a 100644
--- a/gtk/gtklistbase.c
+++ b/gtk/gtklistbase.c
@@ -23,6 +23,7 @@
 
 #include "gtkadjustment.h"
 #include "gtkbitset.h"
+#include "gtkdragsource.h"
 #include "gtkdropcontrollermotion.h"
 #include "gtkgesturedrag.h"
 #include "gtkgizmoprivate.h"
@@ -1696,23 +1697,25 @@ get_selection_modifiers (GtkGesture *gesture,
     *extend = TRUE;
 }
 
-static void
-gtk_list_base_drag_begin (GtkGestureDrag *gesture,
-                          double          start_x,
-                          double          start_y,
-                          GtkListBase    *self)
-{
-  gtk_list_base_start_rubberband (self, start_x, start_y);
-}
-
 static void
 gtk_list_base_drag_update (GtkGestureDrag *gesture,
                            double          offset_x,
                            double          offset_y,
                            GtkListBase    *self)
 {
+  GtkListBasePrivate *priv = gtk_list_base_get_instance_private (self);
   double start_x, start_y;
+
   gtk_gesture_drag_get_start_point (gesture, &start_x, &start_y);
+
+  if (!priv->rubberband)
+    {
+      if (!gtk_drag_check_threshold (GTK_WIDGET (self), 0, 0, offset_x, offset_y))
+        return;
+      
+      gtk_gesture_set_state (GTK_GESTURE (gesture), GTK_EVENT_SEQUENCE_CLAIMED);
+      gtk_list_base_start_rubberband (self, start_x, start_y);
+    }
   gtk_list_base_update_rubberband (self, start_x + offset_x, start_y + offset_y);
 }
 
@@ -1743,7 +1746,6 @@ gtk_list_base_set_enable_rubberband (GtkListBase *self,
   if (enable)
     {
       priv->drag_gesture = gtk_gesture_drag_new ();
-      g_signal_connect (priv->drag_gesture, "drag-begin", G_CALLBACK (gtk_list_base_drag_begin), self);
       g_signal_connect (priv->drag_gesture, "drag-update", G_CALLBACK (gtk_list_base_drag_update), self);
       g_signal_connect (priv->drag_gesture, "drag-end", G_CALLBACK (gtk_list_base_drag_end), self);
       gtk_widget_add_controller (GTK_WIDGET (self), GTK_EVENT_CONTROLLER (priv->drag_gesture));


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