[gnome-color-manager/gnome-2-30] At login do not attempt to remove previously set X atoms, which speeds up gcm-apply by 750ms



commit 1f55a7086f9d60d497f2cf4e51af0b7d901f02f0
Author: Richard Hughes <richard hughsie com>
Date:   Sun May 30 09:23:17 2010 +0100

    At login do not attempt to remove previously set X atoms, which speeds up gcm-apply by 750ms

 data/gcm-apply.desktop.in |    2 +-
 src/egg-debug.c           |    4 +++-
 src/gcm-apply.c           |   12 ++++++++++++
 src/gcm-device-xrandr.c   |   19 +++++++++++++++++++
 src/gcm-device-xrandr.h   |    2 ++
 5 files changed, 37 insertions(+), 2 deletions(-)
---
diff --git a/data/gcm-apply.desktop.in b/data/gcm-apply.desktop.in
index 1800de3..8a8fc83 100644
--- a/data/gcm-apply.desktop.in
+++ b/data/gcm-apply.desktop.in
@@ -4,7 +4,7 @@ _Name=Load device color profiles
 _GenericName=Load device color profiles
 _Comment=Applies device profile settings at session startup
 Icon=gnome-color-manager
-Exec=gcm-apply
+Exec=gcm-apply --login
 Terminal=false
 Type=Application
 Categories=
diff --git a/src/egg-debug.c b/src/egg-debug.c
index 64655a2..c27bc15 100644
--- a/src/egg-debug.c
+++ b/src/egg-debug.c
@@ -219,13 +219,15 @@ egg_debug_print_line (const gchar *func, const gchar *file, const int line, cons
 	gchar *str_time;
 	gchar *header;
 	time_t the_time;
+	GTimeVal timeval;
 
+	g_get_current_time (&timeval);
 	time (&the_time);
 	str_time = g_new0 (gchar, 255);
 	strftime (str_time, 254, "%H:%M:%S", localtime (&the_time));
 
 	/* generate header text */
-	header = g_strdup_printf ("TI:%s\tFI:%s\tFN:%s,%d", str_time, file, func, line);
+	header = g_strdup_printf ("TI:%s.%li\tFI:%s\tFN:%s,%d", str_time, timeval.tv_usec, file, func, line);
 	g_free (str_time);
 
 	/* always in light green */
diff --git a/src/gcm-apply.c b/src/gcm-apply.c
index dbf757d..26d2f12 100644
--- a/src/gcm-apply.c
+++ b/src/gcm-apply.c
@@ -39,6 +39,7 @@ int
 main (int argc, char **argv)
 {
 	gboolean ret;
+	gboolean login = FALSE;
 	guint retval = 0;
 	GError *error = NULL;
 	GOptionContext *context;
@@ -47,6 +48,13 @@ main (int argc, char **argv)
 	GcmClient *client = NULL;
 	GcmDevice *device;
 
+	const GOptionEntry options[] = {
+		{ "login", 'l', 0, G_OPTION_ARG_NONE, &login,
+		  /* TRANSLATORS: we use this mode at login as we're sure there are no previous settings to clear */
+		  _("Do not attempt to clear previously applied settings"), NULL },
+		{ NULL}
+	};
+
 	setlocale (LC_ALL, "");
 
 	bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
@@ -56,6 +64,7 @@ main (int argc, char **argv)
 	gtk_init (&argc, &argv);
 
 	context = g_option_context_new ("gnome-color-manager apply program");
+	g_option_context_add_main_entries (context, options, NULL);
 	g_option_context_add_group (context, egg_debug_get_option_group ());
 	g_option_context_add_group (context, gtk_get_option_group (TRUE));
 	g_option_context_parse (context, &argc, &argv, NULL);
@@ -75,6 +84,9 @@ main (int argc, char **argv)
 	for (i=0; i<array->len; i++) {
 		device = g_ptr_array_index (array, i);
 
+		/* optimize for login to save a few hundred ms */
+		gcm_device_xrandr_set_remove_atom (GCM_DEVICE_XRANDR (device), !login);
+
 		/* set gamma for device */
 		egg_debug ("setting profiles on device: %s", gcm_device_get_id (device));
 		ret = gcm_device_apply (device, &error);
diff --git a/src/gcm-device-xrandr.c b/src/gcm-device-xrandr.c
index 7fdac19..22171e9 100644
--- a/src/gcm-device-xrandr.c
+++ b/src/gcm-device-xrandr.c
@@ -58,6 +58,7 @@ struct _GcmDeviceXrandrPrivate
 	GcmXserver			*xserver;
 	GcmScreen			*screen;
 	gboolean			 xrandr_fallback;
+	gboolean			 remove_atom;
 };
 
 enum {
@@ -421,6 +422,19 @@ out:
 }
 
 /**
+ * gcm_device_xrandr_set_remove_atom:
+ *
+ * This is set to FALSE at login time when we are sure there are going to be
+ * no atoms previously set that have to be removed.
+ **/
+void
+gcm_device_xrandr_set_remove_atom (GcmDeviceXrandr *device_xrandr, gboolean remove_atom)
+{
+	g_return_if_fail (GCM_IS_DEVICE_XRANDR (device_xrandr));
+	device_xrandr->priv->remove_atom = remove_atom;
+}
+
+/**
  * gcm_device_xrandr_apply:
  *
  * Return value: %TRUE for success;
@@ -543,6 +557,10 @@ gcm_device_xrandr_apply (GcmDevice *device, GError **error)
 	use_atom = gconf_client_get_bool (priv->gconf_client, GCM_SETTINGS_SET_ICC_PROFILE_ATOM, NULL);
 	if (!use_atom || filename == NULL) {
 
+		/* at login we don't need to remove any previously set options */
+		if (!priv->remove_atom)
+			goto out;
+
 		/* remove the output atom if there's nothing to show */
 		ret = gcm_xserver_remove_output_profile (priv->xserver, output_name, error);
 		if (!ret)
@@ -671,6 +689,7 @@ gcm_device_xrandr_init (GcmDeviceXrandr *device_xrandr)
 	device_xrandr->priv = GCM_DEVICE_XRANDR_GET_PRIVATE (device_xrandr);
 	device_xrandr->priv->native_device = NULL;
 	device_xrandr->priv->xrandr_fallback = FALSE;
+	device_xrandr->priv->remove_atom = TRUE;
 	device_xrandr->priv->gamma_size = 0;
 	device_xrandr->priv->edid = gcm_edid_new ();
 	device_xrandr->priv->dmi = gcm_dmi_new ();
diff --git a/src/gcm-device-xrandr.h b/src/gcm-device-xrandr.h
index 785e10e..bd2bfb3 100644
--- a/src/gcm-device-xrandr.h
+++ b/src/gcm-device-xrandr.h
@@ -53,6 +53,8 @@ GcmDevice	*gcm_device_xrandr_new			(void);
 gboolean	 gcm_device_xrandr_set_from_output	(GcmDevice		*device,
 							 GnomeRROutput		*output,
 							 GError			**error);
+void		 gcm_device_xrandr_set_remove_atom	(GcmDeviceXrandr	*device_xrandr,
+							 gboolean		 remove_atom);
 const gchar	*gcm_device_xrandr_get_native_device	(GcmDeviceXrandr	*device_xrandr);
 gboolean	 gcm_device_xrandr_get_fallback		(GcmDeviceXrandr	*device_xrandr);
 



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