[file-roller/wip/iainl/keypress-fixes: 311/312] fr-window: Position the Shift-F10 menu at the selected row




commit a3dc1a35310f067aad767b2e23eb90e3fb81d509
Author: Iain Lane <iainl gnome org>
Date:   Tue Apr 23 15:46:15 2019 +0100

    fr-window: Position the Shift-F10 menu at the selected row
    
    ...rather than the location of the mouse cursor
    
    This is the approach taken by nautilus, and it means the menu is at a
    more sensible place.
    
    Requires GTK 3.22.

 src/fr-window.c | 33 ++++++++++++++++++++++++++++++---
 1 file changed, 30 insertions(+), 3 deletions(-)
---
diff --git a/src/fr-window.c b/src/fr-window.c
index 3478a321..3cfe041a 100644
--- a/src/fr-window.c
+++ b/src/fr-window.c
@@ -4818,12 +4818,39 @@ key_press_cb (GtkWidget   *widget,
        case GDK_KEY_F10:
                if (event->state & GDK_SHIFT_MASK) {
                        GtkTreeSelection *selection;
-
-                       selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (window->priv->list_view));
+                       GList *selected_rows;
+                       GtkTreePath *first_selected_row_path;
+                       GtkTreeView *tree_view;
+                       GdkRectangle rect;
+                       GdkWindow   *win;
+
+                       tree_view = GTK_TREE_VIEW (window->priv->list_view);
+                       win = gtk_tree_view_get_bin_window (tree_view);
+
+                       selection = gtk_tree_view_get_selection (tree_view);
+                       selected_rows = gtk_tree_selection_get_selected_rows (selection,
+                                                                             &window->priv->list_store);
                        if (selection == NULL)
                                return GDK_EVENT_PROPAGATE;
 
-                       gtk_menu_popup_at_pointer (GTK_MENU (window->priv->file_popup_menu), (GdkEvent *) 
event);
+                       if (selected_rows == NULL)
+                               return GDK_EVENT_PROPAGATE;
+
+                       first_selected_row_path = (GtkTreePath *) selected_rows->data;
+
+                       gtk_tree_view_get_cell_area (tree_view,
+                                                    first_selected_row_path,
+                                                    NULL,
+                                                    &rect);
+
+                       g_list_free_full (selected_rows, (GDestroyNotify) gtk_tree_path_free);
+
+                       gtk_menu_popup_at_rect (GTK_MENU (window->priv->file_popup_menu),
+                                               win,
+                                               &rect,
+                                               GDK_GRAVITY_SOUTH_WEST,
+                                               GDK_GRAVITY_NORTH_WEST,
+                                               (const GdkEvent *) event);
                        retval = GDK_EVENT_STOP;
                }
                break;


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]