From 77b8fbd27eb895e69c51d5924e29f1077839d389 Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Wed, 18 Jan 2023 04:44:03 +0200 Subject: [PATCH 39/39] gtk4: Add centering to chat links on click See osdn #46540 Signed-off-by: Marko Lindqvist --- client/gui-gtk-4.0/chatline.c | 33 +++++++++++++++------------------ 1 file changed, 15 insertions(+), 18 deletions(-) diff --git a/client/gui-gtk-4.0/chatline.c b/client/gui-gtk-4.0/chatline.c index d99af49546..8a5e5cd77e 100644 --- a/client/gui-gtk-4.0/chatline.c +++ b/client/gui-gtk-4.0/chatline.c @@ -593,24 +593,15 @@ void scroll_if_necessary(GtkTextView *textview, GtkTextMark *scroll_target) /**********************************************************************//** Click a link. **************************************************************************/ -static gboolean event_after(GtkWidget *text_view, GdkEvent *event) +static gboolean event_after(GtkGestureClick *gesture, int n_press, + double x, double y, gpointer data) { + GtkWidget *text_view = gtk_event_controller_get_widget(GTK_EVENT_CONTROLLER(gesture)); GtkTextIter start, end, iter; GtkTextBuffer *buffer; GSList *tags, *tagp; - gint x, y; + gint bx, by; struct tile *ptile = NULL; - guint button; - gdouble e_x, e_y; - - if (gdk_event_get_event_type(event) != GDK_BUTTON_RELEASE) { - return FALSE; - } - - button = gdk_button_event_get_button(event); - if (button != 1) { - return FALSE; - } buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text_view)); @@ -620,12 +611,11 @@ static gboolean event_after(GtkWidget *text_view, GdkEvent *event) return FALSE; } - gdk_event_get_position(event, &e_x, &e_y); gtk_text_view_window_to_buffer_coords(GTK_TEXT_VIEW (text_view), GTK_TEXT_WINDOW_WIDGET, - e_x, e_y, &x, &y); + x, y, &bx, &by); - gtk_text_view_get_iter_at_location(GTK_TEXT_VIEW(text_view), &iter, x, y); + gtk_text_view_get_iter_at_location(GTK_TEXT_VIEW(text_view), &iter, bx, by); if ((tags = gtk_text_iter_get_tags(&iter))) { for (tagp = tags; tagp; tagp = tagp->next) { @@ -759,8 +749,15 @@ static gboolean motion_notify_event(GtkWidget *text_view, **************************************************************************/ void set_message_buffer_view_link_handlers(GtkWidget *view) { - g_signal_connect(view, "event-after", - G_CALLBACK(event_after), NULL); + GtkGesture *gesture; + GtkEventController *controller; + + gesture = gtk_gesture_click_new(); + controller = GTK_EVENT_CONTROLLER(gesture); + g_signal_connect(controller, "released", + G_CALLBACK(event_after), NULL); + gtk_widget_add_controller(view, controller); + g_signal_connect(view, "motion-notify-event", G_CALLBACK(motion_notify_event), NULL); } -- 2.39.0