summaryrefslogtreecommitdiff
path: root/gtk/gtkplacessidebar.c
diff options
context:
space:
mode:
authorMatthias Clasen <mclasen@redhat.com>2022-09-01 15:00:42 +0000
committerMatthias Clasen <mclasen@redhat.com>2022-09-01 15:00:42 +0000
commitadcec93b0275ebb83a7c67a570a68720f902b607 (patch)
tree92ea859d56f8bdbdd4848bb8c01314f226dade87 /gtk/gtkplacessidebar.c
parent79ff151624f43b63f603995d933fa61b9e14ae5b (diff)
parent64347f2c79d46950595e2689dd774832310742ca (diff)
downloadgtk+-adcec93b0275ebb83a7c67a570a68720f902b607.tar.gz
Merge branch 'gtkplacessidebar' into 'main'
gtkplacessidebar: Fix crash when remove or rename bookmark See merge request GNOME/gtk!4625
Diffstat (limited to 'gtk/gtkplacessidebar.c')
-rw-r--r--gtk/gtkplacessidebar.c47
1 files changed, 33 insertions, 14 deletions
diff --git a/gtk/gtkplacessidebar.c b/gtk/gtkplacessidebar.c
index f4d28454a1..1f6aab3d18 100644
--- a/gtk/gtkplacessidebar.c
+++ b/gtk/gtkplacessidebar.c
@@ -2351,22 +2351,41 @@ update_popover_shadowing (GtkWidget *row,
}
static void
-set_prelight (GtkPopover *popover)
+set_prelight (GtkPlacesSidebar *sidebar)
{
- update_popover_shadowing (gtk_widget_get_parent (GTK_WIDGET (popover)), TRUE);
+ update_popover_shadowing (GTK_WIDGET (sidebar->context_row), TRUE);
}
static void
-unset_prelight (GtkPopover *popover)
+unset_prelight (GtkPlacesSidebar *sidebar)
{
- update_popover_shadowing (gtk_widget_get_parent (GTK_WIDGET (popover)), FALSE);
+ update_popover_shadowing (GTK_WIDGET (sidebar->context_row), FALSE);
}
static void
-setup_popover_shadowing (GtkWidget *popover)
+setup_popover_shadowing (GtkWidget *popover,
+ GtkPlacesSidebar *sidebar)
{
- g_signal_connect (popover, "map", G_CALLBACK (set_prelight), NULL);
- g_signal_connect (popover, "unmap", G_CALLBACK (unset_prelight), NULL);
+ g_signal_connect_swapped (popover, "map", G_CALLBACK (set_prelight), sidebar);
+ g_signal_connect_swapped (popover, "unmap", G_CALLBACK (unset_prelight), sidebar);
+}
+
+static void
+_popover_set_pointing_to_widget (GtkPopover *popover,
+ GtkWidget *target)
+{
+ GtkWidget *parent;
+ double x, y, w, h;
+
+ parent = gtk_widget_get_parent (GTK_WIDGET (popover));
+
+ if (!gtk_widget_translate_coordinates (target, parent, 0, 0, &x, &y))
+ return;
+
+ w = gtk_widget_get_allocated_width (GTK_WIDGET (target));
+ h = gtk_widget_get_allocated_height (GTK_WIDGET (target));
+
+ gtk_popover_set_pointing_to (popover, &(GdkRectangle){x, y, w, h});
}
static void
@@ -2389,12 +2408,11 @@ show_rename_popover (GtkSidebarRow *row)
sidebar->rename_uri = g_strdup (uri);
gtk_editable_set_text (GTK_EDITABLE (sidebar->rename_entry), name);
- g_object_ref (sidebar->rename_popover);
- gtk_widget_unparent (sidebar->rename_popover);
- gtk_widget_set_parent (sidebar->rename_popover, GTK_WIDGET (row));
- g_object_unref (sidebar->rename_popover);
- setup_popover_shadowing (sidebar->rename_popover);
+ _popover_set_pointing_to_widget (GTK_POPOVER (sidebar->rename_popover),
+ GTK_WIDGET (row));
+
+ setup_popover_shadowing (sidebar->rename_popover, sidebar);
gtk_popover_popup (GTK_POPOVER (sidebar->rename_popover));
gtk_widget_grab_focus (sidebar->rename_entry);
@@ -3325,9 +3343,10 @@ create_row_popover (GtkPlacesSidebar *sidebar,
sidebar->popover = gtk_popover_menu_new_from_model (G_MENU_MODEL (menu));
g_object_unref (menu);
+ gtk_widget_set_parent (sidebar->popover, GTK_WIDGET (sidebar));
g_signal_connect (sidebar->popover, "destroy", G_CALLBACK (on_row_popover_destroy), sidebar);
- setup_popover_shadowing (sidebar->popover);
+ setup_popover_shadowing (sidebar->popover, sidebar);
}
static void
@@ -3341,7 +3360,7 @@ show_row_popover (GtkSidebarRow *row)
create_row_popover (sidebar, row);
- gtk_widget_set_parent (sidebar->popover, GTK_WIDGET (row));
+ _popover_set_pointing_to_widget (GTK_POPOVER (sidebar->popover), GTK_WIDGET (row));
sidebar->context_row = row;
gtk_popover_popup (GTK_POPOVER (sidebar->popover));