Function: window-edges
window-edges is a byte-compiled function defined in window.el.gz.
Signature
(window-edges &optional WINDOW BODY ABSOLUTE PIXELWISE)
Documentation
Return a list of the edge distances of WINDOW.
WINDOW must be a valid window and defaults to the selected one. The list returned has the form (LEFT TOP RIGHT BOTTOM).
If the optional argument BODY is nil, this means to return the edges corresponding to the total size of WINDOW. BODY non-nil means to return the edges of WINDOW's body (aka text area). If BODY is non-nil, WINDOW must specify a live window.
Optional argument ABSOLUTE nil means to return edges relative to the position of WINDOW's native frame. ABSOLUTE non-nil means to return coordinates relative to the origin - the position (0, 0) - of FRAME's display. On non-graphical systems this argument has no effect.
Optional argument PIXELWISE nil means to return the coordinates in terms of the canonical character width and height of WINDOW's frame, rounded if necessary. PIXELWISE non-nil means to return the coordinates in pixels where the values for RIGHT and BOTTOM are one more than the actual value of these edges. Note that if ABSOLUTE is non-nil, PIXELWISE is implicitly non-nil too.
Probably introduced at or before Emacs version 25.1.
Source Code
;; Defined in /usr/src/emacs/lisp/window.el.gz
;;; Window edges
(defun window-edges (&optional window body absolute pixelwise)
"Return a list of the edge distances of WINDOW.
WINDOW must be a valid window and defaults to the selected one.
The list returned has the form (LEFT TOP RIGHT BOTTOM).
If the optional argument BODY is nil, this means to return the
edges corresponding to the total size of WINDOW. BODY non-nil
means to return the edges of WINDOW's body (aka text area). If
BODY is non-nil, WINDOW must specify a live window.
Optional argument ABSOLUTE nil means to return edges relative to
the position of WINDOW's native frame. ABSOLUTE non-nil means to
return coordinates relative to the origin - the position (0, 0) -
of FRAME's display. On non-graphical systems this argument has
no effect.
Optional argument PIXELWISE nil means to return the coordinates
in terms of the canonical character width and height of WINDOW's
frame, rounded if necessary. PIXELWISE non-nil means to return
the coordinates in pixels where the values for RIGHT and BOTTOM
are one more than the actual value of these edges. Note that if
ABSOLUTE is non-nil, PIXELWISE is implicitly non-nil too."
(declare (side-effect-free t))
(let* ((window (window-normalize-window window body))
(frame (window-frame window))
(border-width (frame-internal-border-width frame))
(char-width (frame-char-width frame))
(char-height (frame-char-height frame))
(left (if pixelwise
(+ (window-pixel-left window) border-width)
(+ (window-left-column window)
(/ border-width char-width))))
(left-body
(when body
(+ (window-pixel-left window) border-width
(if (eq (car (window-current-scroll-bars window)) 'left)
(window-scroll-bar-width window)
0)
(nth 0 (window-fringes window))
(* (or (nth 0 (window-margins window)) 0) char-width))))
(top (if pixelwise
(+ (window-pixel-top window) border-width)
(+ (window-top-line window)
(/ border-width char-height))))
(top-body
(when body
(+ (window-pixel-top window) border-width
(window-header-line-height window))))
(right (+ left (if pixelwise
(window-pixel-width window)
(window-total-width window))))
(right-body (and body (+ left-body (window-body-width window t))))
(bottom (+ top (if pixelwise
(window-pixel-height window)
(window-total-height window))))
(bottom-body (and body (+ top-body (window-body-height window t)))))
(if absolute
(let* ((native-edges (frame-edges frame 'native-edges))
(left-off (nth 0 native-edges))
(top-off (nth 1 native-edges)))
(if body
(list (+ left-body left-off) (+ top-body top-off)
(+ right-body left-off) (+ bottom-body top-off))
(list (+ left left-off) (+ top top-off)
(+ right left-off) (+ bottom top-off))))
(if body
(if pixelwise
(list left-body top-body right-body bottom-body)
(list (/ left-body char-width) (/ top-body char-height)
;; Round up.
(/ (+ right-body char-width -1) char-width)
(/ (+ bottom-body char-height -1) char-height)))
(list left top right bottom)))))