(width-diff (- img-width win-width))
(height-diff (- img-height win-height))
(new-frame-params
+ ;; If we can't resize the window, try and resize the frame.
+ ;; We used to compare the `window-width/height` and the
+ ;; `frame-width/height` instead of catching the errors, but
+ ;; it's too fiddly (e.g. in the presence of the miniwindow,
+ ;; the height the frame should be equal to the height of the
+ ;; root window +1).
(append
- (if (= (window-width) (frame-width))
- `((width . (text-pixels
- . ,(+ (frame-text-width) width-diff))))
- (enlarge-window (/ width-diff (frame-char-width)) 'horiz)
- nil)
- (if (= (window-height) (frame-height))
- `((height . (text-pixels
- . ,(+ (frame-text-height) height-diff))))
- (enlarge-window (/ height-diff (frame-char-height)) nil)
- nil))))
+ (condition-case nil
+ (progn
+ (enlarge-window (/ width-diff (frame-char-width)) 'horiz)
+ nil)
+ (error
+ `((width . (text-pixels
+ . ,(+ (frame-text-width) width-diff))))))
+ (condition-case nil
+ (progn
+ (enlarge-window (/ height-diff (frame-char-height)) nil)
+ nil)
+ (error
+ `((height . (text-pixels
+ . ,(+ (frame-text-height) height-diff)))))))))
(when new-frame-params
(modify-frame-parameters (selected-frame) new-frame-params))))