--- src/window.h.orig	2003-03-17 01:36:34.000000000 -0500
+++ src/window.h	2003-05-26 18:27:54.000000000 -0400
@@ -95,6 +95,12 @@
   /* Whether we're maximized */
   guint maximized : 1;
 
+  /* Whether we're maximized vertically */
+  guint maximized_vertically : 1;
+
+  /* Whether we're maximized horizontally */
+  guint maximized_horizontally : 1;
+
   /* Whether we're shaded */
   guint shaded : 1;
 
@@ -334,7 +340,10 @@
 
 
 void        meta_window_fill_horizontal     (MetaWindow  *window);
+void        meta_window_unfill_horizontal (MetaWindow  *window);
+
 void        meta_window_fill_vertical       (MetaWindow  *window);
+void        meta_window_unfill_vertical (MetaWindow  *window);
 
 /* This recalcs the window/frame size, and recalcs the frame
  * size/contents as well.
--- src/window.c.orig	2003-03-28 09:39:18.000000000 -0500
+++ src/window.c	2003-05-26 18:27:54.000000000 -0400
@@ -384,6 +384,9 @@
   window->user_has_move_resized = FALSE;
   
   window->maximized = FALSE;
+  window->maximized_vertically = FALSE;
+  window->maximized_horizontally = FALSE;
+  
   window->fullscreen = FALSE;
   window->on_all_workspaces = FALSE;
   window->shaded = FALSE;
@@ -1799,6 +1802,9 @@
       meta_window_save_rect (window);
       
       window->maximized = TRUE;
+      window->maximized_vertically = FALSE;
+      window->maximized_horizontally = FALSE;
+
 
       /* FIXME why did I put this here? */
       meta_window_raise (window);      
@@ -1821,6 +1827,8 @@
                   "Unmaximizing %s\n", window->desc);
       
       window->maximized = FALSE;
+      window->maximized_vertically = FALSE;
+      window->maximized_horizontally = FALSE;
 
       meta_window_move_resize (window,
                                TRUE,
@@ -2673,19 +2681,10 @@
   /* If we now fill the screen, maximize.
    * the point here is that fill horz + fill vert = maximized
    */
-  MetaRectangle rect;
-
   if (!window->has_maximize_func)
     return;
   
-  meta_window_get_outer_rect (window, &rect);
-
-  if ( rect.x >= work_area->x &&
-       rect.y >= work_area->y &&
-       (((work_area->width - work_area->x) - rect.width) <
-        window->size_hints.width_inc) &&
-       (((work_area->height - work_area->y) - rect.height) <
-        window->size_hints.height_inc) )
+  if (window->maximized_vertically && window->maximized_horizontally)
     meta_window_maximize (window);
 }
 
@@ -2711,6 +2710,10 @@
       w -= (window->frame->child_x + window->frame->right_width);
     }
   
+  meta_window_save_rect (window);
+
+  window->maximized_horizontally = TRUE;
+
   meta_window_move_resize (window, TRUE,
                            x, y, w, h);
 
@@ -2718,6 +2721,25 @@
 }
 
 void
+meta_window_unfill_horizontal (MetaWindow  *window)
+{
+  if (window->maximized_horizontally)
+    {
+      window->maximized_horizontally = FALSE;
+      
+      meta_window_move_resize (window,
+                               TRUE,
+                               window->saved_rect.x,
+                               window->user_rect.y,
+                               window->saved_rect.width,
+                               window->user_rect.height);
+
+      recalc_window_features (window);
+      set_net_wm_state (window);
+    }
+}
+
+void
 meta_window_fill_vertical (MetaWindow  *window)
 {
   MetaRectangle work_area;
@@ -2739,12 +2761,35 @@
       h -= (window->frame->child_y + window->frame->bottom_height);
     }
   
+  meta_window_save_rect (window); 
+  window->maximized_vertically = TRUE;
+
+
   meta_window_move_resize (window, TRUE,
                            x, y, w, h);
 
   check_maximize_to_work_area (window, &work_area);
 }
 
+void
+meta_window_unfill_vertical (MetaWindow  *window)
+{
+  if (window->maximized_vertically)
+    {
+      window->maximized_vertically = FALSE;
+ 
+      meta_window_move_resize (window,
+                               TRUE,
+                               window->user_rect.x,
+                               window->saved_rect.y,
+                               window->user_rect.width,
+                               window->saved_rect.height);
+
+      recalc_window_features (window);
+      set_net_wm_state (window);
+    }
+}
+
 static guint move_resize_idle = 0;
 static GSList *move_resize_pending = NULL;
 
--- src/keybindings.c.orig	2003-05-20 23:43:04.000000000 -0400
+++ src/keybindings.c	2003-05-26 18:27:54.000000000 -0400
@@ -2371,8 +2371,11 @@
                       MetaKeyBinding *binding)
 {
   if (window)
-    {
       if (window->has_resize_func)
+      {
+          if (window->maximized_vertically)
+              meta_window_unfill_vertical(window);
+          else
         meta_window_fill_vertical (window);
     }
 }
@@ -2385,8 +2388,11 @@
                        MetaKeyBinding *binding)
 {
   if (window)
-    {
       if (window->has_resize_func)
+      {
+          if (window->maximized_horizontally)
+              meta_window_unfill_horizontal(window);
+          else
         meta_window_fill_horizontal (window);
     }
 }
