From a8613377a571fcf860c2031eb152ea145731f9bf Mon Sep 17 00:00:00 2001 From: Sergey Bugaev Date: Fri, 25 Aug 2023 19:13:43 +0300 Subject: [PATCH 1/2] colorbutton, fontbutton: Propagate focus-on-click to inner buttons These widgets wrap a GtkButton internally. Make it possible to prevent the inner button from grabbing focus on click by propagating the value of the focus-on-click property from the widget to the inner button. Signed-off-by: Sergey Bugaev --- gtk/deprecated/gtkcolorbutton.c | 3 +++ gtk/deprecated/gtkfontbutton.c | 3 +++ 2 files changed, 6 insertions(+) diff --git a/gtk/deprecated/gtkcolorbutton.c b/gtk/deprecated/gtkcolorbutton.c index 6cd40101aa..83c777e857 100644 --- a/gtk/deprecated/gtkcolorbutton.c +++ b/gtk/deprecated/gtkcolorbutton.c @@ -290,6 +290,9 @@ gtk_color_button_init (GtkColorButton *button) button->button = gtk_button_new (); 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)); button->swatch = g_object_new (GTK_TYPE_COLOR_SWATCH, diff --git a/gtk/deprecated/gtkfontbutton.c b/gtk/deprecated/gtkfontbutton.c index 2a6f037e3c..21d59a247e 100644 --- a/gtk/deprecated/gtkfontbutton.c +++ b/gtk/deprecated/gtkfontbutton.c @@ -594,6 +594,9 @@ gtk_font_button_init (GtkFontButton *font_button) font_button->button = gtk_button_new (); 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")); gtk_widget_set_hexpand (font_button->font_label, TRUE); font_button->size_label = gtk_label_new ("14"); From 271d7632cbabe67a11449f50b2bf987c3bddb167 Mon Sep 17 00:00:00 2001 From: Sergey Bugaev Date: Tue, 5 Sep 2023 08:39:35 +0300 Subject: [PATCH 2/2] text: Respect focus-on-click property It does make sense to have GtkText not focus on click in some cases, such as when its editable property is set to false. Signed-off-by: Sergey Bugaev --- gtk/gtktext.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/gtk/gtktext.c b/gtk/gtktext.c index 147c8fa047..2d303f3765 100644 --- a/gtk/gtktext.c +++ b/gtk/gtktext.c @@ -2745,6 +2745,16 @@ gtk_text_click_gesture_pressed (GtkGestureClick *gesture, guint button; 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)); current = gtk_gesture_single_get_current_sequence (GTK_GESTURE_SINGLE (gesture)); event = gtk_gesture_get_last_event (GTK_GESTURE (gesture), current); @@ -2753,14 +2763,6 @@ gtk_text_click_gesture_pressed (GtkGestureClick *gesture, y = widget_y; 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); if (gdk_event_triggers_context_menu (event))