aboutsummaryrefslogtreecommitdiffstats
path: root/lisp
diff options
context:
space:
mode:
authorMartin Rudalics2015-08-19 11:20:44 +0200
committerMartin Rudalics2015-08-19 11:20:44 +0200
commitf5a14da109b1ddbcf0e9e31cf0f1d385a95c0b60 (patch)
treebab0b1c449a884f341d4bbc8e3c4a7c0e71ee10a /lisp
parenta83be20b2f3b1ad499c7584caa08434cc66bb98f (diff)
downloademacs-f5a14da109b1ddbcf0e9e31cf0f1d385a95c0b60.tar.gz
emacs-f5a14da109b1ddbcf0e9e31cf0f1d385a95c0b60.zip
Move window edge functions to Elisp.
* src/window.c (Fwindow_edges, Fwindow_pixel_edges) (Fwindow_absolute_pixel_edges, Fwindow_inside_edges) (Fwindow_inside_pixel_edges, Fwindow_inside_absolute_pixel_edges): Move to window.el. (calc_absolute_offset): Remove. * lisp/frame.el (frame-edges): New function. * lisp/window.el (window-edges, window-pixel-edges) (window-absolute-pixel-edges): Move here from window.c. (window-body-edges, window-body-pixel-edges) (window-absolute-body-pixel-edges): Move here from window.c and rename "inside" to "body". Keep old names as aliases. (window-absolute-pixel-position): New function.
Diffstat (limited to 'lisp')
-rw-r--r--lisp/frame.el18
-rw-r--r--lisp/window.el128
2 files changed, 146 insertions, 0 deletions
diff --git a/lisp/frame.el b/lisp/frame.el
index d1e7c003411..391f23922f8 100644
--- a/lisp/frame.el
+++ b/lisp/frame.el
@@ -1312,6 +1312,24 @@ live frame and defaults to the selected one."
1312 (setq vertical default-frame-scroll-bars)) 1312 (setq vertical default-frame-scroll-bars))
1313 (cons vertical (and horizontal 'bottom)))) 1313 (cons vertical (and horizontal 'bottom))))
1314 1314
1315(defun frame-edges (&optional frame type)
1316 "Return coordinates of FRAME's edges.
1317FRAME must be a live frame and defaults to the selected one. The
1318list returned has the form (LEFT TOP RIGHT BOTTOM) where all
1319values are in pixels relative to the origin - the position (0, 0)
1320- of FRAME's display. For terminal frames all values are
1321relative to LEFT and TOP which are both zero.
1322
1323Optional argument TYPE specifies the type of the edges. TYPE
1324`outer-edges' means to return the outer edges of FRAME. TYPE
1325`native-edges' (or nil) means to return the native edges of
1326FRAME. TYPE `inner-edges' means to return the inner edges of
1327FRAME."
1328 (let ((frame (window-normalize-frame frame)))
1329 (if (display-graphic-p (frame-parameter nil 'display))
1330 (x-frame-edges frame (or type 'native-edges))
1331 (list 0 0 (frame-width frame) (frame-height frame)))))
1332
1315(defun frame-monitor-attributes (&optional frame) 1333(defun frame-monitor-attributes (&optional frame)
1316 "Return the attributes of the physical monitor dominating FRAME. 1334 "Return the attributes of the physical monitor dominating FRAME.
1317If FRAME is omitted or nil, describe the currently selected frame. 1335If FRAME is omitted or nil, describe the currently selected frame.
diff --git a/lisp/window.el b/lisp/window.el
index d9c0d0afbe1..ebe7054b090 100644
--- a/lisp/window.el
+++ b/lisp/window.el
@@ -3422,6 +3422,134 @@ WINDOW pixelwise."
3422 (- (window-min-delta window t nil nil nil nil window-resize-pixelwise)) 3422 (- (window-min-delta window t nil nil nil nil window-resize-pixelwise))
3423 t nil window-resize-pixelwise)) 3423 t nil window-resize-pixelwise))
3424 3424
3425;;; Window edges
3426(defun window-edges (&optional window body absolute pixelwise)
3427 "Return a list of the edge distances of WINDOW.
3428WINDOW must be a valid window and defaults to the selected one.
3429The list returned has the form (LEFT TOP RIGHT BOTTOM).
3430
3431If the optional argument BODY is nil, this means to return the
3432edges corresponding to the total size of WINDOW. BODY non-nil
3433means to return the edges of WINDOW's body (aka text area). If
3434BODY is non-nil, WINDOW must specify a live window.
3435
3436Optional argument ABSOLUTE nil means to return edges relative to
3437the position of WINDOW's native frame. ABSOLUTE non-nil means to
3438return coordinates relative to the origin - the position (0, 0) -
3439of FRAME's display. On non-graphical systems this argument has
3440no effect.
3441
3442Optional argument PIXELWISE nil means to return the coordinates
3443in terms of the canonical character width and height of WINDOW's
3444frame, rounded if necessary. PIXELWISE non-nil means to return
3445the coordinates in pixels where the values for RIGHT and BOTTOM
3446are one more than the actual value of these edges. Note that if
3447ABSOLUTE is non-nil, PIXELWISE is implicily non-nil too."
3448 (let* ((window (window-normalize-window window body))
3449 (frame (window-frame window))
3450 (border-width (frame-border-width frame))
3451 (char-width (frame-char-width frame))
3452 (char-height (frame-char-height frame))
3453 (left (if pixelwise
3454 (+ (window-pixel-left window) border-width)
3455 (+ (window-left-column window)
3456 (/ border-width char-width))))
3457 (left-body
3458 (when body
3459 (+ (window-pixel-left window) border-width
3460 (if (eq (car (window-current-scroll-bars window)) 'left)
3461 (window-scroll-bar-width window)
3462 0)
3463 (nth 0 (window-fringes window))
3464 (* (or (nth 0 (window-margins window)) 0) char-width))))
3465 (top (if pixelwise
3466 (+ (window-pixel-top window) border-width)
3467 (+ (window-top-line window)
3468 (/ border-width char-height))))
3469 (top-body
3470 (when body
3471 (+ (window-pixel-top window) border-width
3472 (window-header-line-height window))))
3473 (right (+ left (if pixelwise
3474 (window-pixel-width window)
3475 (window-total-width window))))
3476 (right-body (and body (+ left-body (window-body-width window t))))
3477 (bottom (+ top (if pixelwise
3478 (window-pixel-height window)
3479 (window-total-height window))))
3480 (bottom-body (and body (+ top-body (window-body-height window t))))
3481 left-off right-off)
3482 (if absolute
3483 (let* ((native-edges (frame-edges frame 'native-edges))
3484 (left-off (nth 0 native-edges))
3485 (top-off (nth 1 native-edges)))
3486 (if body
3487 (list (+ left-body left-off) (+ top-body top-off)
3488 (+ right-body left-off) (+ bottom-body top-off))
3489 (list (+ left left-off) (+ top top-off)
3490 (+ right left-off) (+ bottom top-off))))
3491 (if body
3492 (if pixelwise
3493 (list left-body top-body right-body bottom-body)
3494 (list (/ left-body char-width) (/ top-body char-height)
3495 ;; Round up.
3496 (/ (+ right-body char-width -1) char-width)
3497 (/ (+ bottom-body char-height -1) char-height)))
3498 (list left top right bottom)))))
3499
3500(defun window-body-edges (&optional window)
3501 "Return a list of the edge coordinates of WINDOW's body.
3502The return value is that of `window-edges' called with argument
3503BODY non-nil."
3504 (window-edges window t))
3505(defalias 'window-inside-edges 'window-body-edges)
3506
3507(defun window-pixel-edges (&optional window)
3508 "Return a list of the edge pixel coordinates of WINDOW.
3509The return value is that of `window-edges' called with argument
3510PIXELWISE non-nil."
3511 (window-edges window nil nil t))
3512
3513(defun window-body-pixel-edges (&optional window)
3514 "Return a list of the edge pixel coordinates of WINDOW's body.
3515The return value is that of `window-edges' called with arguments
3516BODY and PIXELWISE non-nil."
3517 (window-edges window t nil t))
3518(defalias 'window-inside-pixel-edges 'window-body-pixel-edges)
3519
3520(defun window-absolute-pixel-edges (&optional window)
3521 "Return a list of the edge pixel coordinates of WINDOW.
3522The return value is that of `window-edges' called with argument
3523ABSOLUTE non-nil."
3524 (window-edges window nil t t))
3525
3526(defun window-absolute-body-pixel-edges (&optional window)
3527 "Return a list of the edge pixel coordinates of WINDOW's text area.
3528The return value is that of `window-edges' called with arguments
3529BODY and ABSOLUTE non-nil."
3530 (window-edges window t t t))
3531(defalias 'window-inside-absolute-pixel-edges 'window-absolute-body-pixel-edges)
3532
3533(defun window-absolute-pixel-position (&optional position window)
3534 "Return display coordinates of POSITION in WINDOW.
3535If the buffer position POSITION is visible in window WINDOW,
3536return the display coordinates of the upper/left corner of the
3537glyph at POSITION. The return value is a cons of the X- and
3538Y-coordinates of that corner, relative to an origin at (0, 0) of
3539WINDOW's display. Return nil if POSITION is not visible in
3540WINDOW.
3541
3542WINDOW must be a live window and defaults to the selected window.
3543POSITION defaults to the value of `window-point' of WINDOW."
3544 (let* ((window (window-normalize-window window t))
3545 (pos-in-window
3546 (pos-visible-in-window-p
3547 (or position (window-point window)) window t)))
3548 (when pos-in-window
3549 (let ((edges (window-absolute-body-pixel-edges window)))
3550 (cons (+ (nth 0 edges) (nth 0 pos-in-window))
3551 (+ (nth 1 edges) (nth 1 pos-in-window)))))))
3552
3425(defun frame-root-window-p (window) 3553(defun frame-root-window-p (window)
3426 "Return non-nil if WINDOW is the root window of its frame." 3554 "Return non-nil if WINDOW is the root window of its frame."
3427 (eq window (frame-root-window window))) 3555 (eq window (frame-root-window window)))