From: Ira W. Snyder Date: Fri, 18 Jan 2008 04:11:44 +0000 (-0800) Subject: [Window] Add centering capability X-Git-Url: https://www.irasnyder.com/gitweb/?a=commitdiff_plain;h=af7f3b5e63d467420a69435b02745a9065f7f797;p=tilda-gobject.git [Window] Add centering capability Add the missing implementations of the "centered-horizontally" and "centered-vertically" properties. They now work as expected. --- diff --git a/tilda-window.c b/tilda-window.c index 929a934..354155e 100644 --- a/tilda-window.c +++ b/tilda-window.c @@ -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;