Commit a81bd53c authored by Federico Mena Quintero's avatar Federico Mena Quintero
Browse files

gnome_rr_screen_new() now creates a singleton for the specified GdkScreen



Gnome-settings-daemon has now more than plugin that requires a GnomeRRScreen.  Having two
instances of a GnomeRRScreen would mean extra roundtrips to the X server when RANDR events
come in.  Also, it is better if GObject signals can be emitted in order from a single
GnomeRRScreen instance.

So, we now create a single GnomeRRScreen instance per GdkScreen, and return that.
Signed-off-by: Federico Mena Quintero's avatarFederico Mena Quintero <federico@gnome.org>
parent 7d3cd44c
......@@ -935,6 +935,15 @@ gnome_rr_screen_init (GnomeRRScreen *self)
priv->rr_minor_version = 0;
}
/* Weak reference callback set in gnome_rr_screen_new(); we remove the GObject data from the GdkScreen. */
static void
rr_screen_weak_notify_cb (gpointer data, GObject *where_the_object_was)
{
GdkScreen *screen = GDK_SCREEN (data);
g_object_set_data (G_OBJECT (screen), "GnomeRRScreen", NULL);
}
/**
* gnome_rr_screen_new:
* Creates a new #GnomeRRScreen instance
......@@ -949,8 +958,25 @@ GnomeRRScreen *
gnome_rr_screen_new (GdkScreen *screen,
GError **error)
{
_gnome_desktop_init_i18n ();
return g_initable_new (GNOME_TYPE_RR_SCREEN, NULL, error, "gdk-screen", screen, NULL);
GnomeRRScreen *rr_screen;
g_return_val_if_fail (GDK_IS_SCREEN (screen), NULL);
g_return_val_if_fail (error == NULL || *error == NULL, NULL);
rr_screen = g_object_get_data (G_OBJECT (screen), "GnomeRRScreen");
if (rr_screen)
g_object_ref (rr_screen);
else {
_gnome_desktop_init_i18n ();
rr_screen = g_initable_new (GNOME_TYPE_RR_SCREEN, NULL, error, "gdk-screen", screen, NULL);
if (rr_screen) {
g_object_set_data (G_OBJECT (screen), "GnomeRRScreen", rr_screen);
g_object_weak_ref (G_OBJECT (rr_screen), rr_screen_weak_notify_cb, screen);
}
}
return rr_screen;
}
void
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment