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



commit 8841b583d497245bf6db7afadef389053cd85a5f
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 | 20 +++++++++++++++++---
 1 file changed, 17 insertions(+), 3 deletions(-)
---
diff --git a/src/nautilus-files-view.c b/src/nautilus-files-view.c
index f85aadf7d..70cafd8e7 100644
--- a/src/nautilus-files-view.c
+++ b/src/nautilus-files-view.c
@@ -8144,7 +8144,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.
  *
  **/
@@ -8153,7 +8153,7 @@ nautilus_files_view_pop_up_background_context_menu (NautilusFilesView *view,
                                                     GdkEventButton    *event)
 {
     NautilusFilesViewPrivate *priv;
-
+    GdkRectangle             *rectangle;
     g_assert (NAUTILUS_IS_FILES_VIEW (view));
 
     priv = nautilus_files_view_get_instance_private (view);
@@ -8163,7 +8163,21 @@ 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);
+    rectangle = 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 (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]