[nautilus/wip/ernestask/gtk4-continued: 7/50] canvas-container: Draw DnD highlight in snapshot()



commit 6e473f22d76543c2dd61a683626a9082e3afba5d
Author: Ernestas Kulik <ernestask gnome org>
Date:   Wed Jul 25 09:16:58 2018 +0300

    canvas-container: Draw DnD highlight in snapshot()
    
    …instead of connecting to GtkWidget::draw, which has been removed.

 src/nautilus-canvas-container.c | 31 +++++++++++++++++++++++++++++++
 src/nautilus-canvas-dnd.c       | 34 +---------------------------------
 2 files changed, 32 insertions(+), 33 deletions(-)
---
diff --git a/src/nautilus-canvas-container.c b/src/nautilus-canvas-container.c
index db91e84a3..ee727d6b3 100644
--- a/src/nautilus-canvas-container.c
+++ b/src/nautilus-canvas-container.c
@@ -3421,6 +3421,36 @@ nautilus_canvas_container_constructor (GType                  type,
     return object;
 }
 
+static void
+nautilus_canvas_container_snapshot (GtkWidget   *widget,
+                                    GtkSnapshot *snapshot)
+{
+    NautilusCanvasContainer *container;
+
+    container = NAUTILUS_CANVAS_CONTAINER (widget);
+
+    GTK_WIDGET_CLASS (nautilus_canvas_container_parent_class)->snapshot (widget, snapshot);
+
+    if (container->details->dnd_info->highlighted)
+    {
+        GtkStyleContext *context;
+        int width;
+        int height;
+
+        context = gtk_widget_get_style_context (widget);
+        width = gtk_widget_get_width (widget);
+        height = gtk_widget_get_height (widget);
+
+        gtk_style_context_save (context);
+        gtk_style_context_add_class (context, GTK_STYLE_CLASS_DND);
+        gtk_style_context_set_state (context, GTK_STATE_FLAG_FOCUSED);
+
+        gtk_snapshot_render_frame (snapshot, context, 0, 0, width, height);
+
+        gtk_style_context_restore (context);
+    }
+}
+
 /* Initialization.  */
 
 static void
@@ -3647,6 +3677,7 @@ nautilus_canvas_container_class_init (NautilusCanvasContainerClass *class)
     widget_class->unrealize = unrealize;
     widget_class->style_updated = style_updated;
     widget_class->grab_notify = grab_notify_cb;
+    widget_class->snapshot = nautilus_canvas_container_snapshot;
 
     gtk_widget_class_set_accessible_type (widget_class, nautilus_canvas_container_accessible_get_type ());
 }
diff --git a/src/nautilus-canvas-dnd.c b/src/nautilus-canvas-dnd.c
index 2e9974339..c43ac5e4c 100644
--- a/src/nautilus-canvas-dnd.c
+++ b/src/nautilus-canvas-dnd.c
@@ -1084,32 +1084,6 @@ nautilus_canvas_dnd_begin_drag (NautilusCanvasContainer *container,
                     dnd_info->drag_info.start_y);
 }
 
-static gboolean
-drag_highlight_draw (GtkWidget *widget,
-                     cairo_t   *cr,
-                     gpointer   user_data)
-{
-    gint width, height;
-    GdkSurface *surface;
-    GtkStyleContext *style;
-
-    surface = gtk_widget_get_surface (widget);
-    width = gdk_surface_get_width (surface);
-    height = gdk_surface_get_height (surface);
-
-    style = gtk_widget_get_style_context (widget);
-
-    gtk_style_context_save (style);
-    gtk_style_context_add_class (style, GTK_STYLE_CLASS_DND);
-    gtk_style_context_set_state (style, GTK_STATE_FLAG_FOCUSED);
-
-    gtk_render_frame (style, cr, 0, 0, width, height);
-
-    gtk_style_context_restore (style);
-
-    return FALSE;
-}
-
 static void
 start_dnd_highlight (GtkWidget *widget)
 {
@@ -1120,9 +1094,6 @@ start_dnd_highlight (GtkWidget *widget)
     if (!dnd_info->highlighted)
     {
         dnd_info->highlighted = TRUE;
-        g_signal_connect_after (widget, "draw",
-                                G_CALLBACK (drag_highlight_draw),
-                                NULL);
         gtk_widget_queue_draw (widget);
     }
 }
@@ -1136,11 +1107,8 @@ stop_dnd_highlight (GtkWidget *widget)
 
     if (dnd_info->highlighted)
     {
-        g_signal_handlers_disconnect_by_func (widget,
-                                              drag_highlight_draw,
-                                              NULL);
-        gtk_widget_queue_draw (widget);
         dnd_info->highlighted = FALSE;
+        gtk_widget_queue_draw (widget);
     }
 }
 


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