From ee6d9478c80d2d913c98dcf9e7db5c7d31e28fbd Mon Sep 17 00:00:00 2001 From: Carlos Garnacho Date: Sun, 27 Nov 2022 13:10:53 +0100 Subject: [PATCH] gtktext: Invoke OSK on button/touch taps that move/undo selection If the ::release handler is invoked, the press/release happened without drags in between. Additionally check that the press did not happen within the selection, and that there is no selection at all. This makes OSK invoked on taps that move the caret around, while tapping in the selection invokes edition popup and text handles without bringing in the OSK. --- gtk/gtktext.c | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/gtk/gtktext.c b/gtk/gtktext.c index e58355e403..0cc3a6c4f1 100644 --- a/gtk/gtktext.c +++ b/gtk/gtktext.c @@ -42,6 +42,7 @@ #include "gtkgestureclick.h" #include "gtkgesturesingle.h" #include "gtkimageprivate.h" +#include "gtkimcontextprivate.h" #include "gtkimcontextsimple.h" #include "gtkimmulticontext.h" #include @@ -465,10 +466,15 @@ static void gtk_text_motion_controller_motion (GtkEventControllerMotion *c double y, GtkText *self); static void gtk_text_click_gesture_pressed (GtkGestureClick *gesture, - int n_press, - double x, - double y, - GtkText *self); + int n_press, + double x, + double y, + GtkText *self); +static void gtk_text_click_gesture_released (GtkGestureClick *gesture, + int n_press, + double x, + double y, + GtkText *self); static void gtk_text_drag_gesture_update (GtkGestureDrag *gesture, double offset_x, double offset_y, @@ -1897,6 +1903,8 @@ gtk_text_init (GtkText *self) gtk_event_controller_set_static_name (GTK_EVENT_CONTROLLER (gesture), "gtk-text-click-gesture"); g_signal_connect (gesture, "pressed", G_CALLBACK (gtk_text_click_gesture_pressed), self); + g_signal_connect (gesture, "released", + G_CALLBACK (gtk_text_click_gesture_released), self); gtk_gesture_single_set_button (GTK_GESTURE_SINGLE (gesture), 0); gtk_gesture_single_set_exclusive (GTK_GESTURE_SINGLE (gesture), TRUE); gtk_widget_add_controller (GTK_WIDGET (self), GTK_EVENT_CONTROLLER (gesture)); @@ -2876,6 +2884,21 @@ gtk_text_click_gesture_pressed (GtkGestureClick *gesture, gtk_event_controller_reset (GTK_EVENT_CONTROLLER (gesture)); } +static void +gtk_text_click_gesture_released (GtkGestureClick *gesture, + int n_press, + double widget_x, + double widget_y, + GtkText *self) +{ + GtkTextPrivate *priv = gtk_text_get_instance_private (self); + + if (n_press == 1 && + !priv->in_drag && + priv->current_pos == priv->selection_bound) + gtk_im_context_activate_osk (priv->im_context); +} + static char * _gtk_text_get_selected_text (GtkText *self) {