[gnome-color-manager] trivial: add some code so we can center the GcmSampleWindow on the correct GcmX11Output



commit 1d0879de5dd470c9fb2bcee6082728d8afa0fc6c
Author: Richard Hughes <richard hughsie com>
Date:   Thu Aug 5 14:30:13 2010 +0100

    trivial: add some code so we can center the GcmSampleWindow on the correct GcmX11Output

 libcolor-glib/gcm-sample-window.c |    2 -
 libcolor-glib/gcm-self-test.c     |   46 ++++++++++++++++++++++++++++++++++++-
 2 files changed, 45 insertions(+), 3 deletions(-)
---
diff --git a/libcolor-glib/gcm-sample-window.c b/libcolor-glib/gcm-sample-window.c
index 97a542c..f1a681d 100644
--- a/libcolor-glib/gcm-sample-window.c
+++ b/libcolor-glib/gcm-sample-window.c
@@ -193,7 +193,6 @@ gcm_sample_window_finalize (GObject *object)
 	GcmSampleWindow *sample_window = GCM_SAMPLE_WINDOW (object);
 	GcmSampleWindowPrivate *priv = sample_window->priv;
 
-	g_object_unref (priv->image);
 	if (priv->pulse_id != 0)
 		g_source_remove (priv->pulse_id);
 
@@ -223,7 +222,6 @@ gcm_sample_window_new (void)
 				      "title", "calibration square",
 				      "type-hint", GDK_WINDOW_TYPE_HINT_SPLASHSCREEN,
 				      "urgency-hint", TRUE,
-				      "window-position", GTK_WIN_POS_CENTER_ALWAYS,
 				      NULL);
 	return GTK_WINDOW (sample_window);
 }
diff --git a/libcolor-glib/gcm-self-test.c b/libcolor-glib/gcm-self-test.c
index ddedf38..2c229e6 100644
--- a/libcolor-glib/gcm-self-test.c
+++ b/libcolor-glib/gcm-self-test.c
@@ -730,6 +730,45 @@ gcm_test_sample_window_loop_cb (GMainLoop *loop)
 }
 
 static void
+gcm_test_sample_window_move_window (GtkWindow *window, const gchar *output_name)
+{
+	GcmX11Screen *screen;
+	GcmX11Output *output;
+	guint x, y;
+	guint width, height;
+	gint window_width, window_height;
+	GError *error = NULL;
+	gboolean ret;
+
+	/* get new screen */
+	screen = gcm_x11_screen_new ();
+	ret = gcm_x11_screen_assign (screen, NULL, &error);
+	if (!ret) {
+		g_warning ("failed to assign screen: %s", error->message);
+		g_error_free (error);
+		goto out;
+	}
+
+	/* get output */
+	output = gcm_x11_screen_get_output_by_name (screen, output_name, &error);
+	if (output == NULL) {
+		g_warning ("failed to get output: %s", error->message);
+		g_error_free (error);
+		goto out;
+	}
+
+	/* center the window on this output */
+	gcm_x11_output_get_position (output, &x, &y);
+	gcm_x11_output_get_size (output, &width, &height);
+	gtk_window_get_size (window, &window_width, &window_height);
+	gtk_window_move (window, x + ((width - window_width) / 2), y + ((height - window_height) / 2));
+out:
+	if (output != NULL)
+		g_object_unref (output);
+	g_object_unref (screen);
+}
+
+static void
 gcm_test_sample_window_func (void)
 {
 	GtkWindow *window;
@@ -743,12 +782,17 @@ gcm_test_sample_window_func (void)
 	source.B = 0.0f;
 	gcm_sample_window_set_color (GCM_SAMPLE_WINDOW (window), &source);
 	gcm_sample_window_set_percentage (GCM_SAMPLE_WINDOW (window), GCM_SAMPLE_WINDOW_PERCENTAGE_PULSE);
+
+	/* move to the center of device lvds1 */
+	gcm_test_sample_window_move_window (window, "LVDS1");
 	gtk_window_present (window);
+
 	loop = g_main_loop_new (NULL, FALSE);
 	g_timeout_add_seconds (2, (GSourceFunc) gcm_test_sample_window_loop_cb, loop);
 	g_main_loop_run (loop);
+
 	g_main_loop_unref (loop);
-	g_object_unref (window);
+	gtk_widget_destroy (GTK_WIDGET (window));
 }
 
 int



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