gtk-demo: Stop using gtk_widget_get_allocation
authorMatthias Clasen <mclasen@redhat.com>
Sun, 9 Apr 2023 11:32:38 +0000 (07:32 -0400)
committerMatthias Clasen <mclasen@redhat.com>
Sun, 9 Apr 2023 12:38:14 +0000 (08:38 -0400)
demos/gtk-demo/bluroverlay.c
demos/gtk-demo/paint.c

index 3a7585ff09bf8f9ba366a301a0622ee9d8dac3bd..a4f1d450fd51864bebfbc9534795b93f5ebf1a2d 100644 (file)
@@ -297,12 +297,13 @@ blur_overlay_snapshot (GtkWidget   *widget,
   GtkWidget *main_widget;
   GskRenderNode *main_widget_node = NULL;
   GtkWidget *child;
-  GtkAllocation main_alloc;
+  int width, height;
   cairo_region_t *clip = NULL;
   int i;
 
   main_widget = BLUR_OVERLAY (widget)->main_widget;
-  gtk_widget_get_allocation (widget, &main_alloc);
+  width = gtk_widget_get_width (widget);
+  height = gtk_widget_get_height (widget);
 
   for (child = gtk_widget_get_first_child (widget);
        child != NULL;
@@ -315,7 +316,7 @@ blur_overlay_snapshot (GtkWidget   *widget,
 
       if (blur > 0)
         {
-          GtkAllocation alloc;
+          cairo_rectangle_int_t rect;
           graphene_rect_t bounds;
 
           if (main_widget_node == NULL)
@@ -327,8 +328,8 @@ blur_overlay_snapshot (GtkWidget   *widget,
               main_widget_node = gtk_snapshot_free_to_node (child_snapshot);
             }
 
-          gtk_widget_get_allocation (child, &alloc);
-          graphene_rect_init (&bounds, alloc.x, alloc.y, alloc.width, alloc.height);
+          if (!gtk_widget_compute_bounds (child, gtk_widget_get_parent (child), &bounds))
+            graphene_rect_init (&bounds, 0, 0, 0, 0);
           gtk_snapshot_push_blur (snapshot, blur);
           gtk_snapshot_push_clip (snapshot, &bounds);
           gtk_snapshot_append_node (snapshot, main_widget_node);
@@ -337,13 +338,17 @@ blur_overlay_snapshot (GtkWidget   *widget,
 
           if (clip == NULL)
             {
-              cairo_rectangle_int_t rect;
               rect.x = rect.y = 0;
-              rect.width = main_alloc.width;
-              rect.height = main_alloc.height;
+              rect.width = width;
+              rect.height = height;
               clip = cairo_region_create_rectangle (&rect);
             }
-          cairo_region_subtract_rectangle (clip, (cairo_rectangle_int_t *)&alloc);
+
+          rect.x = floor (bounds.origin.x);
+          rect.y = floor (bounds.origin.y);
+          rect.width = ceil (bounds.origin.x + bounds.size.width - rect.x);
+          rect.height = ceil (bounds.origin.y + bounds.size.height - rect.y);
+          cairo_region_subtract_rectangle (clip, &rect);
         }
     }
 
index 1696ca8e99545e9de0f016588f5c7f7a3d55eb9c..34830284b936002570f42c8fb76e9c233f43fe7c 100644 (file)
@@ -103,13 +103,11 @@ drawing_area_size_allocate (GtkWidget *widget,
 static void
 drawing_area_map (GtkWidget *widget)
 {
-  GtkAllocation allocation;
-
   GTK_WIDGET_CLASS (drawing_area_parent_class)->map (widget);
 
-  gtk_widget_get_allocation (widget, &allocation);
   drawing_area_ensure_surface ((DrawingArea *) widget,
-                               allocation.width, allocation.height);
+                               gtk_widget_get_width (widget),
+                               gtk_widget_get_height (widget));
 }
 
 static void