Subject: Re: bug#19972: 24.4; Font size change doesn't update (window-total-width)

From: martin rudalics <[email-masked]>
Date: Mon, 02 Mar 2015 18:09:40 +0100

> Here are the results from the calls to `window--dump-frame` (done on
 > Emacs 25.0.50.1):

Thanks.  Presumably with a maximized frame.

 > ========== one ==============================
 > right before `face-spec-recalc'
 >
 > frame pixel: 1920 x 971   cols/lines: 240 x 57   units: 8 x 17
 > frame text pixel: 1888 x 971   cols/lines: 236 x 57
 > tool: 0  scroll: 16/0  fringe: 16  border: 0  right: 0  bottom: 0
 >
 > #<window 3 on *ielm*>   parent: nil
 > pixel left: 0   top: 0   size: 1920 x 954   new: 0
 > char left: 0   top: 0   size: 240 x 56   new: 0

240 is the "old" total width of your window.

 > normal: 1.0 x 1.0   new: 0
 > body pixel: 1888 x 937   char: 236 x 55
 > width left fringe: 8  left margin: 0  right margin: 0
 > width right fringe: 8  scroll-bar: 16  divider: 0
 > height header-line: 0  mode-line: 17  divider: 0
 >
 > #<window 4 on  *Minibuf-0*>   parent: nil
 > pixel left: 0   top: 954   size: 1920 x 17   new: 0
 > char left: 0   top: 56   size: 1920 x 1   new: 0
 > normal: 1.0 x 1.0   new: 0
 > body pixel: 1888 x 17   char: 236 x 1
 > width left fringe: 8  left margin: 0  right margin: 0
 > width right fringe: 8  scroll-bar: 16  divider: 0
 > height header-line: 0  mode-line: 0  divider: 0
 >
 > =============================================
 >
 > ========== two ==============================
 > right after `face-spec-recalc`
 >
 > frame pixel: 1920 x 971   cols/lines: 192 x 46   units: 10 x 21
 > frame text pixel: 1888 x 971   cols/lines: 188 x 46

Here we see the new default font set to 10 x 21, the various frame sizes
remain unaltered as you observed.

 > tool: 0  scroll: 16/0  fringe: 16  border: 0  right: 0  bottom: 0
 >
 > #<window 3 on *ielm*>   parent: nil
 > pixel left: 0   top: 0   size: 1920 x 950   new: 950
 > char left: 0   top: 0   size: 240 x 45   new: 56

The total width of your window remained unaltered at 240.  Clearly the
bug you observed.

 > normal: 1.0 x 1.0   new: ignore
 > body pixel: 1888 x 929   char: 188 x 44
 > width left fringe: 8  left margin: 0  right margin: 0
 > width right fringe: 8  scroll-bar: 16  divider: 0
 > height header-line: 0  mode-line: 21  divider: 0
 >
 > #<window 4 on  *Minibuf-0*>   parent: nil
 > pixel left: 0   top: 950   size: 1920 x 21   new: 0
 > char left: 0   top: 45   size: 1920 x 1   new: 0
 > normal: 1.0 x 1.0   new: 0
 > body pixel: 1888 x 21   char: 188 x 1
 > width left fringe: 8  left margin: 0  right margin: 0
 > width right fringe: 8  scroll-bar: 16  divider: 0
 > height header-line: 0  mode-line: 0  divider: 0
 >
 > =============================================
 >
 > ========== three ============================
 > after doing `C-x 3` + `C-x 1`
 >
 > frame pixel: 1920 x 971   cols/lines: 192 x 46   units: 10 x 21
 > frame text pixel: 1888 x 971   cols/lines: 188 x 46
 > tool: 0  scroll: 16/0  fringe: 16  border: 0  right: 0  bottom: 0
 >
 > #<window 3 on *ielm*>   parent: nil
 > pixel left: 0   top: 0   size: 1920 x 950   new: 960
 > char left: 0   top: 0   size: 192 x 45   new: 96

The total width got updated now to 192 as you observed.

 > normal: 1.0 x 1.0   new: 0.5
 > body pixel: 1888 x 929   char: 188 x 44
 > width left fringe: 8  left margin: 0  right margin: 0
 > width right fringe: 8  scroll-bar: 16  divider: 0
 > height header-line: 0  mode-line: 21  divider: 0
 >
 > #<window 4 on  *Minibuf-0*>   parent: nil
 > pixel left: 0   top: 950   size: 1920 x 21   new: 0
 > char left: 0   top: 45   size: 192 x 1   new: 192
 > normal: 1.0 x 1.0   new: 0
 > body pixel: 1888 x 21   char: 188 x 1
 > width left fringe: 8  left margin: 0  right margin: 0
 > width right fringe: 8  scroll-bar: 16  divider: 0
 > height header-line: 0  mode-line: 0  divider: 0
 >
 > =============================================

OK.  The fix for Emacs 25 is attached.  Please try it.

I'm not yet sure whether to fix this for Emacs 24.5 as well.  Basically,
the fix "should" be harmless and resolve a problem not present in Emacs
24.3.  However, wrong values for `window-total-width' or
`window-left-column' should not really harm if they occur _only_ after
setting the default font on a system whose window manager refuses to
resize the Emacs frame as requested.

Thanks, martin
diff --git a/src/frame.c b/src/frame.c
index 4a526e2..bac2b24 100644
--- a/src/frame.c
+++ b/src/frame.c
@@ -537,6 +537,8 @@ adjust_frame_size (struct frame *f, int new_width, int new_height, int inhibit,
 	}
 #endif
     }
+  else if (new_cols != old_cols)
+    call2 (Qwindow_pixel_to_total, frame, Qt);
 
   if (new_windows_height != old_windows_height
       /* When the top margin has changed we have to recalculate the top
@@ -551,6 +553,8 @@ adjust_frame_size (struct frame *f, int new_width, int new_height, int inhibit,
       if ((FRAME_TERMCAP_P (f) && !pretend) || FRAME_MSDOS_P (f))
 	FrameRows (FRAME_TTY (f)) = new_lines + FRAME_TOP_MARGIN (f);
     }
+  else if (new_lines != old_lines)
+    call2 (Qwindow_pixel_to_total, frame, Qnil);
 
   frame_size_history_add
     (f, Qadjust_frame_size_3, new_text_width, new_text_height,
@@ -4831,6 +4835,7 @@ syms_of_frame (void)
   DEFSYM (Qframep, "framep");
   DEFSYM (Qframe_live_p, "frame-live-p");
   DEFSYM (Qframe_windows_min_size, "frame-windows-min-size");
+  DEFSYM (Qwindow_pixel_to_total, "window--pixel-to-total");
   DEFSYM (Qexplicit_name, "explicit-name");
   DEFSYM (Qheight, "height");
   DEFSYM (Qicon, "icon");