Be more careful if selected window shows the buffer other than current,
[bpt/emacs.git] / src / window.h
CommitLineData
83b2229f 1/* Window definitions for GNU Emacs.
ab422c4d
PE
2 Copyright (C) 1985-1986, 1993, 1995, 1997-2013 Free Software
3 Foundation, Inc.
83b2229f
JB
4
5This file is part of GNU Emacs.
6
b9b1cc14 7GNU Emacs is free software: you can redistribute it and/or modify
83b2229f 8it under the terms of the GNU General Public License as published by
b9b1cc14
GM
9the Free Software Foundation, either version 3 of the License, or
10(at your option) any later version.
83b2229f
JB
11
12GNU Emacs is distributed in the hope that it will be useful,
13but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15GNU General Public License for more details.
16
17You should have received a copy of the GNU General Public License
b9b1cc14 18along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
83b2229f 19
f43dd834
GM
20#ifndef WINDOW_H_INCLUDED
21#define WINDOW_H_INCLUDED
22
23#include "dispextern.h"
83b2229f 24
e8c17b81
PE
25INLINE_HEADER_BEGIN
26#ifndef WINDOW_INLINE
27# define WINDOW_INLINE INLINE
28#endif
29
83b2229f
JB
30/* Windows are allocated as if they were vectors, but then the
31Lisp data type is changed to Lisp_Window. They are garbage
32collected along with the vectors.
33
34All windows in use are arranged into a tree, with pointers up and down.
35
36Windows that are leaves of the tree are actually displayed
37and show the contents of buffers. Windows that are not leaves
38are used for representing the way groups of leaf windows are
44fa5b1e 39arranged on the frame. Leaf windows never become non-leaves.
83b2229f
JB
40They are deleted only by calling delete-window on them (but
41this can be done implicitly). Combination windows can be created
42and deleted at any time.
43
e74aeda8
DA
44A leaf window has a buffer stored in contents field and markers in its start
45and pointm fields. Non-leaf windows have nil in the latter two fields.
83b2229f
JB
46
47Non-leaf windows are either vertical or horizontal combinations.
48
44fa5b1e 49A vertical combination window has children that are arranged on the frame
e74aeda8 50one above the next. Its contents field points to the uppermost child.
83b2229f
JB
51The parent field of each of the children points to the vertical
52combination window. The next field of each child points to the
53child below it, or is nil for the lowest child. The prev field
54of each child points to the child above it, or is nil for the
55highest child.
56
57A horizontal combination window has children that are side by side.
e74aeda8 58Its contents field points to the leftmost child. In each child
83b2229f
JB
59the next field points to the child to the right and the prev field
60points to the child to the left.
61
62The children of a vertical combination window may be leaf windows
63or horizontal combination windows. The children of a horizontal
64combination window may be leaf windows or vertical combination windows.
65
66At the top of the tree are two windows which have nil as parent.
67The second of these is minibuf_window. The first one manages all
44fa5b1e 68the frame area that is not minibuffer, and is called the root window.
83b2229f
JB
69Different windows can be the root at different times;
70initially the root window is a leaf window, but if more windows
71are created then that leaf window ceases to be root and a newly
72made combination window becomes root instead.
73
fbfed6f0
JB
74In any case, on screens which have an ordinary window and a
75minibuffer, prev of the minibuf window is the root window and next of
76the root window is the minibuf window. On minibufferless screens or
77minibuffer-only screens, the root window and the minibuffer window are
27daff1e 78one and the same, so its prev and next members are nil.
83b2229f 79
e74aeda8 80A dead window has its contents field set to nil. */
83b2229f 81
f43dd834
GM
82struct cursor_pos
83{
84 /* Pixel position. These are always window relative. */
85 int x, y;
86
87 /* Glyph matrix position. */
88 int hpos, vpos;
89};
90
83b2229f
JB
91struct window
92 {
eab3844f 93 /* This is for Lisp; the terminal code does not refer to it. */
b102ceb1 94 struct vectorlike_header header;
eab3844f 95
44fa5b1e 96 /* The frame this window is on. */
d3d50620 97 Lisp_Object frame;
496e208e 98
496e208e
MR
99 /* Following (to right or down) and preceding (to left or up) child
100 at same level of tree. */
d3d50620
DA
101 Lisp_Object next;
102 Lisp_Object prev;
496e208e 103
496e208e 104 /* The window this one is a child of. */
d3d50620 105 Lisp_Object parent;
496e208e 106
5f24fa51
DA
107 /* The normal size of the window. These are fractions, but we do
108 not use C doubles to avoid creating new Lisp_Float objects while
109 interfacing Lisp in Fwindow_normal_size. */
d3d50620
DA
110 Lisp_Object normal_lines;
111 Lisp_Object normal_cols;
496e208e 112
5f24fa51
DA
113 /* New sizes of the window. Note that Lisp code may set new_normal
114 to something beyond an integer, so C int can't be used here. */
d3d50620
DA
115 Lisp_Object new_total;
116 Lisp_Object new_normal;
496e208e 117
e74aeda8
DA
118 /* May be buffer, window, or nil. */
119 Lisp_Object contents;
496e208e 120
6bff6497
EZ
121 /* A marker pointing to where in the text to start displaying.
122 BIDI Note: This is the _logical-order_ start, i.e. the smallest
123 buffer position visible in the window, not necessarily the
124 character displayed in the top left corner of the window. */
d3d50620 125 Lisp_Object start;
496e208e 126
83b2229f
JB
127 /* A marker pointing to where in the text point is in this window,
128 used only when the window is not selected.
129 This exists so that when multiple windows show one buffer
130 each one can have its own value of point. */
d3d50620 131 Lisp_Object pointm;
496e208e 132
496e208e
MR
133 /* No permanent meaning; used by save-window-excursion's
134 bookkeeping. */
d3d50620 135 Lisp_Object temslot;
496e208e 136
a3c87d4e 137 /* This window's vertical scroll bar. This field is only for use
7c299e7a 138 by the window-system-dependent code which implements the
a3c87d4e
JB
139 scroll bars; it can store anything it likes here. If this
140 window is newly created and we haven't displayed a scroll bar in
141 it yet, or if the frame doesn't have any scroll bars, this is nil. */
d3d50620 142 Lisp_Object vertical_scroll_bar;
20a558dc 143
f43dd834
GM
144 /* Width of left and right marginal areas. A value of nil means
145 no margin. */
d3d50620
DA
146 Lisp_Object left_margin_cols;
147 Lisp_Object right_margin_cols;
6000501b
KS
148
149 /* Width of left and right fringes.
150 A value of nil or t means use frame values. */
d3d50620
DA
151 Lisp_Object left_fringe_width;
152 Lisp_Object right_fringe_width;
6000501b
KS
153
154 /* Pixel width of scroll bars.
155 A value of nil or t means use frame values. */
d3d50620 156 Lisp_Object scroll_bar_width;
496e208e 157
6000501b
KS
158 /* Type of vertical scroll bar. A value of nil means
159 no scroll bar. A value of t means use frame value. */
d3d50620 160 Lisp_Object vertical_scroll_bar_type;
f43dd834 161
9d93ce29
DA
162 /* Z - the buffer position of the last glyph in the current
163 matrix of W. Only valid if window_end_valid is nonzero. */
d3d50620 164 Lisp_Object window_end_pos;
9d93ce29 165
f43dd834 166 /* Glyph matrix row of the last glyph in the current matrix
9d93ce29 167 of W. Only valid if window_end_valid is nonzero. */
d3d50620 168 Lisp_Object window_end_vpos;
496e208e 169
83b2229f
JB
170 /* Display-table to use for displaying chars in this window.
171 Nil means use the buffer's own display-table. */
d3d50620 172 Lisp_Object display_table;
496e208e 173
c98ff5dd
DA
174 /* Non-nil usually means window is marked as dedicated.
175 Note Lisp code may set this to something beyond Qnil
176 and Qt, so bitfield can't be used here. */
d3d50620 177 Lisp_Object dedicated;
496e208e 178
a3bee872
RS
179 /* If redisplay in this window goes beyond this buffer position,
180 must run the redisplay-end-trigger-hook. */
d3d50620 181 Lisp_Object redisplay_end_trigger;
177c0ea7 182
b6f67890 183 /* t means this window's child windows are not (re-)combined. */
d3d50620 184 Lisp_Object combination_limit;
496e208e 185
e1dbe924 186 /* An alist with parameters. */
d3d50620 187 Lisp_Object window_parameters;
e6841c3b 188
f43dd834
GM
189 /* No Lisp data may follow below this point without changing
190 mark_object in alloc.c. The member current_matrix must be the
191 first non-Lisp member. */
192
193 /* Glyph matrices. */
194 struct glyph_matrix *current_matrix;
195 struct glyph_matrix *desired_matrix;
196
e99f70c8
SM
197 /* The two Lisp_Object fields below are marked in a special way,
198 which is why they're placed after `current_matrix'. */
199 /* Alist of <buffer, window-start, window-point> triples listing
200 buffers previously shown in this window. */
201 Lisp_Object prev_buffers;
202 /* List of buffers re-shown in this window. */
203 Lisp_Object next_buffers;
204
45942c7d
DA
205 /* Number saying how recently window was selected. */
206 int use_time;
207
5f24fa51
DA
208 /* The upper left corner coordinates of this window,
209 relative to upper left corner of frame = 0, 0. */
210 int left_col;
211 int top_line;
212
213 /* The size of the window. */
214 int total_lines;
215 int total_cols;
216
80b00b08 217 /* Number of columns display within the window is scrolled to the left. */
ea2ac797 218 ptrdiff_t hscroll;
80b00b08
DA
219
220 /* Minimum hscroll for automatic hscrolling. This is the value
221 the user has set, by set-window-hscroll for example. */
ea2ac797 222 ptrdiff_t min_hscroll;
80b00b08
DA
223
224 /* Displayed buffer's text modification events counter as of last time
225 display completed. */
226 EMACS_INT last_modified;
227
228 /* Displayed buffer's overlays modification events counter as of last
229 complete update. */
230 EMACS_INT last_overlay_modified;
231
232 /* Value of point at that time. Since this is a position in a buffer,
1e101a4b 233 it should be positive. */
80b00b08
DA
234 ptrdiff_t last_point;
235
422ff52b
DA
236 /* Line number and position of a line somewhere above the top of the
237 screen. If this field is zero, it means we don't have a base line. */
238 ptrdiff_t base_line_number;
239
240 /* If this field is zero, it means we don't have a base line.
241 If it is -1, it means don't display the line number as long
242 as the window shows its buffer. */
243 ptrdiff_t base_line_pos;
244
245 /* The column number currently displayed in this window's mode
246 line, or -1 if column numbers are not being displayed. */
247 ptrdiff_t column_number_displayed;
248
71a0ff9a
KS
249 /* Scaling factor for the glyph_matrix size calculation in this window.
250 Used if window contains many small images or uses proportional fonts,
251 as the normal may yield a matrix which is too small. */
252 int nrows_scale_factor, ncols_scale_factor;
253
f43dd834
GM
254 /* Cursor position as of last update that completed without
255 pause. This is the position of last_point. */
256 struct cursor_pos last_cursor;
257
258 /* Intended cursor position. This is a position within the
259 glyph matrix. */
260 struct cursor_pos cursor;
177c0ea7 261
f43dd834
GM
262 /* Where the cursor actually is. */
263 struct cursor_pos phys_cursor;
177c0ea7
JB
264
265 /* Cursor type and width of last cursor drawn on the window.
7e913f91
KS
266 Used for X and w32 frames; -1 initially. */
267 int phys_cursor_type, phys_cursor_width;
f43dd834
GM
268
269 /* This is handy for undrawing the cursor. */
270 int phys_cursor_ascent, phys_cursor_height;
177c0ea7 271
c98ff5dd
DA
272 /* Non-zero if this window is a minibuffer window. */
273 unsigned mini : 1;
274
e74aeda8
DA
275 /* Meaningful only if contents is a window, non-zero if this
276 internal window is used in horizontal combination. */
277 unsigned horizontal : 1;
278
1e101a4b 279 /* Non-zero means must regenerate mode line of this window. */
c98ff5dd
DA
280 unsigned update_mode_line : 1;
281
282 /* Non-nil if the buffer was "modified" when the window
283 was last updated. */
284 unsigned last_had_star : 1;
285
286 /* Non-zero means current value of `start'
287 was the beginning of a line when it was chosen. */
288 unsigned start_at_line_beg : 1;
289
290 /* Non-zero means next redisplay must use the value of start
291 set up for it in advance. Set by scrolling commands. */
292 unsigned force_start : 1;
293
294 /* Non-zero means we have explicitly changed the value of start,
295 but that the next redisplay is not obliged to use the new value.
296 This is used in Fdelete_other_windows to force a call to
297 Vwindow_scroll_functions; also by Frecenter with argument. */
298 unsigned optional_new_start : 1;
299
f43dd834
GM
300 /* Non-zero means the cursor is currently displayed. This can be
301 set to zero by functions overpainting the cursor image. */
302 unsigned phys_cursor_on_p : 1;
303
304 /* 0 means cursor is logically on, 1 means it's off. Used for
305 blinking cursor. */
306 unsigned cursor_off_p : 1;
307
308 /* Value of cursor_off_p as of the last redisplay. */
309 unsigned last_cursor_off_p : 1;
310
311 /* 1 means desired matrix has been build and window must be
312 updated in update_frame. */
313 unsigned must_be_updated_p : 1;
314
315 /* Flag indicating that this window is not a real one.
316 Currently only used for menu bar windows of frames. */
317 unsigned pseudo_window_p : 1;
318
91a47a68
DN
319 /* 1 means the window start of this window is frozen and may not
320 be changed during redisplay. If point is not in the window,
321 accept that. */
322 unsigned frozen_window_start_p : 1;
323
2af3565e
DA
324 /* Non-zero means fringes are drawn outside display margins.
325 Otherwise draw them between margin areas and text. */
326 unsigned fringes_outside_margins : 1;
327
9d93ce29
DA
328 /* Nonzero if window_end_pos and window_end_vpos are truly valid.
329 This is zero if nontrivial redisplay is preempted since in that case
330 the frame image that window_end_pos did not get onto the frame. */
331 unsigned window_end_valid : 1;
332
f43dd834
GM
333 /* Amount by which lines of this window are scrolled in
334 y-direction (smooth scrolling). */
335 int vscroll;
177c0ea7 336
86f7c0fe 337 /* If we have highlighted the region (or any part of it), the mark
33b49d71 338 (region start) position; otherwise zero. */
86f7c0fe
EZ
339 ptrdiff_t region_showing;
340
9d93ce29
DA
341 /* Z_BYTE - buffer position of the last glyph in the current matrix of W.
342 Should be nonnegative, and only valid if window_end_valid is nonzero. */
2af3565e 343 ptrdiff_t window_end_bytepos;
f43dd834 344};
83b2229f 345
e8c17b81
PE
346/* Most code should use these functions to set Lisp fields in struct
347 window. */
348WINDOW_INLINE void
e8c17b81
PE
349wset_frame (struct window *w, Lisp_Object val)
350{
351 w->frame = val;
352}
353WINDOW_INLINE void
e8c17b81
PE
354wset_next (struct window *w, Lisp_Object val)
355{
356 w->next = val;
357}
358WINDOW_INLINE void
359wset_prev (struct window *w, Lisp_Object val)
360{
361 w->prev = val;
362}
363WINDOW_INLINE void
364wset_redisplay_end_trigger (struct window *w, Lisp_Object val)
365{
366 w->redisplay_end_trigger = val;
367}
368WINDOW_INLINE void
e8c17b81
PE
369wset_vertical_scroll_bar (struct window *w, Lisp_Object val)
370{
371 w->vertical_scroll_bar = val;
372}
373WINDOW_INLINE void
374wset_window_end_pos (struct window *w, Lisp_Object val)
375{
376 w->window_end_pos = val;
377}
378WINDOW_INLINE void
e8c17b81
PE
379wset_window_end_vpos (struct window *w, Lisp_Object val)
380{
381 w->window_end_vpos = val;
382}
d73e321c
DA
383WINDOW_INLINE void
384wset_prev_buffers (struct window *w, Lisp_Object val)
385{
386 w->prev_buffers = val;
387}
388WINDOW_INLINE void
389wset_next_buffers (struct window *w, Lisp_Object val)
390{
391 w->next_buffers = val;
392}
e8c17b81 393
83b2229f
JB
394/* 1 if W is a minibuffer window. */
395
c98ff5dd 396#define MINI_WINDOW_P(W) ((W)->mini)
83b2229f 397
6000501b
KS
398/* General window layout:
399
400 LEFT_EDGE_COL RIGHT_EDGE_COL
401 | |
402 | |
403 | BOX_LEFT_EDGE_COL |
404 | | BOX_RIGHT_EDGE_COL |
405 | | | |
406 v v v v
407 <-><-><---><-----------><---><-><->
408 ^ ^ ^ ^ ^ ^ ^
409 | | | | | | |
410 | | | | | | +-- RIGHT_SCROLL_BAR_COLS
411 | | | | | +----- RIGHT_FRINGE_WIDTH
412 | | | | +--------- RIGHT_MARGIN_COLS
413 | | | |
414 | | | +------------------ TEXT_AREA_COLS
415 | | |
416 | | +--------------------------- LEFT_MARGIN_COLS
417 | +------------------------------- LEFT_FRINGE_WIDTH
418 +---------------------------------- LEFT_SCROLL_BAR_COLS
754dc3d8 419
6000501b
KS
420*/
421
422
423/* A handy macro. */
424
e74aeda8
DA
425/* Non-zero if W is leaf (carry the buffer). */
426
427#define WINDOW_LEAF_P(W) \
428 (BUFFERP ((W)->contents))
429
430/* Non-zero if W is a member of horizontal combination. */
431
432#define WINDOW_HORIZONTAL_COMBINATION_P(W) \
433 (WINDOWP ((W)->contents) && (W)->horizontal)
434
435/* Non-zero if W is a member of vertical combination. */
436
437#define WINDOW_VERTICAL_COMBINATION_P(W) \
438 (WINDOWP ((W)->contents) && !(W)->horizontal)
439
6000501b
KS
440#define WINDOW_XFRAME(W) \
441 (XFRAME (WINDOW_FRAME ((W))))
442
443/* Return the canonical column width of the frame of window W. */
444
445#define WINDOW_FRAME_COLUMN_WIDTH(W) \
446 (FRAME_COLUMN_WIDTH (WINDOW_XFRAME ((W))))
447
448/* Return the canonical column width of the frame of window W. */
449
450#define WINDOW_FRAME_LINE_HEIGHT(W) \
451 (FRAME_LINE_HEIGHT (WINDOW_XFRAME ((W))))
452
92f774f3 453/* Return the width of window W in canonical column units.
6000501b 454 This includes scroll bars and fringes. */
8516ba9a 455
5f24fa51 456#define WINDOW_TOTAL_COLS(W) (W)->total_cols
6000501b 457
92f774f3 458/* Return the height of window W in canonical line units.
6000501b
KS
459 This includes header and mode lines, if any. */
460
5f24fa51 461#define WINDOW_TOTAL_LINES(W) (W)->total_lines
6000501b 462
6000501b
KS
463/* Return the total pixel width of window W. */
464
465#define WINDOW_TOTAL_WIDTH(W) \
466 (WINDOW_TOTAL_COLS (W) * WINDOW_FRAME_COLUMN_WIDTH (W))
467
468/* Return the total pixel height of window W. */
469
470#define WINDOW_TOTAL_HEIGHT(W) \
471 (WINDOW_TOTAL_LINES (W) * WINDOW_FRAME_LINE_HEIGHT (W))
472
496e208e
MR
473/* For HORFLAG non-zero the total number of columns of window W. Otherwise
474 the total number of lines of W. */
475
476#define WINDOW_TOTAL_SIZE(w, horflag) \
477 (horflag ? WINDOW_TOTAL_COLS (w) : WINDOW_TOTAL_LINES (w))
478
479/* The smallest acceptable dimensions for a window. Anything smaller
480 might crash Emacs. */
481
482#define MIN_SAFE_WINDOW_WIDTH (2)
483#define MIN_SAFE_WINDOW_HEIGHT (1)
6000501b
KS
484
485/* Return the canonical frame column at which window W starts.
486 This includes a left-hand scroll bar, if any. */
487
5f24fa51 488#define WINDOW_LEFT_EDGE_COL(W) (W)->left_col
6000501b
KS
489
490/* Return the canonical frame column before which window W ends.
8516ba9a
RS
491 This includes a right-hand scroll bar, if any. */
492
6000501b
KS
493#define WINDOW_RIGHT_EDGE_COL(W) \
494 (WINDOW_LEFT_EDGE_COL (W) + WINDOW_TOTAL_COLS (W))
8516ba9a 495
6000501b
KS
496/* Return the canonical frame line at which window W starts.
497 This includes a header line, if any. */
498
5f24fa51 499#define WINDOW_TOP_EDGE_LINE(W) (W)->top_line
6000501b
KS
500
501/* Return the canonical frame line before which window W ends.
502 This includes a mode line, if any. */
503
504#define WINDOW_BOTTOM_EDGE_LINE(W) \
505 (WINDOW_TOP_EDGE_LINE (W) + WINDOW_TOTAL_LINES (W))
506
507
508/* Return the frame x-position at which window W starts.
509 This includes a left-hand scroll bar, if any. */
510
511#define WINDOW_LEFT_EDGE_X(W) \
512 (FRAME_INTERNAL_BORDER_WIDTH (WINDOW_XFRAME (W)) \
513 + WINDOW_LEFT_EDGE_COL (W) * WINDOW_FRAME_COLUMN_WIDTH (W))
514
515/* Return the frame x- position before which window W ends.
516 This includes a right-hand scroll bar, if any. */
517
518#define WINDOW_RIGHT_EDGE_X(W) \
519 (FRAME_INTERNAL_BORDER_WIDTH (WINDOW_XFRAME (W)) \
520 + WINDOW_RIGHT_EDGE_COL (W) * WINDOW_FRAME_COLUMN_WIDTH (W))
521
4b00d3b1
YM
522/* 1 if W is a menu bar window. */
523
5a49b79c 524#if defined (HAVE_X_WINDOWS) && ! defined (USE_X_TOOLKIT) && ! defined (USE_GTK)
4b00d3b1 525#define WINDOW_MENU_BAR_P(W) \
e69b0960
DA
526 (WINDOWP (WINDOW_XFRAME (W)->menu_bar_window) \
527 && (W) == XWINDOW (WINDOW_XFRAME (W)->menu_bar_window))
5a49b79c
DA
528#else
529/* No menu bar windows if X toolkit is in use. */
530#define WINDOW_MENU_BAR_P(W) (0)
531#endif
4b00d3b1
YM
532
533/* 1 if W is a tool bar window. */
534
535#define WINDOW_TOOL_BAR_P(W) \
e69b0960
DA
536 (WINDOWP (WINDOW_XFRAME (W)->tool_bar_window) \
537 && (W) == XWINDOW (WINDOW_XFRAME (W)->tool_bar_window))
4b00d3b1 538
6000501b
KS
539/* Return the frame y-position at which window W starts.
540 This includes a header line, if any. */
541
542#define WINDOW_TOP_EDGE_Y(W) \
4b00d3b1
YM
543 (((WINDOW_MENU_BAR_P (W) || WINDOW_TOOL_BAR_P (W)) \
544 ? 0 : FRAME_INTERNAL_BORDER_WIDTH (WINDOW_XFRAME (W))) \
6000501b
KS
545 + WINDOW_TOP_EDGE_LINE (W) * WINDOW_FRAME_LINE_HEIGHT (W))
546
547/* Return the frame y-position before which window W ends.
548 This includes a mode line, if any. */
549
550#define WINDOW_BOTTOM_EDGE_Y(W) \
4b00d3b1
YM
551 (((WINDOW_MENU_BAR_P (W) || WINDOW_TOOL_BAR_P (W)) \
552 ? 0 : FRAME_INTERNAL_BORDER_WIDTH (WINDOW_XFRAME (W))) \
6000501b 553 + WINDOW_BOTTOM_EDGE_LINE (W) * WINDOW_FRAME_LINE_HEIGHT (W))
14a65ffe 554
8516ba9a 555
177c0ea7 556/* 1 if window W takes up the full width of its frame. */
8516ba9a
RS
557
558#define WINDOW_FULL_WIDTH_P(W) \
6000501b
KS
559 (WINDOW_TOTAL_COLS (W) == FRAME_TOTAL_COLS (WINDOW_XFRAME (W)))
560
561/* 1 if window W's has no other windows to its left in its frame. */
562
563#define WINDOW_LEFTMOST_P(W) \
564 (WINDOW_LEFT_EDGE_COL (W) == 0)
8516ba9a 565
177c0ea7 566/* 1 if window W's has no other windows to its right in its frame. */
8516ba9a
RS
567
568#define WINDOW_RIGHTMOST_P(W) \
6000501b
KS
569 (WINDOW_RIGHT_EDGE_COL (W) == FRAME_TOTAL_COLS (WINDOW_XFRAME (W)))
570
571
572/* Return the frame column at which the text (or left fringe) in
573 window W starts. This is different from the `LEFT_EDGE' because it
574 does not include a left-hand scroll bar if any. */
575
576#define WINDOW_BOX_LEFT_EDGE_COL(W) \
577 (WINDOW_LEFT_EDGE_COL (W) \
578 + WINDOW_LEFT_SCROLL_BAR_COLS (W))
579
580/* Return the window column before which the text in window W ends.
581 This is different from WINDOW_RIGHT_EDGE_COL because it does not
582 include a scroll bar or window-separating line on the right edge. */
583
584#define WINDOW_BOX_RIGHT_EDGE_COL(W) \
585 (WINDOW_RIGHT_EDGE_COL (W) \
586 - WINDOW_RIGHT_SCROLL_BAR_COLS (W))
587
588
589/* Return the frame position at which the text (or left fringe) in
590 window W starts. This is different from the `LEFT_EDGE' because it
591 does not include a left-hand scroll bar if any. */
592
593#define WINDOW_BOX_LEFT_EDGE_X(W) \
594 (FRAME_INTERNAL_BORDER_WIDTH (WINDOW_XFRAME (W)) \
595 + WINDOW_BOX_LEFT_EDGE_COL (W) * WINDOW_FRAME_COLUMN_WIDTH (W))
596
597/* Return the window column before which the text in window W ends.
598 This is different from WINDOW_RIGHT_EDGE_COL because it does not
599 include a scroll bar or window-separating line on the right edge. */
600
601#define WINDOW_BOX_RIGHT_EDGE_X(W) \
602 (FRAME_INTERNAL_BORDER_WIDTH (WINDOW_XFRAME (W)) \
603 + WINDOW_BOX_RIGHT_EDGE_COL (W) * WINDOW_FRAME_COLUMN_WIDTH (W))
604
605
606/* Width of left margin area in columns. */
607
d3d50620
DA
608#define WINDOW_LEFT_MARGIN_COLS(W) \
609 (NILP (W->left_margin_cols) \
610 ? 0 \
611 : XINT (W->left_margin_cols))
6000501b
KS
612
613/* Width of right marginal area in columns. */
614
d3d50620
DA
615#define WINDOW_RIGHT_MARGIN_COLS(W) \
616 (NILP (W->right_margin_cols) \
617 ? 0 \
618 : XINT (W->right_margin_cols))
6000501b
KS
619
620/* Width of left margin area in pixels. */
621
d3d50620
DA
622#define WINDOW_LEFT_MARGIN_WIDTH(W) \
623 (NILP (W->left_margin_cols) \
624 ? 0 \
625 : (XINT (W->left_margin_cols) \
6000501b
KS
626 * WINDOW_FRAME_COLUMN_WIDTH (W)))
627
628/* Width of right marginal area in pixels. */
629
d3d50620
DA
630#define WINDOW_RIGHT_MARGIN_WIDTH(W) \
631 (NILP (W->right_margin_cols) \
632 ? 0 \
633 : (XINT (W->right_margin_cols) \
6000501b
KS
634 * WINDOW_FRAME_COLUMN_WIDTH (W)))
635
636/* Total width of fringes reserved for drawing truncation bitmaps,
637 continuation bitmaps and alike. The width is in canonical char
638 units of the frame. This must currently be the case because window
639 sizes aren't pixel values. If it weren't the case, we wouldn't be
640 able to split windows horizontally nicely. */
641
d3d50620
DA
642#define WINDOW_FRINGE_COLS(W) \
643 ((INTEGERP (W->left_fringe_width) \
644 || INTEGERP (W->right_fringe_width)) \
645 ? ((WINDOW_LEFT_FRINGE_WIDTH (W) \
646 + WINDOW_RIGHT_FRINGE_WIDTH (W) \
647 + WINDOW_FRAME_COLUMN_WIDTH (W) - 1) \
648 / WINDOW_FRAME_COLUMN_WIDTH (W)) \
6000501b
KS
649 : FRAME_FRINGE_COLS (WINDOW_XFRAME (W)))
650
01aa0b2e
RS
651/* Column-width of the left and right fringe. */
652
d3d50620
DA
653#define WINDOW_LEFT_FRINGE_COLS(W) \
654 ((WINDOW_LEFT_FRINGE_WIDTH ((W)) \
655 + WINDOW_FRAME_COLUMN_WIDTH (W) - 1) \
01aa0b2e
RS
656 / WINDOW_FRAME_COLUMN_WIDTH (W))
657
d3d50620
DA
658#define WINDOW_RIGHT_FRINGE_COLS(W) \
659 ((WINDOW_RIGHT_FRINGE_WIDTH ((W)) \
660 + WINDOW_FRAME_COLUMN_WIDTH (W) - 1) \
01aa0b2e
RS
661 / WINDOW_FRAME_COLUMN_WIDTH (W))
662
6000501b
KS
663/* Pixel-width of the left and right fringe. */
664
665#define WINDOW_LEFT_FRINGE_WIDTH(W) \
d3d50620
DA
666 (INTEGERP (W->left_fringe_width) \
667 ? XFASTINT (W->left_fringe_width) \
6000501b
KS
668 : FRAME_LEFT_FRINGE_WIDTH (WINDOW_XFRAME (W)))
669
670#define WINDOW_RIGHT_FRINGE_WIDTH(W) \
d3d50620
DA
671 (INTEGERP (W->right_fringe_width) \
672 ? XFASTINT (W->right_fringe_width) \
6000501b
KS
673 : FRAME_RIGHT_FRINGE_WIDTH (WINDOW_XFRAME (W)))
674
675/* Total width of fringes in pixels. */
676
677#define WINDOW_TOTAL_FRINGE_WIDTH(W) \
678 (WINDOW_LEFT_FRINGE_WIDTH (W) + WINDOW_RIGHT_FRINGE_WIDTH (W))
679
680/* Are fringes outside display margins in window W. */
681
682#define WINDOW_HAS_FRINGES_OUTSIDE_MARGINS(W) \
2af3565e 683 ((W)->fringes_outside_margins)
6000501b
KS
684
685/* Say whether scroll bars are currently enabled for window W,
686 and which side they are on. */
687
688#define WINDOW_VERTICAL_SCROLL_BAR_TYPE(w) \
d3d50620 689 (EQ (w->vertical_scroll_bar_type, Qt) \
6000501b 690 ? FRAME_VERTICAL_SCROLL_BAR_TYPE (WINDOW_XFRAME (w)) \
d3d50620 691 : EQ (w->vertical_scroll_bar_type, Qleft) \
6000501b 692 ? vertical_scroll_bar_left \
d3d50620 693 : EQ (w->vertical_scroll_bar_type, Qright) \
6000501b
KS
694 ? vertical_scroll_bar_right \
695 : vertical_scroll_bar_none) \
696
697#define WINDOW_HAS_VERTICAL_SCROLL_BAR(w) \
d3d50620 698 (EQ (w->vertical_scroll_bar_type, Qt) \
6000501b 699 ? FRAME_HAS_VERTICAL_SCROLL_BARS (WINDOW_XFRAME (w)) \
d3d50620 700 : !NILP (w->vertical_scroll_bar_type))
6000501b
KS
701
702#define WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT(w) \
d3d50620 703 (EQ (w->vertical_scroll_bar_type, Qt) \
6000501b 704 ? FRAME_HAS_VERTICAL_SCROLL_BARS_ON_LEFT (WINDOW_XFRAME (w)) \
d3d50620 705 : EQ (w->vertical_scroll_bar_type, Qleft))
6000501b 706
d3d50620
DA
707#define WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_RIGHT(w) \
708 (EQ (w->vertical_scroll_bar_type, Qt) \
709 ? FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (WINDOW_XFRAME (w)) \
710 : EQ (w->vertical_scroll_bar_type, Qright))
6000501b
KS
711
712/* Width that a scroll bar in window W should have, if there is one.
713 Measured in pixels. If scroll bars are turned off, this is still
714 nonzero. */
715
716#define WINDOW_CONFIG_SCROLL_BAR_WIDTH(w) \
d3d50620
DA
717 (INTEGERP (w->scroll_bar_width) \
718 ? XFASTINT (w->scroll_bar_width) \
6000501b
KS
719 : FRAME_CONFIG_SCROLL_BAR_WIDTH (WINDOW_XFRAME (w)))
720
721/* Width that a scroll bar in window W should have, if there is one.
722 Measured in columns (characters). If scroll bars are turned off,
723 this is still nonzero. */
724
725#define WINDOW_CONFIG_SCROLL_BAR_COLS(w) \
d3d50620
DA
726 (INTEGERP (w->scroll_bar_width) \
727 ? ((XFASTINT (w->scroll_bar_width) \
6000501b
KS
728 + WINDOW_FRAME_COLUMN_WIDTH (w) - 1) \
729 / WINDOW_FRAME_COLUMN_WIDTH (w)) \
730 : FRAME_CONFIG_SCROLL_BAR_COLS (WINDOW_XFRAME (w)))
731
732/* Width of a scroll bar in window W, measured in columns (characters),
733 but only if scroll bars are on the left. If scroll bars are on
734 the right in this frame, or there are no scroll bars, value is 0. */
735
736#define WINDOW_LEFT_SCROLL_BAR_COLS(w) \
d3d50620 737 (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w) \
6000501b
KS
738 ? (WINDOW_CONFIG_SCROLL_BAR_COLS (w)) \
739 : 0)
740
741/* Width of a left scroll bar area in window W , measured in pixels. */
742
d3d50620
DA
743#define WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH(w) \
744 (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w) \
6000501b
KS
745 ? (WINDOW_CONFIG_SCROLL_BAR_COLS (w) * WINDOW_FRAME_COLUMN_WIDTH (w)) \
746 : 0)
747
748/* Width of a scroll bar in window W, measured in columns (characters),
749 but only if scroll bars are on the right. If scroll bars are on
750 the left in this frame, or there are no scroll bars, value is 0. */
751
752#define WINDOW_RIGHT_SCROLL_BAR_COLS(w) \
d3d50620 753 (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_RIGHT (w) \
6000501b
KS
754 ? WINDOW_CONFIG_SCROLL_BAR_COLS (w) \
755 : 0)
756
757/* Width of a left scroll bar area in window W , measured in pixels. */
758
759#define WINDOW_RIGHT_SCROLL_BAR_AREA_WIDTH(w) \
760 (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_RIGHT (w) \
761 ? (WINDOW_CONFIG_SCROLL_BAR_COLS (w) * WINDOW_FRAME_COLUMN_WIDTH (w)) \
762 : 0)
763
764
765/* Actual width of a scroll bar in window W, measured in columns. */
766
767#define WINDOW_SCROLL_BAR_COLS(w) \
768 (WINDOW_HAS_VERTICAL_SCROLL_BAR (w) \
769 ? WINDOW_CONFIG_SCROLL_BAR_COLS (w) \
770 : 0)
771
772/* Width of a left scroll bar area in window W , measured in pixels. */
773
774#define WINDOW_SCROLL_BAR_AREA_WIDTH(w) \
d3d50620 775 (WINDOW_HAS_VERTICAL_SCROLL_BAR (w) \
6000501b
KS
776 ? (WINDOW_CONFIG_SCROLL_BAR_COLS (w) * WINDOW_FRAME_COLUMN_WIDTH (w)) \
777 : 0)
778
779
780/* Return the frame position where the scroll bar of window W starts. */
781
782#define WINDOW_SCROLL_BAR_AREA_X(W) \
783 (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_RIGHT (W) \
784 ? WINDOW_BOX_RIGHT_EDGE_X (W) \
785 : WINDOW_LEFT_EDGE_X (W))
786
787
01aa0b2e
RS
788/* Height in pixels, and in lines, of the mode line.
789 May be zero if W doesn't have a mode line. */
6000501b
KS
790
791#define WINDOW_MODE_LINE_HEIGHT(W) \
792 (WINDOW_WANTS_MODELINE_P ((W)) \
793 ? CURRENT_MODE_LINE_HEIGHT (W) \
794 : 0)
795
d3d50620 796#define WINDOW_MODE_LINE_LINES(W) \
01aa0b2e
RS
797 (!! WINDOW_WANTS_MODELINE_P ((W)))
798
799/* Height in pixels, and in lines, of the header line.
800 Zero if W doesn't have a header line. */
6000501b
KS
801
802#define WINDOW_HEADER_LINE_HEIGHT(W) \
803 (WINDOW_WANTS_HEADER_LINE_P ((W)) \
804 ? CURRENT_HEADER_LINE_HEIGHT (W) \
805 : 0)
806
d3d50620 807#define WINDOW_HEADER_LINE_LINES(W) \
01aa0b2e
RS
808 (!! WINDOW_WANTS_HEADER_LINE_P ((W)))
809
6000501b
KS
810/* Pixel height of window W without mode line. */
811
812#define WINDOW_BOX_HEIGHT_NO_MODE_LINE(W) \
813 (WINDOW_TOTAL_HEIGHT ((W)) \
814 - WINDOW_MODE_LINE_HEIGHT ((W)))
815
816/* Pixel height of window W without mode and header line. */
817
d3d50620
DA
818#define WINDOW_BOX_TEXT_HEIGHT(W) \
819 (WINDOW_TOTAL_HEIGHT ((W)) \
820 - WINDOW_MODE_LINE_HEIGHT ((W)) \
6000501b
KS
821 - WINDOW_HEADER_LINE_HEIGHT ((W)))
822
823
824/* Convert window W relative pixel X to frame pixel coordinates. */
825
d3d50620 826#define WINDOW_TO_FRAME_PIXEL_X(W, X) \
6000501b
KS
827 ((X) + WINDOW_BOX_LEFT_EDGE_X ((W)))
828
829/* Convert window W relative pixel Y to frame pixel coordinates. */
830
d3d50620 831#define WINDOW_TO_FRAME_PIXEL_Y(W, Y) \
6000501b
KS
832 ((Y) + WINDOW_TOP_EDGE_Y ((W)))
833
834/* Convert frame relative pixel X to window relative pixel X. */
835
d3d50620 836#define FRAME_TO_WINDOW_PIXEL_X(W, X) \
6000501b
KS
837 ((X) - WINDOW_BOX_LEFT_EDGE_X ((W)))
838
839/* Convert frame relative pixel Y to window relative pixel Y. */
840
d3d50620 841#define FRAME_TO_WINDOW_PIXEL_Y(W, Y) \
6000501b
KS
842 ((Y) - WINDOW_TOP_EDGE_Y ((W)))
843
844/* Convert a text area relative x-position in window W to frame X
845 pixel coordinates. */
177c0ea7 846
d3d50620 847#define WINDOW_TEXT_TO_FRAME_PIXEL_X(W, X) \
6000501b 848 (window_box_left ((W), TEXT_AREA) + (X))
f43dd834 849
83b2229f
JB
850/* This is the window in which the terminal's cursor should
851 be left when nothing is being done with it. This must
852 always be a leaf window, and its buffer is selected by
853 the top level editing loop at the end of each command.
854
855 This value is always the same as
44fa5b1e 856 FRAME_SELECTED_WINDOW (selected_frame). */
83b2229f
JB
857
858extern Lisp_Object selected_window;
859
860/* This is a time stamp for window selection, so we can find the least
861 recently used window. Its only users are Fselect_window,
44fa5b1e 862 init_window_once, and make_frame. */
83b2229f
JB
863
864extern int window_select_count;
865
44fa5b1e 866/* The minibuffer window of the selected frame.
83b2229f 867 Note that you cannot test for minibufferness of an arbitrary window
fbfed6f0 868 by comparing against this; use the MINI_WINDOW_P macro instead. */
83b2229f
JB
869
870extern Lisp_Object minibuf_window;
871
76e316e0
KS
872/* Non-nil means it is the window whose mode line should be
873 shown as the selected window when the minibuffer is selected. */
874
5705966b 875extern Lisp_Object minibuf_selected_window;
76e316e0 876
83b2229f 877/* Window that the mouse is over (nil if no mouse support). */
f43dd834 878
83b2229f
JB
879extern Lisp_Object Vmouse_window;
880
881/* Last mouse-click event (nil if no mouse support). */
f43dd834 882
83b2229f
JB
883extern Lisp_Object Vmouse_event;
884
383e0970 885extern Lisp_Object make_window (void);
383e0970 886extern Lisp_Object window_from_coordinates (struct frame *, int, int,
748fa866
DA
887 enum window_part *, bool);
888extern void resize_frame_windows (struct frame *, int, bool);
27e498e6 889extern void restore_window_configuration (Lisp_Object);
be7f5545 890extern void delete_all_child_windows (Lisp_Object);
748fa866 891extern void freeze_window_starts (struct frame *, bool);
383e0970
J
892extern void grow_mini_window (struct window *, int);
893extern void shrink_mini_window (struct window *);
9173a8fb 894extern int window_relative_x_coord (struct window *, enum window_part, int);
57209cba 895
ef264c42 896void run_window_configuration_change_hook (struct frame *f);
83b2229f 897
f43dd834
GM
898/* Make WINDOW display BUFFER as its contents. RUN_HOOKS_P non-zero
899 means it's allowed to run hooks. See make_frame for a case where
900 it's not allowed. */
901
383e0970 902void set_window_buffer (Lisp_Object window, Lisp_Object buffer,
748fa866 903 bool run_hooks_p, bool keep_margins_p);
f43dd834 904
f43dd834
GM
905/* This is the window where the echo area message was displayed. It
906 is always a minibuffer window, but it may not be the same window
907 currently active as a minibuffer. */
908
c0acc112
RS
909extern Lisp_Object echo_area_window;
910
83b2229f 911/* Depth in recursive edits. */
f43dd834 912
62f19c19 913extern EMACS_INT command_loop_level;
83b2229f
JB
914
915/* Depth in minibuffer invocations. */
f43dd834 916
62f19c19 917extern EMACS_INT minibuf_level;
83b2229f 918
e0f24100 919/* true if we should redraw the mode lines on the next redisplay. */
f43dd834 920
83b2229f
JB
921extern int update_mode_lines;
922
f43dd834 923/* Nonzero if window sizes or contents have changed since last
1e101a4b 924 redisplay that finished. */
f43dd834 925
83b2229f
JB
926extern int windows_or_buffers_changed;
927
d1a0ea0a
RS
928/* Nonzero means a frame's cursor type has been changed. */
929
930extern int cursor_type_changed;
931
fbfed6f0
JB
932/* If *ROWS or *COLS are too small a size for FRAME, set them to the
933 minimum allowable size. */
f43dd834 934
383e0970 935extern void check_frame_size (struct frame *frame, int *rows, int *cols);
f43dd834
GM
936
937/* Return a pointer to the glyph W's physical cursor is on. Value is
c80e3b4a 938 null if W's current matrix is invalid, so that no meaningful glyph
f43dd834
GM
939 can be returned. */
940
383e0970 941struct glyph *get_phys_cursor_glyph (struct window *w);
f43dd834 942
52162052 943/* Value is non-zero if WINDOW is a valid window. */
e74aeda8
DA
944#define WINDOW_VALID_P(WINDOW) \
945 (WINDOWP (WINDOW) && !NILP (XWINDOW (WINDOW)->contents)) \
946
947/* A window of any sort, leaf or interior, is "valid" if its
948 contents slot is non-nil. */
b9e9df47
DA
949#define CHECK_VALID_WINDOW(WINDOW) \
950 CHECK_TYPE (WINDOW_VALID_P (WINDOW), Qwindow_valid_p, WINDOW)
91523be9 951
52162052 952/* Value is non-zero if WINDOW is a live window. */
077288cf 953#define WINDOW_LIVE_P(WINDOW) \
e74aeda8 954 (WINDOWP (WINDOW) && BUFFERP (XWINDOW (WINDOW)->contents))
9a274fbd 955
b9e9df47
DA
956/* A window is "live" if and only if it shows a buffer. */
957#define CHECK_LIVE_WINDOW(WINDOW) \
958 CHECK_TYPE (WINDOW_LIVE_P (WINDOW), Qwindow_live_p, WINDOW)
959
9a274fbd
SM
960/* These used to be in lisp.h. */
961
84575e67 962extern Lisp_Object Qwindow_live_p;
9a274fbd
SM
963extern Lisp_Object Vwindow_list;
964
52162052 965extern struct window *decode_live_window (Lisp_Object);
b9e9df47 966extern struct window *decode_any_window (Lisp_Object);
f75d7a91 967extern bool compare_window_configurations (Lisp_Object, Lisp_Object, bool);
383e0970
J
968extern void mark_window_cursors_off (struct window *);
969extern int window_internal_height (struct window *);
496e208e 970extern int window_body_cols (struct window *w);
383e0970 971extern void temp_output_buffer_show (Lisp_Object);
b6e3633c 972extern void replace_buffer_in_windows (Lisp_Object);
9397e56f 973extern void replace_buffer_in_windows_safely (Lisp_Object);
98a07056
DA
974/* This looks like a setter, but it is a bit special. */
975extern void wset_buffer (struct window *, Lisp_Object);
170da1ec 976extern bool window_outdated (struct window *);
383e0970
J
977extern void init_window_once (void);
978extern void init_window (void);
979extern void syms_of_window (void);
980extern void keys_of_window (void);
981
e8c17b81
PE
982INLINE_HEADER_END
983
f43dd834 984#endif /* not WINDOW_H_INCLUDED */