[gtk/matthiasc/for-master: 2/2] text: Properly handle focus moving to a descendent
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/matthiasc/for-master: 2/2] text: Properly handle focus moving to a descendent
- Date: Mon, 24 Aug 2020 22:33:07 +0000 (UTC)
commit 43ec96684a5cc6d9955002c52345a86cffb449bd
Author: Matthias Clasen <mclasen redhat com>
Date: Mon Aug 24 18:31:35 2020 -0400
text: Properly handle focus moving to a descendent
To discriminate between is-focus and contains-focus,
we need to use notify::is-focus. This makes sure
we don't get annoying warnings when the blink_cb
gets triggered on an unfocused entry.
Fixes: #2979
gtk/gtktext.c | 20 ++++++++++++++++----
1 file changed, 16 insertions(+), 4 deletions(-)
---
diff --git a/gtk/gtktext.c b/gtk/gtktext.c
index 873dd1df64..a87f21b798 100644
--- a/gtk/gtktext.c
+++ b/gtk/gtktext.c
@@ -326,6 +326,9 @@ static void gtk_text_snapshot (GtkWidget *widget,
GtkSnapshot *snapshot);
static void gtk_text_focus_in (GtkWidget *widget);
static void gtk_text_focus_out (GtkWidget *widget);
+static void gtk_text_focus_changed (GtkEventControllerFocus *focus,
+ GParamSpec *pspec,
+ GtkWidget *widget);
static gboolean gtk_text_grab_focus (GtkWidget *widget);
static void gtk_text_css_changed (GtkWidget *widget,
GtkCssStyleChange *change);
@@ -1894,10 +1897,8 @@ gtk_text_init (GtkText *self)
controller = gtk_event_controller_focus_new ();
gtk_event_controller_set_name (controller, "gtk-text-focus-controller");
- g_signal_connect_swapped (controller, "enter",
- G_CALLBACK (gtk_text_focus_in), self);
- g_signal_connect_swapped (controller, "leave",
- G_CALLBACK (gtk_text_focus_out), self);
+ g_signal_connect (controller, "notify::is-focus",
+ G_CALLBACK (gtk_text_focus_changed), self);
gtk_widget_add_controller (GTK_WIDGET (self), controller);
widget_node = gtk_widget_get_css_node (GTK_WIDGET (self));
@@ -3196,6 +3197,17 @@ gtk_text_focus_out (GtkWidget *widget)
gtk_text_check_cursor_blink (self);
}
+static void
+gtk_text_focus_changed (GtkEventControllerFocus *controller,
+ GParamSpec *pspec,
+ GtkWidget *widget)
+{
+ if (gtk_event_controller_focus_is_focus (controller))
+ gtk_text_focus_in (widget);
+ else
+ gtk_text_focus_out (widget);
+}
+
static gboolean
gtk_text_grab_focus (GtkWidget *widget)
{
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]