Commit f5a14da1 authored by Martin Rudalics's avatar Martin Rudalics

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.
parent a83be20b
......@@ -1312,6 +1312,24 @@ live frame and defaults to the selected one."
(setq vertical default-frame-scroll-bars))
(cons vertical (and horizontal 'bottom))))
(defun frame-edges (&optional frame type)
"Return coordinates of FRAME's edges.
FRAME must be a live frame and defaults to the selected one. The
list returned has the form (LEFT TOP RIGHT BOTTOM) where all
values are in pixels relative to the origin - the position (0, 0)
- of FRAME's display. For terminal frames all values are
relative to LEFT and TOP which are both zero.
Optional argument TYPE specifies the type of the edges. TYPE
`outer-edges' means to return the outer edges of FRAME. TYPE
`native-edges' (or nil) means to return the native edges of
FRAME. TYPE `inner-edges' means to return the inner edges of
FRAME."
(let ((frame (window-normalize-frame frame)))
(if (display-graphic-p (frame-parameter nil 'display))
(x-frame-edges frame (or type 'native-edges))
(list 0 0 (frame-width frame) (frame-height frame)))))
(defun frame-monitor-attributes (&optional frame)
"Return the attributes of the physical monitor dominating FRAME.
If FRAME is omitted or nil, describe the currently selected frame.
......
......@@ -3422,6 +3422,134 @@ WINDOW pixelwise."
(- (window-min-delta window t nil nil nil nil window-resize-pixelwise))
t nil window-resize-pixelwise))
;;; 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 implicily non-nil too."
(let* ((window (window-normalize-window window body))
(frame (window-frame window))
(border-width (frame-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))))
left-off right-off)
(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)))))
(defun window-body-edges (&optional window)
"Return a list of the edge coordinates of WINDOW's body.
The return value is that of `window-edges' called with argument
BODY non-nil."
(window-edges window t))
(defalias 'window-inside-edges 'window-body-edges)
(defun window-pixel-edges (&optional window)
"Return a list of the edge pixel coordinates of WINDOW.
The return value is that of `window-edges' called with argument
PIXELWISE non-nil."
(window-edges window nil nil t))
(defun window-body-pixel-edges (&optional window)
"Return a list of the edge pixel coordinates of WINDOW's body.
The return value is that of `window-edges' called with arguments
BODY and PIXELWISE non-nil."
(window-edges window t nil t))
(defalias 'window-inside-pixel-edges 'window-body-pixel-edges)
(defun window-absolute-pixel-edges (&optional window)
"Return a list of the edge pixel coordinates of WINDOW.
The return value is that of `window-edges' called with argument
ABSOLUTE non-nil."
(window-edges window nil t t))
(defun window-absolute-body-pixel-edges (&optional window)
"Return a list of the edge pixel coordinates of WINDOW's text area.
The return value is that of `window-edges' called with arguments
BODY and ABSOLUTE non-nil."
(window-edges window t t t))
(defalias 'window-inside-absolute-pixel-edges 'window-absolute-body-pixel-edges)
(defun window-absolute-pixel-position (&optional position window)
"Return display coordinates of POSITION in WINDOW.
If the buffer position POSITION is visible in window WINDOW,
return the display coordinates of the upper/left corner of the
glyph at POSITION. The return value is a cons of the X- and
Y-coordinates of that corner, relative to an origin at (0, 0) of
WINDOW's display. Return nil if POSITION is not visible in
WINDOW.
WINDOW must be a live window and defaults to the selected window.
POSITION defaults to the value of `window-point' of WINDOW."
(let* ((window (window-normalize-window window t))
(pos-in-window
(pos-visible-in-window-p
(or position (window-point window)) window t)))
(when pos-in-window
(let ((edges (window-absolute-body-pixel-edges window)))
(cons (+ (nth 0 edges) (nth 0 pos-in-window))
(+ (nth 1 edges) (nth 1 pos-in-window)))))))
(defun frame-root-window-p (window)
"Return non-nil if WINDOW is the root window of its frame."
(eq window (frame-root-window window)))
......
......@@ -1101,186 +1101,6 @@ end-trigger value is reset to nil. */)
return value;
}
DEFUN ("window-edges", Fwindow_edges, Swindow_edges, 0, 1, 0,
doc: /* Return a list of the edge coordinates of WINDOW.
WINDOW must be a valid window and defaults to the selected one.
The returned list has the form (LEFT TOP RIGHT BOTTOM). TOP and BOTTOM
count by lines, and LEFT and RIGHT count by columns, all relative to 0,
0 at top left corner of frame.
RIGHT is one more than the rightmost column occupied by WINDOW. BOTTOM
is one more than the bottommost row occupied by WINDOW. The edges
include the space used by WINDOW's scroll bar, display margins, fringes,
header line, and/or mode line. For the edges of just the text area, use
`window-inside-edges'. */)
(Lisp_Object window)
{
register struct window *w = decode_valid_window (window);
return list4i (WINDOW_LEFT_EDGE_COL (w), WINDOW_TOP_EDGE_LINE (w),
WINDOW_RIGHT_EDGE_COL (w), WINDOW_BOTTOM_EDGE_LINE (w));
}
DEFUN ("window-pixel-edges", Fwindow_pixel_edges, Swindow_pixel_edges, 0, 1, 0,
doc: /* Return a list of the edge pixel coordinates of WINDOW.
WINDOW must be a valid window and defaults to the selected one.
The returned list has the form (LEFT TOP RIGHT BOTTOM), all relative to
0, 0 at the top left corner of the frame.
RIGHT is one more than the rightmost x position occupied by WINDOW.
BOTTOM is one more than the bottommost y position occupied by WINDOW.
The pixel edges include the space used by WINDOW's scroll bar, display
margins, fringes, header line, and/or mode line. For the pixel edges
of just the text area, use `window-inside-pixel-edges'. */)
(Lisp_Object window)
{
register struct window *w = decode_valid_window (window);
return list4i (WINDOW_LEFT_EDGE_X (w), WINDOW_TOP_EDGE_Y (w),
WINDOW_RIGHT_EDGE_X (w), WINDOW_BOTTOM_EDGE_Y (w));
}
static void
calc_absolute_offset (struct window *w, int *add_x, int *add_y)
{
struct frame *f = XFRAME (w->frame);
*add_y = f->top_pos;
#ifdef FRAME_MENUBAR_HEIGHT
*add_y += FRAME_MENUBAR_HEIGHT (f);
#endif
#ifdef FRAME_TOOLBAR_TOP_HEIGHT
*add_y += FRAME_TOOLBAR_TOP_HEIGHT (f);
#elif defined (FRAME_TOOLBAR_HEIGHT)
*add_y += FRAME_TOOLBAR_HEIGHT (f);
#endif
#ifdef FRAME_NS_TITLEBAR_HEIGHT
*add_y += FRAME_NS_TITLEBAR_HEIGHT (f);
#endif
*add_x = f->left_pos;
#ifdef FRAME_TOOLBAR_LEFT_WIDTH
*add_x += FRAME_TOOLBAR_LEFT_WIDTH (f);
#endif
}
DEFUN ("window-absolute-pixel-edges", Fwindow_absolute_pixel_edges,
Swindow_absolute_pixel_edges, 0, 1, 0,
doc: /* Return a list of the edge pixel coordinates of WINDOW.
WINDOW must be a valid window and defaults to the selected one.
The returned list has the form (LEFT TOP RIGHT BOTTOM), all relative to
0, 0 at the top left corner of the display.
RIGHT is one more than the rightmost x position occupied by WINDOW.
BOTTOM is one more than the bottommost y position occupied by WINDOW.
The pixel edges include the space used by WINDOW's scroll bar, display
margins, fringes, header line, and/or mode line. For the pixel edges
of just the text area, use `window-inside-absolute-pixel-edges'. */)
(Lisp_Object window)
{
register struct window *w = decode_valid_window (window);
int add_x, add_y;
calc_absolute_offset (w, &add_x, &add_y);
return list4i (WINDOW_LEFT_EDGE_X (w) + add_x,
WINDOW_TOP_EDGE_Y (w) + add_y,
WINDOW_RIGHT_EDGE_X (w) + add_x,
WINDOW_BOTTOM_EDGE_Y (w) + add_y);
}
DEFUN ("window-inside-edges", Fwindow_inside_edges, Swindow_inside_edges, 0, 1, 0,
doc: /* Return a list of the edge coordinates of WINDOW.
WINDOW must be a live window and defaults to the selected one.
The returned list has the form (LEFT TOP RIGHT BOTTOM). TOP and BOTTOM
count by lines, and LEFT and RIGHT count by columns, all relative to 0,
0 at top left corner of frame.
RIGHT is one more than the rightmost column of WINDOW's text area.
BOTTOM is one more than the bottommost row of WINDOW's text area. The
inside edges do not include the space used by the WINDOW's scroll bar,
display margins, fringes, header line, and/or mode line. */)
(Lisp_Object window)
{
register struct window *w = decode_live_window (window);
return list4i ((WINDOW_BOX_LEFT_EDGE_COL (w)
+ WINDOW_LEFT_MARGIN_COLS (w)
+ ((WINDOW_LEFT_FRINGE_WIDTH (w)
+ WINDOW_FRAME_COLUMN_WIDTH (w) - 1)
/ WINDOW_FRAME_COLUMN_WIDTH (w))),
(WINDOW_TOP_EDGE_LINE (w)
+ WINDOW_HEADER_LINE_LINES (w)),
(WINDOW_BOX_RIGHT_EDGE_COL (w)
- WINDOW_RIGHT_MARGIN_COLS (w)
- ((WINDOW_RIGHT_FRINGE_WIDTH (w)
+ WINDOW_FRAME_COLUMN_WIDTH (w) - 1)
/ WINDOW_FRAME_COLUMN_WIDTH (w))),
(WINDOW_BOTTOM_EDGE_LINE (w)
- WINDOW_MODE_LINE_LINES (w)));
}
DEFUN ("window-inside-pixel-edges", Fwindow_inside_pixel_edges, Swindow_inside_pixel_edges, 0, 1, 0,
doc: /* Return a list of the edge pixel coordinates of WINDOW's text area.
WINDOW must be a live window and defaults to the selected one.
The returned list has the form (LEFT TOP RIGHT BOTTOM), all relative to
(0,0) at the top left corner of the frame's window area.
RIGHT is one more than the rightmost x position of WINDOW's text area.
BOTTOM is one more than the bottommost y position of WINDOW's text area.
The inside edges do not include the space used by WINDOW's scroll bar,
display margins, fringes, header line, and/or mode line. */)
(Lisp_Object window)
{
register struct window *w = decode_live_window (window);
return list4i ((WINDOW_BOX_LEFT_EDGE_X (w)
+ WINDOW_LEFT_MARGIN_WIDTH (w)
+ WINDOW_LEFT_FRINGE_WIDTH (w)),
(WINDOW_TOP_EDGE_Y (w)
+ WINDOW_HEADER_LINE_HEIGHT (w)),
(WINDOW_BOX_RIGHT_EDGE_X (w)
- WINDOW_RIGHT_MARGIN_WIDTH (w)
- WINDOW_RIGHT_FRINGE_WIDTH (w)),
(WINDOW_BOTTOM_EDGE_Y (w)
- WINDOW_MODE_LINE_HEIGHT (w)));
}
DEFUN ("window-inside-absolute-pixel-edges",
Fwindow_inside_absolute_pixel_edges,
Swindow_inside_absolute_pixel_edges, 0, 1, 0,
doc: /* Return a list of the edge pixel coordinates of WINDOW's text area.
WINDOW must be a live window and defaults to the selected one.
The returned list has the form (LEFT TOP RIGHT BOTTOM), all relative to
(0,0) at the top left corner of the frame's window area.
RIGHT is one more than the rightmost x position of WINDOW's text area.
BOTTOM is one more than the bottommost y position of WINDOW's text area.
The inside edges do not include the space used by WINDOW's scroll bar,
display margins, fringes, header line, and/or mode line. */)
(Lisp_Object window)
{
register struct window *w = decode_live_window (window);
int add_x, add_y;
calc_absolute_offset (w, &add_x, &add_y);
return list4i ((WINDOW_BOX_LEFT_EDGE_X (w)
+ WINDOW_LEFT_MARGIN_WIDTH (w)
+ WINDOW_LEFT_FRINGE_WIDTH (w) + add_x),
(WINDOW_TOP_EDGE_Y (w)
+ WINDOW_HEADER_LINE_HEIGHT (w) + add_y),
(WINDOW_BOX_RIGHT_EDGE_X (w)
- WINDOW_RIGHT_MARGIN_WIDTH (w)
- WINDOW_RIGHT_FRINGE_WIDTH (w) + add_x),
(WINDOW_BOTTOM_EDGE_Y (w)
- WINDOW_MODE_LINE_HEIGHT (w) + add_y));
}
/* Test if the character at column X, row Y is within window W.
If it is not, return ON_NOTHING;
if it is on the window's vertical divider, return
......@@ -7548,18 +7368,12 @@ displayed after a scrolling operation to be somewhat inaccurate. */);
defsubr (&Sset_window_hscroll);
defsubr (&Swindow_redisplay_end_trigger);
defsubr (&Sset_window_redisplay_end_trigger);
defsubr (&Swindow_edges);
defsubr (&Swindow_pixel_edges);
defsubr (&Swindow_absolute_pixel_edges);
defsubr (&Swindow_mode_line_height);
defsubr (&Swindow_header_line_height);
defsubr (&Swindow_right_divider_width);
defsubr (&Swindow_bottom_divider_width);
defsubr (&Swindow_scroll_bar_width);
defsubr (&Swindow_scroll_bar_height);
defsubr (&Swindow_inside_edges);
defsubr (&Swindow_inside_pixel_edges);
defsubr (&Swindow_inside_absolute_pixel_edges);
defsubr (&Scoordinates_in_window_p);
defsubr (&Swindow_at);
defsubr (&Swindow_point);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment