[balsa: 1/3] mime-widget-image: Connect to the "pressed" signal



commit c4e6e1df0ac5da83e99c392c883877854a792faf
Author: Peter Bloomfield <PeterBloomfield bellsouth net>
Date:   Tue Jun 2 10:27:09 2020 -0400

    mime-widget-image: Connect to the "pressed" signal
    
    Connect to the "pressed" signal of a GtkGestureMultiPress instead of the
    "button-press-event" widget signal.
    
    * src/balsa-mime-widget-image.c (balsa_image_button_press_cb), (balsa_mime_widget_new_image):
    
    balsa-message: Get right-click events in capture

 ChangeLog                     |  9 +++++++++
 src/balsa-message.c           |  3 +--
 src/balsa-mime-widget-image.c | 31 ++++++++++++++++++++++---------
 3 files changed, 32 insertions(+), 11 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index bc363f4a3..630fae7de 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2020-06-02  Peter Bloomfield  <pbloomfield bellsouth net>
+
+       mime-widget-image: Connect to the "pressed" signal of a
+       GtkGestureMultiPress instead of the "button-press-event" widget
+       signal.
+
+       * src/balsa-mime-widget-image.c (balsa_image_button_press_cb),
+       (balsa_mime_widget_new_image):
+
 2020-06-01  Peter Bloomfield  <pbloomfield bellsouth net>
 
        balsa-message: Connect to the "pressed" signal of a
diff --git a/src/balsa-message.c b/src/balsa-message.c
index 39ac060c4..933391e98 100644
--- a/src/balsa-message.c
+++ b/src/balsa-message.c
@@ -712,6 +712,7 @@ balsa_message_init(BalsaMessage * balsa_message)
     gtk_gesture_single_set_button(GTK_GESTURE_SINGLE(gesture), 0);
     g_signal_connect(gesture, "pressed",
                      G_CALLBACK(tree_button_press_cb), balsa_message);
+    gtk_event_controller_set_propagation_phase(GTK_EVENT_CONTROLLER(gesture), GTK_PHASE_CAPTURE);
 
     g_signal_connect(balsa_message->treeview, "popup-menu",
                      G_CALLBACK(tree_menu_popup_key_cb), balsa_message);
@@ -993,8 +994,6 @@ tree_button_press_cb(GtkGestureMultiPress *multi_press_gesture,
         gdk_event_get_window(event) != gtk_tree_view_get_bin_window(tree_view))
         return;
 
-    gtk_gesture_set_sequence_state(gesture, sequence, GTK_EVENT_SEQUENCE_CLAIMED);
-
     gtk_tree_view_convert_widget_to_bin_window_coords(tree_view, (gint) x, (gint) y,
                                                       &bx, &by);
 
diff --git a/src/balsa-mime-widget-image.c b/src/balsa-mime-widget-image.c
index e54c912ec..f358b9457 100644
--- a/src/balsa-mime-widget-image.c
+++ b/src/balsa-mime-widget-image.c
@@ -139,16 +139,26 @@ img_check_size(BalsaMimeWidgetImage * mwi)
     return G_SOURCE_REMOVE;
 }
 
-static gboolean
-balsa_image_button_press_cb(GtkWidget * widget, GdkEventButton * event,
-                            GtkMenu * menu)
+static void
+balsa_image_button_press_cb(GtkGestureMultiPress *multi_press_gesture,
+                            gint                  n_press,
+                            gdouble               x,
+                            gdouble               y,
+                            gpointer              user_data)
 {
-    if (gdk_event_triggers_context_menu((GdkEvent *) event)) {
-        gtk_menu_popup_at_pointer(menu, (GdkEvent *) event);
-        return TRUE;
+    GtkMenu *menu = user_data;
+    GtkGesture *gesture;
+    GdkEventSequence *sequence;
+    const GdkEvent *event;
+
+    gesture  = GTK_GESTURE(multi_press_gesture);
+    sequence = gtk_gesture_single_get_current_sequence(GTK_GESTURE_SINGLE(multi_press_gesture));
+    event    = gtk_gesture_get_last_event(gesture, sequence);
+
+    if (gdk_event_triggers_context_menu(event)) {
+        gtk_menu_popup_at_pointer(menu, event);
+        gtk_gesture_set_sequence_state(gesture, sequence, GTK_EVENT_SEQUENCE_CLAIMED);
     }
-
-    return FALSE;
 }
 
 static void
@@ -174,6 +184,7 @@ balsa_mime_widget_new_image(BalsaMessage * bm,
     BalsaMimeWidgetImage *mwi;
     BalsaMimeWidget *mw;
     GtkWidget *widget;
+    GtkGesture *gesture;
 
     g_return_val_if_fail(mime_body != NULL, NULL);
     g_return_val_if_fail(content_type != NULL, NULL);
@@ -197,7 +208,9 @@ balsa_mime_widget_new_image(BalsaMessage * bm,
     widget = gtk_event_box_new();
     gtk_container_add(GTK_CONTAINER(mw), widget);
 
-    g_signal_connect(widget, "button-press-event",
+    gesture = gtk_gesture_multi_press_new(widget);
+    gtk_gesture_single_set_button(GTK_GESTURE_SINGLE(gesture), 0);
+    g_signal_connect(gesture, "pressed",
                      G_CALLBACK(balsa_image_button_press_cb), data);
 
     mwi->image = image = gtk_image_new_from_icon_name("image-missing",


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