Subject: bug#17142: 24.4.50; Initial frame geometry on OSX

From: martin rudalics <[email-masked]>
Date: Sun, 30 Mar 2014 15:46:47 +0200

> When changing the default font and the height in default-frame-alist,
 > the width is not set correctly.  I have the following lines in the
 > .emacs file:

When processing frame parameters we initially recorded the old frame
width first.  The following font change requested by

 > (add-to-list 'default-frame-alist '(font . "Courier-14"))

implicitly enlarged the frame width but the next size change requested
by

 > (add-to-list 'default-frame-alist '(height . 71))

applies the old width recorded initially, discarding the width value
implied by the new font size.

This scenario

 > When I change my settings to
 >
 > (add-to-list 'default-frame-alist '(font . "Courier-14"))
 > (add-to-list 'default-frame-alist '(width . 80))
 > (add-to-list 'default-frame-alist '(height . 71))
 >
 > everything is fine.

doesn't show the problem because it requests a new frame width as well,
so the new value is used instead of the recorded old value.

This scenario

 > When I change my settings to
 >
 > (add-to-list 'default-frame-alist '(font . "Courier-14"))
 >
 > leaving the height as ist is, the width of 80 characters per line is
 > also set correctly.

doesn't show the problem because no explicit change of the frame size is
requested, so none of the old recorded values gets applied.

I checked in a fix on the emacs-24 release branch which will get merged
to trunk sooner or later.  If you are on trunk and want to test the fix
immediately (recommended), please try the attached patch.

Thanks once more for the recipe, martin
=== modified file 'src/frame.c'
--- src/frame.c	2014-03-20 14:09:37 +0000
+++ src/frame.c	2014-03-30 13:10:11 +0000
@@ -2795,6 +2795,7 @@
      set them both at once.  So we wait until we've looked at the
      entire list before we set them.  */
   int width, height;
+  bool width_change = 0, height_change = 0;

   /* Same here.  */
   Lisp_Object left, top;
@@ -2810,7 +2811,6 @@
 #ifdef HAVE_X_WINDOWS
   bool icon_left_no_change = 0, icon_top_no_change = 0;
 #endif
-  bool size_changed = 0;
   struct gcpro gcpro1, gcpro2;

   i = 0;
@@ -2844,18 +2844,6 @@
   top = left = Qunbound;
   icon_left = icon_top = Qunbound;

-  /* Provide default values for HEIGHT and WIDTH.  */
-  width = (f->new_width
-	   ? (f->new_pixelwise
-	      ? f->new_width
-	      : (f->new_width * FRAME_COLUMN_WIDTH (f)))
-	   : FRAME_TEXT_WIDTH (f));
-  height = (f->new_height
-	    ? (f->new_pixelwise
-	       ? f->new_height
-	       : (f->new_height * FRAME_LINE_HEIGHT (f)))
-	    : FRAME_TEXT_HEIGHT (f));
-
   /* Process foreground_color and background_color before anything else.
      They are independent of other properties, but other properties (e.g.,
      cursor_color) are dependent upon them.  */
@@ -2897,12 +2885,12 @@

       if (EQ (prop, Qwidth) && RANGED_INTEGERP (0, val, INT_MAX))
         {
-          size_changed = 1;
+	  width_change = 1;
           width = XFASTINT (val) * FRAME_COLUMN_WIDTH (f) ;
         }
       else if (EQ (prop, Qheight) && RANGED_INTEGERP (0, val, INT_MAX))
         {
-          size_changed = 1;
+	  height_change = 1;
           height = XFASTINT (val) * FRAME_LINE_HEIGHT (f);
         }
       else if (EQ (prop, Qtop))
@@ -2989,11 +2977,30 @@

     XSETFRAME (frame, f);

-    if (size_changed
+    if ((width_change || height_change)
         && (width != FRAME_TEXT_WIDTH (f)
             || height != FRAME_TEXT_HEIGHT (f)
             || f->new_height || f->new_width))
-      Fset_frame_size (frame, make_number (width), make_number (height), Qt);
+      {
+	/* If necessary provide default values for HEIGHT and WIDTH.  Do
+	   that here since otherwise a size change implied by an
+	   intermittent font change may get lost as in Bug#17142.  */
+	if (!width_change)
+	  width = (f->new_width
+		   ? (f->new_pixelwise
+		      ? f->new_width
+		      : (f->new_width * FRAME_COLUMN_WIDTH (f)))
+		   : FRAME_TEXT_WIDTH (f));
+
+	if (!height_change)
+	  height = (f->new_height
+		    ? (f->new_pixelwise
+		       ? f->new_height
+		       : (f->new_height * FRAME_LINE_HEIGHT (f)))
+		    : FRAME_TEXT_HEIGHT (f));
+
+	Fset_frame_size (frame, make_number (width), make_number (height), Qt);
+      }

     if ((!NILP (left) || !NILP (top))
 	&& ! (left_no_change && top_no_change)