Index: constraints.c
===================================================================
RCS file: /cvs/gnome/metacity/src/constraints.c,v
retrieving revision 1.12
diff -p -u -r1.12 constraints.c
--- constraints.c	29 Jun 2003 22:33:28 -0000	1.12
+++ constraints.c	27 Jul 2003 16:48:37 -0000
@@ -1411,7 +1411,6 @@ meta_window_constrain (MetaWindow       
       current = *new;
     }
 
-#if 0
   /* Now we have to sort out the aspect ratio */
   if (!window->fullscreen)
     {
@@ -1429,19 +1428,33 @@ meta_window_constrain (MetaWindow       
       width = current.width;
       height = current.height;
 
-      /* Use the standard cut-and-pasted-between-every-WM code: */
       if (min_aspect * height > width)
         {
           int delta;
           
-          delta = FLOOR (height - width / min_aspect, window->size_hints.height_inc);
-          if (height - delta >= window->size_hints.min_height)
-            height -= delta;
-          else
+          if (y_direction == META_RESIZE_CENTER)
             {
               delta = FLOOR (height * min_aspect - width, window->size_hints.width_inc);
               if (width + delta <= window->size_hints.max_width)
                 width += delta;
+              else
+                {
+                  delta = FLOOR (height - width / min_aspect, window->size_hints.height_inc);
+                  if (height - delta >= window->size_hints.min_height)
+                    height -= delta;
+                }
+            }
+          else
+            {
+              delta = FLOOR (height - width / min_aspect, window->size_hints.height_inc);
+              if (height - delta >= window->size_hints.min_height)
+                height -= delta;
+              else
+                {
+                  delta = FLOOR (height * min_aspect - width, window->size_hints.width_inc);
+                  if (width + delta <= window->size_hints.max_width)
+                    width += delta;
+                }
             }
         }
       
@@ -1449,14 +1462,29 @@ meta_window_constrain (MetaWindow       
         {
           int delta;
           
-          delta = FLOOR (width - height * max_aspect, window->size_hints.width_inc);
-          if (width - delta >= window->size_hints.min_width)
-            width -= delta;
-          else
+          if (x_direction == META_RESIZE_CENTER)
             {
               delta = FLOOR (width / max_aspect - height, window->size_hints.height_inc);
               if (height + delta <= window->size_hints.max_height)
                 height += delta;
+              else
+                {
+                  delta = FLOOR (width - height * max_aspect, window->size_hints.width_inc);
+                  if (width - delta >= window->size_hints.min_width)
+                    width -= delta;
+                }
+            }
+          else
+            {
+              delta = FLOOR (width - height * max_aspect, window->size_hints.width_inc);
+              if (width - delta >= window->size_hints.min_width)
+                width -= delta;
+              else
+                {
+                  delta = FLOOR (width / max_aspect - height, window->size_hints.height_inc);
+                  if (height + delta <= window->size_hints.max_height)
+                    height += delta;
+                }
             }
         }
       
@@ -1508,13 +1536,8 @@ meta_window_constrain (MetaWindow       
         }
       
       current = *new;
-
-      g_print ("3 x_delta = %d y_delta = %d pos = %d,%d size = %dx%d\n",
-               x_delta, y_delta,
-               current.x, current.y, current.width, current.height);
     }
 
-#endif
   meta_topic (META_DEBUG_GEOMETRY,
               "Constrained %s new %d,%d %dx%d old %d,%d %dx%d\n",
               window->desc,
Index: tools/metacity-window-demo.c
===================================================================
RCS file: /cvs/gnome/metacity/src/tools/metacity-window-demo.c,v
retrieving revision 1.15
diff -p -u -r1.15 metacity-window-demo.c
--- tools/metacity-window-demo.c	26 Jun 2003 03:09:38 -0000	1.15
+++ tools/metacity-window-demo.c	27 Jul 2003 16:48:39 -0000
@@ -26,6 +26,8 @@
 
 static GtkWidget* do_appwindow (void);
 
+gboolean aspect_on;
+
 static void
 set_gdk_window_struts (GdkWindow *window,
                        int        left,
@@ -702,6 +704,34 @@ sleep_cb (GtkWidget *button,
   sleep (1000);
 }
 
+toggle_aspect_ratio (GtkWidget *button,
+                     gpointer   data)
+{
+  GtkWidget *window;
+  GdkGeometry geom;
+
+  if (aspect_on)
+    {
+      geom.min_aspect = 0;
+      geom.max_aspect = 65535;
+    }
+  else
+    {
+      geom.min_aspect = 1.777778;
+      geom.max_aspect = 1.777778;
+    }
+
+  aspect_on = !aspect_on;
+
+  window = gtk_widget_get_ancestor (button, GTK_TYPE_WINDOW);
+  if (window)
+    gtk_window_set_geometry_hints (GTK_WINDOW (window),
+				   GTK_WIDGET (data),
+				   &geom,
+				   GDK_HINT_ASPECT);
+				   
+}
+
 static void
 toggle_decorated_cb (GtkWidget *button,
                      gpointer   data)
@@ -799,7 +829,9 @@ do_appwindow (void)
    */
 
   ++window_count;
-  
+
+  aspect_on = FALSE;
+
   window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
   gtk_window_set_title (GTK_WINDOW (window), "Application Window");
   
@@ -838,6 +870,35 @@ do_appwindow (void)
                     GTK_EXPAND | GTK_FILL,     0,
                     0,                         0);
 
+  /* Create document
+   */
+
+  sw = gtk_scrolled_window_new (NULL, NULL);
+
+  gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw),
+                                  GTK_POLICY_AUTOMATIC,
+                                  GTK_POLICY_AUTOMATIC);
+
+  gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (sw),
+                                       GTK_SHADOW_IN);
+      
+  gtk_table_attach (GTK_TABLE (table),
+                    sw,
+                    /* X direction */       /* Y direction */
+                    0, 1,                   2, 3,
+                    GTK_EXPAND | GTK_FILL,  GTK_EXPAND | GTK_FILL,
+                    0,                      0);
+
+  gtk_window_set_default_size (GTK_WINDOW (window),
+                               200, 200);
+      
+  contents = gtk_text_view_new ();
+  gtk_text_view_set_wrap_mode (GTK_TEXT_VIEW (contents),
+                               PANGO_WRAP_WORD);
+      
+  gtk_container_add (GTK_CONTAINER (sw),
+                     contents);
+
   /* Create the toolbar
    */
   toolbar = gtk_toolbar_new ();
@@ -867,6 +928,14 @@ do_appwindow (void)
                             -1);  /* -1 means "append" */
   
   gtk_toolbar_insert_stock (GTK_TOOLBAR (toolbar),
+                            GTK_STOCK_OPEN,
+                            "This is a demo button that locks the aspect ratio using a hint",
+                            NULL,
+                            G_CALLBACK (toggle_aspect_ratio),
+                            contents, /* user data for callback */
+                            -1);  /* -1 means "append" */
+  
+  gtk_toolbar_insert_stock (GTK_TOOLBAR (toolbar),
                             GTK_STOCK_QUIT,
                             "This is a demo button with a 'quit' icon",
                             NULL,
@@ -884,35 +953,6 @@ do_appwindow (void)
                     0, 1,                   1, 2,
                     GTK_EXPAND | GTK_FILL,  0,
                     0,                      0);
-
-  /* Create document
-   */
-
-  sw = gtk_scrolled_window_new (NULL, NULL);
-
-  gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw),
-                                  GTK_POLICY_AUTOMATIC,
-                                  GTK_POLICY_AUTOMATIC);
-
-  gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (sw),
-                                       GTK_SHADOW_IN);
-      
-  gtk_table_attach (GTK_TABLE (table),
-                    sw,
-                    /* X direction */       /* Y direction */
-                    0, 1,                   2, 3,
-                    GTK_EXPAND | GTK_FILL,  GTK_EXPAND | GTK_FILL,
-                    0,                      0);
-
-  gtk_window_set_default_size (GTK_WINDOW (window),
-                               200, 200);
-      
-  contents = gtk_text_view_new ();
-  gtk_text_view_set_wrap_mode (GTK_TEXT_VIEW (contents),
-                               PANGO_WRAP_WORD);
-      
-  gtk_container_add (GTK_CONTAINER (sw),
-                     contents);
 
   /* Create statusbar */
 
