[nautilus: 1/2] nautilus-canvas-view, nautilus-view-icon-controller: Add longpress gesture to open context popup men



commit e874ae70604de5f4893f011b0bf1c2eb339dd356
Author: Jan-Michael Brummer <jan brummer tabos org>
Date:   Sun Dec 17 13:07:04 2017 +0100

    nautilus-canvas-view, nautilus-view-icon-controller: Add longpress gesture to open context popup menu

 src/nautilus-canvas-container.c     |  6 ++---
 src/nautilus-canvas-view.c          | 45 +++++++++++++++++++++++++++++++++----
 src/nautilus-files-view.c           | 15 ++++++++-----
 src/nautilus-files-view.h           |  4 ++--
 src/nautilus-list-view.c            | 38 ++++++++++++++++++++++++++++---
 src/nautilus-pathbar.c              |  4 ++--
 src/nautilus-ui-utilities.c         |  4 ++--
 src/nautilus-ui-utilities.h         |  2 +-
 src/nautilus-view-icon-controller.c |  4 ++--
 9 files changed, 98 insertions(+), 24 deletions(-)
---
diff --git a/src/nautilus-canvas-container.c b/src/nautilus-canvas-container.c
index 0f69bdf68..923046142 100644
--- a/src/nautilus-canvas-container.c
+++ b/src/nautilus-canvas-container.c
@@ -3621,13 +3621,13 @@ nautilus_canvas_container_get_icon_text (NautilusCanvasContainer  *container,
 
 static gboolean
 handle_popups (NautilusCanvasContainer *container,
-               GdkEventKey             *event,
+               GdkEvent                *event,
                const char              *signal)
 {
     /* ensure we clear the drag state before showing the menu */
     clear_drag_state (container);
 
-    g_signal_emit_by_name (container, signal, NULL);
+    g_signal_emit_by_name (container, signal, event);
 
     return TRUE;
 }
@@ -3723,7 +3723,7 @@ key_press_event (GtkWidget   *widget,
              */
             if (event->state & GDK_CONTROL_MASK)
             {
-                handled = handle_popups (container, event,
+                handled = handle_popups (container, (GdkEvent *) event,
                                          "context_click_background");
             }
         }
diff --git a/src/nautilus-canvas-view.c b/src/nautilus-canvas-view.c
index f00fa5064..fc3111728 100644
--- a/src/nautilus-canvas-view.c
+++ b/src/nautilus-canvas-view.c
@@ -1134,24 +1134,26 @@ selection_changed_callback (NautilusCanvasContainer *container,
 
 static void
 canvas_container_context_click_selection_callback (NautilusCanvasContainer *container,
-                                                   GdkEventButton          *event,
+                                                   const GdkEvent          *event,
                                                    NautilusCanvasView      *canvas_view)
 {
     g_assert (NAUTILUS_IS_CANVAS_CONTAINER (container));
     g_assert (NAUTILUS_IS_CANVAS_VIEW (canvas_view));
 
-    nautilus_files_view_pop_up_selection_context_menu (NAUTILUS_FILES_VIEW (canvas_view), event);
+    nautilus_files_view_pop_up_selection_context_menu (NAUTILUS_FILES_VIEW (canvas_view),
+                                                       (GdkEvent *) event);
 }
 
 static void
 canvas_container_context_click_background_callback (NautilusCanvasContainer *container,
-                                                    GdkEventButton          *event,
+                                                    const GdkEvent          *event,
                                                     NautilusCanvasView      *canvas_view)
 {
     g_assert (NAUTILUS_IS_CANVAS_CONTAINER (container));
     g_assert (NAUTILUS_IS_CANVAS_VIEW (canvas_view));
 
-    nautilus_files_view_pop_up_background_context_menu (NAUTILUS_FILES_VIEW (canvas_view), event);
+    nautilus_files_view_pop_up_background_context_menu (NAUTILUS_FILES_VIEW (canvas_view),
+                                                        (GdkEvent *) event);
 }
 
 static char *
@@ -1295,17 +1297,52 @@ nautilus_canvas_view_update_click_mode (NautilusCanvasView *canvas_view)
                                                      click_mode == NAUTILUS_CLICK_POLICY_SINGLE);
 }
 
+static void
+canvas_container_longpress_gesture_pressed_callback (GtkGestureLongPress *gesture,
+                                                     gdouble              x,
+                                                     gdouble              y,
+                                                     gpointer             user_data)
+{
+    GdkEventSequence *event_sequence;
+    GdkEvent *event;
+    NautilusCanvasView *view = NAUTILUS_CANVAS_VIEW (user_data);
+
+    event_sequence = gtk_gesture_get_last_updated_sequence (GTK_GESTURE (gesture));
+    event = (GdkEvent *) gtk_gesture_get_last_event (GTK_GESTURE (gesture), event_sequence);
+
+    if (nautilus_view_get_selection (NAUTILUS_VIEW (view)))
+    {
+        nautilus_files_view_pop_up_selection_context_menu (NAUTILUS_FILES_VIEW (view),
+                                                           event);
+    }
+    else
+    {
+        nautilus_files_view_pop_up_background_context_menu (NAUTILUS_FILES_VIEW (view),
+                                                           (GdkEvent *) event);
+    }
+}
+
 static void
 initialize_canvas_container (NautilusCanvasView      *canvas_view,
                              NautilusCanvasContainer *canvas_container)
 {
     GtkWidget *content_widget;
+    GtkGesture *longpress_gesture;
 
     content_widget = nautilus_files_view_get_content_widget (NAUTILUS_FILES_VIEW (canvas_view));
     canvas_view->canvas_container = GTK_WIDGET (canvas_container);
     g_object_add_weak_pointer (G_OBJECT (canvas_container),
                                (gpointer *) &canvas_view->canvas_container);
 
+    longpress_gesture = gtk_gesture_long_press_new (GTK_WIDGET (content_widget));
+    gtk_event_controller_set_propagation_phase (GTK_EVENT_CONTROLLER (longpress_gesture),
+                                                GTK_PHASE_CAPTURE);
+    gtk_gesture_single_set_touch_only (GTK_GESTURE_SINGLE (longpress_gesture),
+                                       TRUE);
+    g_signal_connect (longpress_gesture, "pressed",
+                      (GCallback) canvas_container_longpress_gesture_pressed_callback,
+                      canvas_view);
+
     gtk_widget_set_can_focus (GTK_WIDGET (canvas_container), TRUE);
 
     g_signal_connect_object (canvas_container, "activate",
diff --git a/src/nautilus-files-view.c b/src/nautilus-files-view.c
index e74123a7a..ee9f8bc98 100644
--- a/src/nautilus-files-view.c
+++ b/src/nautilus-files-view.c
@@ -4734,7 +4734,7 @@ open_one_in_new_window (gpointer data,
 
 static void
 update_context_menu_position_from_event (NautilusFilesView *view,
-                                         GdkEventButton    *event)
+                                         const GdkEvent    *event)
 {
     NautilusFilesViewPrivate *priv;
 
@@ -4743,8 +4743,13 @@ update_context_menu_position_from_event (NautilusFilesView *view,
     priv = nautilus_files_view_get_instance_private (view);
     if (event != NULL)
     {
-        priv->context_menu_position.x = event->x;
-        priv->context_menu_position.y = event->y;
+        gdouble x;
+        gdouble y;
+
+        gdk_event_get_coords (event, &x, &y);
+
+        priv->context_menu_position.x = x;
+        priv->context_menu_position.y = y;
     }
     else
     {
@@ -8134,7 +8139,7 @@ nautilus_files_view_update_toolbar_menus (NautilusFilesView *view)
  **/
 void
 nautilus_files_view_pop_up_selection_context_menu  (NautilusFilesView *view,
-                                                    GdkEventButton    *event)
+                                                    GdkEvent          *event)
 {
     NautilusFilesViewPrivate *priv;
 
@@ -8161,7 +8166,7 @@ nautilus_files_view_pop_up_selection_context_menu  (NautilusFilesView *view,
  **/
 void
 nautilus_files_view_pop_up_background_context_menu (NautilusFilesView *view,
-                                                    GdkEventButton    *event)
+                                                    GdkEvent          *event)
 {
     NautilusFilesViewPrivate *priv;
 
diff --git a/src/nautilus-files-view.h b/src/nautilus-files-view.h
index 80384f27d..1f386b400 100644
--- a/src/nautilus-files-view.h
+++ b/src/nautilus-files-view.h
@@ -272,9 +272,9 @@ void                nautilus_files_view_notify_selection_changed         (Nautil
 NautilusDirectory  *nautilus_files_view_get_model                        (NautilusFilesView *view);
 NautilusFile       *nautilus_files_view_get_directory_as_file            (NautilusFilesView *view);
 void                nautilus_files_view_pop_up_background_context_menu   (NautilusFilesView *view,
-                                                                          GdkEventButton    *event);
+                                                                          GdkEvent          *event);
 void                nautilus_files_view_pop_up_selection_context_menu    (NautilusFilesView *view,
-                                                                          GdkEventButton    *event);
+                                                                          GdkEvent          *event);
 gboolean            nautilus_files_view_should_show_file                 (NautilusFilesView *view,
                                                                           NautilusFile      *file);
 gboolean            nautilus_files_view_should_sort_directories_first    (NautilusFilesView *view);
diff --git a/src/nautilus-list-view.c b/src/nautilus-list-view.c
index c39d2ca33..6976e0764 100644
--- a/src/nautilus-list-view.c
+++ b/src/nautilus-list-view.c
@@ -436,7 +436,7 @@ enter_notify_callback (GtkWidget        *widget,
 static void
 do_popup_menu (GtkWidget        *widget,
                NautilusListView *view,
-               GdkEventButton   *event)
+               GdkEvent         *event)
 {
     if (tree_view_has_selection (GTK_TREE_VIEW (widget)))
     {
@@ -634,7 +634,7 @@ button_press_callback (GtkWidget      *widget,
 
         if (event->button == 3)
         {
-            do_popup_menu (widget, view, event);
+            do_popup_menu (widget, view, (GdkEvent *) event);
         }
 
         return TRUE;
@@ -790,7 +790,7 @@ button_press_callback (GtkWidget      *widget,
 
         if (event->button == 3)
         {
-            do_popup_menu (widget, view, event);
+            do_popup_menu (widget, view, (GdkEvent *) event);
         }
     }
 
@@ -2000,6 +2000,27 @@ get_icon_scale_callback (NautilusListModel *model,
     return gtk_widget_get_scale_factor (GTK_WIDGET (view->details->tree_view));
 }
 
+static void
+on_longpress_gesture_pressed_event (GtkGestureLongPress *gesture,
+                                    gdouble              x,
+                                    gdouble              y,
+                                    gpointer             user_data)
+{
+    GdkEventSequence *event_sequence;
+    GdkEvent *event;
+    NautilusListView *view = user_data;
+
+    event_sequence = gtk_gesture_get_last_updated_sequence (GTK_GESTURE (gesture));
+    if (event_sequence == NULL)
+    {
+        return;
+    }
+
+    event = (GdkEvent *) gtk_gesture_get_last_event (GTK_GESTURE (gesture), event_sequence);
+
+    do_popup_menu (GTK_WIDGET (view->details->tree_view), view, event);
+}
+
 static void
 create_and_set_up_tree_view (NautilusListView *view)
 {
@@ -2013,6 +2034,7 @@ create_and_set_up_tree_view (NautilusListView *view)
     NautilusDirectory *directory = NULL;
     NautilusQuery *query = NULL;
     NautilusQuerySearchContent content;
+    GtkGesture *longpress_gesture;
 
     content_widget = nautilus_files_view_get_content_widget (NAUTILUS_FILES_VIEW (view));
     view->details->tree_view = GTK_TREE_VIEW (gtk_tree_view_new ());
@@ -2090,6 +2112,16 @@ create_and_set_up_tree_view (NautilusListView *view)
     g_signal_connect_object (view->details->model, "get-icon-scale",
                              G_CALLBACK (get_icon_scale_callback), view, 0);
 
+    longpress_gesture = gtk_gesture_long_press_new (GTK_WIDGET (content_widget));
+    gtk_event_controller_set_propagation_phase (GTK_EVENT_CONTROLLER (longpress_gesture),
+                                                GTK_PHASE_CAPTURE);
+    gtk_gesture_single_set_touch_only (GTK_GESTURE_SINGLE (longpress_gesture),
+                                       TRUE);
+    g_signal_connect (longpress_gesture,
+                      "pressed",
+                      (GCallback) on_longpress_gesture_pressed_event,
+                      view);
+
     gtk_tree_selection_set_mode (gtk_tree_view_get_selection (view->details->tree_view), 
GTK_SELECTION_MULTIPLE);
 
     g_settings_bind (nautilus_list_view_preferences, NAUTILUS_PREFERENCES_LIST_VIEW_USE_TREE,
diff --git a/src/nautilus-pathbar.c b/src/nautilus-pathbar.c
index dc8ee6dbe..695f36268 100644
--- a/src/nautilus-pathbar.c
+++ b/src/nautilus-pathbar.c
@@ -102,7 +102,7 @@ typedef struct
 
     GMenu *context_menu;
     NautilusFile *context_menu_file;
-    GdkEventButton *context_menu_event;
+    GdkEvent *context_menu_event;
 } NautilusPathBarPrivate;
 
 
@@ -1680,7 +1680,7 @@ schedule_pop_up_context_menu (NautilusPathBar *self,
     {
         gdk_event_free ((GdkEvent *) priv->context_menu_event);
     }
-    priv->context_menu_event = (GdkEventButton *) gdk_event_copy ((GdkEvent *) event);
+    priv->context_menu_event = gdk_event_copy ((GdkEvent *) event);
 
     if (file == priv->context_menu_file)
     {
diff --git a/src/nautilus-ui-utilities.c b/src/nautilus-ui-utilities.c
index 58958e5e4..68c42138b 100644
--- a/src/nautilus-ui-utilities.c
+++ b/src/nautilus-ui-utilities.c
@@ -171,7 +171,7 @@ nautilus_gmenu_add_item_in_submodel (GMenu       *menu,
 void
 nautilus_pop_up_context_menu (GtkWidget      *parent,
                               GMenu          *menu,
-                              GdkEventButton *button_event)
+                              GdkEvent       *event)
 {
     GtkWidget *gtk_menu;
 
@@ -182,7 +182,7 @@ nautilus_pop_up_context_menu (GtkWidget      *parent,
     gtk_menu_attach_to_widget (GTK_MENU (gtk_menu), parent, NULL);
 
     gtk_menu_popup_at_pointer (GTK_MENU (gtk_menu),
-                               button_event ? (GdkEvent *) button_event :
+                               event ? (GdkEvent *) event :
                                gtk_get_current_event ());
 
     g_object_ref_sink (gtk_menu);
diff --git a/src/nautilus-ui-utilities.h b/src/nautilus-ui-utilities.h
index 0dfd31ca9..36dfbdb9e 100644
--- a/src/nautilus-ui-utilities.h
+++ b/src/nautilus-ui-utilities.h
@@ -36,7 +36,7 @@ void nautilus_gmenu_merge                          (GMenu             *original,
                                                    gboolean           prepend);
 void nautilus_pop_up_context_menu                  (GtkWidget         *parent,
                                                     GMenu             *menu,
-                                                    GdkEventButton    *button_event);
+                                                    GdkEvent          *event);
 
 void   nautilus_ui_frame_image                     (GdkPixbuf        **pixbuf);
 void   nautilus_ui_frame_video                     (GdkPixbuf        **pixbuf);
diff --git a/src/nautilus-view-icon-controller.c b/src/nautilus-view-icon-controller.c
index 1b7007982..353f48572 100644
--- a/src/nautilus-view-icon-controller.c
+++ b/src/nautilus-view-icon-controller.c
@@ -669,7 +669,7 @@ on_button_press_event (GtkWidget *widget,
         if (event_button->button == GDK_BUTTON_SECONDARY)
         {
             nautilus_files_view_pop_up_selection_context_menu (NAUTILUS_FILES_VIEW (self),
-                                                               event_button);
+                                                               event);
         }
     }
     else
@@ -678,7 +678,7 @@ on_button_press_event (GtkWidget *widget,
         if (event_button->button == GDK_BUTTON_SECONDARY)
         {
             nautilus_files_view_pop_up_background_context_menu (NAUTILUS_FILES_VIEW (self),
-                                                                event_button);
+                                                                event);
         }
     }
 


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