Merge branch 'focus-on-click' into 'main'

Focus-on-click improvements

See merge request GNOME/gtk!6336
This commit is contained in:
Matthias Clasen 2023-09-18 10:41:52 +00:00
commit a5fdd1228f
3 changed files with 16 additions and 8 deletions

View File

@ -290,6 +290,9 @@ gtk_color_button_init (GtkColorButton *button)
button->button = gtk_button_new (); button->button = gtk_button_new ();
g_signal_connect (button->button, "clicked", G_CALLBACK (gtk_color_button_clicked), button); g_signal_connect (button->button, "clicked", G_CALLBACK (gtk_color_button_clicked), button);
g_object_bind_property (button, "focus-on-click",
button->button, "focus-on-click",
0);
gtk_widget_set_parent (button->button, GTK_WIDGET (button)); gtk_widget_set_parent (button->button, GTK_WIDGET (button));
button->swatch = g_object_new (GTK_TYPE_COLOR_SWATCH, button->swatch = g_object_new (GTK_TYPE_COLOR_SWATCH,

View File

@ -594,6 +594,9 @@ gtk_font_button_init (GtkFontButton *font_button)
font_button->button = gtk_button_new (); font_button->button = gtk_button_new ();
g_signal_connect (font_button->button, "clicked", G_CALLBACK (gtk_font_button_clicked), font_button); g_signal_connect (font_button->button, "clicked", G_CALLBACK (gtk_font_button_clicked), font_button);
g_object_bind_property (font_button, "focus-on-click",
font_button->button, "focus-on-click",
0);
font_button->font_label = gtk_label_new (_("Font")); font_button->font_label = gtk_label_new (_("Font"));
gtk_widget_set_hexpand (font_button->font_label, TRUE); gtk_widget_set_hexpand (font_button->font_label, TRUE);
font_button->size_label = gtk_label_new ("14"); font_button->size_label = gtk_label_new ("14");

View File

@ -2745,6 +2745,16 @@ gtk_text_click_gesture_pressed (GtkGestureClick *gesture,
guint button; guint button;
int tmp_pos; int tmp_pos;
if (!gtk_widget_has_focus (widget))
{
if (!gtk_widget_get_focus_on_click (widget))
return;
priv->in_click = TRUE;
gtk_widget_grab_focus (widget);
gtk_gesture_set_state (GTK_GESTURE (gesture), GTK_EVENT_SEQUENCE_CLAIMED);
priv->in_click = FALSE;
}
button = gtk_gesture_single_get_current_button (GTK_GESTURE_SINGLE (gesture)); button = gtk_gesture_single_get_current_button (GTK_GESTURE_SINGLE (gesture));
current = gtk_gesture_single_get_current_sequence (GTK_GESTURE_SINGLE (gesture)); current = gtk_gesture_single_get_current_sequence (GTK_GESTURE_SINGLE (gesture));
event = gtk_gesture_get_last_event (GTK_GESTURE (gesture), current); event = gtk_gesture_get_last_event (GTK_GESTURE (gesture), current);
@ -2753,14 +2763,6 @@ gtk_text_click_gesture_pressed (GtkGestureClick *gesture,
y = widget_y; y = widget_y;
gtk_text_reset_blink_time (self); gtk_text_reset_blink_time (self);
if (!gtk_widget_has_focus (widget))
{
priv->in_click = TRUE;
gtk_widget_grab_focus (widget);
gtk_gesture_set_state (GTK_GESTURE (gesture), GTK_EVENT_SEQUENCE_CLAIMED);
priv->in_click = FALSE;
}
tmp_pos = gtk_text_find_position (self, x); tmp_pos = gtk_text_find_position (self, x);
if (gdk_event_triggers_context_menu (event)) if (gdk_event_triggers_context_menu (event))