1999-05-12  Jan Vroonhof  <vroonhof@math.ethz.ch>

	* src/window.c (Fcurrent_window_configuration):
		Save minibuffer height;

	* src/window.c (set_window_configuration): use it.



Index: src/window.c
===================================================================
RCS file: /usr/CVSroot/XEmacs/xemacs-20/src/window.c,v
retrieving revision 1.45
diff -u -u -r1.45 window.c
--- window.c	1999/05/12 14:29:13	1.45
+++ window.c	1999/05/12 20:51:36
@@ -4630,6 +4630,7 @@
   Lisp_Object current_buffer;
   Lisp_Object minibuffer_scroll_window;
   Lisp_Object root_window;
+  int minibuf_height; /* 0 = no minibuffer, <0, size in lines, >0 in pixels */
   /* Record the values of window-min-width and window-min-height
      so that window sizes remain consistent with them.  */
   int min_width, min_height;
@@ -4866,6 +4867,9 @@
   int previous_pixel_height;
   int previous_pixel_left;
   int previous_pixel_width;
+  int previous_minibuf_height, previous_minibuf_top,previous_minibuf_width;
+  int real_font_height;
+  int converted_minibuf_height,target_minibuf_height; 
   int specpdl_count = specpdl_depth ();
 
   GCPRO1 (configuration);
@@ -4960,7 +4964,30 @@
       previous_pixel_left = XWINDOW (FRAME_ROOT_WINDOW (f))->pixel_left;
       previous_pixel_width = XWINDOW (FRAME_ROOT_WINDOW (f))->pixel_width;
 
-	
+      /* remember some properties of the minibuffer */
+
+      default_face_height_and_width (frame, &real_font_height, 0);
+      assert(real_font_height > 0);
+  
+      if (FRAME_HAS_MINIBUF_P (f) && ! FRAME_MINIBUF_ONLY_P (f))
+	{
+	  previous_minibuf_height
+	    = XWINDOW(FRAME_MINIBUF_WINDOW(f))->pixel_height;
+	  previous_minibuf_top
+	    = XWINDOW(FRAME_MINIBUF_WINDOW(f))->pixel_top;
+	  previous_minibuf_width
+	    = XWINDOW(FRAME_MINIBUF_WINDOW(f))->pixel_width;
+	}
+      else
+	{
+	  previous_minibuf_height = 0;
+	  previous_minibuf_width = 0;
+	}
+      converted_minibuf_height =
+	(previous_minibuf_height % real_font_height) == 0 ?
+	- (previous_minibuf_height / real_font_height ) :    /* lines */
+	    previous_minibuf_height;   /* pixels */
+           
       /* Temporarily avoid any problems with windows that are smaller
 	 than they are supposed to be.  */
       window_min_height = 1;
@@ -5132,6 +5159,40 @@
 	  || previous_frame_width != FRAME_WIDTH (f))
 	change_frame_size (f, previous_frame_height, previous_frame_width, 0);
 #endif
+      /* We just reset the size and position of the minibuffer, to its old
+	 value, which needn't be valid. So we do some magic to see which value
+	 to actually take. Then we set it.
+
+	 The magic:
+	 We take the old value if is in the same units but differs from the
+	 current value.
+
+         #### Now we get more cases correct then ever before, but
+	 are we treating all? For instance what if the frames minibuf window
+	 is no longer the same one? 
+      */
+      target_minibuf_height = previous_minibuf_height;
+      if (converted_minibuf_height &&
+	  (converted_minibuf_height * config->minibuf_height) > 0 &&
+	  (converted_minibuf_height !=  config->minibuf_height))
+	{
+	  target_minibuf_height = config->minibuf_height < 0 ?
+	    - (config->minibuf_height * real_font_height) :
+	    config->minibuf_height;
+	  target_minibuf_height =
+	    max(target_minibuf_height,real_font_height);
+	}
+      if (previous_minibuf_height)
+	{
+	  XWINDOW (FRAME_MINIBUF_WINDOW (f))->pixel_top
+	    = previous_minibuf_top -
+	          (target_minibuf_height - previous_minibuf_height);
+	  set_window_pixheight (FRAME_MINIBUF_WINDOW (f),
+				target_minibuf_height, 0);
+	  set_window_pixwidth  (FRAME_MINIBUF_WINDOW (f),
+			    previous_minibuf_width, 0);
+	}
+	
       /* This is a better way to deal with frame resizing, etc.
 	 What we _actually_ want is for the old (just restored)
 	 root window to fit
@@ -5139,7 +5200,9 @@
       XWINDOW (FRAME_ROOT_WINDOW (f))->pixel_top = previous_pixel_top;
       /* Note that this function also updates the subwindow
 	 "pixel_top"s */
-      set_window_pixheight (FRAME_ROOT_WINDOW (f), previous_pixel_height, 0);
+      set_window_pixheight (FRAME_ROOT_WINDOW (f),
+	  previous_pixel_height -
+		  (target_minibuf_height - previous_minibuf_height), 0);
       XWINDOW (FRAME_ROOT_WINDOW (f))->pixel_left = previous_pixel_left;
       /* Note that this function also updates the subwindow
 	 "pixel_left"s */
@@ -5359,6 +5422,8 @@
   struct frame *f = decode_frame (frame);
   struct window_config *config;
   int n_windows = count_windows (XWINDOW (FRAME_ROOT_WINDOW (f)));
+  int minibuf_height;
+  int real_font_height;
 
   if (n_windows <= countof (Vwindow_configuration_free_list))
     config = XWINDOW_CONFIGURATION (allocate_managed_lcrecord
@@ -5381,6 +5446,22 @@
   config->min_width = window_min_width;
   config->saved_windows_count = n_windows;
   save_window_save (FRAME_ROOT_WINDOW (f), config, 0);
+
+  /* save the minibuffer height using the heuristics from
+     change_frame_size_1 */
+  
+  XSETFRAME (frame, f); /* frame could have been nil ! */
+  default_face_height_and_width (frame, &real_font_height, 0);
+  assert(real_font_height > 0);
+  
+  if (FRAME_HAS_MINIBUF_P (f) && ! FRAME_MINIBUF_ONLY_P (f))
+    minibuf_height = XWINDOW(FRAME_MINIBUF_WINDOW(f))->pixel_height;
+  else
+    minibuf_height = 0;
+  config->minibuf_height = (minibuf_height % real_font_height) == 0 ?
+    - (minibuf_height / real_font_height ) :    /* lines */
+    minibuf_height;   /* pixels */
+
   return result;
 }
 
