diff options
author | Matthias Clasen <mclasen@redhat.com> | 2022-09-09 14:59:03 +0000 |
---|---|---|
committer | Matthias Clasen <mclasen@redhat.com> | 2022-09-09 14:59:03 +0000 |
commit | d7817e6fc620799af5ab6b496f0cdf58c7616fe2 (patch) | |
tree | beae6f8201a259c7b37838086e3b6053ec3704c1 /gtk/gtkplacesview.c | |
parent | de94f3d97f346a76a92697710453e42039e8058a (diff) | |
parent | 7df347d9a5927037803eaca8711e52305238c691 (diff) | |
download | gtk+-d7817e6fc620799af5ab6b496f0cdf58c7616fe2.tar.gz |
Merge branch 'gtkplaces' into 'main'
gtkplacesview: Right click popover fix crash and align menu with mouse
See merge request GNOME/gtk!4662
Diffstat (limited to 'gtk/gtkplacesview.c')
-rw-r--r-- | gtk/gtkplacesview.c | 52 |
1 files changed, 43 insertions, 9 deletions
diff --git a/gtk/gtkplacesview.c b/gtk/gtkplacesview.c index d62f8f2a40..453b87b417 100644 --- a/gtk/gtkplacesview.c +++ b/gtk/gtkplacesview.c @@ -1319,6 +1319,7 @@ volume_mount_ready_cb (GObject *source_volume, return; } + view->row_for_action = NULL; view->mounting_volume = FALSE; update_loading (view); @@ -1700,16 +1701,35 @@ get_menu_model (void) return G_MENU_MODEL (menu); } +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 gboolean -on_row_popup_menu (GtkWidget *widget, - GVariant *args, - gpointer user_data) +real_popup_menu (GtkWidget *widget, + double x, + double y) { GtkPlacesViewRow *row = GTK_PLACES_VIEW_ROW (widget); GtkPlacesView *view; GMount *mount; GFile *file; gboolean is_network; + double x_in_view, y_in_view; view = GTK_PLACES_VIEW (gtk_widget_get_ancestor (GTK_WIDGET (row), GTK_TYPE_PLACES_VIEW)); @@ -1734,7 +1754,8 @@ on_row_popup_menu (GtkWidget *widget, gtk_popover_set_position (GTK_POPOVER (view->popup_menu), GTK_POS_BOTTOM); gtk_popover_set_has_arrow (GTK_POPOVER (view->popup_menu), FALSE); - gtk_widget_set_halign (view->popup_menu, GTK_ALIGN_CENTER); + gtk_widget_set_halign (view->popup_menu, GTK_ALIGN_START); + gtk_widget_set_parent (view->popup_menu, GTK_WIDGET (view)); g_object_unref (model); } @@ -1742,10 +1763,15 @@ on_row_popup_menu (GtkWidget *widget, if (view->row_for_action) g_object_set_data (G_OBJECT (view->row_for_action), "menu", NULL); - g_object_ref (view->popup_menu); - gtk_widget_unparent (view->popup_menu); - gtk_widget_set_parent (view->popup_menu, GTK_WIDGET (row)); - g_object_unref (view->popup_menu); + if (x == -1 && y == -1) + _popover_set_pointing_to_widget (GTK_POPOVER (view->popup_menu), GTK_WIDGET (row)); + else + { + gtk_widget_translate_coordinates (widget, GTK_WIDGET (view), + x, y, &x_in_view, &y_in_view); + gtk_popover_set_pointing_to (GTK_POPOVER (view->popup_menu), + &(GdkRectangle){x_in_view, y_in_view, 0, 0}); + } view->row_for_action = row; if (view->row_for_action) @@ -1756,6 +1782,14 @@ on_row_popup_menu (GtkWidget *widget, return TRUE; } +static gboolean +on_row_popup_menu (GtkWidget *widget, + GVariant *args, + gpointer user_data) +{ + return real_popup_menu (widget, -1, -1); +} + static void click_cb (GtkGesture *gesture, int n_press, @@ -1763,7 +1797,7 @@ click_cb (GtkGesture *gesture, double y, gpointer user_data) { - on_row_popup_menu (GTK_WIDGET (user_data), NULL, NULL); + real_popup_menu (GTK_WIDGET (user_data), x, y); } static gboolean |