popover: Stop using gtk_widget_get_surface_allocation
authorMatthias Clasen <mclasen@redhat.com>
Sat, 25 Mar 2023 13:45:31 +0000 (09:45 -0400)
committerMatthias Clasen <mclasen@redhat.com>
Sat, 25 Mar 2023 14:14:35 +0000 (10:14 -0400)
The function is going away, and the computation
here was wrong anyway. Instead, add a helper that
properly computes the pointing-to rect in surface
coordinates and use it everywhere.

gtk/gtkpopover.c

index d7376bc8c6b60bcfb3829d8e5321bc2451e65467..ff2e12cd8746f65eef452be441b1ea16411a4610 100644 (file)
@@ -431,21 +431,15 @@ update_popover_layout (GtkPopover     *popover,
   gtk_widget_queue_draw (GTK_WIDGET (popover));
 }
 
-static GdkPopupLayout *
-create_popup_layout (GtkPopover *popover)
+static void
+compute_surface_pointing_to (GtkPopover   *popover,
+                             GdkRectangle *rect)
 {
   GtkPopoverPrivate *priv = gtk_popover_get_instance_private (popover);
-  GdkRectangle rect;
-  GdkGravity parent_anchor;
-  GdkGravity surface_anchor;
-  GdkAnchorHints anchor_hints;
-  GdkPopupLayout *layout;
   GtkWidget *parent;
-  GtkCssStyle *style;
-  GtkBorder shadow_width;
   GtkNative *native;
-  double nx, ny;
   graphene_rect_t bounds;
+  double nx, ny;
 
   parent = gtk_widget_get_parent (GTK_WIDGET (popover));
   native = gtk_widget_get_native (parent);
@@ -471,10 +465,25 @@ create_popup_layout (GtkPopover *popover)
 
   gtk_native_get_surface_transform (native, &nx, &ny);
 
-  rect.x = (int) floor (bounds.origin.x + nx);
-  rect.y = (int) floor (bounds.origin.y + ny);
-  rect.width = (int) ceilf (bounds.size.width);
-  rect.width = (int) ceilf (bounds.size.height);
+  rect->x = (int) floor (bounds.origin.x + nx);
+  rect->y = (int) floor (bounds.origin.y + ny);
+  rect->width = (int) ceilf (bounds.size.width);
+  rect->width = (int) ceilf (bounds.size.height);
+}
+
+static GdkPopupLayout *
+create_popup_layout (GtkPopover *popover)
+{
+  GtkPopoverPrivate *priv = gtk_popover_get_instance_private (popover);
+  GdkRectangle rect;
+  GdkGravity parent_anchor;
+  GdkGravity surface_anchor;
+  GdkAnchorHints anchor_hints;
+  GdkPopupLayout *layout;
+  GtkCssStyle *style;
+  GtkBorder shadow_width;
+
+  compute_surface_pointing_to (popover, &rect);
 
   style = gtk_css_node_get_style (gtk_widget_get_css_node (GTK_WIDGET (priv->contents_widget)));
   gtk_css_shadow_value_get_extents (style->background->box_shadow, &shadow_width);
@@ -1207,21 +1216,12 @@ gtk_popover_get_gap_coords (GtkPopover *popover,
   int border_radius;
   int popover_width, popover_height;
   GtkCssStyle *style;
-  GtkWidget *parent;
   GtkBorder shadow_width;
 
   popover_width = gtk_widget_get_allocated_width (widget);
   popover_height = gtk_widget_get_allocated_height (widget);
-  parent = gtk_widget_get_parent (widget);
 
-  gtk_widget_get_surface_allocation (parent, &rect);
-  if (priv->has_pointing_to)
-    {
-      rect.x += priv->pointing_to.x;
-      rect.y += priv->pointing_to.y;
-      rect.width = priv->pointing_to.width;
-      rect.height = priv->pointing_to.height;
-    }
+  compute_surface_pointing_to (popover, &rect);
 
   rect.x -= priv->final_rect.x;
   rect.y -= priv->final_rect.y;