This command adjusts the size of @var{frame} to display the contents of
its buffer exactly. @var{frame} can be any live frame and defaults to
the selected one. Fitting is done only if @var{frame}'s root window is
-live.
+a live window. On window systems that use size hints, exact fitting can
+be often achieved if and only if @code{frame-resize-pixelwise}
+(@pxref{Frame Size}) is non-@code{nil}.
The arguments @var{max-height}, @var{min-height}, @var{max-width} and
@var{min-width}, if non-@code{nil}, specify bounds on the new body size
;; Move frame down.
(setq top top-margin)))))
;; Apply our changes.
+ (unless frame-resize-pixelwise
+ ;; When 'frame-resize-pixelwise' is nil, a frame cannot be
+ ;; necessarily fit completely even if the window's calculated
+ ;; width and height are integral multiples of the frame's
+ ;; character width and height. The size hints Emacs produces
+ ;; are inept to handle that when the combined sizes of the
+ ;; frame's fringes, scroll bar and internal border are not an
+ ;; integral multiple of the frame's character width (Bug#74866).
+ ;; Consequently, the window manager will round sizes down and
+ ;; this may cause lines getting wrapped. To avoid that, round
+ ;; sizes up here which will, however, leave a blank space at the
+ ;; end of the longest line(s).
+ (setq text-minus-body-width
+ (+ text-minus-body-width
+ (- char-width
+ (% text-minus-body-width char-width))))
+ (setq text-minus-body-height
+ (+ text-minus-body-height
+ (- char-height
+ (% text-minus-body-height char-height)))))
(setq text-width
(if width
(+ width text-minus-body-width)