[nautilus] ui-utilities: use gtk_menu_popup_at_pointer instead of gtk_popup_menu



commit 1f57c5b19c099ae44b2c8ec8ca9a1904f1ed7885
Author: Carlos Soriano <csoriano gnome org>
Date:   Thu Oct 6 16:09:33 2016 +0200

    ui-utilities: use gtk_menu_popup_at_pointer instead of gtk_popup_menu
    
    We were using gtk_popup_menu which is problematic in backends with no
    global coordinates like wayland.
    
    To fix it, we can use gtk_menu_popup_at_pointer which uses the event
    relative coordinates.
    
    Also, seems the custom handling we were doing for the popup menu in that
    code is obsoleted, so there is not need to specify the button.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=772507

 src/nautilus-ui-utilities.c |   30 ++++--------------------------
 src/nautilus-ui-utilities.h |    4 ++--
 2 files changed, 6 insertions(+), 28 deletions(-)
---
diff --git a/src/nautilus-ui-utilities.c b/src/nautilus-ui-utilities.c
index fedbb48..e8fdab8 100644
--- a/src/nautilus-ui-utilities.c
+++ b/src/nautilus-ui-utilities.c
@@ -169,41 +169,19 @@ nautilus_gmenu_add_item_in_submodel (GMenu       *menu,
 void
 nautilus_pop_up_context_menu (GtkWidget      *parent,
                               GMenu          *menu,
-                              GdkEventButton *event)
+                              GdkEventButton *button_event)
 {
     GtkWidget *gtk_menu;
 
-    int button;
-
     g_return_if_fail (G_IS_MENU (menu));
     g_return_if_fail (GTK_IS_WIDGET (parent));
 
     gtk_menu = gtk_menu_new_from_model (G_MENU_MODEL (menu));
     gtk_menu_attach_to_widget (GTK_MENU (gtk_menu), parent, NULL);
 
-    /* The event button needs to be 0 if we're popping up this menu from
-     * a button release, else a 2nd click outside the menu with any button
-     * other than the one that invoked the menu will be ignored (instead
-     * of dismissing the menu). This is a subtle fragility of the GTK menu code.
-     */
-    if (event)
-    {
-        button = event->type == GDK_BUTTON_RELEASE
-                 ? 0
-                 : event->button;
-    }
-    else
-    {
-        button = 0;
-    }
-
-    gtk_menu_popup (GTK_MENU (gtk_menu),                        /* menu */
-                    NULL,                                       /* parent_menu_shell */
-                    NULL,                                       /* parent_menu_item */
-                    NULL,                                       /* popup_position_func */
-                    NULL,                                       /* popup_position_data */
-                    button,                                     /* button */
-                    event ? event->time : gtk_get_current_event_time ());     /* activate_time */
+    gtk_menu_popup_at_pointer (GTK_MENU (gtk_menu),
+                               button_event ? (GdkEvent *) button_event :
+                                              gtk_get_current_event ());
 
     g_object_ref_sink (gtk_menu);
     g_object_unref (gtk_menu);
diff --git a/src/nautilus-ui-utilities.h b/src/nautilus-ui-utilities.h
index c214b80..aa90424 100644
--- a/src/nautilus-ui-utilities.h
+++ b/src/nautilus-ui-utilities.h
@@ -35,8 +35,8 @@ void nautilus_gmenu_merge                          (GMenu             *original,
                                                    const gchar       *submodel_name,
                                                    gboolean           prepend);
 void nautilus_pop_up_context_menu                  (GtkWidget         *parent,
-                                                   GMenu             *menu,
-                                                   GdkEventButton    *event);
+                                                    GMenu             *menu,
+                                                    GdkEventButton    *button_event);
 
 char * nautilus_escape_action_name                 (const char        *action_name,
                                                    const char        *prefix);


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