[balsa] mime-widget-text: Use event-controllers
- From: Peter Bloomfield <peterb src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [balsa] mime-widget-text: Use event-controllers
- Date: Wed, 3 Jun 2020 16:08:05 +0000 (UTC)
commit 52ded54c30d4e044a3e9f02fd0c68751e1ea05ba
Author: Peter Bloomfield <PeterBloomfield bellsouth net>
Date: Wed Jun 3 12:06:53 2020 -0400
mime-widget-text: Use event-controllers
Use event-controllers instead of connecting to event signals.
* src/balsa-mime-widget-text.c
(mwt_controller_motion_cb), (mwt_controller_leave_cb):
GtkEventControllerMotion callbacks;
(balsa_mime_widget_new_text): use event-controllers instead of connecting
to event signals;
(store_button_coords), (check_over_url), (check_call_url): new API.
ChangeLog | 12 ++++
src/balsa-mime-widget-text.c | 141 ++++++++++++++++++++++++++++++-------------
2 files changed, 111 insertions(+), 42 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 630fae7de..29c95ec7a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,15 @@
+2020-06-03 Peter Bloomfield <pbloomfield bellsouth net>
+
+ mime-widget-text: Use event-controllers instead of connecting to
+ event signals.
+
+ * src/balsa-mime-widget-text.c
+ (mwt_controller_motion_cb), (mwt_controller_leave_cb):
+ GtkEventControllerMotion callbacks;
+ (balsa_mime_widget_new_text): use event-controllers instead of connecting
+ to event signals;
+ (store_button_coords), (check_over_url), (check_call_url): new API.
+
2020-06-02 Peter Bloomfield <pbloomfield bellsouth net>
mime-widget-image: Connect to the "pressed" signal of a
diff --git a/src/balsa-mime-widget-text.c b/src/balsa-mime-widget-text.c
index 19a71804a..b737b324c 100644
--- a/src/balsa-mime-widget-text.c
+++ b/src/balsa-mime-widget-text.c
@@ -91,13 +91,22 @@ static GdkCursor *url_cursor_normal = NULL;
static GdkCursor *url_cursor_over_url = NULL;
-static gboolean store_button_coords(GtkWidget * widget, GdkEventButton * event, gpointer data);
-static gboolean check_over_url(GtkWidget * widget, GdkEventMotion * event, gpointer user_data);
+static void store_button_coords(GtkGestureMultiPress *multi_press,
+ gint n_press,
+ gdouble x,
+ gdouble y,
+ gpointer user_data);
+static void check_over_url(BalsaMimeWidgetText * mwt,
+ message_url_t * url);
static void pointer_over_url(GtkWidget * widget, message_url_t * url, gboolean set);
static void prepare_url_offsets(GtkTextBuffer * buffer, GList * url_list);
static void url_found_cb(GtkTextBuffer * buffer, GtkTextIter * iter,
const gchar * buf, guint len, gpointer data);
-static gboolean check_call_url(GtkWidget * widget, GdkEventButton * event, gpointer user_data);
+static void check_call_url(GtkGestureMultiPress *multi_press,
+ gint n_press,
+ gdouble x,
+ gdouble y,
+ gpointer user_data);
static message_url_t * find_url(BalsaMimeWidgetText *mwt,
gint x,
gint y);
@@ -173,6 +182,40 @@ balsa_mime_widget_text_init(BalsaMimeWidgetText * self)
* End of class definition
*/
+/*
+ * Callbacks
+ */
+
+static void
+mwt_controller_motion_cb(GtkEventControllerMotion * motion,
+ gdouble x,
+ gdouble y,
+ gpointer user_data)
+{
+ BalsaMimeWidgetText *mwt = user_data;
+ message_url_t *url;
+
+ url = find_url(mwt, (gint) x, (gint) y);
+ check_over_url(mwt, url);
+}
+
+static void
+mwt_controller_leave_cb(GtkEventControllerMotion * motion,
+ gdouble x,
+ gdouble y,
+ GdkCrossingMode mode,
+ GdkNotifyType detail,
+ gpointer user_data)
+{
+ BalsaMimeWidgetText *mwt = user_data;
+
+ check_over_url(mwt, NULL);
+}
+
+/*
+ * Public method
+ */
+
BalsaMimeWidget *
balsa_mime_widget_new_text(BalsaMessage * bm, LibBalsaMessageBody * mime_body,
const gchar * content_type, gpointer data)
@@ -269,14 +312,20 @@ balsa_mime_widget_new_text(BalsaMessage * bm, LibBalsaMessageBody * mime_body,
G_CALLBACK(fix_text_widget), mwt);
if (mwt->url_list != NULL) {
- g_signal_connect(widget, "button_press_event",
+ GtkGesture *gesture;
+ GtkEventController *motion_controller;
+
+ gesture = gtk_gesture_multi_press_new(widget);
+ g_signal_connect(gesture, "pressed",
G_CALLBACK(store_button_coords), NULL);
- g_signal_connect(widget, "button_release_event",
- G_CALLBACK(check_call_url), mwt);
- g_signal_connect(widget, "motion-notify-event",
- G_CALLBACK(check_over_url), mwt);
- g_signal_connect(widget, "leave-notify-event",
- G_CALLBACK(check_over_url), mwt);
+ g_signal_connect(gesture, "released",
+ G_CALLBACK(check_call_url), mwt);
+
+ motion_controller = gtk_event_controller_motion_new(widget);
+ g_signal_connect(motion_controller, "motion",
+ G_CALLBACK(mwt_controller_motion_cb), mwt);
+ g_signal_connect(motion_controller, "leave",
+ G_CALLBACK(mwt_controller_leave_cb), mwt);
}
buffer = gtk_text_view_get_buffer(text_view);
@@ -593,38 +642,43 @@ text_view_populate_popup(GtkWidget *widget, GtkMenu *menu,
/* -- URL related stuff -- */
-static gboolean
-store_button_coords(GtkWidget * widget, GdkEventButton * event, gpointer data)
+static void
+store_button_coords(GtkGestureMultiPress *multi_press,
+ gint n_press,
+ gdouble x,
+ gdouble y,
+ gpointer user_data)
{
- if (event->type == GDK_BUTTON_PRESS && event->button == 1) {
- stored_x = event->x;
- stored_y = event->y;
- stored_mask = event->state;
+ GtkGesture *gesture;
+ const GdkEvent *event;
+ GdkModifierType state;
+
+ gesture = GTK_GESTURE(multi_press);
+ event = gtk_gesture_get_last_event(gesture, gtk_gesture_get_last_updated_sequence(gesture));
+
+ stored_x = (gint) x;
+ stored_y = (gint) y;
+
+ if (gdk_event_get_state(event, &state)) {
/* compare only shift, ctrl, and mod1-mod5 */
- stored_mask &= STORED_MASK_BITS;
+ state &= STORED_MASK_BITS;
+ stored_mask = state;
}
-
- return GDK_EVENT_PROPAGATE;
}
/* check if we are over an url and change the cursor in this case */
-static gboolean
-check_over_url(GtkWidget * widget, GdkEventMotion * event, gpointer user_data)
+static void
+check_over_url(BalsaMimeWidgetText * mwt,
+ message_url_t * url)
{
- BalsaMimeWidgetText *mwt = user_data;
static gboolean was_over_url = FALSE;
+ GtkWidget *widget;
GdkWindow *window;
- message_url_t *url;
+ widget = mwt->text_widget;
window = gtk_text_view_get_window(GTK_TEXT_VIEW(widget),
GTK_TEXT_WINDOW_TEXT);
- if (event->type == GDK_LEAVE_NOTIFY) {
- url = NULL;
- } else {
- url = find_url(mwt, (gint) event->x, (gint) event->y);
- }
-
if (url != NULL) {
if (url_cursor_normal == NULL || url_cursor_over_url == NULL) {
GdkDisplay *display;
@@ -650,8 +704,6 @@ check_over_url(GtkWidget * widget, GdkEventMotion * event, gpointer user_data)
}
mwt->current_url = url;
-
- return GDK_EVENT_PROPAGATE;
}
@@ -727,28 +779,33 @@ url_found_cb(GtkTextBuffer * buffer, GtkTextIter * iter,
/* if the mouse button was released over an URL, and the mouse hasn't
* moved since the button was pressed, try to call the URL */
-static gboolean
-check_call_url(GtkWidget * widget, GdkEventButton * event, gpointer user_data)
+static void
+check_call_url(GtkGestureMultiPress *multi_press,
+ gint n_press,
+ gdouble x,
+ gdouble y,
+ gpointer user_data)
{
BalsaMimeWidgetText *mwt = user_data;
- gint x, y;
+ GtkGesture *gesture;
+ const GdkEvent *event;
+ GdkModifierType state;
- if (event->type != GDK_BUTTON_RELEASE || event->button != 1)
- return GDK_EVENT_PROPAGATE;
+ gesture = GTK_GESTURE(multi_press);
+ event = gtk_gesture_get_last_event(gesture, gtk_gesture_get_last_updated_sequence(gesture));
+
+ if (event == NULL || !gdk_event_get_state(event, &state))
+ return;
- x = event->x;
- y = event->y;
/* 2-pixel motion tolerance */
- if (abs(x - stored_x) <= 2 && abs(y - stored_y) <= 2
- && (event->state & STORED_MASK_BITS) == stored_mask) {
+ if (abs((int) x - stored_x) <= 2 && abs((int) y - stored_y) <= 2
+ && (state & STORED_MASK_BITS) == stored_mask) {
message_url_t *url;
url = find_url(mwt, x, y);
if (url != NULL)
handle_url(url->url);
}
-
- return GDK_EVENT_PROPAGATE;
}
/* find_url:
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]