[balsa] autocrypt: Connect to "pressed" signal



commit bbf6958d948224bd48cfd28516ccb2ea2e247798
Author: Peter Bloomfield <PeterBloomfield bellsouth net>
Date:   Fri May 29 20:48:26 2020 -0400

    autocrypt: Connect to "pressed" signal
    
    Connect to the "pressed" signal of a GtkGestureMultiPress instead of the
    "button_press_event" widget signal.
    
    * libbalsa/autocrypt.c (autocrypt_db_dialog_run), (gesture_pressed_cb):

 ChangeLog            |  9 +++++++++
 libbalsa/autocrypt.c | 35 +++++++++++++++++++----------------
 2 files changed, 28 insertions(+), 16 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 3426b17ea..bda8302fd 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2020-05-29  Peter Bloomfield  <pbloomfield bellsouth net>
+
+       autocrypt: Connect to the "pressed" signal of a
+       GtkGestureMultiPress instead of the "button_press_event" widget
+       signal.
+
+       * libbalsa/autocrypt.c (autocrypt_db_dialog_run),
+       (gesture_pressed_cb):
+
 2020-05-29  Peter Bloomfield  <pbloomfield bellsouth net>
 
        address-view: Connect to "notify::has-focus" signal instead of
diff --git a/libbalsa/autocrypt.c b/libbalsa/autocrypt.c
index 0abeeb276..407f16062 100644
--- a/libbalsa/autocrypt.c
+++ b/libbalsa/autocrypt.c
@@ -118,9 +118,11 @@ static AutocryptRecommend autocrypt_check_ia_list(gpgme_ctx_t           gpgme_ct
                                                                                                  time_t      
          ref_time,
                                                                                                  GList       
        **missing_keys,
                                                                                                  GError      
        **error);
-static gboolean key_button_event_press_cb(GtkWidget *widget,
-                                          GdkEvent  *event,
-                                          gpointer   data);
+static void gesture_pressed_cb(GtkGestureMultiPress *gesture,
+                               gint                  n_press,
+                               gdouble               x,
+                               gdouble               y,
+                               gpointer              user_data);
 
 
 static sqlite3 *autocrypt_db = NULL;
@@ -430,6 +432,7 @@ autocrypt_db_dialog_run(const gchar *date_string, GtkWindow *parent)
        GtkTreeViewColumn *column;
     GList *keys = NULL;
        int sqlite_res;
+    GtkGesture *gesture;
 
        dialog = gtk_dialog_new_with_buttons(_("Autocrypt database"), parent,
                GTK_DIALOG_DESTROY_WITH_PARENT | libbalsa_dialog_flags(), _("_Close"), GTK_RESPONSE_CLOSE, 
NULL);
@@ -454,7 +457,10 @@ autocrypt_db_dialog_run(const gchar *date_string, GtkWindow *parent)
                G_TYPE_POINTER);                                                                              
          /* key */
 
     tree_view = gtk_tree_view_new_with_model(GTK_TREE_MODEL(model));
-    g_signal_connect(tree_view, "button_press_event", G_CALLBACK(key_button_event_press_cb), dialog);
+
+    gesture = gtk_gesture_multi_press_new(tree_view);
+    g_signal_connect(gesture, "pressed", G_CALLBACK(gesture_pressed_cb), dialog);
+
     gtk_container_add(GTK_CONTAINER(scrolled_window), tree_view);
     selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(tree_view));
     gtk_tree_selection_set_mode(selection, GTK_SELECTION_SINGLE);
@@ -767,23 +773,22 @@ update_last_seen(GMimeAutocryptHeader *autocrypt_header, GError **error)
 }
 
 
-static gboolean
-key_button_event_press_cb(GtkWidget *widget,
-                          GdkEvent  *event,
-                          gpointer   data)
+static void
+gesture_pressed_cb(GtkGestureMultiPress *gesture,
+                   gint                  n_press,
+                   gdouble               x,
+                   gdouble               y,
+                   gpointer              data)
 {
+    GtkWidget *widget = gtk_event_controller_get_widget(GTK_EVENT_CONTROLLER(gesture));
     GtkTreeView *tree_view = GTK_TREE_VIEW(widget);
-    gdouble x, y;
     GtkTreeSelection *selection = gtk_tree_view_get_selection(tree_view);
     GtkTreePath *path;
     GtkTreeIter iter;
     GtkTreeModel *model;
 
-    if ((gdk_event_get_event_type(event) != GDK_2BUTTON_PRESS) ||
-        (gdk_event_get_window(event) != gtk_tree_view_get_bin_window(tree_view)) ||
-        !gdk_event_get_coords(event, &x, &y)) {
-        return FALSE;
-    }
+    if (n_press != 2)
+        return;
 
     if (gtk_tree_view_get_path_at_pos(tree_view, x, y, &path, NULL, NULL, NULL)) {
         if (!gtk_tree_selection_path_is_selected(selection, path)) {
@@ -826,8 +831,6 @@ key_button_event_press_cb(GtkWidget *widget,
                        gpgme_release(ctx);
                }
     }
-
-    return TRUE;
 }
 
 #endif  /* ENABLE_AUTOCRYPT */


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