[gtk+/wip/matthiasc/kill-event-signals: 107/123] popover: Stop using ::focus-in/out-event



commit 9d8f035f3b6ffdc1cc1a4b8e401d93c7cd986248
Author: Matthias Clasen <mclasen redhat com>
Date:   Sat Jan 6 12:21:31 2018 -0500

    popover: Stop using ::focus-in/out-event
    
    We can use the is-active property of the window instead.

 gtk/gtkpopover.c |   42 ++++++++++++++++--------------------------
 1 files changed, 16 insertions(+), 26 deletions(-)
---
diff --git a/gtk/gtkpopover.c b/gtk/gtkpopover.c
index 00d6e03..3e0a172 100644
--- a/gtk/gtkpopover.c
+++ b/gtk/gtkpopover.c
@@ -504,22 +504,25 @@ gtk_popover_realize (GtkWidget *widget)
   gtk_widget_set_realized (widget, TRUE);
 }
 
-static gboolean
-window_focus_in (GtkWidget  *widget,
-                 GdkEvent   *event,
-                 GtkPopover *popover)
+static void
+window_active_changed (GtkWindow  *window,
+                       GParamSpec *pspec,
+                       GtkPopover *popover)
 {
   GtkPopoverPrivate *priv = gtk_popover_get_instance_private (popover);
 
-  /* Regain the grab when the window is focused */
-  if (priv->modal &&
-      gtk_widget_is_drawable (GTK_WIDGET (popover)))
+  if (!priv->modal ||
+      !gtk_widget_is_drawable (GTK_WIDGET (popover)))
+    return;
+
+  if (gtk_window_is_active (window))
     {
+      /* Regain the grab when the window is focused */
       GtkWidget *focus;
 
       gtk_grab_add (GTK_WIDGET (popover));
 
-      focus = gtk_window_get_focus (GTK_WINDOW (widget));
+      focus = gtk_window_get_focus (window);
 
       if (focus == NULL || !gtk_widget_is_ancestor (focus, GTK_WIDGET (popover)))
         gtk_widget_grab_focus (GTK_WIDGET (popover));
@@ -529,25 +532,14 @@ window_focus_in (GtkWidget  *widget,
 
       priv->grab_notify_blocked = FALSE;
     }
-  return FALSE;
-}
-
-static gboolean
-window_focus_out (GtkWidget  *widget,
-                  GdkEvent   *event,
-                  GtkPopover *popover)
-{
-  GtkPopoverPrivate *priv = gtk_popover_get_instance_private (popover);
-
-  /* Temporarily remove the grab when unfocused */
-  if (priv->modal &&
-      gtk_widget_is_drawable (GTK_WIDGET (popover)))
+  else
     {
+      /* Temporarily remove the grab when unfocused */
       g_signal_handler_block (priv->widget, priv->grab_notify_id);
       gtk_grab_remove (GTK_WIDGET (popover));
+
       priv->grab_notify_blocked = TRUE;
     }
-  return FALSE;
 }
 
 static void
@@ -609,10 +601,8 @@ gtk_popover_apply_modality (GtkPopover *popover,
       gtk_window_set_focus (priv->window, NULL);
       gtk_widget_grab_focus (GTK_WIDGET (popover));
 
-      g_signal_connect (priv->window, "focus-in-event",
-                        G_CALLBACK (window_focus_in), popover);
-      g_signal_connect (priv->window, "focus-out-event",
-                        G_CALLBACK (window_focus_out), popover);
+      g_signal_connect (priv->window, "notify::is-active",
+                        G_CALLBACK (window_active_changed), popover);
       g_signal_connect (priv->window, "set-focus",
                         G_CALLBACK (window_set_focus), popover);
     }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]