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
This commit is contained in:
Matthias Clasen 2016-04-19 15:27:08 -04:00
parent 7397fe0eab
commit 5efb574055

View File

@ -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
@ -254,6 +257,22 @@ _gtk_magnifier_destroy (GtkWidget *widget)
GTK_WIDGET_CLASS (_gtk_magnifier_parent_class)->destroy (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)
{
@ -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");