[epiphany/gnome-3-24-loki: 1/16] Revert "Don't use deprecated gtk_menu_popup"



commit 67cfa0755cfd994550c14b28006a683ac2165421
Author: Michael Catanzaro <mcatanzaro igalia com>
Date:   Thu Sep 21 17:42:26 2017 -0500

    Revert "Don't use deprecated gtk_menu_popup"
    
    This reverts commit 8d4267a6910ac4d32b5c6ad188c70c1762f2cc72.

 lib/ephy-gui.c            |   68 +++++++++++++++++++++++++++++++++++++++++++++
 lib/ephy-gui.h            |    6 ++++
 src/ephy-header-bar.c     |    9 ++---
 src/ephy-history-dialog.c |    2 +-
 src/ephy-window.c         |   13 ++++----
 src/passwords-dialog.c    |    2 +-
 6 files changed, 86 insertions(+), 14 deletions(-)
---
diff --git a/lib/ephy-gui.c b/lib/ephy-gui.c
index 989012f..3d1836c 100644
--- a/lib/ephy-gui.c
+++ b/lib/ephy-gui.c
@@ -24,6 +24,74 @@
 #include <glib/gi18n.h>
 #include <gtk/gtk.h>
 
+/**
+ * ephy_gui_menu_position_under_widget:
+ * @menu:
+ * @x:
+ * @y:
+ * @push_in:
+ * @user_data: a #GtkWidget
+ *
+ * Positions @menu under (or over, depending on space available) the widget
+ * @user_data.
+ */
+void
+ephy_gui_menu_position_under_widget (GtkMenu  *menu,
+                                     gint     *x,
+                                     gint     *y,
+                                     gboolean *push_in,
+                                     gpointer  user_data)
+{
+  /* Adapted from gtktoolbar.c */
+  GtkWidget *widget = GTK_WIDGET (user_data);
+  GtkWidget *container;
+  GtkRequisition req;
+  GtkRequisition menu_req;
+  GtkAllocation allocation;
+  GdkRectangle monitor;
+  GdkWindow *window;
+  int monitor_num;
+  GdkScreen *screen;
+
+  g_return_if_fail (GTK_IS_WIDGET (widget));
+
+  container = gtk_widget_get_ancestor (widget, GTK_TYPE_CONTAINER);
+  g_return_if_fail (container != NULL);
+
+  gtk_widget_get_preferred_size (widget, &req, NULL);
+  gtk_widget_get_preferred_size (GTK_WIDGET (menu), &menu_req, NULL);
+
+  screen = gtk_widget_get_screen (GTK_WIDGET (menu));
+  window = gtk_widget_get_window (widget);
+  monitor_num = gdk_screen_get_monitor_at_window (screen, window);
+  if (monitor_num < 0)
+    monitor_num = 0;
+  gdk_screen_get_monitor_geometry (screen, monitor_num, &monitor);
+
+  gtk_widget_get_allocation (widget, &allocation);
+  gdk_window_get_origin (window, x, y);
+  if (!gtk_widget_get_has_window (widget)) {
+    *x += allocation.x;
+    *y += allocation.y;
+  }
+
+  if (gtk_widget_get_direction (container) == GTK_TEXT_DIR_LTR)
+    *x += allocation.width - req.width;
+  else
+    *x += req.width - menu_req.width;
+
+  if ((*y + allocation.height + menu_req.height) <= monitor.y + monitor.height)
+    *y += allocation.height;
+  else if ((*y - menu_req.height) >= monitor.y)
+    *y -= menu_req.height;
+  else if (monitor.y + monitor.height - (*y + allocation.height) > *y)
+    *y += allocation.height;
+  else
+    *y -= menu_req.height;
+
+  *push_in = FALSE;
+}
+
 GtkWindowGroup *
 ephy_gui_ensure_window_group (GtkWindow *window)
 {
diff --git a/lib/ephy-gui.h b/lib/ephy-gui.h
index 6283e73..39e19a7 100644
--- a/lib/ephy-gui.h
+++ b/lib/ephy-gui.h
@@ -24,6 +24,12 @@
 
 G_BEGIN_DECLS
 
+void            ephy_gui_menu_position_under_widget      (GtkMenu   *menu,
+                                                          gint      *x,
+                                                          gint      *y,
+                                                          gboolean  *push_in,
+                                                          gpointer  user_data);
+
 GtkWindowGroup *ephy_gui_ensure_window_group             (GtkWindow *window);
 
 void            ephy_gui_get_current_event               (GdkEventType *type,
diff --git a/src/ephy-header-bar.c b/src/ephy-header-bar.c
index 701e331..79fe0b2 100644
--- a/src/ephy-header-bar.c
+++ b/src/ephy-header-bar.c
@@ -418,11 +418,10 @@ popup_history_menu (GtkWidget                     *widget,
   GtkWidget *menu;
 
   menu = build_dropdown_menu (window, direction);
-  gtk_menu_popup_at_widget (GTK_MENU (menu),
-                            widget,
-                            GDK_GRAVITY_SOUTH_WEST,
-                            GDK_GRAVITY_NORTH_WEST,
-                            (GdkEvent *)event);
+  gtk_menu_popup (GTK_MENU (menu),
+                  NULL, NULL,
+                  ephy_gui_menu_position_under_widget, widget,
+                  event->button, event->time);
 }
 
 typedef struct {
diff --git a/src/ephy-history-dialog.c b/src/ephy-history-dialog.c
index b1e43c7..8b38e85 100644
--- a/src/ephy-history-dialog.c
+++ b/src/ephy-history-dialog.c
@@ -452,7 +452,7 @@ on_treeview_button_press_event (GtkWidget         *widget,
 
     menu = gtk_menu_new_from_model (self->treeview_popup_menu_model);
     gtk_menu_attach_to_widget (GTK_MENU (menu), GTK_WIDGET (self), NULL);
-    gtk_menu_popup_at_pointer (GTK_MENU (menu), (GdkEvent *)event);
+    gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL, event->button, event->time);
     return TRUE;
   }
 
diff --git a/src/ephy-window.c b/src/ephy-window.c
index 3cd1579..9709ab1 100644
--- a/src/ephy-window.c
+++ b/src/ephy-window.c
@@ -2360,17 +2360,16 @@ show_notebook_popup_menu (GtkNotebook    *notebook,
                                          "move-right");
     g_simple_action_set_enabled (G_SIMPLE_ACTION (action), page_num < n_pages - 1);
 
-    gtk_menu_popup_at_pointer (GTK_MENU (menu), (GdkEvent *)event);
+    gtk_menu_popup (GTK_MENU (menu), NULL, NULL,
+                    NULL, NULL,
+                    event->button, event->time);
   } else {
     tab = GTK_WIDGET (window->active_embed);
     tab_label = gtk_notebook_get_tab_label (notebook, tab);
 
-    /* Not tested, because I don't know how to trigger this code. */
-    gtk_menu_popup_at_widget (GTK_MENU (menu),
-                              tab_label,
-                              GDK_GRAVITY_SOUTH_WEST,
-                              GDK_GRAVITY_NORTH_WEST,
-                              NULL);
+    gtk_menu_popup (GTK_MENU (menu), NULL, NULL,
+                    ephy_gui_menu_position_under_widget, tab_label,
+                    0, gtk_get_current_event_time ());
     gtk_menu_shell_select_first (GTK_MENU_SHELL (menu), FALSE);
   }
 
diff --git a/src/passwords-dialog.c b/src/passwords-dialog.c
index fcdaafa..ba5df14 100644
--- a/src/passwords-dialog.c
+++ b/src/passwords-dialog.c
@@ -328,7 +328,7 @@ on_passwords_treeview_button_press_event (GtkWidget           *widget,
 
     menu = gtk_menu_new_from_model (dialog->treeview_popup_menu_model);
     gtk_menu_attach_to_widget (GTK_MENU (menu), GTK_WIDGET (dialog), NULL);
-    gtk_menu_popup_at_pointer (GTK_MENU (menu), (GdkEvent *)event);
+    gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL, event->button, event->time);
     return TRUE;
   }
 


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