[gtk+] places sidebar: Stop using ::button-press/release-event



commit 15e67e27ca19188a80480ae1a1bc1ae940659a03
Author: Matthias Clasen <mclasen redhat com>
Date:   Tue Jan 16 00:15:22 2018 -0500

    places sidebar: Stop using ::button-press/release-event
    
    We'll use a generic ::event signal instead.

 gtk/gtkplacessidebar.c |  103 ++++++++++++++++++++++-------------------------
 1 files changed, 48 insertions(+), 55 deletions(-)
---
diff --git a/gtk/gtkplacessidebar.c b/gtk/gtkplacessidebar.c
index 4a09742..044bcb6 100644
--- a/gtk/gtkplacessidebar.c
+++ b/gtk/gtkplacessidebar.c
@@ -281,12 +281,9 @@ static void  check_unmount_and_eject       (GMount   *mount,
                                             GDrive   *drive,
                                             gboolean *show_unmount,
                                             gboolean *show_eject);
-static gboolean on_button_press_event (GtkWidget      *widget,
-                                       GdkEventButton *event,
-                                       GtkSidebarRow  *sidebar);
-static gboolean on_button_release_event (GtkWidget      *widget,
-                                         GdkEventButton *event,
-                                         GtkSidebarRow  *sidebar);
+static gboolean on_row_event (GtkWidget     *widget,
+                              GdkEvent      *event,
+                              GtkSidebarRow *sidebar);
 static void popup_menu_cb    (GtkSidebarRow   *row);
 static void long_press_cb    (GtkGesture      *gesture,
                               gdouble          x,
@@ -495,10 +492,8 @@ add_place (GtkPlacesSidebar            *sidebar,
 
   g_signal_connect_swapped (eject_button, "clicked",
                             G_CALLBACK (eject_or_unmount_bookmark), row);
-  g_signal_connect (GTK_SIDEBAR_ROW (row), "button-press-event",
-                    G_CALLBACK (on_button_press_event), row);
-  g_signal_connect (GTK_SIDEBAR_ROW (row), "button-release-event",
-                    G_CALLBACK (on_button_release_event), row);
+  g_signal_connect (GTK_SIDEBAR_ROW (row), "event",
+                    G_CALLBACK (on_row_event), row);
 
   gtk_container_add (GTK_CONTAINER (sidebar->list_box), GTK_WIDGET (row));
 
@@ -3721,71 +3716,69 @@ on_row_activated (GtkListBox    *list_box,
 }
 
 static gboolean
-on_button_press_event (GtkWidget      *widget,
-                       GdkEventButton *event,
-                       GtkSidebarRow  *row)
+on_row_event (GtkWidget     *widget,
+              GdkEvent      *event,
+              GtkSidebarRow *row)
 {
   GtkPlacesSidebar *sidebar;
   GtkPlacesSidebarSectionType section_type;
+  GtkPlacesSidebarPlaceType row_type;
   gdouble x, y;
 
-  g_object_get (GTK_SIDEBAR_ROW (row),
+  g_object_get (row,
                 "sidebar", &sidebar,
                 "section_type", &section_type,
+                "place-type", &row_type,
                 NULL);
 
-  if (section_type == SECTION_BOOKMARKS)
+  if (gdk_event_get_event_type (event) == GDK_BUTTON_PRESS)
     {
-      gdk_event_get_coords ((GdkEvent *) event, &x, &y);
-      sidebar->drag_row = GTK_WIDGET (row);
-      sidebar->drag_row_x = (gint)x;
-      sidebar->drag_row_y = (gint)y;
-
-      sidebar->drag_x = x;
-      sidebar->drag_y = y;
-    }
-
-  g_object_unref (sidebar);
-
-  return FALSE;
-}
+      if (section_type == SECTION_BOOKMARKS)
+        {
+          gdk_event_get_coords ((GdkEvent *) event, &x, &y);
+          sidebar->drag_row = GTK_WIDGET (row);
+          sidebar->drag_row_x = (gint)x;
+          sidebar->drag_row_y = (gint)y;
 
-static gboolean
-on_button_release_event (GtkWidget      *widget,
-                         GdkEventButton *event,
-                         GtkSidebarRow  *row)
-{
-  gboolean ret = FALSE;
-  GtkPlacesSidebarPlaceType row_type;
-  guint button, state;
+          sidebar->drag_x = x;
+          sidebar->drag_y = y;
+        }
 
-  if (event && row &&
-      gdk_event_get_button ((GdkEvent *) event, &button) &&
-      gdk_event_get_state ((GdkEvent *) event, &state))
+      g_object_unref (sidebar);
+    }
+  else if (gdk_event_get_event_type (event) == GDK_BUTTON_RELEASE)
     {
-      g_object_get (row, "place-type", &row_type, NULL);
+      gboolean ret = FALSE;
+      guint button, state;
 
-      if (button == 1)
-        ret = FALSE;
-      else if (button == 2)
+      if (row &&
+          gdk_event_get_button (event, &button) &&
+          gdk_event_get_state (event, &state))
         {
-          GtkPlacesOpenFlags open_flags = GTK_PLACES_OPEN_NORMAL;
+          if (button == 1)
+            ret = FALSE;
+          else if (button == 2)
+            {
+              GtkPlacesOpenFlags open_flags = GTK_PLACES_OPEN_NORMAL;
 
-          open_flags = (state & GDK_CONTROL_MASK) ?
-                        GTK_PLACES_OPEN_NEW_WINDOW :
-                        GTK_PLACES_OPEN_NEW_TAB;
+              open_flags = (state & GDK_CONTROL_MASK) ?
+                            GTK_PLACES_OPEN_NEW_WINDOW :
+                            GTK_PLACES_OPEN_NEW_TAB;
 
-          open_row (GTK_SIDEBAR_ROW (row), open_flags);
-          ret = TRUE;
-        }
-      else if (button == 3)
-        {
-          if (row_type != PLACES_CONNECT_TO_SERVER)
-            show_row_popover (GTK_SIDEBAR_ROW (row));
+              open_row (GTK_SIDEBAR_ROW (row), open_flags);
+              ret = TRUE;
+            }
+          else if (button == 3)
+            {
+              if (row_type != PLACES_CONNECT_TO_SERVER)
+                show_row_popover (GTK_SIDEBAR_ROW (row));
+            }
         }
+
+      return ret;
     }
 
-  return ret;
+  return FALSE;
 }
 
 static void


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