gtk_widget_compute_transform() not working correctly with GtkPopover
It appears that gtk_widget_compute_point
is not able to translate coordinates from a GtkPopover to the parent widget.
Here's a test case:
#include <gtk/gtk.h>
static void
button_clicked (GtkButton *button,
gpointer user_data)
{
GtkWidget *from = GTK_WIDGET (gtk_widget_get_native (GTK_WIDGET (button)));
GtkWidget *to = GTK_WIDGET (user_data);
graphene_point_t point;
if (gtk_widget_compute_point (from, to, &GRAPHENE_POINT_INIT (1.f, 1.f), &point))
{
g_print ("Point (%d, %d) on %s corresponds to point (%d, %d) on %s\n",
1,
1,
gtk_widget_get_name (from),
(int)point.x,
(int)point.y,
gtk_widget_get_name (to));
}
}
static void
activate (GtkApplication *app)
{
GtkWidget *window = gtk_application_window_new (app);
GtkWidget *menu_button = gtk_menu_button_new ();
GtkWidget *popover = gtk_popover_new ();
GtkWidget *button = gtk_button_new_with_label ("Click me");
g_signal_connect (button, "clicked", G_CALLBACK (button_clicked), window);
gtk_popover_set_child (GTK_POPOVER (popover), button);
gtk_menu_button_set_label (GTK_MENU_BUTTON (menu_button), "Open popover");
gtk_menu_button_set_popover (GTK_MENU_BUTTON (menu_button), popover);
gtk_widget_set_hexpand (menu_button, TRUE);
gtk_widget_set_vexpand (menu_button, TRUE);
gtk_window_set_default_size (GTK_WINDOW (window), 450, 300);
gtk_window_set_child (GTK_WINDOW (window), menu_button);
gtk_window_present (GTK_WINDOW (window));
}
int
main (int argc, char *argv[])
{
// Create a new application
GtkApplication *app = gtk_application_new ("com.example.GtkApplication",
G_APPLICATION_DEFAULT_FLAGS);
g_signal_connect (app, "activate", G_CALLBACK (activate), NULL);
return g_application_run (G_APPLICATION (app), argc, argv);
}
Edited by Luca Bacci