diff options
author | Matthias Clasen <mclasen@redhat.com> | 2016-04-19 15:27:08 -0400 |
---|---|---|
committer | Matthias Clasen <mclasen@redhat.com> | 2016-04-19 15:29:04 -0400 |
commit | 5efb574055f3b6845e4ff5e0c06151b48d544cb2 (patch) | |
tree | f46911e33e00b13afb6c0793bd7fe0d330e9a980 /gtk/gtkmagnifier.c | |
parent | 7397fe0eab8d2e1f5a04a368e819b9ff4fb4c6a3 (diff) | |
download | gtk+-5efb574055f3b6845e4ff5e0c06151b48d544cb2.tar.gz |
magnifier: Only connect to ::draw when needed
This making us take the slow path in ::draw handling, so we
want to avoid it if we can.
https://bugzilla.gnome.org/show_bug.cgi?id=765238
Diffstat (limited to 'gtk/gtkmagnifier.c')
-rw-r--r-- | gtk/gtkmagnifier.c | 30 |
1 files changed, 26 insertions, 4 deletions
diff --git a/gtk/gtkmagnifier.c b/gtk/gtkmagnifier.c index 29905fb584..5d937673d1 100644 --- a/gtk/gtkmagnifier.c +++ b/gtk/gtkmagnifier.c @@ -226,9 +226,12 @@ connect_draw_handler (GtkMagnifier *magnifier) priv = _gtk_magnifier_get_instance_private (magnifier); - if (priv->inspected) - priv->draw_handler = g_signal_connect (priv->inspected, "draw", - G_CALLBACK (draw_handler), magnifier); + if (!priv->draw_handler) + { + if (priv->inspected) + priv->draw_handler = g_signal_connect (priv->inspected, "draw", + G_CALLBACK (draw_handler), magnifier); + } } static void @@ -255,6 +258,22 @@ _gtk_magnifier_destroy (GtkWidget *widget) } static void +gtk_magnifier_map (GtkWidget *widget) +{ + connect_draw_handler (GTK_MAGNIFIER (widget)); + + GTK_WIDGET_CLASS (_gtk_magnifier_parent_class)->map (widget); +} + +static void +gtk_magnifier_unmap (GtkWidget *widget) +{ + GTK_WIDGET_CLASS (_gtk_magnifier_parent_class)->unmap (widget); + + disconnect_draw_handler (GTK_MAGNIFIER (widget)); +} + +static void _gtk_magnifier_class_init (GtkMagnifierClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); @@ -267,6 +286,8 @@ _gtk_magnifier_class_init (GtkMagnifierClass *klass) widget_class->draw = _gtk_magnifier_draw; widget_class->get_preferred_width = gtk_magnifier_get_preferred_width; widget_class->get_preferred_height = gtk_magnifier_get_preferred_height; + widget_class->map = gtk_magnifier_map; + widget_class->unmap = gtk_magnifier_unmap; g_object_class_install_property (object_class, PROP_INSPECTED, @@ -353,7 +374,8 @@ _gtk_magnifier_set_inspected (GtkMagnifier *magnifier, g_object_add_weak_pointer (G_OBJECT (priv->inspected), (gpointer *) &priv->inspected); - connect_draw_handler (magnifier); + if (gtk_widget_get_mapped (GTK_WIDGET (magnifier))) + connect_draw_handler (magnifier); connect_resize_handler (magnifier); g_object_notify (G_OBJECT (magnifier), "inspected"); |