[gtk/dnd-gestures-2: 156/173] notebook: Receive tab dnd on the tabs



commit 5ce7bfbbd803bb7fb935991c8f2d91050119fcf2
Author: Matthias Clasen <mclasen redhat com>
Date:   Tue Jan 7 18:08:25 2020 -0500

    notebook: Receive tab dnd on the tabs
    
    Don't make the whole notebook a drop target
    for tab dnd, but just the tab bar. This will
    help with drag highlighting, and it arguably
    more correct anyway.

 gtk/gtknotebook.c | 30 ++++++++++++++++--------------
 1 file changed, 16 insertions(+), 14 deletions(-)
---
diff --git a/gtk/gtknotebook.c b/gtk/gtknotebook.c
index 04dfc677df..108eee659c 100644
--- a/gtk/gtknotebook.c
+++ b/gtk/gtknotebook.c
@@ -1324,15 +1324,6 @@ gtk_notebook_init (GtkNotebook *notebook)
   priv->detached_tab = NULL;
   priv->has_scrolled = FALSE;
 
-  targets = gdk_content_formats_new (dst_notebook_targets, G_N_ELEMENTS (dst_notebook_targets));
-  dest = gtk_drop_target_new (targets, GDK_ACTION_MOVE);
-  g_signal_connect (dest, "drag-motion", G_CALLBACK (gtk_notebook_drag_motion), NULL);
-  g_signal_connect (dest, "drag-leave", G_CALLBACK (gtk_notebook_drag_leave), NULL);
-  g_signal_connect (dest, "drag-drop", G_CALLBACK (gtk_notebook_drag_drop), NULL);
-  gtk_widget_add_controller (GTK_WIDGET (notebook), GTK_EVENT_CONTROLLER (dest));
-
-  gdk_content_formats_unref (targets);
-
   priv->header_widget = g_object_new (GTK_TYPE_BOX,
                                       "css-name", "header",
                                       NULL);
@@ -1354,6 +1345,14 @@ gtk_notebook_init (GtkNotebook *notebook)
   gtk_widget_set_vexpand (priv->stack_widget, TRUE);
   gtk_widget_set_parent (priv->stack_widget, GTK_WIDGET (notebook));
 
+  targets = gdk_content_formats_new (dst_notebook_targets, G_N_ELEMENTS (dst_notebook_targets));
+  dest = gtk_drop_target_new (targets, GDK_ACTION_MOVE);
+  g_signal_connect (dest, "drag-motion", G_CALLBACK (gtk_notebook_drag_motion), NULL);
+  g_signal_connect (dest, "drag-leave", G_CALLBACK (gtk_notebook_drag_leave), NULL);
+  g_signal_connect (dest, "drag-drop", G_CALLBACK (gtk_notebook_drag_drop), NULL);
+  gtk_widget_add_controller (GTK_WIDGET (priv->tabs_widget), GTK_EVENT_CONTROLLER (dest));
+  gdk_content_formats_unref (targets);
+
   gesture = gtk_gesture_click_new ();
   gtk_gesture_single_set_button (GTK_GESTURE_SINGLE (gesture), 0);
   gtk_event_controller_set_propagation_phase (GTK_EVENT_CONTROLLER (gesture), GTK_PHASE_CAPTURE);
@@ -3192,7 +3191,8 @@ gtk_notebook_drag_motion (GtkDropTarget *dest,
                           int            x,
                           int            y)
 {
-  GtkWidget *widget = gtk_event_controller_get_widget (GTK_EVENT_CONTROLLER (dest));
+  GtkWidget *tabs = gtk_event_controller_get_widget (GTK_EVENT_CONTROLLER (dest));
+  GtkWidget *widget = gtk_widget_get_ancestor (tabs, GTK_TYPE_NOTEBOOK);
   GdkDrop *drop = gtk_drop_target_get_drop (dest);
   GtkNotebook *notebook = GTK_NOTEBOOK (widget);
   GtkNotebookPrivate *priv = notebook->priv;
@@ -3287,7 +3287,8 @@ gtk_notebook_drag_motion (GtkDropTarget *dest,
 static void
 gtk_notebook_drag_leave (GtkDropTarget *dest)
 {
-  GtkWidget *widget = gtk_event_controller_get_widget (GTK_EVENT_CONTROLLER (dest));
+  GtkWidget *tabs = gtk_event_controller_get_widget (GTK_EVENT_CONTROLLER (dest));
+  GtkWidget *widget = gtk_widget_get_ancestor (tabs, GTK_TYPE_NOTEBOOK);
   GtkNotebook *notebook = GTK_NOTEBOOK (widget);
 
   remove_switch_tab_timer (notebook);
@@ -3306,7 +3307,7 @@ got_page (GObject *source,
   GInputStream *stream;
   const char *mime_type;
 
-  source_widget = drag ? gtk_event_controller_get_widget (GTK_EVENT_CONTROLLER (drag)) : NULL;
+  source_widget = GTK_WIDGET (drag ? g_object_get_data (G_OBJECT (drag), "gtk-notebook-drag-origin") : NULL);
 
   stream = gdk_drop_read_finish (drop, result, &mime_type, NULL);
 
@@ -3333,14 +3334,15 @@ gtk_notebook_drag_drop (GtkDropTarget *dest,
                         int            x,
                         int            y)
 {
-  GtkWidget *widget = gtk_event_controller_get_widget (GTK_EVENT_CONTROLLER (dest));
+  GtkWidget *tabs = gtk_event_controller_get_widget (GTK_EVENT_CONTROLLER (dest));
+  GtkWidget *widget = gtk_widget_get_ancestor (tabs, GTK_TYPE_NOTEBOOK);
   GtkNotebook *notebook = GTK_NOTEBOOK (widget);
   GdkDrop *drop = gtk_drop_target_get_drop (dest);
   GdkDrag *drag = gdk_drop_get_drag (drop);
   GtkWidget *source_widget;
   GdkAtom target, tab_target;
 
-  source_widget = drag ? gtk_event_controller_get_widget (GTK_EVENT_CONTROLLER (drag)) : NULL;
+  source_widget = GTK_WIDGET (drag ? g_object_get_data (G_OBJECT (drag), "gtk-notebook-drag-origin") : NULL);
 
   target = gtk_drop_target_find_mimetype (dest);
   tab_target = g_intern_static_string ("GTK_NOTEBOOK_TAB");


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