[nautilus/antonioffix-menus-and-popovers: 20/28] files-view: Always pop up background menu in view



commit 8416ee0c53490e01b87d564a16bfb24603e71495
Author: António Fernandes <antoniof gnome org>
Date:   Tue Jan 9 22:40:51 2018 +0000

    files-view: Always pop up background menu in view
    
    Background context menu pops up from the pointer's position, which
    is good when using a poiting device to open it.
    
    When using keyboard shortcuts to open the background context menu,
    the pointer may be outside the view, so the background context menu
    will pop up out of context.
    
    Instead, when triggered from the keyboard, pop up from the starting
    corner of the view.

 src/nautilus-files-view.c | 18 ++++++++++++++++--
 1 file changed, 16 insertions(+), 2 deletions(-)
---
diff --git a/src/nautilus-files-view.c b/src/nautilus-files-view.c
index 388475ee6..dc4a35366 100644
--- a/src/nautilus-files-view.c
+++ b/src/nautilus-files-view.c
@@ -8141,7 +8141,7 @@ nautilus_files_view_pop_up_selection_context_menu  (NautilusFilesView *view,
 /**
  * nautilus_files_view_pop_up_background_context_menu
  *
- * Pop up a context menu appropriate to the view globally at the last right click location.
+ * Pop up a context menu appropriate to the location in view.
  * @view: NautilusFilesView of interest.
  *
  **/
@@ -8150,6 +8150,7 @@ nautilus_files_view_pop_up_background_context_menu (NautilusFilesView *view,
                                                     GdkEventButton    *event)
 {
     NautilusFilesViewPrivate *priv;
+    g_autofree GdkRectangle *rectangle = NULL;
 
     g_assert (NAUTILUS_IS_FILES_VIEW (view));
 
@@ -8160,7 +8161,20 @@ nautilus_files_view_pop_up_background_context_menu (NautilusFilesView *view,
      */
     update_context_menus_if_pending (view);
 
-    nautilus_pop_up_context_menu (GTK_WIDGET (view), priv->background_menu, event, NULL);
+    if (!event)
+    {
+        /* It was triggered from the keyboard, so pop up from the starting
+         * corner of the view.
+         */
+        gboolean rtl;
+
+        rtl = gtk_widget_get_direction (GTK_WIDGET (view)) == GTK_TEXT_DIR_RTL;
+        rectangle = g_new0 (GdkRectangle, 1);
+        rectangle->x = rtl ? gtk_widget_get_allocated_width (GTK_WIDGET (view)) : 0;
+        rectangle->y = 0;
+    }
+
+    nautilus_pop_up_context_menu (GTK_WIDGET (view), priv->background_menu, event, rectangle);
 }
 
 static void


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