[Window] Add centering capability
authorIra W. Snyder <devel@irasnyder.com>
Fri, 18 Jan 2008 04:11:44 +0000 (20:11 -0800)
committerIra W. Snyder <devel@irasnyder.com>
Fri, 18 Jan 2008 04:11:44 +0000 (20:11 -0800)
Add the missing implementations of the "centered-horizontally" and
"centered-vertically" properties. They now work as expected.

tilda-window.c

index 929a934..354155e 100644 (file)
@@ -156,6 +156,28 @@ tilda_window_setup_real_transparency (TildaWindow *self)
        self->have_real_transparency = FALSE;
 }
 
+/* Center the given TildaWindow in the horizontal axis */
+static void
+tilda_window_center_horizontally (TildaWindow *self)
+{
+       const gint screen_center = gdk_screen_width() / 2;
+       const gint tilda_center  = self->width / 2;
+       const gint center_coord  = screen_center - tilda_center;
+
+       g_object_set (G_OBJECT(self), "x-position", center_coord, NULL);
+}
+
+/* Center the given TildaWindow in the vertical axis */
+static void
+tilda_window_center_vertically (TildaWindow *self)
+{
+       const gint screen_center = gdk_screen_height() / 2;
+       const gint tilda_center  = self->height / 2;
+       const gint center_coord  = screen_center - tilda_center;
+
+       g_object_set (G_OBJECT(self), "y-position", center_coord, NULL);
+}
+
 static void
 tilda_window_keybinding_cb (const gchar *keystr, gpointer data)
 {
@@ -401,11 +423,15 @@ tilda_window_set_property (GObject      *object,
 
                case TILDA_WINDOW_CENTERED_HORIZONTALLY:
                        self->centered_horizontally = g_value_get_boolean (value);
+                       if (self->centered_horizontally)
+                               tilda_window_center_horizontally (self);
                        g_print ("window centered horizontally: %d\n", self->centered_horizontally);
                        break;
 
                case TILDA_WINDOW_CENTERED_VERTICALLY:
                        self->centered_vertically = g_value_get_boolean (value);
+                       if (self->centered_vertically)
+                               tilda_window_center_vertically (self);
                        g_print ("window centered vertically: %d\n", self->centered_vertically);
                        break;