[gtk/issue-179] Use a separate gesture for middle clicks on PlaceView rows



commit 028c60d9f21b3bad59a7bba7363bad329a6a9495
Author: Emmanuele Bassi <ebassi gnome org>
Date:   Mon Nov 18 13:59:41 2019 +0000

    Use a separate gesture for middle clicks on PlaceView rows
    
    The click gesture in GtkListBox is exclusively for primary button
    clicks; this means we're never going to get a click from the middle
    button. We need to use a separate GtkGestureClick controller for middle
    clicks, in order to activate rows with the 'open-in-tab' flag.
    
    Fixes: #179

 gtk/gtkplacesview.c | 46 +++++++++++++++++++++++++++++++---------------
 1 file changed, 31 insertions(+), 15 deletions(-)
---
diff --git a/gtk/gtkplacesview.c b/gtk/gtkplacesview.c
index e23a628b3a..aabc4b9299 100644
--- a/gtk/gtkplacesview.c
+++ b/gtk/gtkplacesview.c
@@ -1786,6 +1786,24 @@ on_key_press_event (GtkEventController *controller,
   return FALSE;
 }
 
+static void
+on_middle_click_row_event (GtkGestureClick *gesture,
+                           guint            n_press,
+                           double           x,
+                           double           y,
+                           GtkPlacesView   *self)
+{
+  GtkListBoxRow *row;
+
+  if (n_press != 1)
+    return;
+
+  row = gtk_list_box_get_row_at_y (GTK_LIST_BOX (self), y);
+  if (row != NULL && gtk_widget_is_sensitive (GTK_WIDGET (row)))
+    activate_row (self, GTK_PLACES_VIEW_ROW (row), GTK_PLACES_OPEN_NEW_TAB);
+}
+
+
 static void
 on_eject_button_clicked (GtkWidget        *widget,
                          GtkPlacesViewRow *row)
@@ -1909,22 +1927,9 @@ on_listbox_row_activated (GtkPlacesView    *view,
                           GtkPlacesViewRow *row,
                           GtkWidget        *listbox)
 {
-  GtkPlacesViewPrivate *priv;
-  GdkEvent *event;
-  guint button;
-  GtkPlacesOpenFlags open_flags;
+  GtkPlacesViewPrivate *priv = gtk_places_view_get_instance_private (view);
 
-  priv = gtk_places_view_get_instance_private (view);
-
-  event = gtk_get_current_event ();
-  gdk_event_get_button (event, &button);
-
-  if (gdk_event_get_event_type (event) == GDK_BUTTON_RELEASE && button == GDK_BUTTON_MIDDLE)
-    open_flags = GTK_PLACES_OPEN_NEW_TAB;
-  else
-    open_flags = priv->current_open_flags;
-
-  activate_row (view, row, open_flags);
+  activate_row (view, row, priv->current_open_flags);
 }
 
 static gboolean
@@ -2344,6 +2349,17 @@ gtk_places_view_init (GtkPlacesView *self)
   g_signal_connect (controller, "key-pressed", G_CALLBACK (on_key_press_event), self);
   gtk_widget_add_controller (GTK_WIDGET (self), controller);
 
+  /* We need an additional controller because GtkListBox only
+   * activates rows for GDK_BUTTON_PRIMARY clicks
+   */
+  controller = (GtkEventController *) gtk_gesture_click_new ();
+  gtk_event_controller_set_propagation_phase (GTK_EVENT_CONTROLLER (controller),
+                                              GTK_PHASE_BUBBLE);
+  gtk_gesture_single_set_button (GTK_GESTURE_SINGLE (controller), GDK_BUTTON_MIDDLE);
+  g_signal_connect (controller, "released",
+                    G_CALLBACK (on_middle_click_row_event), self);
+  gtk_widget_add_controller (GTK_WIDGET (self), controller);
+
   gtk_widget_init_template (GTK_WIDGET (self));
 
   populate_available_protocols_grid (GTK_GRID (priv->available_protocols_grid));


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