diff --git a/docs/reference/gtk/gtk4-sections.txt b/docs/reference/gtk/gtk4-sections.txt index e9af026182..835f17f26a 100644 --- a/docs/reference/gtk/gtk4-sections.txt +++ b/docs/reference/gtk/gtk4-sections.txt @@ -4445,6 +4445,7 @@ gtk_widget_set_sensitive gtk_widget_set_parent gtk_widget_get_toplevel gtk_widget_get_root +gtk_widget_get_native gtk_widget_get_ancestor gtk_widget_is_ancestor gtk_widget_translate_coordinates diff --git a/gtk/gtktypes.h b/gtk/gtktypes.h index 8a48c1c4c8..2798bd1b02 100644 --- a/gtk/gtktypes.h +++ b/gtk/gtktypes.h @@ -39,6 +39,7 @@ typedef struct _GtkClipboard GtkClipboard; typedef struct _GtkEventController GtkEventController; typedef struct _GtkGesture GtkGesture; typedef struct _GtkLayoutManager GtkLayoutManager; +typedef struct _GtkNative GtkNative; typedef struct _GtkRequisition GtkRequisition; typedef struct _GtkRoot GtkRoot; typedef struct _GtkSelectionData GtkSelectionData; diff --git a/gtk/gtkwidget.c b/gtk/gtkwidget.c index 4f1d444cec..c2f26e170d 100644 --- a/gtk/gtkwidget.c +++ b/gtk/gtkwidget.c @@ -3652,8 +3652,18 @@ sync_widget_surface_transform (GtkWidget *widget) } else { - g_warning ("Could not compute surface transform"); - surface_transform_data->cached_surface_transform_valid = FALSE; + GtkWidget *native = GTK_WIDGET (gtk_widget_get_native (widget)); + + if (gtk_widget_compute_transform (widget, native, + &surface_transform_data->cached_surface_transform)) + { + surface_transform_data->cached_surface_transform_valid = TRUE; + } + else + { + g_warning ("Could not compute surface transform"); + surface_transform_data->cached_surface_transform_valid = FALSE; + } } if (was_valid != surface_transform_data->cached_surface_transform_valid || @@ -6672,6 +6682,27 @@ gtk_widget_get_root (GtkWidget *widget) return _gtk_widget_get_root (widget); } +/** + * gtk_widget_get_native: + * @widget: a #GtkWidget + * + * Returns the GtkNative widget that contains @widget, + * or %NULL if the widget is not contained inside a + * widget tree with a native ancestor. + * + * #GtkNative widgets will return themselves here. + * + * Returns: (transfer none) (nullable): the #GtkNative + * widget of @widget, or %NULL + */ +GtkNative * +gtk_widget_get_native (GtkWidget *widget) +{ + g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL); + + return GTK_NATIVE (gtk_widget_get_ancestor (widget, GTK_TYPE_NATIVE)); +} + static void gtk_widget_real_direction_changed (GtkWidget *widget, GtkTextDirection previous_direction) diff --git a/gtk/gtkwidget.h b/gtk/gtkwidget.h index 11703a6922..7e11a545d0 100644 --- a/gtk/gtkwidget.h +++ b/gtk/gtkwidget.h @@ -549,6 +549,9 @@ GtkWidget * gtk_widget_get_parent (GtkWidget *widget); GDK_AVAILABLE_IN_ALL GtkRoot * gtk_widget_get_root (GtkWidget *widget); +GDK_AVAILABLE_IN_ALL +GtkNative * gtk_widget_get_native (GtkWidget *widget); + GDK_AVAILABLE_IN_ALL void gtk_widget_set_child_visible (GtkWidget *widget, gboolean child_visible);