[gtk/wip/baedert/for-master: 124/128] text: Fold focus_{in, out} into only caller




commit 85d4b865456702d257aefa83dd595671036bdee5
Author: Timm Bäder <mail baedert org>
Date:   Fri Oct 16 22:04:37 2020 +0200

    text: Fold focus_{in,out} into only caller

 gtk/gtktext.c | 75 +++++++++++++++++++++--------------------------------------
 1 file changed, 27 insertions(+), 48 deletions(-)
---
diff --git a/gtk/gtktext.c b/gtk/gtktext.c
index ceb7addbfd..7117ae39c6 100644
--- a/gtk/gtktext.c
+++ b/gtk/gtktext.c
@@ -329,8 +329,6 @@ static void   gtk_text_size_allocate        (GtkWidget        *widget,
                                              int               baseline);
 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);
@@ -3153,74 +3151,55 @@ gtk_text_key_controller_key_pressed (GtkEventControllerKey *controller,
 }
 
 static void
-gtk_text_focus_in (GtkWidget *widget)
+gtk_text_focus_changed (GtkEventControllerFocus *controller,
+                        GParamSpec              *pspec,
+                        GtkWidget               *widget)
 {
   GtkText *self = GTK_TEXT (widget);
   GtkTextPrivate *priv = gtk_text_get_instance_private (self);
   GdkSeat *seat = NULL;
   GdkDevice *keyboard = NULL;
 
-  gtk_widget_queue_draw (widget);
-
   seat = gdk_display_get_default_seat (gtk_widget_get_display (widget));
   if (seat)
     keyboard = gdk_seat_get_keyboard (seat);
-  if (keyboard)
-    g_signal_connect (keyboard, "notify::direction",
-                      G_CALLBACK (direction_changed), self);
 
+  gtk_widget_queue_draw (widget);
 
-  if (priv->editable)
+  if (gtk_event_controller_focus_is_focus (controller))
     {
-      gtk_text_schedule_im_reset (self);
-      gtk_im_context_focus_in (priv->im_context);
-    }
+      if (keyboard)
+        g_signal_connect (keyboard, "notify::direction",
+                          G_CALLBACK (direction_changed), self);
 
-  gtk_text_reset_blink_time (self);
-  gtk_text_check_cursor_blink (self);
-}
-
-static void
-gtk_text_focus_out (GtkWidget *widget)
-{
-  GtkText *self = GTK_TEXT (widget);
-  GtkTextPrivate *priv = gtk_text_get_instance_private (self);
-  GdkSeat *seat = NULL;
-  GdkDevice *keyboard = NULL;
-
-  gtk_text_selection_bubble_popup_unset (self);
+      if (priv->editable)
+        {
+          gtk_text_schedule_im_reset (self);
+          gtk_im_context_focus_in (priv->im_context);
+        }
 
-  priv->text_handles_enabled = FALSE;
-  gtk_text_update_handles (self);
+      gtk_text_reset_blink_time (self);
+    }
+  else /* Focus out */
+    {
+      gtk_text_selection_bubble_popup_unset (self);
 
-  gtk_widget_queue_draw (widget);
+      priv->text_handles_enabled = FALSE;
+      gtk_text_update_handles (self);
 
-  seat = gdk_display_get_default_seat (gtk_widget_get_display (widget));
-  if (seat)
-    keyboard = gdk_seat_get_keyboard (seat);
-  if (keyboard)
-    g_signal_handlers_disconnect_by_func (keyboard, direction_changed, self);
+      if (keyboard)
+        g_signal_handlers_disconnect_by_func (keyboard, direction_changed, self);
 
-  if (priv->editable)
-    {
-      gtk_text_schedule_im_reset (self);
-      gtk_im_context_focus_out (priv->im_context);
+      if (priv->editable)
+        {
+          gtk_text_schedule_im_reset (self);
+          gtk_im_context_focus_out (priv->im_context);
+        }
     }
 
   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]