d0e8d54
From 33c2ba849b1f752deb38cf8715571eadbc4b323b Mon Sep 17 00:00:00 2001
d0e8d54
From: Ray Strode <rstrode@redhat.com>
d0e8d54
Date: Thu, 13 Dec 2007 14:38:16 -0500
d0e8d54
Subject: [PATCH] add lame animation to greeter login window
d0e8d54
d0e8d54
---
d0e8d54
 gui/simple-greeter/gdm-greeter-login-window.c |   90 +++++++++++++++++++++++-
d0e8d54
 1 files changed, 86 insertions(+), 4 deletions(-)
d0e8d54
d0e8d54
diff --git a/gui/simple-greeter/gdm-greeter-login-window.c b/gui/simple-greeter/gdm-greeter-login-window.c
d0e8d54
index ca14b38..ceb9e88 100644
d0e8d54
--- a/gui/simple-greeter/gdm-greeter-login-window.c
d0e8d54
+++ b/gui/simple-greeter/gdm-greeter-login-window.c
d0e8d54
@@ -72,6 +72,8 @@ struct GdmGreeterLoginWindowPrivate
d0e8d54
         char            *timeformat;
d0e8d54
         guint            update_clock_id;
d0e8d54
         gboolean         clock_show_seconds;
d0e8d54
+
d0e8d54
+        guint            animation_timeout_id;
d0e8d54
 };
d0e8d54
 
d0e8d54
 enum {
d0e8d54
@@ -860,12 +862,60 @@ load_theme (GdmGreeterLoginWindow *login_window)
d0e8d54
         switch_mode (login_window, MODE_SELECTION);
d0e8d54
 }
d0e8d54
 
d0e8d54
+static gboolean
d0e8d54
+fit_window_to_children (GdmGreeterLoginWindow *window)
d0e8d54
+{
d0e8d54
+        int x;
d0e8d54
+        int y;
d0e8d54
+        int width;
d0e8d54
+        int height;
d0e8d54
+        int height_step;
d0e8d54
+        int width_step;
d0e8d54
+
d0e8d54
+        /* FIXME: this animation logic is really dumb
d0e8d54
+         */
d0e8d54
+
d0e8d54
+        if (!GTK_WIDGET_REALIZED (GTK_WIDGET (window))) {
d0e8d54
+                return FALSE;
d0e8d54
+        }
d0e8d54
+
d0e8d54
+        gdk_window_get_geometry (GTK_WIDGET (window)->window,
d0e8d54
+                                 &x, &y, &width, &height, NULL);
d0e8d54
+
d0e8d54
+        if (height == GTK_WIDGET (window)->requisition.height) {
d0e8d54
+                return FALSE;
d0e8d54
+        }
d0e8d54
+
d0e8d54
+        if (width < GTK_WIDGET (window)->requisition.width) {
d0e8d54
+                width_step = MIN (1, GTK_WIDGET (window)->requisition.width - width);
d0e8d54
+        } else if (width > GTK_WIDGET (window)->requisition.width) {
d0e8d54
+                width_step = -1 * MIN (1, width - GTK_WIDGET (window)->requisition.width);
d0e8d54
+        } else {
d0e8d54
+                width_step = 0;
d0e8d54
+        }
d0e8d54
+
d0e8d54
+        if (height < GTK_WIDGET (window)->requisition.height) {
d0e8d54
+                height_step = MIN ((int) 25, GTK_WIDGET (window)->requisition.height - height);
d0e8d54
+        } else if (height > GTK_WIDGET (window)->requisition.height) {
d0e8d54
+                height_step = -1 * MIN ((int) 25, height - GTK_WIDGET (window)->requisition.height);
d0e8d54
+        } else {
d0e8d54
+                height_step = 0;
d0e8d54
+        }
d0e8d54
+
d0e8d54
+        gdk_window_resize (GTK_WIDGET (window)->window,
d0e8d54
+                           width + width_step,
d0e8d54
+                           height + height_step);
d0e8d54
+
d0e8d54
+        return TRUE;
d0e8d54
+}
d0e8d54
+
d0e8d54
 static void
d0e8d54
 gdm_greeter_login_window_size_request (GtkWidget      *widget,
d0e8d54
                                        GtkRequisition *requisition)
d0e8d54
 {
d0e8d54
-        int screen_w;
d0e8d54
-        int screen_h;
d0e8d54
+        int            screen_w;
d0e8d54
+        int            screen_h;
d0e8d54
+        GtkRequisition child_requisition;
d0e8d54
 
d0e8d54
         if (GTK_WIDGET_CLASS (gdm_greeter_login_window_parent_class)->size_request) {
d0e8d54
                 GTK_WIDGET_CLASS (gdm_greeter_login_window_parent_class)->size_request (widget, requisition);
d0e8d54
@@ -874,8 +924,39 @@ gdm_greeter_login_window_size_request (GtkWidget      *widget,
d0e8d54
         screen_w = gdk_screen_get_width (gtk_widget_get_screen (widget));
d0e8d54
         screen_h = gdk_screen_get_height (gtk_widget_get_screen (widget));
d0e8d54
 
d0e8d54
-        requisition->height = screen_h * 0.5;
d0e8d54
-        requisition->width = screen_w * 0.3;
d0e8d54
+        gtk_widget_size_request (GTK_BIN (widget)->child, &child_requisition);
d0e8d54
+        *requisition = child_requisition;
d0e8d54
+
d0e8d54
+        requisition->width += 2 * GTK_CONTAINER (widget)->border_width;
d0e8d54
+        requisition->height += 2 * GTK_CONTAINER (widget)->border_width;
d0e8d54
+
d0e8d54
+        requisition->width = MIN (requisition->width, .50 * screen_w);
d0e8d54
+        requisition->height = MIN (requisition->height, .80 * screen_h);
d0e8d54
+}
d0e8d54
+
d0e8d54
+static void
d0e8d54
+clear_animation_timeout_id (GdmGreeterLoginWindow *window)
d0e8d54
+{
d0e8d54
+        window->priv->animation_timeout_id = 0;
d0e8d54
+}
d0e8d54
+
d0e8d54
+static void
d0e8d54
+gdm_greeter_login_window_size_allocate (GtkWidget      *widget,
d0e8d54
+                                        GtkAllocation  *allocation)
d0e8d54
+{
d0e8d54
+        GdmGreeterLoginWindow *window;
d0e8d54
+
d0e8d54
+        window = GDM_GREETER_LOGIN_WINDOW (widget);
d0e8d54
+
d0e8d54
+        if (window->priv->animation_timeout_id == 0) {
d0e8d54
+                window->priv->animation_timeout_id =
d0e8d54
+                    g_timeout_add_full (G_PRIORITY_DEFAULT_IDLE, 20,
d0e8d54
+                                        (GSourceFunc) fit_window_to_children,
d0e8d54
+                                        widget,
d0e8d54
+                                        (GDestroyNotify) clear_animation_timeout_id);
d0e8d54
+        }
d0e8d54
+
d0e8d54
+        GTK_WIDGET_CLASS (gdm_greeter_login_window_parent_class)->size_allocate (widget, allocation);
d0e8d54
 }
d0e8d54
 
d0e8d54
 static GObject *
d0e8d54
@@ -910,6 +991,7 @@ gdm_greeter_login_window_class_init (GdmGreeterLoginWindowClass *klass)
d0e8d54
         object_class->finalize = gdm_greeter_login_window_finalize;
d0e8d54
 
d0e8d54
         widget_class->size_request = gdm_greeter_login_window_size_request;
d0e8d54
+        widget_class->size_allocate = gdm_greeter_login_window_size_allocate;
d0e8d54
 
d0e8d54
         signals [BEGIN_VERIFICATION] =
d0e8d54
                 g_signal_new ("begin-verification",
d0e8d54
-- 
d0e8d54
1.5.3.6
d0e8d54