[epiphany] Open bookmark in new tab when clicking with middle button



commit 3341eed61f48877985887d5a5c65a3f4312f961a
Author: Jan-Michael Brummer <jan brummer tabos org>
Date:   Wed Nov 13 16:40:17 2019 +0100

    Open bookmark in new tab when clicking with middle button
    
    Fixes: https://gitlab.gnome.org/GNOME/epiphany/issues/86

 src/bookmarks/ephy-bookmarks-popover.c | 54 +++++++++++++++++++++++++---------
 1 file changed, 40 insertions(+), 14 deletions(-)
---
diff --git a/src/bookmarks/ephy-bookmarks-popover.c b/src/bookmarks/ephy-bookmarks-popover.c
index 088af0513..2fbfb0f9c 100644
--- a/src/bookmarks/ephy-bookmarks-popover.c
+++ b/src/bookmarks/ephy-bookmarks-popover.c
@@ -425,6 +425,26 @@ ephy_bookmarks_popover_show_tag_detail (EphyBookmarksPopover *self,
   g_sequence_free (bookmarks);
 }
 
+static void
+ephy_bookmarks_popover_open_bookmark (EphyBookmarksPopover *self,
+                                      GtkListBoxRow        *row)
+{
+  GtkWidget *window;
+  GActionGroup *action_group;
+  GAction *action;
+  const char *url;
+
+  window = gtk_widget_get_ancestor (GTK_WIDGET (self), EPHY_TYPE_WINDOW);
+  g_assert (EPHY_IS_WINDOW (window));
+  action_group = gtk_widget_get_action_group (window, "win");
+  g_assert (action_group != NULL);
+  action = g_action_map_lookup_action (G_ACTION_MAP (action_group), "open-bookmark");
+  g_assert (action != NULL);
+  url = ephy_bookmark_row_get_bookmark_url (EPHY_BOOKMARK_ROW (row));
+
+  g_action_activate (action, g_variant_new_string (url));
+}
+
 static void
 ephy_bookmarks_popover_list_box_row_activated_cb (EphyBookmarksPopover *self,
                                                   GtkListBoxRow        *row,
@@ -439,26 +459,29 @@ ephy_bookmarks_popover_list_box_row_activated_cb (EphyBookmarksPopover *self,
 
   type = g_object_get_data (G_OBJECT (row), "type");
   if (g_strcmp0 (type, EPHY_LIST_BOX_ROW_TYPE_BOOKMARK) == 0) {
-    GtkWidget *window;
-    GActionGroup *action_group;
-    GAction *action;
-    const char *url;
-
-    window = gtk_widget_get_ancestor (GTK_WIDGET (self), EPHY_TYPE_WINDOW);
-    g_assert (EPHY_IS_WINDOW (window));
-    action_group = gtk_widget_get_action_group (window, "win");
-    g_assert (action_group != NULL);
-    action = g_action_map_lookup_action (G_ACTION_MAP (action_group), "open-bookmark");
-    g_assert (action != NULL);
-    url = ephy_bookmark_row_get_bookmark_url (EPHY_BOOKMARK_ROW (row));
-
-    g_action_activate (action, g_variant_new_string (url));
+    ephy_bookmarks_popover_open_bookmark (self, row);
   } else {
     tag = g_object_get_data (G_OBJECT (row), "title");
     ephy_bookmarks_popover_show_tag_detail (self, tag);
   }
 }
 
+static gboolean
+ephy_bookmarks_popover_list_box_button_release_event_cb (EphyBookmarksPopover *self,
+                                                         GdkEvent             *event,
+                                                         GtkListBox           *box)
+{
+  GdkEventButton *event_button = (GdkEventButton *)event;
+  GtkListBoxRow *row = gtk_list_box_get_row_at_y (box, event_button->y);
+
+  if (event_button->button != GDK_BUTTON_MIDDLE)
+    return GDK_EVENT_PROPAGATE;
+
+  ephy_bookmarks_popover_open_bookmark (self, row);
+
+  return GDK_EVENT_STOP;
+}
+
 static void
 ephy_bookmarks_popover_finalize (GObject *object)
 {
@@ -577,6 +600,9 @@ ephy_bookmarks_popover_init (EphyBookmarksPopover *self)
   g_signal_connect_object (self->tag_detail_list_box, "row-activated",
                            G_CALLBACK (ephy_bookmarks_popover_list_box_row_activated_cb),
                            self, G_CONNECT_SWAPPED);
+  g_signal_connect_object (self->bookmarks_list_box, "button-release-event",
+                           G_CALLBACK (ephy_bookmarks_popover_list_box_button_release_event_cb),
+                           self, G_CONNECT_SWAPPED);
 }
 
 EphyBookmarksPopover *


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