aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMartin Rudalics2015-08-19 11:20:44 +0200
committerMartin Rudalics2015-08-19 11:20:44 +0200
commitf5a14da109b1ddbcf0e9e31cf0f1d385a95c0b60 (patch)
treebab0b1c449a884f341d4bbc8e3c4a7c0e71ee10a
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.
-rw-r--r--lisp/frame.el18
-rw-r--r--lisp/window.el128
-rw-r--r--src/window.c186
3 files changed, 146 insertions, 186 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)))
diff --git a/src/window.c b/src/window.c
index ad5ac79bd8e..863a7926a1e 100644
--- a/src/window.c
+++ b/src/window.c
@@ -1101,186 +1101,6 @@ end-trigger value is reset to nil. */)
1101 return value; 1101 return value;
1102} 1102}
1103 1103
1104DEFUN ("window-edges", Fwindow_edges, Swindow_edges, 0, 1, 0,
1105 doc: /* Return a list of the edge coordinates of WINDOW.
1106WINDOW must be a valid window and defaults to the selected one.
1107
1108The returned list has the form (LEFT TOP RIGHT BOTTOM). TOP and BOTTOM
1109count by lines, and LEFT and RIGHT count by columns, all relative to 0,
11100 at top left corner of frame.
1111
1112RIGHT is one more than the rightmost column occupied by WINDOW. BOTTOM
1113is one more than the bottommost row occupied by WINDOW. The edges
1114include the space used by WINDOW's scroll bar, display margins, fringes,
1115header line, and/or mode line. For the edges of just the text area, use
1116`window-inside-edges'. */)
1117 (Lisp_Object window)
1118{
1119 register struct window *w = decode_valid_window (window);
1120
1121 return list4i (WINDOW_LEFT_EDGE_COL (w), WINDOW_TOP_EDGE_LINE (w),
1122 WINDOW_RIGHT_EDGE_COL (w), WINDOW_BOTTOM_EDGE_LINE (w));
1123}
1124
1125DEFUN ("window-pixel-edges", Fwindow_pixel_edges, Swindow_pixel_edges, 0, 1, 0,
1126 doc: /* Return a list of the edge pixel coordinates of WINDOW.
1127WINDOW must be a valid window and defaults to the selected one.
1128
1129The returned list has the form (LEFT TOP RIGHT BOTTOM), all relative to
11300, 0 at the top left corner of the frame.
1131
1132RIGHT is one more than the rightmost x position occupied by WINDOW.
1133BOTTOM is one more than the bottommost y position occupied by WINDOW.
1134The pixel edges include the space used by WINDOW's scroll bar, display
1135margins, fringes, header line, and/or mode line. For the pixel edges
1136of just the text area, use `window-inside-pixel-edges'. */)
1137 (Lisp_Object window)
1138{
1139 register struct window *w = decode_valid_window (window);
1140
1141 return list4i (WINDOW_LEFT_EDGE_X (w), WINDOW_TOP_EDGE_Y (w),
1142 WINDOW_RIGHT_EDGE_X (w), WINDOW_BOTTOM_EDGE_Y (w));
1143}
1144
1145static void
1146calc_absolute_offset (struct window *w, int *add_x, int *add_y)
1147{
1148 struct frame *f = XFRAME (w->frame);
1149 *add_y = f->top_pos;
1150#ifdef FRAME_MENUBAR_HEIGHT
1151 *add_y += FRAME_MENUBAR_HEIGHT (f);
1152#endif
1153#ifdef FRAME_TOOLBAR_TOP_HEIGHT
1154 *add_y += FRAME_TOOLBAR_TOP_HEIGHT (f);
1155#elif defined (FRAME_TOOLBAR_HEIGHT)
1156 *add_y += FRAME_TOOLBAR_HEIGHT (f);
1157#endif
1158#ifdef FRAME_NS_TITLEBAR_HEIGHT
1159 *add_y += FRAME_NS_TITLEBAR_HEIGHT (f);
1160#endif
1161 *add_x = f->left_pos;
1162#ifdef FRAME_TOOLBAR_LEFT_WIDTH
1163 *add_x += FRAME_TOOLBAR_LEFT_WIDTH (f);
1164#endif
1165}
1166
1167DEFUN ("window-absolute-pixel-edges", Fwindow_absolute_pixel_edges,
1168 Swindow_absolute_pixel_edges, 0, 1, 0,
1169 doc: /* Return a list of the edge pixel coordinates of WINDOW.
1170WINDOW must be a valid window and defaults to the selected one.
1171
1172The returned list has the form (LEFT TOP RIGHT BOTTOM), all relative to
11730, 0 at the top left corner of the display.
1174
1175RIGHT is one more than the rightmost x position occupied by WINDOW.
1176BOTTOM is one more than the bottommost y position occupied by WINDOW.
1177The pixel edges include the space used by WINDOW's scroll bar, display
1178margins, fringes, header line, and/or mode line. For the pixel edges
1179of just the text area, use `window-inside-absolute-pixel-edges'. */)
1180 (Lisp_Object window)
1181{
1182 register struct window *w = decode_valid_window (window);
1183 int add_x, add_y;
1184
1185 calc_absolute_offset (w, &add_x, &add_y);
1186
1187 return list4i (WINDOW_LEFT_EDGE_X (w) + add_x,
1188 WINDOW_TOP_EDGE_Y (w) + add_y,
1189 WINDOW_RIGHT_EDGE_X (w) + add_x,
1190 WINDOW_BOTTOM_EDGE_Y (w) + add_y);
1191}
1192
1193DEFUN ("window-inside-edges", Fwindow_inside_edges, Swindow_inside_edges, 0, 1, 0,
1194 doc: /* Return a list of the edge coordinates of WINDOW.
1195WINDOW must be a live window and defaults to the selected one.
1196
1197The returned list has the form (LEFT TOP RIGHT BOTTOM). TOP and BOTTOM
1198count by lines, and LEFT and RIGHT count by columns, all relative to 0,
11990 at top left corner of frame.
1200
1201RIGHT is one more than the rightmost column of WINDOW's text area.
1202BOTTOM is one more than the bottommost row of WINDOW's text area. The
1203inside edges do not include the space used by the WINDOW's scroll bar,
1204display margins, fringes, header line, and/or mode line. */)
1205 (Lisp_Object window)
1206{
1207 register struct window *w = decode_live_window (window);
1208
1209 return list4i ((WINDOW_BOX_LEFT_EDGE_COL (w)
1210 + WINDOW_LEFT_MARGIN_COLS (w)
1211 + ((WINDOW_LEFT_FRINGE_WIDTH (w)
1212 + WINDOW_FRAME_COLUMN_WIDTH (w) - 1)
1213 / WINDOW_FRAME_COLUMN_WIDTH (w))),
1214 (WINDOW_TOP_EDGE_LINE (w)
1215 + WINDOW_HEADER_LINE_LINES (w)),
1216 (WINDOW_BOX_RIGHT_EDGE_COL (w)
1217 - WINDOW_RIGHT_MARGIN_COLS (w)
1218 - ((WINDOW_RIGHT_FRINGE_WIDTH (w)
1219 + WINDOW_FRAME_COLUMN_WIDTH (w) - 1)
1220 / WINDOW_FRAME_COLUMN_WIDTH (w))),
1221 (WINDOW_BOTTOM_EDGE_LINE (w)
1222 - WINDOW_MODE_LINE_LINES (w)));
1223}
1224
1225DEFUN ("window-inside-pixel-edges", Fwindow_inside_pixel_edges, Swindow_inside_pixel_edges, 0, 1, 0,
1226 doc: /* Return a list of the edge pixel coordinates of WINDOW's text area.
1227WINDOW must be a live window and defaults to the selected one.
1228
1229The returned list has the form (LEFT TOP RIGHT BOTTOM), all relative to
1230(0,0) at the top left corner of the frame's window area.
1231
1232RIGHT is one more than the rightmost x position of WINDOW's text area.
1233BOTTOM is one more than the bottommost y position of WINDOW's text area.
1234The inside edges do not include the space used by WINDOW's scroll bar,
1235display margins, fringes, header line, and/or mode line. */)
1236 (Lisp_Object window)
1237{
1238 register struct window *w = decode_live_window (window);
1239
1240 return list4i ((WINDOW_BOX_LEFT_EDGE_X (w)
1241 + WINDOW_LEFT_MARGIN_WIDTH (w)
1242 + WINDOW_LEFT_FRINGE_WIDTH (w)),
1243 (WINDOW_TOP_EDGE_Y (w)
1244 + WINDOW_HEADER_LINE_HEIGHT (w)),
1245 (WINDOW_BOX_RIGHT_EDGE_X (w)
1246 - WINDOW_RIGHT_MARGIN_WIDTH (w)
1247 - WINDOW_RIGHT_FRINGE_WIDTH (w)),
1248 (WINDOW_BOTTOM_EDGE_Y (w)
1249 - WINDOW_MODE_LINE_HEIGHT (w)));
1250}
1251
1252DEFUN ("window-inside-absolute-pixel-edges",
1253 Fwindow_inside_absolute_pixel_edges,
1254 Swindow_inside_absolute_pixel_edges, 0, 1, 0,
1255 doc: /* Return a list of the edge pixel coordinates of WINDOW's text area.
1256WINDOW must be a live window and defaults to the selected one.
1257
1258The returned list has the form (LEFT TOP RIGHT BOTTOM), all relative to
1259(0,0) at the top left corner of the frame's window area.
1260
1261RIGHT is one more than the rightmost x position of WINDOW's text area.
1262BOTTOM is one more than the bottommost y position of WINDOW's text area.
1263The inside edges do not include the space used by WINDOW's scroll bar,
1264display margins, fringes, header line, and/or mode line. */)
1265 (Lisp_Object window)
1266{
1267 register struct window *w = decode_live_window (window);
1268 int add_x, add_y;
1269
1270 calc_absolute_offset (w, &add_x, &add_y);
1271
1272 return list4i ((WINDOW_BOX_LEFT_EDGE_X (w)
1273 + WINDOW_LEFT_MARGIN_WIDTH (w)
1274 + WINDOW_LEFT_FRINGE_WIDTH (w) + add_x),
1275 (WINDOW_TOP_EDGE_Y (w)
1276 + WINDOW_HEADER_LINE_HEIGHT (w) + add_y),
1277 (WINDOW_BOX_RIGHT_EDGE_X (w)
1278 - WINDOW_RIGHT_MARGIN_WIDTH (w)
1279 - WINDOW_RIGHT_FRINGE_WIDTH (w) + add_x),
1280 (WINDOW_BOTTOM_EDGE_Y (w)
1281 - WINDOW_MODE_LINE_HEIGHT (w) + add_y));
1282}
1283
1284/* Test if the character at column X, row Y is within window W. 1104/* Test if the character at column X, row Y is within window W.
1285 If it is not, return ON_NOTHING; 1105 If it is not, return ON_NOTHING;
1286 if it is on the window's vertical divider, return 1106 if it is on the window's vertical divider, return
@@ -7548,18 +7368,12 @@ displayed after a scrolling operation to be somewhat inaccurate. */);
7548 defsubr (&Sset_window_hscroll); 7368 defsubr (&Sset_window_hscroll);
7549 defsubr (&Swindow_redisplay_end_trigger); 7369 defsubr (&Swindow_redisplay_end_trigger);
7550 defsubr (&Sset_window_redisplay_end_trigger); 7370 defsubr (&Sset_window_redisplay_end_trigger);
7551 defsubr (&Swindow_edges);
7552 defsubr (&Swindow_pixel_edges);
7553 defsubr (&Swindow_absolute_pixel_edges);
7554 defsubr (&Swindow_mode_line_height); 7371 defsubr (&Swindow_mode_line_height);
7555 defsubr (&Swindow_header_line_height); 7372 defsubr (&Swindow_header_line_height);
7556 defsubr (&Swindow_right_divider_width); 7373 defsubr (&Swindow_right_divider_width);
7557 defsubr (&Swindow_bottom_divider_width); 7374 defsubr (&Swindow_bottom_divider_width);
7558 defsubr (&Swindow_scroll_bar_width); 7375 defsubr (&Swindow_scroll_bar_width);
7559 defsubr (&Swindow_scroll_bar_height); 7376 defsubr (&Swindow_scroll_bar_height);
7560 defsubr (&Swindow_inside_edges);
7561 defsubr (&Swindow_inside_pixel_edges);
7562 defsubr (&Swindow_inside_absolute_pixel_edges);
7563 defsubr (&Scoordinates_in_window_p); 7377 defsubr (&Scoordinates_in_window_p);
7564 defsubr (&Swindow_at); 7378 defsubr (&Swindow_at);
7565 defsubr (&Swindow_point); 7379 defsubr (&Swindow_point);