我觉得这个函数比较简单方便,工作原理是以屏幕分辨率的相对比例来确定。
frame-width
和 frame-height
调节窗口的大小。相对分辨率宽度/高度的几分之几。
left-offset
和 top-offset
则是调节窗口的位置。相对距离屏幕左边/上边的距离是分别是屏幕分辨率宽度/高度的几分之几。
(defun set-frame-size-according-to-display ()
"Set the size of the frame according to the size of the primary display."
(interactive)
(when (eq system-type 'darwin)
(let* ((display-width (display-pixel-width))
(display-height (display-pixel-height))
(frame-width (floor (* 0.7 display-width)))
(frame-height (floor (* 0.9 display-height)))
(left-offset (floor (* 0.1 display-width)))
(top-offset (floor (* 0.05 display-height))))
(set-frame-position (selected-frame) left-offset top-offset)
(set-frame-size (selected-frame) frame-width frame-height t))))