[gtk+/wip/matthiasc/kill-event-signals: 122/123] places view: Stop using ::button-press-event



commit 74ef4982f9e2906aa07e2b06dc6ddf36f457251c
Author: Matthias Clasen <mclasen redhat com>
Date:   Sun Jan 7 20:40:11 2018 -0500

    places view: Stop using ::button-press-event
    
    Instead, use a multi-press gesture in the row widget,
    and emit ::popup-menu from there.

 gtk/gtkplacesview.c    |   29 +----------------------------
 gtk/gtkplacesviewrow.c |   18 ++++++++++++++++++
 2 files changed, 19 insertions(+), 28 deletions(-)
---
diff --git a/gtk/gtkplacesview.c b/gtk/gtkplacesview.c
index 3281a09..2451f11 100644
--- a/gtk/gtkplacesview.c
+++ b/gtk/gtkplacesview.c
@@ -99,9 +99,6 @@ struct _GtkPlacesViewPrivate
 static void        mount_volume                                  (GtkPlacesView *view,
                                                                   GVolume       *volume);
 
-static gboolean    on_button_press_event                         (GtkPlacesViewRow *row,
-                                                                  GdkEventButton   *event);
-
 static void        on_eject_button_clicked                       (GtkWidget        *widget,
                                                                   GtkPlacesViewRow *row);
 
@@ -662,15 +659,7 @@ insert_row (GtkPlacesView *view,
 
   g_object_set_data (G_OBJECT (row), "is-network", GINT_TO_POINTER (is_network));
 
-  g_signal_connect_swapped (GTK_PLACES_VIEW_ROW (row),
-                            "button-press-event",
-                            G_CALLBACK (on_button_press_event),
-                            row);
-
-  g_signal_connect (row,
-                    "popup-menu",
-                    G_CALLBACK (on_row_popup_menu),
-                    row);
+  g_signal_connect (row, "popup-menu", G_CALLBACK (on_row_popup_menu), row);
 
   g_signal_connect (gtk_places_view_row_get_eject_button (GTK_PLACES_VIEW_ROW (row)),
                     "clicked",
@@ -1698,22 +1687,6 @@ on_row_popup_menu (GtkPlacesViewRow *row)
 }
 
 static gboolean
-on_button_press_event (GtkPlacesViewRow *row,
-                       GdkEventButton   *event)
-{
-  if (row &&
-      gdk_event_triggers_context_menu ((GdkEvent*) event) &&
-      gdk_event_get_event_type ((GdkEvent *)event) == GDK_BUTTON_PRESS)
-    {
-      popup_menu (row, event);
-
-      return TRUE;
-    }
-
-  return FALSE;
-}
-
-static gboolean
 on_key_press_event (GtkWidget     *widget,
                     GdkEventKey   *event,
                     GtkPlacesView *view)
diff --git a/gtk/gtkplacesviewrow.c b/gtk/gtkplacesviewrow.c
index c7236af..c64c063 100644
--- a/gtk/gtkplacesviewrow.c
+++ b/gtk/gtkplacesviewrow.c
@@ -34,6 +34,7 @@
 #include "gtkspinner.h"
 #include "gtkstack.h"
 #include "gtktypebuiltins.h"
+#include "gtkgesturemultipress.h"
 #else
 #include <gtk/gtk.h>
 #endif
@@ -55,6 +56,8 @@ struct _GtkPlacesViewRow
   GMount        *mount;
   GFile         *file;
 
+  GtkGesture    *gesture;
+
   GCancellable  *cancellable;
 
   gint           is_network : 1;
@@ -193,6 +196,16 @@ measure_available_space (GtkPlacesViewRow *row)
 }
 
 static void
+pressed_cb (GtkGesture       *gesture,
+            int               n_pressed,
+            double            x,
+            double            y,
+            GtkPlacesViewRow *row)
+{
+  g_signal_emit_by_name (row, "popup-menu", 0);
+}
+
+static void
 gtk_places_view_row_finalize (GObject *object)
 {
   GtkPlacesViewRow *self = GTK_PLACES_VIEW_ROW (object);
@@ -203,6 +216,7 @@ gtk_places_view_row_finalize (GObject *object)
   g_clear_object (&self->mount);
   g_clear_object (&self->file);
   g_clear_object (&self->cancellable);
+  g_clear_object (&self->gesture);
 
   G_OBJECT_CLASS (gtk_places_view_row_parent_class)->finalize (object);
 }
@@ -384,6 +398,10 @@ static void
 gtk_places_view_row_init (GtkPlacesViewRow *self)
 {
   gtk_widget_init_template (GTK_WIDGET (self));
+
+  self->gesture = gtk_gesture_multi_press_new (GTK_WIDGET (self));
+  gtk_gesture_single_set_button (GTK_GESTURE_SINGLE (self->gesture), GDK_BUTTON_SECONDARY);
+  g_signal_connect (self->gesture, "pressed", G_CALLBACK (pressed_cb), self);
 }
 
 GtkWidget*


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