1 /* Updating of data structures for redisplay.
2 Copyright (C) 1985, 1986, 1987, 1988, 1993, 1994, 1995,
3 1997, 1998, 1999, 2000, 2001, 2002, 2003,
4 2004, 2005, 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
6 This file is part of GNU Emacs.
8 GNU Emacs is free software: you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation, either version 3 of the License, or
11 (at your option) any later version.
13 GNU Emacs is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
34 /* cm.h must come after dispextern.h on Windows. */
35 #include "dispextern.h"
38 #include "character.h"
41 #include "termhooks.h"
46 #include "intervals.h"
47 #include "blockinput.h"
50 /* I don't know why DEC Alpha OSF1 fail to compile this file if we
51 include the following file. */
52 /* #include "systty.h" */
53 #include "syssignal.h"
57 #endif /* HAVE_X_WINDOWS */
61 #endif /* HAVE_NTGUI */
67 /* Include systime.h after xterm.h to avoid double inclusion of time.h. */
72 /* To get the prototype for `sleep'. */
78 /* Get number of chars of output now in the buffer of a stdio stream.
79 This ought to be built in in stdio, but it isn't. Some s- files
80 override this because their stdio internals differ. */
82 #ifdef __GNU_LIBRARY__
84 /* The s- file might have overridden the definition with one that
85 works for the system's C library. But we are using the GNU C
86 library, so this is the right definition for every system. */
88 #ifdef GNU_LIBRARY_PENDING_OUTPUT_COUNT
89 #define PENDING_OUTPUT_COUNT GNU_LIBRARY_PENDING_OUTPUT_COUNT
91 #undef PENDING_OUTPUT_COUNT
92 #define PENDING_OUTPUT_COUNT(FILE) ((FILE)->__bufp - (FILE)->__buffer)
94 #else /* not __GNU_LIBRARY__ */
95 #if !defined (PENDING_OUTPUT_COUNT) && HAVE_STDIO_EXT_H && HAVE___FPENDING
96 #include <stdio_ext.h>
97 #define PENDING_OUTPUT_COUNT(FILE) __fpending (FILE)
99 #ifndef PENDING_OUTPUT_COUNT
100 #define PENDING_OUTPUT_COUNT(FILE) ((FILE)->_ptr - (FILE)->_base)
102 #endif /* not __GNU_LIBRARY__ */
104 #if defined(HAVE_TERM_H) && defined (GNU_LINUX) && defined (HAVE_LIBNCURSES)
105 #include <term.h> /* for tgetent */
108 /* Structure to pass dimensions around. Used for character bounding
109 boxes, glyph matrix dimensions and alike. */
118 /* Function prototypes. */
120 static struct glyph_matrix
*save_current_matrix
P_ ((struct frame
*));
121 static void restore_current_matrix
P_ ((struct frame
*, struct glyph_matrix
*));
122 static int showing_window_margins_p
P_ ((struct window
*));
123 static void fake_current_matrices
P_ ((Lisp_Object
));
124 static void redraw_overlapping_rows
P_ ((struct window
*, int));
125 static void redraw_overlapped_rows
P_ ((struct window
*, int));
126 static int count_blanks
P_ ((struct glyph
*, int));
127 static int count_match
P_ ((struct glyph
*, struct glyph
*,
128 struct glyph
*, struct glyph
*));
129 static unsigned line_draw_cost
P_ ((struct glyph_matrix
*, int));
130 static void update_frame_line
P_ ((struct frame
*, int));
131 static struct dim allocate_matrices_for_frame_redisplay
132 P_ ((Lisp_Object
, int, int, int, int *));
133 static void allocate_matrices_for_window_redisplay
P_ ((struct window
*));
134 static int realloc_glyph_pool
P_ ((struct glyph_pool
*, struct dim
));
135 static void adjust_frame_glyphs
P_ ((struct frame
*));
136 struct glyph_matrix
*new_glyph_matrix
P_ ((struct glyph_pool
*));
137 static void free_glyph_matrix
P_ ((struct glyph_matrix
*));
138 static void adjust_glyph_matrix
P_ ((struct window
*, struct glyph_matrix
*,
139 int, int, struct dim
));
140 static void change_frame_size_1
P_ ((struct frame
*, int, int, int, int, int));
141 static void swap_glyph_pointers
P_ ((struct glyph_row
*, struct glyph_row
*));
143 static int glyph_row_slice_p
P_ ((struct glyph_row
*, struct glyph_row
*));
145 static void fill_up_frame_row_with_spaces
P_ ((struct glyph_row
*, int));
146 static void build_frame_matrix_from_window_tree
P_ ((struct glyph_matrix
*,
148 static void build_frame_matrix_from_leaf_window
P_ ((struct glyph_matrix
*,
150 static struct glyph_pool
*new_glyph_pool
P_ ((void));
151 static void free_glyph_pool
P_ ((struct glyph_pool
*));
152 static void adjust_frame_glyphs_initially
P_ ((void));
153 static void adjust_frame_message_buffer
P_ ((struct frame
*));
154 static void adjust_decode_mode_spec_buffer
P_ ((struct frame
*));
155 static void fill_up_glyph_row_with_spaces
P_ ((struct glyph_row
*));
156 static void build_frame_matrix
P_ ((struct frame
*));
157 void clear_current_matrices
P_ ((struct frame
*));
158 void scroll_glyph_matrix_range
P_ ((struct glyph_matrix
*, int, int,
160 static void clear_window_matrices
P_ ((struct window
*, int));
161 static void fill_up_glyph_row_area_with_spaces
P_ ((struct glyph_row
*, int));
162 static int scrolling_window
P_ ((struct window
*, int));
163 static int update_window_line
P_ ((struct window
*, int, int *));
164 static void update_marginal_area
P_ ((struct window
*, int, int));
165 static int update_text_area
P_ ((struct window
*, int));
166 static void make_current
P_ ((struct glyph_matrix
*, struct glyph_matrix
*,
168 static void mirror_make_current
P_ ((struct window
*, int));
169 void check_window_matrix_pointers
P_ ((struct window
*));
171 static void check_matrix_pointers
P_ ((struct glyph_matrix
*,
172 struct glyph_matrix
*));
174 static void mirror_line_dance
P_ ((struct window
*, int, int, int *, char *));
175 static int update_window_tree
P_ ((struct window
*, int));
176 static int update_window
P_ ((struct window
*, int));
177 static int update_frame_1
P_ ((struct frame
*, int, int));
178 static void set_window_cursor_after_update
P_ ((struct window
*));
179 static int row_equal_p
P_ ((struct window
*, struct glyph_row
*,
180 struct glyph_row
*, int));
181 static void adjust_frame_glyphs_for_window_redisplay
P_ ((struct frame
*));
182 static void adjust_frame_glyphs_for_frame_redisplay
P_ ((struct frame
*));
183 static void reverse_rows
P_ ((struct glyph_matrix
*, int, int));
184 static int margin_glyphs_to_reserve
P_ ((struct window
*, int, Lisp_Object
));
185 static void sync_window_with_frame_matrix_rows
P_ ((struct window
*));
186 struct window
*frame_row_to_window
P_ ((struct window
*, int));
189 /* Non-zero means don't pause redisplay for pending input. (This is
190 for debugging and for a future implementation of EDT-like
193 int redisplay_dont_pause
;
195 /* Define PERIODIC_PREEMPTION_CHECKING to 1, if micro-second timers
196 are supported, so we can check for input during redisplay at
197 regular intervals. */
198 #ifdef EMACS_HAS_USECS
199 #define PERIODIC_PREEMPTION_CHECKING 1
201 #define PERIODIC_PREEMPTION_CHECKING 0
204 #if PERIODIC_PREEMPTION_CHECKING
206 /* If a number (float), check for user input every N seconds. */
208 Lisp_Object Vredisplay_preemption_period
;
210 /* Redisplay preemption timers. */
212 static EMACS_TIME preemption_period
;
213 static EMACS_TIME preemption_next_check
;
217 /* Nonzero upon entry to redisplay means do not assume anything about
218 current contents of actual terminal frame; clear and redraw it. */
222 /* Nonzero means last display completed. Zero means it was preempted. */
224 int display_completed
;
226 /* Lisp variable visible-bell; enables use of screen-flash instead of
231 /* Invert the color of the whole frame, at a low level. */
235 /* Line speed of the terminal. */
239 /* Either nil or a symbol naming the window system under which Emacs
240 creates the first frame. */
242 Lisp_Object Vinitial_window_system
;
244 /* Version number of X windows: 10, 11 or nil. */
246 Lisp_Object Vwindow_system_version
;
248 /* Vector of glyph definitions. Indexed by glyph number, the contents
249 are a string which is how to output the glyph.
251 If Vglyph_table is nil, a glyph is output by using its low 8 bits
254 This is an obsolete feature that is no longer used. The variable
255 is retained for compatibility. */
257 Lisp_Object Vglyph_table
;
259 /* Display table to use for vectors that don't specify their own. */
261 Lisp_Object Vstandard_display_table
;
263 /* Nonzero means reading single-character input with prompt so put
264 cursor on mini-buffer after the prompt. Positive means at end of
265 text in echo area; negative means at beginning of line. */
267 int cursor_in_echo_area
;
269 Lisp_Object Qdisplay_table
, Qredisplay_dont_pause
;
272 /* The currently selected frame. In a single-frame version, this
273 variable always equals the_only_frame. */
275 Lisp_Object selected_frame
;
277 /* A frame which is not just a mini-buffer, or 0 if there are no such
278 frames. This is usually the most recent such frame that was
279 selected. In a single-frame version, this variable always holds
280 the address of the_only_frame. */
282 struct frame
*last_nonminibuf_frame
;
284 /* 1 means SIGWINCH happened when not safe. */
286 int delayed_size_change
;
288 /* 1 means glyph initialization has been completed at startup. */
290 static int glyphs_initialized_initially_p
;
292 /* Updated window if != 0. Set by update_window. */
294 struct window
*updated_window
;
296 /* Glyph row updated in update_window_line, and area that is updated. */
298 struct glyph_row
*updated_row
;
301 /* A glyph for a space. */
303 struct glyph space_glyph
;
305 /* Counts of allocated structures. These counts serve to diagnose
306 memory leaks and double frees. */
308 int glyph_matrix_count
;
309 int glyph_pool_count
;
311 /* If non-null, the frame whose frame matrices are manipulated. If
312 null, window matrices are worked on. */
314 static struct frame
*frame_matrix_frame
;
316 /* Non-zero means that fonts have been loaded since the last glyph
317 matrix adjustments. Redisplay must stop, and glyph matrices must
318 be adjusted when this flag becomes non-zero during display. The
319 reason fonts can be loaded so late is that fonts of fontsets are
320 loaded on demand. Another reason is that a line contains many
321 characters displayed by zero width or very narrow glyphs of
322 variable-width fonts. */
326 /* Convert vpos and hpos from frame to window and vice versa.
327 This may only be used for terminal frames. */
331 static int window_to_frame_vpos
P_ ((struct window
*, int));
332 static int window_to_frame_hpos
P_ ((struct window
*, int));
333 #define WINDOW_TO_FRAME_VPOS(W, VPOS) window_to_frame_vpos ((W), (VPOS))
334 #define WINDOW_TO_FRAME_HPOS(W, HPOS) window_to_frame_hpos ((W), (HPOS))
336 /* One element of the ring buffer containing redisplay history
339 struct redisplay_history
341 char trace
[512 + 100];
344 /* The size of the history buffer. */
346 #define REDISPLAY_HISTORY_SIZE 30
348 /* The redisplay history buffer. */
350 static struct redisplay_history redisplay_history
[REDISPLAY_HISTORY_SIZE
];
352 /* Next free entry in redisplay_history. */
354 static int history_idx
;
356 /* A tick that's incremented each time something is added to the
359 static unsigned history_tick
;
361 static void add_frame_display_history
P_ ((struct frame
*, int));
362 static void add_window_display_history
P_ ((struct window
*, char *, int));
364 /* Add to the redisplay history how window W has been displayed.
365 MSG is a trace containing the information how W's glyph matrix
366 has been constructed. PAUSED_P non-zero means that the update
367 has been interrupted for pending input. */
370 add_window_display_history (w
, msg
, paused_p
)
377 if (history_idx
>= REDISPLAY_HISTORY_SIZE
)
379 buf
= redisplay_history
[history_idx
].trace
;
382 sprintf (buf
, "%d: window %p (`%s')%s\n",
385 ((BUFFERP (w
->buffer
)
386 && STRINGP (XBUFFER (w
->buffer
)->name
))
387 ? (char *) SDATA (XBUFFER (w
->buffer
)->name
)
389 paused_p
? " ***paused***" : "");
394 /* Add to the redisplay history that frame F has been displayed.
395 PAUSED_P non-zero means that the update has been interrupted for
399 add_frame_display_history (f
, paused_p
)
405 if (history_idx
>= REDISPLAY_HISTORY_SIZE
)
407 buf
= redisplay_history
[history_idx
].trace
;
410 sprintf (buf
, "%d: update frame %p%s",
412 f
, paused_p
? " ***paused***" : "");
416 DEFUN ("dump-redisplay-history", Fdump_redisplay_history
,
417 Sdump_redisplay_history
, 0, 0, "",
418 doc
: /* Dump redisplay history to stderr. */)
423 for (i
= history_idx
- 1; i
!= history_idx
; --i
)
426 i
= REDISPLAY_HISTORY_SIZE
- 1;
427 fprintf (stderr
, "%s\n", redisplay_history
[i
].trace
);
434 #else /* GLYPH_DEBUG == 0 */
436 #define WINDOW_TO_FRAME_VPOS(W, VPOS) ((VPOS) + WINDOW_TOP_EDGE_LINE (W))
437 #define WINDOW_TO_FRAME_HPOS(W, HPOS) ((HPOS) + WINDOW_LEFT_EDGE_COL (W))
439 #endif /* GLYPH_DEBUG == 0 */
442 /* Like bcopy except never gets confused by overlap. Let this be the
443 first function defined in this file, or change emacs.c where the
444 address of this function is used. */
447 safe_bcopy (from
, to
, size
)
452 if (size
<= 0 || from
== to
)
455 /* If the source and destination don't overlap, then bcopy can
456 handle it. If they do overlap, but the destination is lower in
457 memory than the source, we'll assume bcopy can handle that. */
458 if (to
< from
|| from
+ size
<= to
)
459 bcopy (from
, to
, size
);
461 /* Otherwise, we'll copy from the end. */
464 register const char *endf
= from
+ size
;
465 register char *endt
= to
+ size
;
467 /* If TO - FROM is large, then we should break the copy into
468 nonoverlapping chunks of TO - FROM bytes each. However, if
469 TO - FROM is small, then the bcopy function call overhead
470 makes this not worth it. The crossover point could be about
471 anywhere. Since I don't think the obvious copy loop is too
472 bad, I'm trying to err in its favor. */
477 while (endf
!= from
);
489 bcopy (endf
, endt
, to
- from
);
492 /* If SIZE wasn't a multiple of TO - FROM, there will be a
493 little left over. The amount left over is (endt + (to -
494 from)) - to, which is endt - from. */
495 bcopy (from
, to
, endt
- from
);
502 /***********************************************************************
504 ***********************************************************************/
506 /* Allocate and return a glyph_matrix structure. POOL is the glyph
507 pool from which memory for the matrix should be allocated, or null
508 for window-based redisplay where no glyph pools are used. The
509 member `pool' of the glyph matrix structure returned is set to
510 POOL, the structure is otherwise zeroed. */
512 struct glyph_matrix
*
513 new_glyph_matrix (pool
)
514 struct glyph_pool
*pool
;
516 struct glyph_matrix
*result
;
518 /* Allocate and clear. */
519 result
= (struct glyph_matrix
*) xmalloc (sizeof *result
);
520 bzero (result
, sizeof *result
);
522 /* Increment number of allocated matrices. This count is used
523 to detect memory leaks. */
524 ++glyph_matrix_count
;
526 /* Set pool and return. */
532 /* Free glyph matrix MATRIX. Passing in a null MATRIX is allowed.
534 The global counter glyph_matrix_count is decremented when a matrix
535 is freed. If the count gets negative, more structures were freed
536 than allocated, i.e. one matrix was freed more than once or a bogus
537 pointer was passed to this function.
539 If MATRIX->pool is null, this means that the matrix manages its own
540 glyph memory---this is done for matrices on X frames. Freeing the
541 matrix also frees the glyph memory in this case. */
544 free_glyph_matrix (matrix
)
545 struct glyph_matrix
*matrix
;
551 /* Detect the case that more matrices are freed than were
553 if (--glyph_matrix_count
< 0)
556 /* Free glyph memory if MATRIX owns it. */
557 if (matrix
->pool
== NULL
)
558 for (i
= 0; i
< matrix
->rows_allocated
; ++i
)
559 xfree (matrix
->rows
[i
].glyphs
[LEFT_MARGIN_AREA
]);
561 /* Free row structures and the matrix itself. */
562 xfree (matrix
->rows
);
568 /* Return the number of glyphs to reserve for a marginal area of
569 window W. TOTAL_GLYPHS is the number of glyphs in a complete
570 display line of window W. MARGIN gives the width of the marginal
571 area in canonical character units. MARGIN should be an integer
575 margin_glyphs_to_reserve (w
, total_glyphs
, margin
)
582 if (NUMBERP (margin
))
584 int width
= XFASTINT (w
->total_cols
);
585 double d
= max (0, XFLOATINT (margin
));
586 d
= min (width
/ 2 - 1, d
);
587 n
= (int) ((double) total_glyphs
/ width
* d
);
596 /* Adjust glyph matrix MATRIX on window W or on a frame to changed
599 W is null if the function is called for a frame glyph matrix.
600 Otherwise it is the window MATRIX is a member of. X and Y are the
601 indices of the first column and row of MATRIX within the frame
602 matrix, if such a matrix exists. They are zero for purely
603 window-based redisplay. DIM is the needed size of the matrix.
605 In window-based redisplay, where no frame matrices exist, glyph
606 matrices manage their own glyph storage. Otherwise, they allocate
607 storage from a common frame glyph pool which can be found in
610 The reason for this memory management strategy is to avoid complete
611 frame redraws if possible. When we allocate from a common pool, a
612 change of the location or size of a sub-matrix within the pool
613 requires a complete redisplay of the frame because we cannot easily
614 make sure that the current matrices of all windows still agree with
615 what is displayed on the screen. While this is usually fast, it
616 leads to screen flickering. */
619 adjust_glyph_matrix (w
, matrix
, x
, y
, dim
)
621 struct glyph_matrix
*matrix
;
627 int marginal_areas_changed_p
= 0;
628 int header_line_changed_p
= 0;
629 int header_line_p
= 0;
630 int left
= -1, right
= -1;
631 int window_width
= -1, window_height
= -1;
633 /* See if W had a header line that has disappeared now, or vice versa.
637 window_box (w
, -1, 0, 0, &window_width
, &window_height
);
639 header_line_p
= WINDOW_WANTS_HEADER_LINE_P (w
);
640 header_line_changed_p
= header_line_p
!= matrix
->header_line_p
;
642 matrix
->header_line_p
= header_line_p
;
644 /* If POOL is null, MATRIX is a window matrix for window-based redisplay.
645 Do nothing if MATRIX' size, position, vscroll, and marginal areas
646 haven't changed. This optimization is important because preserving
647 the matrix means preventing redisplay. */
648 if (matrix
->pool
== NULL
)
650 left
= margin_glyphs_to_reserve (w
, dim
.width
, w
->left_margin_cols
);
651 right
= margin_glyphs_to_reserve (w
, dim
.width
, w
->right_margin_cols
);
652 xassert (left
>= 0 && right
>= 0);
653 marginal_areas_changed_p
= (left
!= matrix
->left_margin_glyphs
654 || right
!= matrix
->right_margin_glyphs
);
656 if (!marginal_areas_changed_p
658 && !header_line_changed_p
659 && matrix
->window_left_col
== WINDOW_LEFT_EDGE_COL (w
)
660 && matrix
->window_top_line
== WINDOW_TOP_EDGE_LINE (w
)
661 && matrix
->window_height
== window_height
662 && matrix
->window_vscroll
== w
->vscroll
663 && matrix
->window_width
== window_width
)
667 /* Enlarge MATRIX->rows if necessary. New rows are cleared. */
668 if (matrix
->rows_allocated
< dim
.height
)
670 int size
= dim
.height
* sizeof (struct glyph_row
);
671 new_rows
= dim
.height
- matrix
->rows_allocated
;
672 matrix
->rows
= (struct glyph_row
*) xrealloc (matrix
->rows
, size
);
673 bzero (matrix
->rows
+ matrix
->rows_allocated
,
674 new_rows
* sizeof *matrix
->rows
);
675 matrix
->rows_allocated
= dim
.height
;
680 /* If POOL is not null, MATRIX is a frame matrix or a window matrix
681 on a frame not using window-based redisplay. Set up pointers for
682 each row into the glyph pool. */
685 xassert (matrix
->pool
->glyphs
);
689 left
= margin_glyphs_to_reserve (w
, dim
.width
,
690 w
->left_margin_cols
);
691 right
= margin_glyphs_to_reserve (w
, dim
.width
,
692 w
->right_margin_cols
);
697 for (i
= 0; i
< dim
.height
; ++i
)
699 struct glyph_row
*row
= &matrix
->rows
[i
];
701 row
->glyphs
[LEFT_MARGIN_AREA
]
702 = (matrix
->pool
->glyphs
703 + (y
+ i
) * matrix
->pool
->ncolumns
707 || row
== matrix
->rows
+ dim
.height
- 1
708 || (row
== matrix
->rows
&& matrix
->header_line_p
))
710 row
->glyphs
[TEXT_AREA
]
711 = row
->glyphs
[LEFT_MARGIN_AREA
];
712 row
->glyphs
[RIGHT_MARGIN_AREA
]
713 = row
->glyphs
[TEXT_AREA
] + dim
.width
;
714 row
->glyphs
[LAST_AREA
]
715 = row
->glyphs
[RIGHT_MARGIN_AREA
];
719 row
->glyphs
[TEXT_AREA
]
720 = row
->glyphs
[LEFT_MARGIN_AREA
] + left
;
721 row
->glyphs
[RIGHT_MARGIN_AREA
]
722 = row
->glyphs
[TEXT_AREA
] + dim
.width
- left
- right
;
723 row
->glyphs
[LAST_AREA
]
724 = row
->glyphs
[LEFT_MARGIN_AREA
] + dim
.width
;
728 matrix
->left_margin_glyphs
= left
;
729 matrix
->right_margin_glyphs
= right
;
733 /* If MATRIX->pool is null, MATRIX is responsible for managing
734 its own memory. It is a window matrix for window-based redisplay.
735 Allocate glyph memory from the heap. */
736 if (dim
.width
> matrix
->matrix_w
738 || header_line_changed_p
739 || marginal_areas_changed_p
)
741 struct glyph_row
*row
= matrix
->rows
;
742 struct glyph_row
*end
= row
+ matrix
->rows_allocated
;
746 row
->glyphs
[LEFT_MARGIN_AREA
]
747 = (struct glyph
*) xrealloc (row
->glyphs
[LEFT_MARGIN_AREA
],
749 * sizeof (struct glyph
)));
751 /* The mode line never has marginal areas. */
752 if (row
== matrix
->rows
+ dim
.height
- 1
753 || (row
== matrix
->rows
&& matrix
->header_line_p
))
755 row
->glyphs
[TEXT_AREA
]
756 = row
->glyphs
[LEFT_MARGIN_AREA
];
757 row
->glyphs
[RIGHT_MARGIN_AREA
]
758 = row
->glyphs
[TEXT_AREA
] + dim
.width
;
759 row
->glyphs
[LAST_AREA
]
760 = row
->glyphs
[RIGHT_MARGIN_AREA
];
764 row
->glyphs
[TEXT_AREA
]
765 = row
->glyphs
[LEFT_MARGIN_AREA
] + left
;
766 row
->glyphs
[RIGHT_MARGIN_AREA
]
767 = row
->glyphs
[TEXT_AREA
] + dim
.width
- left
- right
;
768 row
->glyphs
[LAST_AREA
]
769 = row
->glyphs
[LEFT_MARGIN_AREA
] + dim
.width
;
775 xassert (left
>= 0 && right
>= 0);
776 matrix
->left_margin_glyphs
= left
;
777 matrix
->right_margin_glyphs
= right
;
780 /* Number of rows to be used by MATRIX. */
781 matrix
->nrows
= dim
.height
;
782 xassert (matrix
->nrows
>= 0);
786 if (matrix
== w
->current_matrix
)
788 /* Mark rows in a current matrix of a window as not having
789 valid contents. It's important to not do this for
790 desired matrices. When Emacs starts, it may already be
791 building desired matrices when this function runs. */
792 if (window_width
< 0)
793 window_width
= window_box_width (w
, -1);
795 /* Optimize the case that only the height has changed (C-x 2,
796 upper window). Invalidate all rows that are no longer part
798 if (!marginal_areas_changed_p
799 && !header_line_changed_p
801 && dim
.width
== matrix
->matrix_w
802 && matrix
->window_left_col
== WINDOW_LEFT_EDGE_COL (w
)
803 && matrix
->window_top_line
== WINDOW_TOP_EDGE_LINE (w
)
804 && matrix
->window_width
== window_width
)
806 /* Find the last row in the window. */
807 for (i
= 0; i
< matrix
->nrows
&& matrix
->rows
[i
].enabled_p
; ++i
)
808 if (MATRIX_ROW_BOTTOM_Y (matrix
->rows
+ i
) >= window_height
)
814 /* Window end is invalid, if inside of the rows that
815 are invalidated below. */
816 if (INTEGERP (w
->window_end_vpos
)
817 && XFASTINT (w
->window_end_vpos
) >= i
)
818 w
->window_end_valid
= Qnil
;
820 while (i
< matrix
->nrows
)
821 matrix
->rows
[i
++].enabled_p
= 0;
825 for (i
= 0; i
< matrix
->nrows
; ++i
)
826 matrix
->rows
[i
].enabled_p
= 0;
829 else if (matrix
== w
->desired_matrix
)
831 /* Rows in desired matrices always have to be cleared;
832 redisplay expects this is the case when it runs, so it
833 had better be the case when we adjust matrices between
835 for (i
= 0; i
< matrix
->nrows
; ++i
)
836 matrix
->rows
[i
].enabled_p
= 0;
841 /* Remember last values to be able to optimize frame redraws. */
842 matrix
->matrix_x
= x
;
843 matrix
->matrix_y
= y
;
844 matrix
->matrix_w
= dim
.width
;
845 matrix
->matrix_h
= dim
.height
;
847 /* Record the top y location and height of W at the time the matrix
848 was last adjusted. This is used to optimize redisplay above. */
851 matrix
->window_left_col
= WINDOW_LEFT_EDGE_COL (w
);
852 matrix
->window_top_line
= WINDOW_TOP_EDGE_LINE (w
);
853 matrix
->window_height
= window_height
;
854 matrix
->window_width
= window_width
;
855 matrix
->window_vscroll
= w
->vscroll
;
860 /* Reverse the contents of rows in MATRIX between START and END. The
861 contents of the row at END - 1 end up at START, END - 2 at START +
862 1 etc. This is part of the implementation of rotate_matrix (see
866 reverse_rows (matrix
, start
, end
)
867 struct glyph_matrix
*matrix
;
872 for (i
= start
, j
= end
- 1; i
< j
; ++i
, --j
)
874 /* Non-ISO HP/UX compiler doesn't like auto struct
876 struct glyph_row temp
;
877 temp
= matrix
->rows
[i
];
878 matrix
->rows
[i
] = matrix
->rows
[j
];
879 matrix
->rows
[j
] = temp
;
884 /* Rotate the contents of rows in MATRIX in the range FIRST .. LAST -
885 1 by BY positions. BY < 0 means rotate left, i.e. towards lower
886 indices. (Note: this does not copy glyphs, only glyph pointers in
887 row structures are moved around).
889 The algorithm used for rotating the vector was, I believe, first
890 described by Kernighan. See the vector R as consisting of two
891 sub-vectors AB, where A has length BY for BY >= 0. The result
892 after rotating is then BA. Reverse both sub-vectors to get ArBr
893 and reverse the result to get (ArBr)r which is BA. Similar for
897 rotate_matrix (matrix
, first
, last
, by
)
898 struct glyph_matrix
*matrix
;
903 /* Up (rotate left, i.e. towards lower indices). */
905 reverse_rows (matrix
, first
, first
+ by
);
906 reverse_rows (matrix
, first
+ by
, last
);
907 reverse_rows (matrix
, first
, last
);
911 /* Down (rotate right, i.e. towards higher indices). */
912 reverse_rows (matrix
, last
- by
, last
);
913 reverse_rows (matrix
, first
, last
- by
);
914 reverse_rows (matrix
, first
, last
);
919 /* Increment buffer positions in glyph rows of MATRIX. Do it for rows
920 with indices START <= index < END. Increment positions by DELTA/
924 increment_matrix_positions (matrix
, start
, end
, delta
, delta_bytes
)
925 struct glyph_matrix
*matrix
;
926 int start
, end
, delta
, delta_bytes
;
928 /* Check that START and END are reasonable values. */
929 xassert (start
>= 0 && start
<= matrix
->nrows
);
930 xassert (end
>= 0 && end
<= matrix
->nrows
);
931 xassert (start
<= end
);
933 for (; start
< end
; ++start
)
934 increment_row_positions (matrix
->rows
+ start
, delta
, delta_bytes
);
938 /* Enable a range of rows in glyph matrix MATRIX. START and END are
939 the row indices of the first and last + 1 row to enable. If
940 ENABLED_P is non-zero, enabled_p flags in rows will be set to 1. */
943 enable_glyph_matrix_rows (matrix
, start
, end
, enabled_p
)
944 struct glyph_matrix
*matrix
;
948 xassert (start
<= end
);
949 xassert (start
>= 0 && start
< matrix
->nrows
);
950 xassert (end
>= 0 && end
<= matrix
->nrows
);
952 for (; start
< end
; ++start
)
953 matrix
->rows
[start
].enabled_p
= enabled_p
!= 0;
959 This empties all rows in MATRIX by setting the enabled_p flag for
960 all rows of the matrix to zero. The function prepare_desired_row
961 will eventually really clear a row when it sees one with a zero
964 Resets update hints to defaults value. The only update hint
965 currently present is the flag MATRIX->no_scrolling_p. */
968 clear_glyph_matrix (matrix
)
969 struct glyph_matrix
*matrix
;
973 enable_glyph_matrix_rows (matrix
, 0, matrix
->nrows
, 0);
974 matrix
->no_scrolling_p
= 0;
979 /* Shift part of the glyph matrix MATRIX of window W up or down.
980 Increment y-positions in glyph rows between START and END by DY,
981 and recompute their visible height. */
984 shift_glyph_matrix (w
, matrix
, start
, end
, dy
)
986 struct glyph_matrix
*matrix
;
991 xassert (start
<= end
);
992 xassert (start
>= 0 && start
< matrix
->nrows
);
993 xassert (end
>= 0 && end
<= matrix
->nrows
);
995 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
996 max_y
= WINDOW_BOX_HEIGHT_NO_MODE_LINE (w
);
998 for (; start
< end
; ++start
)
1000 struct glyph_row
*row
= &matrix
->rows
[start
];
1003 row
->visible_height
= row
->height
;
1006 row
->visible_height
-= min_y
- row
->y
;
1007 if (row
->y
+ row
->height
> max_y
)
1008 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
1013 /* Mark all rows in current matrices of frame F as invalid. Marking
1014 invalid is done by setting enabled_p to zero for all rows in a
1018 clear_current_matrices (f
)
1019 register struct frame
*f
;
1021 /* Clear frame current matrix, if we have one. */
1022 if (f
->current_matrix
)
1023 clear_glyph_matrix (f
->current_matrix
);
1025 /* Clear the matrix of the menu bar window, if such a window exists.
1026 The menu bar window is currently used to display menus on X when
1027 no toolkit support is compiled in. */
1028 if (WINDOWP (f
->menu_bar_window
))
1029 clear_glyph_matrix (XWINDOW (f
->menu_bar_window
)->current_matrix
);
1031 /* Clear the matrix of the tool-bar window, if any. */
1032 if (WINDOWP (f
->tool_bar_window
))
1033 clear_glyph_matrix (XWINDOW (f
->tool_bar_window
)->current_matrix
);
1035 /* Clear current window matrices. */
1036 xassert (WINDOWP (FRAME_ROOT_WINDOW (f
)));
1037 clear_window_matrices (XWINDOW (FRAME_ROOT_WINDOW (f
)), 0);
1041 /* Clear out all display lines of F for a coming redisplay. */
1044 clear_desired_matrices (f
)
1045 register struct frame
*f
;
1047 if (f
->desired_matrix
)
1048 clear_glyph_matrix (f
->desired_matrix
);
1050 if (WINDOWP (f
->menu_bar_window
))
1051 clear_glyph_matrix (XWINDOW (f
->menu_bar_window
)->desired_matrix
);
1053 if (WINDOWP (f
->tool_bar_window
))
1054 clear_glyph_matrix (XWINDOW (f
->tool_bar_window
)->desired_matrix
);
1056 /* Do it for window matrices. */
1057 xassert (WINDOWP (FRAME_ROOT_WINDOW (f
)));
1058 clear_window_matrices (XWINDOW (FRAME_ROOT_WINDOW (f
)), 1);
1062 /* Clear matrices in window tree rooted in W. If DESIRED_P is
1063 non-zero clear desired matrices, otherwise clear current matrices. */
1066 clear_window_matrices (w
, desired_p
)
1072 if (!NILP (w
->hchild
))
1074 xassert (WINDOWP (w
->hchild
));
1075 clear_window_matrices (XWINDOW (w
->hchild
), desired_p
);
1077 else if (!NILP (w
->vchild
))
1079 xassert (WINDOWP (w
->vchild
));
1080 clear_window_matrices (XWINDOW (w
->vchild
), desired_p
);
1085 clear_glyph_matrix (w
->desired_matrix
);
1088 clear_glyph_matrix (w
->current_matrix
);
1089 w
->window_end_valid
= Qnil
;
1093 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
1099 /***********************************************************************
1102 See dispextern.h for an overall explanation of glyph rows.
1103 ***********************************************************************/
1105 /* Clear glyph row ROW. Do it in a way that makes it robust against
1106 changes in the glyph_row structure, i.e. addition or removal of
1107 structure members. */
1109 static struct glyph_row null_row
;
1112 clear_glyph_row (row
)
1113 struct glyph_row
*row
;
1115 struct glyph
*p
[1 + LAST_AREA
];
1117 /* Save pointers. */
1118 p
[LEFT_MARGIN_AREA
] = row
->glyphs
[LEFT_MARGIN_AREA
];
1119 p
[TEXT_AREA
] = row
->glyphs
[TEXT_AREA
];
1120 p
[RIGHT_MARGIN_AREA
] = row
->glyphs
[RIGHT_MARGIN_AREA
];
1121 p
[LAST_AREA
] = row
->glyphs
[LAST_AREA
];
1126 /* Restore pointers. */
1127 row
->glyphs
[LEFT_MARGIN_AREA
] = p
[LEFT_MARGIN_AREA
];
1128 row
->glyphs
[TEXT_AREA
] = p
[TEXT_AREA
];
1129 row
->glyphs
[RIGHT_MARGIN_AREA
] = p
[RIGHT_MARGIN_AREA
];
1130 row
->glyphs
[LAST_AREA
] = p
[LAST_AREA
];
1132 #if 0 /* At some point, some bit-fields of struct glyph were not set,
1133 which made glyphs unequal when compared with GLYPH_EQUAL_P.
1134 Redisplay outputs such glyphs, and flickering effects were
1135 the result. This also depended on the contents of memory
1136 returned by xmalloc. If flickering happens again, activate
1137 the code below. If the flickering is gone with that, chances
1138 are that the flickering has the same reason as here. */
1139 bzero (p
[0], (char *) p
[LAST_AREA
] - (char *) p
[0]);
1144 /* Make ROW an empty, enabled row of canonical character height,
1145 in window W starting at y-position Y. */
1148 blank_row (w
, row
, y
)
1150 struct glyph_row
*row
;
1155 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
1156 max_y
= WINDOW_BOX_HEIGHT_NO_MODE_LINE (w
);
1158 clear_glyph_row (row
);
1160 row
->ascent
= row
->phys_ascent
= 0;
1161 row
->height
= row
->phys_height
= FRAME_LINE_HEIGHT (XFRAME (w
->frame
));
1162 row
->visible_height
= row
->height
;
1165 row
->visible_height
-= min_y
- row
->y
;
1166 if (row
->y
+ row
->height
> max_y
)
1167 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
1173 /* Increment buffer positions in glyph row ROW. DELTA and DELTA_BYTES
1174 are the amounts by which to change positions. Note that the first
1175 glyph of the text area of a row can have a buffer position even if
1176 the used count of the text area is zero. Such rows display line
1180 increment_row_positions (row
, delta
, delta_bytes
)
1181 struct glyph_row
*row
;
1182 int delta
, delta_bytes
;
1186 /* Increment start and end positions. */
1187 MATRIX_ROW_START_CHARPOS (row
) += delta
;
1188 MATRIX_ROW_START_BYTEPOS (row
) += delta_bytes
;
1189 MATRIX_ROW_END_CHARPOS (row
) += delta
;
1190 MATRIX_ROW_END_BYTEPOS (row
) += delta_bytes
;
1191 CHARPOS (row
->start
.pos
) += delta
;
1192 BYTEPOS (row
->start
.pos
) += delta_bytes
;
1193 CHARPOS (row
->end
.pos
) += delta
;
1194 BYTEPOS (row
->end
.pos
) += delta_bytes
;
1196 if (!row
->enabled_p
)
1199 /* Increment positions in glyphs. */
1200 for (area
= 0; area
< LAST_AREA
; ++area
)
1201 for (i
= 0; i
< row
->used
[area
]; ++i
)
1202 if (BUFFERP (row
->glyphs
[area
][i
].object
)
1203 && row
->glyphs
[area
][i
].charpos
> 0)
1204 row
->glyphs
[area
][i
].charpos
+= delta
;
1206 /* Capture the case of rows displaying a line end. */
1207 if (row
->used
[TEXT_AREA
] == 0
1208 && MATRIX_ROW_DISPLAYS_TEXT_P (row
))
1209 row
->glyphs
[TEXT_AREA
]->charpos
+= delta
;
1214 /* Swap glyphs between two glyph rows A and B. This exchanges glyph
1215 contents, i.e. glyph structure contents are exchanged between A and
1216 B without changing glyph pointers in A and B. */
1219 swap_glyphs_in_rows (a
, b
)
1220 struct glyph_row
*a
, *b
;
1224 for (area
= 0; area
< LAST_AREA
; ++area
)
1226 /* Number of glyphs to swap. */
1227 int max_used
= max (a
->used
[area
], b
->used
[area
]);
1229 /* Start of glyphs in area of row A. */
1230 struct glyph
*glyph_a
= a
->glyphs
[area
];
1232 /* End + 1 of glyphs in area of row A. */
1233 struct glyph
*glyph_a_end
= a
->glyphs
[max_used
];
1235 /* Start of glyphs in area of row B. */
1236 struct glyph
*glyph_b
= b
->glyphs
[area
];
1238 while (glyph_a
< glyph_a_end
)
1240 /* Non-ISO HP/UX compiler doesn't like auto struct
1244 *glyph_a
= *glyph_b
;
1254 /* Exchange pointers to glyph memory between glyph rows A and B. */
1257 swap_glyph_pointers (a
, b
)
1258 struct glyph_row
*a
, *b
;
1261 for (i
= 0; i
< LAST_AREA
+ 1; ++i
)
1263 struct glyph
*temp
= a
->glyphs
[i
];
1264 a
->glyphs
[i
] = b
->glyphs
[i
];
1265 b
->glyphs
[i
] = temp
;
1270 /* Copy glyph row structure FROM to glyph row structure TO, except
1271 that glyph pointers in the structures are left unchanged. */
1274 copy_row_except_pointers (to
, from
)
1275 struct glyph_row
*to
, *from
;
1277 struct glyph
*pointers
[1 + LAST_AREA
];
1279 /* Save glyph pointers of TO. */
1280 bcopy (to
->glyphs
, pointers
, sizeof to
->glyphs
);
1282 /* Do a structure assignment. */
1285 /* Restore original pointers of TO. */
1286 bcopy (pointers
, to
->glyphs
, sizeof to
->glyphs
);
1290 /* Copy contents of glyph row FROM to glyph row TO. Glyph pointers in
1291 TO and FROM are left unchanged. Glyph contents are copied from the
1292 glyph memory of FROM to the glyph memory of TO. Increment buffer
1293 positions in row TO by DELTA/ DELTA_BYTES. */
1296 copy_glyph_row_contents (to
, from
, delta
, delta_bytes
)
1297 struct glyph_row
*to
, *from
;
1298 int delta
, delta_bytes
;
1302 /* This is like a structure assignment TO = FROM, except that
1303 glyph pointers in the rows are left unchanged. */
1304 copy_row_except_pointers (to
, from
);
1306 /* Copy glyphs from FROM to TO. */
1307 for (area
= 0; area
< LAST_AREA
; ++area
)
1308 if (from
->used
[area
])
1309 bcopy (from
->glyphs
[area
], to
->glyphs
[area
],
1310 from
->used
[area
] * sizeof (struct glyph
));
1312 /* Increment buffer positions in TO by DELTA. */
1313 increment_row_positions (to
, delta
, delta_bytes
);
1317 /* Assign glyph row FROM to glyph row TO. This works like a structure
1318 assignment TO = FROM, except that glyph pointers are not copied but
1319 exchanged between TO and FROM. Pointers must be exchanged to avoid
1323 assign_row (to
, from
)
1324 struct glyph_row
*to
, *from
;
1326 swap_glyph_pointers (to
, from
);
1327 copy_row_except_pointers (to
, from
);
1331 /* Test whether the glyph memory of the glyph row WINDOW_ROW, which is
1332 a row in a window matrix, is a slice of the glyph memory of the
1333 glyph row FRAME_ROW which is a row in a frame glyph matrix. Value
1334 is non-zero if the glyph memory of WINDOW_ROW is part of the glyph
1335 memory of FRAME_ROW. */
1340 glyph_row_slice_p (window_row
, frame_row
)
1341 struct glyph_row
*window_row
, *frame_row
;
1343 struct glyph
*window_glyph_start
= window_row
->glyphs
[0];
1344 struct glyph
*frame_glyph_start
= frame_row
->glyphs
[0];
1345 struct glyph
*frame_glyph_end
= frame_row
->glyphs
[LAST_AREA
];
1347 return (frame_glyph_start
<= window_glyph_start
1348 && window_glyph_start
< frame_glyph_end
);
1351 #endif /* GLYPH_DEBUG */
1355 /* Find the row in the window glyph matrix WINDOW_MATRIX being a slice
1356 of ROW in the frame matrix FRAME_MATRIX. Value is null if no row
1357 in WINDOW_MATRIX is found satisfying the condition. */
1359 static struct glyph_row
*
1360 find_glyph_row_slice (window_matrix
, frame_matrix
, row
)
1361 struct glyph_matrix
*window_matrix
, *frame_matrix
;
1366 xassert (row
>= 0 && row
< frame_matrix
->nrows
);
1368 for (i
= 0; i
< window_matrix
->nrows
; ++i
)
1369 if (glyph_row_slice_p (window_matrix
->rows
+ i
,
1370 frame_matrix
->rows
+ row
))
1373 return i
< window_matrix
->nrows
? window_matrix
->rows
+ i
: 0;
1378 /* Prepare ROW for display. Desired rows are cleared lazily,
1379 i.e. they are only marked as to be cleared by setting their
1380 enabled_p flag to zero. When a row is to be displayed, a prior
1381 call to this function really clears it. */
1384 prepare_desired_row (row
)
1385 struct glyph_row
*row
;
1387 if (!row
->enabled_p
)
1389 unsigned rp
= row
->reversed_p
;
1391 clear_glyph_row (row
);
1393 row
->reversed_p
= rp
;
1398 /* Return a hash code for glyph row ROW. */
1401 line_hash_code (row
)
1402 struct glyph_row
*row
;
1408 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
];
1409 struct glyph
*end
= glyph
+ row
->used
[TEXT_AREA
];
1413 int c
= glyph
->u
.ch
;
1414 int face_id
= glyph
->face_id
;
1415 if (FRAME_MUST_WRITE_SPACES (SELECTED_FRAME ())) /* XXX Is SELECTED_FRAME OK here? */
1417 hash
= (((hash
<< 4) + (hash
>> 24)) & 0x0fffffff) + c
;
1418 hash
= (((hash
<< 4) + (hash
>> 24)) & 0x0fffffff) + face_id
;
1430 /* Return the cost of drawing line VPOS in MATRIX. The cost equals
1431 the number of characters in the line. If must_write_spaces is
1432 zero, leading and trailing spaces are ignored. */
1435 line_draw_cost (matrix
, vpos
)
1436 struct glyph_matrix
*matrix
;
1439 struct glyph_row
*row
= matrix
->rows
+ vpos
;
1440 struct glyph
*beg
= row
->glyphs
[TEXT_AREA
];
1441 struct glyph
*end
= beg
+ row
->used
[TEXT_AREA
];
1443 Lisp_Object
*glyph_table_base
= GLYPH_TABLE_BASE
;
1444 int glyph_table_len
= GLYPH_TABLE_LENGTH
;
1446 /* Ignore trailing and leading spaces if we can. */
1447 if (!FRAME_MUST_WRITE_SPACES (SELECTED_FRAME ())) /* XXX Is SELECTED_FRAME OK here? */
1449 /* Skip from the end over trailing spaces. */
1450 while (end
> beg
&& CHAR_GLYPH_SPACE_P (*(end
- 1)))
1453 /* All blank line. */
1457 /* Skip over leading spaces. */
1458 while (CHAR_GLYPH_SPACE_P (*beg
))
1462 /* If we don't have a glyph-table, each glyph is one character,
1463 so return the number of glyphs. */
1464 if (glyph_table_base
== 0)
1468 /* Otherwise, scan the glyphs and accumulate their total length
1475 SET_GLYPH_FROM_CHAR_GLYPH (g
, *beg
);
1477 if (GLYPH_INVALID_P (g
)
1478 || GLYPH_SIMPLE_P (glyph_table_base
, glyph_table_len
, g
))
1481 len
+= GLYPH_LENGTH (glyph_table_base
, g
);
1491 /* Test two glyph rows A and B for equality. Value is non-zero if A
1492 and B have equal contents. W is the window to which the glyphs
1493 rows A and B belong. It is needed here to test for partial row
1494 visibility. MOUSE_FACE_P non-zero means compare the mouse_face_p
1495 flags of A and B, too. */
1498 row_equal_p (w
, a
, b
, mouse_face_p
)
1500 struct glyph_row
*a
, *b
;
1505 else if (a
->hash
!= b
->hash
)
1509 struct glyph
*a_glyph
, *b_glyph
, *a_end
;
1512 if (mouse_face_p
&& a
->mouse_face_p
!= b
->mouse_face_p
)
1515 /* Compare glyphs. */
1516 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
1518 if (a
->used
[area
] != b
->used
[area
])
1521 a_glyph
= a
->glyphs
[area
];
1522 a_end
= a_glyph
+ a
->used
[area
];
1523 b_glyph
= b
->glyphs
[area
];
1525 while (a_glyph
< a_end
1526 && GLYPH_EQUAL_P (a_glyph
, b_glyph
))
1527 ++a_glyph
, ++b_glyph
;
1529 if (a_glyph
!= a_end
)
1533 if (a
->fill_line_p
!= b
->fill_line_p
1534 || a
->cursor_in_fringe_p
!= b
->cursor_in_fringe_p
1535 || a
->left_fringe_bitmap
!= b
->left_fringe_bitmap
1536 || a
->left_fringe_face_id
!= b
->left_fringe_face_id
1537 || a
->right_fringe_bitmap
!= b
->right_fringe_bitmap
1538 || a
->right_fringe_face_id
!= b
->right_fringe_face_id
1539 || a
->overlay_arrow_bitmap
!= b
->overlay_arrow_bitmap
1540 || a
->exact_window_width_line_p
!= b
->exact_window_width_line_p
1541 || a
->overlapped_p
!= b
->overlapped_p
1542 || (MATRIX_ROW_CONTINUATION_LINE_P (a
)
1543 != MATRIX_ROW_CONTINUATION_LINE_P (b
))
1544 || a
->reversed_p
!= b
->reversed_p
1545 /* Different partially visible characters on left margin. */
1547 /* Different height. */
1548 || a
->ascent
!= b
->ascent
1549 || a
->phys_ascent
!= b
->phys_ascent
1550 || a
->phys_height
!= b
->phys_height
1551 || a
->visible_height
!= b
->visible_height
)
1560 /***********************************************************************
1563 See dispextern.h for an overall explanation of glyph pools.
1564 ***********************************************************************/
1566 /* Allocate a glyph_pool structure. The structure returned is
1567 initialized with zeros. The global variable glyph_pool_count is
1568 incremented for each pool allocated. */
1570 static struct glyph_pool
*
1573 struct glyph_pool
*result
;
1575 /* Allocate a new glyph_pool and clear it. */
1576 result
= (struct glyph_pool
*) xmalloc (sizeof *result
);
1577 bzero (result
, sizeof *result
);
1579 /* For memory leak and double deletion checking. */
1586 /* Free a glyph_pool structure POOL. The function may be called with
1587 a null POOL pointer. The global variable glyph_pool_count is
1588 decremented with every pool structure freed. If this count gets
1589 negative, more structures were freed than allocated, i.e. one
1590 structure must have been freed more than once or a bogus pointer
1591 was passed to free_glyph_pool. */
1594 free_glyph_pool (pool
)
1595 struct glyph_pool
*pool
;
1599 /* More freed than allocated? */
1601 xassert (glyph_pool_count
>= 0);
1603 xfree (pool
->glyphs
);
1609 /* Enlarge a glyph pool POOL. MATRIX_DIM gives the number of rows and
1610 columns we need. This function never shrinks a pool. The only
1611 case in which this would make sense, would be when a frame's size
1612 is changed from a large value to a smaller one. But, if someone
1613 does it once, we can expect that he will do it again.
1615 Value is non-zero if the pool changed in a way which makes
1616 re-adjusting window glyph matrices necessary. */
1619 realloc_glyph_pool (pool
, matrix_dim
)
1620 struct glyph_pool
*pool
;
1621 struct dim matrix_dim
;
1626 changed_p
= (pool
->glyphs
== 0
1627 || matrix_dim
.height
!= pool
->nrows
1628 || matrix_dim
.width
!= pool
->ncolumns
);
1630 /* Enlarge the glyph pool. */
1631 needed
= matrix_dim
.width
* matrix_dim
.height
;
1632 if (needed
> pool
->nglyphs
)
1634 int size
= needed
* sizeof (struct glyph
);
1637 pool
->glyphs
= (struct glyph
*) xrealloc (pool
->glyphs
, size
);
1640 pool
->glyphs
= (struct glyph
*) xmalloc (size
);
1641 bzero (pool
->glyphs
, size
);
1644 pool
->nglyphs
= needed
;
1647 /* Remember the number of rows and columns because (a) we use them
1648 to do sanity checks, and (b) the number of columns determines
1649 where rows in the frame matrix start---this must be available to
1650 determine pointers to rows of window sub-matrices. */
1651 pool
->nrows
= matrix_dim
.height
;
1652 pool
->ncolumns
= matrix_dim
.width
;
1659 /***********************************************************************
1661 ***********************************************************************/
1666 /* Flush standard output. This is sometimes useful to call from the debugger.
1667 XXX Maybe this should be changed to flush the current terminal instead of
1678 /* Check that no glyph pointers have been lost in MATRIX. If a
1679 pointer has been lost, e.g. by using a structure assignment between
1680 rows, at least one pointer must occur more than once in the rows of
1684 check_matrix_pointer_lossage (matrix
)
1685 struct glyph_matrix
*matrix
;
1689 for (i
= 0; i
< matrix
->nrows
; ++i
)
1690 for (j
= 0; j
< matrix
->nrows
; ++j
)
1692 || (matrix
->rows
[i
].glyphs
[TEXT_AREA
]
1693 != matrix
->rows
[j
].glyphs
[TEXT_AREA
]));
1697 /* Get a pointer to glyph row ROW in MATRIX, with bounds checks. */
1700 matrix_row (matrix
, row
)
1701 struct glyph_matrix
*matrix
;
1704 xassert (matrix
&& matrix
->rows
);
1705 xassert (row
>= 0 && row
< matrix
->nrows
);
1707 /* That's really too slow for normal testing because this function
1708 is called almost everywhere. Although---it's still astonishingly
1709 fast, so it is valuable to have for debugging purposes. */
1711 check_matrix_pointer_lossage (matrix
);
1714 return matrix
->rows
+ row
;
1718 #if 0 /* This function makes invalid assumptions when text is
1719 partially invisible. But it might come handy for debugging
1722 /* Check invariants that must hold for an up to date current matrix of
1726 check_matrix_invariants (w
)
1729 struct glyph_matrix
*matrix
= w
->current_matrix
;
1730 int yb
= window_text_bottom_y (w
);
1731 struct glyph_row
*row
= matrix
->rows
;
1732 struct glyph_row
*last_text_row
= NULL
;
1733 struct buffer
*saved
= current_buffer
;
1734 struct buffer
*buffer
= XBUFFER (w
->buffer
);
1737 /* This can sometimes happen for a fresh window. */
1738 if (matrix
->nrows
< 2)
1741 set_buffer_temp (buffer
);
1743 /* Note: last row is always reserved for the mode line. */
1744 while (MATRIX_ROW_DISPLAYS_TEXT_P (row
)
1745 && MATRIX_ROW_BOTTOM_Y (row
) < yb
)
1747 struct glyph_row
*next
= row
+ 1;
1749 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
1750 last_text_row
= row
;
1752 /* Check that character and byte positions are in sync. */
1753 xassert (MATRIX_ROW_START_BYTEPOS (row
)
1754 == CHAR_TO_BYTE (MATRIX_ROW_START_CHARPOS (row
)));
1755 xassert (BYTEPOS (row
->start
.pos
)
1756 == CHAR_TO_BYTE (CHARPOS (row
->start
.pos
)));
1758 /* CHAR_TO_BYTE aborts when invoked for a position > Z. We can
1759 have such a position temporarily in case of a minibuffer
1760 displaying something like `[Sole completion]' at its end. */
1761 if (MATRIX_ROW_END_CHARPOS (row
) < BUF_ZV (current_buffer
))
1763 xassert (MATRIX_ROW_END_BYTEPOS (row
)
1764 == CHAR_TO_BYTE (MATRIX_ROW_END_CHARPOS (row
)));
1765 xassert (BYTEPOS (row
->end
.pos
)
1766 == CHAR_TO_BYTE (CHARPOS (row
->end
.pos
)));
1769 /* Check that end position of `row' is equal to start position
1771 if (next
->enabled_p
&& MATRIX_ROW_DISPLAYS_TEXT_P (next
))
1773 xassert (MATRIX_ROW_END_CHARPOS (row
)
1774 == MATRIX_ROW_START_CHARPOS (next
));
1775 xassert (MATRIX_ROW_END_BYTEPOS (row
)
1776 == MATRIX_ROW_START_BYTEPOS (next
));
1777 xassert (CHARPOS (row
->end
.pos
) == CHARPOS (next
->start
.pos
));
1778 xassert (BYTEPOS (row
->end
.pos
) == BYTEPOS (next
->start
.pos
));
1783 xassert (w
->current_matrix
->nrows
== w
->desired_matrix
->nrows
);
1784 xassert (w
->desired_matrix
->rows
!= NULL
);
1785 set_buffer_temp (saved
);
1790 #endif /* GLYPH_DEBUG != 0 */
1794 /**********************************************************************
1795 Allocating/ Adjusting Glyph Matrices
1796 **********************************************************************/
1798 /* Allocate glyph matrices over a window tree for a frame-based
1801 X and Y are column/row within the frame glyph matrix where
1802 sub-matrices for the window tree rooted at WINDOW must be
1803 allocated. DIM_ONLY_P non-zero means that the caller of this
1804 function is only interested in the result matrix dimension, and
1805 matrix adjustments should not be performed.
1807 The function returns the total width/height of the sub-matrices of
1808 the window tree. If called on a frame root window, the computation
1809 will take the mini-buffer window into account.
1811 *WINDOW_CHANGE_FLAGS is set to a bit mask with bits
1813 NEW_LEAF_MATRIX set if any window in the tree did not have a
1814 glyph matrices yet, and
1816 CHANGED_LEAF_MATRIX set if the dimension or location of a matrix of
1817 any window in the tree will be changed or have been changed (see
1820 *WINDOW_CHANGE_FLAGS must be initialized by the caller of this
1823 Windows are arranged into chains of windows on the same level
1824 through the next fields of window structures. Such a level can be
1825 either a sequence of horizontally adjacent windows from left to
1826 right, or a sequence of vertically adjacent windows from top to
1827 bottom. Each window in a horizontal sequence can be either a leaf
1828 window or a vertical sequence; a window in a vertical sequence can
1829 be either a leaf or a horizontal sequence. All windows in a
1830 horizontal sequence have the same height, and all windows in a
1831 vertical sequence have the same width.
1833 This function uses, for historical reasons, a more general
1834 algorithm to determine glyph matrix dimensions that would be
1837 The matrix height of a horizontal sequence is determined by the
1838 maximum height of any matrix in the sequence. The matrix width of
1839 a horizontal sequence is computed by adding up matrix widths of
1840 windows in the sequence.
1842 |<------- result width ------->|
1843 +---------+----------+---------+ ---
1846 +---------+ | | result height
1851 The matrix width of a vertical sequence is the maximum matrix width
1852 of any window in the sequence. Its height is computed by adding up
1853 matrix heights of windows in the sequence.
1855 |<---- result width -->|
1863 +------------+---------+ |
1866 +------------+---------+ --- */
1868 /* Bit indicating that a new matrix will be allocated or has been
1871 #define NEW_LEAF_MATRIX (1 << 0)
1873 /* Bit indicating that a matrix will or has changed its location or
1876 #define CHANGED_LEAF_MATRIX (1 << 1)
1879 allocate_matrices_for_frame_redisplay (window
, x
, y
, dim_only_p
,
1880 window_change_flags
)
1884 int *window_change_flags
;
1886 struct frame
*f
= XFRAME (WINDOW_FRAME (XWINDOW (window
)));
1888 int wmax
= 0, hmax
= 0;
1892 int in_horz_combination_p
;
1894 /* What combination is WINDOW part of? Compute this once since the
1895 result is the same for all windows in the `next' chain. The
1896 special case of a root window (parent equal to nil) is treated
1897 like a vertical combination because a root window's `next'
1898 points to the mini-buffer window, if any, which is arranged
1899 vertically below other windows. */
1900 in_horz_combination_p
1901 = (!NILP (XWINDOW (window
)->parent
)
1902 && !NILP (XWINDOW (XWINDOW (window
)->parent
)->hchild
));
1904 /* For WINDOW and all windows on the same level. */
1907 w
= XWINDOW (window
);
1909 /* Get the dimension of the window sub-matrix for W, depending
1910 on whether this is a combination or a leaf window. */
1911 if (!NILP (w
->hchild
))
1912 dim
= allocate_matrices_for_frame_redisplay (w
->hchild
, x
, y
,
1914 window_change_flags
);
1915 else if (!NILP (w
->vchild
))
1916 dim
= allocate_matrices_for_frame_redisplay (w
->vchild
, x
, y
,
1918 window_change_flags
);
1921 /* If not already done, allocate sub-matrix structures. */
1922 if (w
->desired_matrix
== NULL
)
1924 w
->desired_matrix
= new_glyph_matrix (f
->desired_pool
);
1925 w
->current_matrix
= new_glyph_matrix (f
->current_pool
);
1926 *window_change_flags
|= NEW_LEAF_MATRIX
;
1929 /* Width and height MUST be chosen so that there are no
1930 holes in the frame matrix. */
1931 dim
.width
= required_matrix_width (w
);
1932 dim
.height
= required_matrix_height (w
);
1934 /* Will matrix be re-allocated? */
1935 if (x
!= w
->desired_matrix
->matrix_x
1936 || y
!= w
->desired_matrix
->matrix_y
1937 || dim
.width
!= w
->desired_matrix
->matrix_w
1938 || dim
.height
!= w
->desired_matrix
->matrix_h
1939 || (margin_glyphs_to_reserve (w
, dim
.width
,
1940 w
->left_margin_cols
)
1941 != w
->desired_matrix
->left_margin_glyphs
)
1942 || (margin_glyphs_to_reserve (w
, dim
.width
,
1943 w
->right_margin_cols
)
1944 != w
->desired_matrix
->right_margin_glyphs
))
1945 *window_change_flags
|= CHANGED_LEAF_MATRIX
;
1947 /* Actually change matrices, if allowed. Do not consider
1948 CHANGED_LEAF_MATRIX computed above here because the pool
1949 may have been changed which we don't now here. We trust
1950 that we only will be called with DIM_ONLY_P != 0 when
1954 adjust_glyph_matrix (w
, w
->desired_matrix
, x
, y
, dim
);
1955 adjust_glyph_matrix (w
, w
->current_matrix
, x
, y
, dim
);
1959 /* If we are part of a horizontal combination, advance x for
1960 windows to the right of W; otherwise advance y for windows
1962 if (in_horz_combination_p
)
1967 /* Remember maximum glyph matrix dimensions. */
1968 wmax
= max (wmax
, dim
.width
);
1969 hmax
= max (hmax
, dim
.height
);
1971 /* Next window on same level. */
1974 while (!NILP (window
));
1976 /* Set `total' to the total glyph matrix dimension of this window
1977 level. In a vertical combination, the width is the width of the
1978 widest window; the height is the y we finally reached, corrected
1979 by the y we started with. In a horizontal combination, the total
1980 height is the height of the tallest window, and the width is the
1981 x we finally reached, corrected by the x we started with. */
1982 if (in_horz_combination_p
)
1984 total
.width
= x
- x0
;
1985 total
.height
= hmax
;
1990 total
.height
= y
- y0
;
1997 /* Return the required height of glyph matrices for window W. */
2000 required_matrix_height (w
)
2003 #ifdef HAVE_WINDOW_SYSTEM
2004 struct frame
*f
= XFRAME (w
->frame
);
2006 if (FRAME_WINDOW_P (f
))
2008 int ch_height
= FRAME_SMALLEST_FONT_HEIGHT (f
);
2009 int window_pixel_height
= window_box_height (w
) + eabs (w
->vscroll
);
2010 return (((window_pixel_height
+ ch_height
- 1)
2011 / ch_height
) * w
->nrows_scale_factor
2012 /* One partially visible line at the top and
2013 bottom of the window. */
2015 /* 2 for header and mode line. */
2018 #endif /* HAVE_WINDOW_SYSTEM */
2020 return WINDOW_TOTAL_LINES (w
);
2024 /* Return the required width of glyph matrices for window W. */
2027 required_matrix_width (w
)
2030 #ifdef HAVE_WINDOW_SYSTEM
2031 struct frame
*f
= XFRAME (w
->frame
);
2032 if (FRAME_WINDOW_P (f
))
2034 int ch_width
= FRAME_SMALLEST_CHAR_WIDTH (f
);
2035 int window_pixel_width
= WINDOW_TOTAL_WIDTH (w
);
2037 /* Compute number of glyphs needed in a glyph row. */
2038 return (((window_pixel_width
+ ch_width
- 1)
2039 / ch_width
) * w
->ncols_scale_factor
2040 /* 2 partially visible columns in the text area. */
2042 /* One partially visible column at the right
2043 edge of each marginal area. */
2046 #endif /* HAVE_WINDOW_SYSTEM */
2048 return XINT (w
->total_cols
);
2052 /* Allocate window matrices for window-based redisplay. W is the
2053 window whose matrices must be allocated/reallocated. */
2056 allocate_matrices_for_window_redisplay (w
)
2061 if (!NILP (w
->vchild
))
2062 allocate_matrices_for_window_redisplay (XWINDOW (w
->vchild
));
2063 else if (!NILP (w
->hchild
))
2064 allocate_matrices_for_window_redisplay (XWINDOW (w
->hchild
));
2067 /* W is a leaf window. */
2070 /* If matrices are not yet allocated, allocate them now. */
2071 if (w
->desired_matrix
== NULL
)
2073 w
->desired_matrix
= new_glyph_matrix (NULL
);
2074 w
->current_matrix
= new_glyph_matrix (NULL
);
2077 dim
.width
= required_matrix_width (w
);
2078 dim
.height
= required_matrix_height (w
);
2079 adjust_glyph_matrix (w
, w
->desired_matrix
, 0, 0, dim
);
2080 adjust_glyph_matrix (w
, w
->current_matrix
, 0, 0, dim
);
2083 w
= NILP (w
->next
) ? NULL
: XWINDOW (w
->next
);
2088 /* Re-allocate/ re-compute glyph matrices on frame F. If F is null,
2089 do it for all frames; otherwise do it just for the given frame.
2090 This function must be called when a new frame is created, its size
2091 changes, or its window configuration changes. */
2097 /* Block input so that expose events and other events that access
2098 glyph matrices are not processed while we are changing them. */
2102 adjust_frame_glyphs (f
);
2105 Lisp_Object tail
, lisp_frame
;
2107 FOR_EACH_FRAME (tail
, lisp_frame
)
2108 adjust_frame_glyphs (XFRAME (lisp_frame
));
2115 /* Adjust frame glyphs when Emacs is initialized.
2117 To be called from init_display.
2119 We need a glyph matrix because redraw will happen soon.
2120 Unfortunately, window sizes on selected_frame are not yet set to
2121 meaningful values. I believe we can assume that there are only two
2122 windows on the frame---the mini-buffer and the root window. Frame
2123 height and width seem to be correct so far. So, set the sizes of
2124 windows to estimated values. */
2127 adjust_frame_glyphs_initially ()
2129 struct frame
*sf
= SELECTED_FRAME ();
2130 struct window
*root
= XWINDOW (sf
->root_window
);
2131 struct window
*mini
= XWINDOW (root
->next
);
2132 int frame_lines
= FRAME_LINES (sf
);
2133 int frame_cols
= FRAME_COLS (sf
);
2134 int top_margin
= FRAME_TOP_MARGIN (sf
);
2136 /* Do it for the root window. */
2137 XSETFASTINT (root
->top_line
, top_margin
);
2138 XSETFASTINT (root
->total_cols
, frame_cols
);
2139 set_window_height (sf
->root_window
, frame_lines
- 1 - top_margin
, 0);
2141 /* Do it for the mini-buffer window. */
2142 XSETFASTINT (mini
->top_line
, frame_lines
- 1);
2143 XSETFASTINT (mini
->total_cols
, frame_cols
);
2144 set_window_height (root
->next
, 1, 0);
2146 adjust_frame_glyphs (sf
);
2147 glyphs_initialized_initially_p
= 1;
2151 /* Allocate/reallocate glyph matrices of a single frame F. */
2154 adjust_frame_glyphs (f
)
2157 if (FRAME_WINDOW_P (f
))
2158 adjust_frame_glyphs_for_window_redisplay (f
);
2160 adjust_frame_glyphs_for_frame_redisplay (f
);
2162 /* Don't forget the message buffer and the buffer for
2163 decode_mode_spec. */
2164 adjust_frame_message_buffer (f
);
2165 adjust_decode_mode_spec_buffer (f
);
2167 f
->glyphs_initialized_p
= 1;
2170 /* Return 1 if any window in the tree has nonzero window margins. See
2171 the hack at the end of adjust_frame_glyphs_for_frame_redisplay. */
2173 showing_window_margins_p (w
)
2178 if (!NILP (w
->hchild
))
2180 if (showing_window_margins_p (XWINDOW (w
->hchild
)))
2183 else if (!NILP (w
->vchild
))
2185 if (showing_window_margins_p (XWINDOW (w
->vchild
)))
2188 else if (!NILP (w
->left_margin_cols
)
2189 || !NILP (w
->right_margin_cols
))
2192 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
2198 /* In the window tree with root W, build current matrices of leaf
2199 windows from the frame's current matrix. */
2202 fake_current_matrices (window
)
2207 for (; !NILP (window
); window
= w
->next
)
2209 w
= XWINDOW (window
);
2211 if (!NILP (w
->hchild
))
2212 fake_current_matrices (w
->hchild
);
2213 else if (!NILP (w
->vchild
))
2214 fake_current_matrices (w
->vchild
);
2218 struct frame
*f
= XFRAME (w
->frame
);
2219 struct glyph_matrix
*m
= w
->current_matrix
;
2220 struct glyph_matrix
*fm
= f
->current_matrix
;
2222 xassert (m
->matrix_h
== WINDOW_TOTAL_LINES (w
));
2223 xassert (m
->matrix_w
== WINDOW_TOTAL_COLS (w
));
2225 for (i
= 0; i
< m
->matrix_h
; ++i
)
2227 struct glyph_row
*r
= m
->rows
+ i
;
2228 struct glyph_row
*fr
= fm
->rows
+ i
+ WINDOW_TOP_EDGE_LINE (w
);
2230 xassert (r
->glyphs
[TEXT_AREA
] >= fr
->glyphs
[TEXT_AREA
]
2231 && r
->glyphs
[LAST_AREA
] <= fr
->glyphs
[LAST_AREA
]);
2233 r
->enabled_p
= fr
->enabled_p
;
2236 r
->used
[LEFT_MARGIN_AREA
] = m
->left_margin_glyphs
;
2237 r
->used
[RIGHT_MARGIN_AREA
] = m
->right_margin_glyphs
;
2238 r
->used
[TEXT_AREA
] = (m
->matrix_w
2239 - r
->used
[LEFT_MARGIN_AREA
]
2240 - r
->used
[RIGHT_MARGIN_AREA
]);
2249 /* Save away the contents of frame F's current frame matrix. Value is
2250 a glyph matrix holding the contents of F's current frame matrix. */
2252 static struct glyph_matrix
*
2253 save_current_matrix (f
)
2257 struct glyph_matrix
*saved
;
2259 saved
= (struct glyph_matrix
*) xmalloc (sizeof *saved
);
2260 bzero (saved
, sizeof *saved
);
2261 saved
->nrows
= f
->current_matrix
->nrows
;
2262 saved
->rows
= (struct glyph_row
*) xmalloc (saved
->nrows
2263 * sizeof *saved
->rows
);
2264 bzero (saved
->rows
, saved
->nrows
* sizeof *saved
->rows
);
2266 for (i
= 0; i
< saved
->nrows
; ++i
)
2268 struct glyph_row
*from
= f
->current_matrix
->rows
+ i
;
2269 struct glyph_row
*to
= saved
->rows
+ i
;
2270 size_t nbytes
= from
->used
[TEXT_AREA
] * sizeof (struct glyph
);
2271 to
->glyphs
[TEXT_AREA
] = (struct glyph
*) xmalloc (nbytes
);
2272 bcopy (from
->glyphs
[TEXT_AREA
], to
->glyphs
[TEXT_AREA
], nbytes
);
2273 to
->used
[TEXT_AREA
] = from
->used
[TEXT_AREA
];
2280 /* Restore the contents of frame F's current frame matrix from SAVED,
2281 and free memory associated with SAVED. */
2284 restore_current_matrix (f
, saved
)
2286 struct glyph_matrix
*saved
;
2290 for (i
= 0; i
< saved
->nrows
; ++i
)
2292 struct glyph_row
*from
= saved
->rows
+ i
;
2293 struct glyph_row
*to
= f
->current_matrix
->rows
+ i
;
2294 size_t nbytes
= from
->used
[TEXT_AREA
] * sizeof (struct glyph
);
2295 bcopy (from
->glyphs
[TEXT_AREA
], to
->glyphs
[TEXT_AREA
], nbytes
);
2296 to
->used
[TEXT_AREA
] = from
->used
[TEXT_AREA
];
2297 xfree (from
->glyphs
[TEXT_AREA
]);
2300 xfree (saved
->rows
);
2306 /* Allocate/reallocate glyph matrices of a single frame F for
2307 frame-based redisplay. */
2310 adjust_frame_glyphs_for_frame_redisplay (f
)
2313 struct dim matrix_dim
;
2315 int window_change_flags
;
2318 if (!FRAME_LIVE_P (f
))
2321 top_window_y
= FRAME_TOP_MARGIN (f
);
2323 /* Allocate glyph pool structures if not already done. */
2324 if (f
->desired_pool
== NULL
)
2326 f
->desired_pool
= new_glyph_pool ();
2327 f
->current_pool
= new_glyph_pool ();
2330 /* Allocate frames matrix structures if needed. */
2331 if (f
->desired_matrix
== NULL
)
2333 f
->desired_matrix
= new_glyph_matrix (f
->desired_pool
);
2334 f
->current_matrix
= new_glyph_matrix (f
->current_pool
);
2337 /* Compute window glyph matrices. (This takes the mini-buffer
2338 window into account). The result is the size of the frame glyph
2339 matrix needed. The variable window_change_flags is set to a bit
2340 mask indicating whether new matrices will be allocated or
2341 existing matrices change their size or location within the frame
2343 window_change_flags
= 0;
2345 = allocate_matrices_for_frame_redisplay (FRAME_ROOT_WINDOW (f
),
2348 &window_change_flags
);
2350 /* Add in menu bar lines, if any. */
2351 matrix_dim
.height
+= top_window_y
;
2353 /* Enlarge pools as necessary. */
2354 pool_changed_p
= realloc_glyph_pool (f
->desired_pool
, matrix_dim
);
2355 realloc_glyph_pool (f
->current_pool
, matrix_dim
);
2357 /* Set up glyph pointers within window matrices. Do this only if
2358 absolutely necessary since it requires a frame redraw. */
2359 if (pool_changed_p
|| window_change_flags
)
2361 /* Do it for window matrices. */
2362 allocate_matrices_for_frame_redisplay (FRAME_ROOT_WINDOW (f
),
2364 &window_change_flags
);
2366 /* Size of frame matrices must equal size of frame. Note
2367 that we are called for X frames with window widths NOT equal
2368 to the frame width (from CHANGE_FRAME_SIZE_1). */
2369 xassert (matrix_dim
.width
== FRAME_COLS (f
)
2370 && matrix_dim
.height
== FRAME_LINES (f
));
2372 /* Pointers to glyph memory in glyph rows are exchanged during
2373 the update phase of redisplay, which means in general that a
2374 frame's current matrix consists of pointers into both the
2375 desired and current glyph pool of the frame. Adjusting a
2376 matrix sets the frame matrix up so that pointers are all into
2377 the same pool. If we want to preserve glyph contents of the
2378 current matrix over a call to adjust_glyph_matrix, we must
2379 make a copy of the current glyphs, and restore the current
2380 matrix' contents from that copy. */
2381 if (display_completed
2382 && !FRAME_GARBAGED_P (f
)
2383 && matrix_dim
.width
== f
->current_matrix
->matrix_w
2384 && matrix_dim
.height
== f
->current_matrix
->matrix_h
2385 /* For some reason, the frame glyph matrix gets corrupted if
2386 any of the windows contain margins. I haven't been able
2387 to hunt down the reason, but for the moment this prevents
2388 the problem from manifesting. -- cyd */
2389 && !showing_window_margins_p (XWINDOW (FRAME_ROOT_WINDOW (f
))))
2391 struct glyph_matrix
*copy
= save_current_matrix (f
);
2392 adjust_glyph_matrix (NULL
, f
->desired_matrix
, 0, 0, matrix_dim
);
2393 adjust_glyph_matrix (NULL
, f
->current_matrix
, 0, 0, matrix_dim
);
2394 restore_current_matrix (f
, copy
);
2395 fake_current_matrices (FRAME_ROOT_WINDOW (f
));
2399 adjust_glyph_matrix (NULL
, f
->desired_matrix
, 0, 0, matrix_dim
);
2400 adjust_glyph_matrix (NULL
, f
->current_matrix
, 0, 0, matrix_dim
);
2401 SET_FRAME_GARBAGED (f
);
2407 /* Allocate/reallocate glyph matrices of a single frame F for
2408 window-based redisplay. */
2411 adjust_frame_glyphs_for_window_redisplay (f
)
2416 xassert (FRAME_WINDOW_P (f
) && FRAME_LIVE_P (f
));
2418 /* Allocate/reallocate window matrices. */
2419 allocate_matrices_for_window_redisplay (XWINDOW (FRAME_ROOT_WINDOW (f
)));
2421 #ifdef HAVE_X_WINDOWS
2422 /* Allocate/ reallocate matrices of the dummy window used to display
2423 the menu bar under X when no X toolkit support is available. */
2424 #if ! defined (USE_X_TOOLKIT) && ! defined (USE_GTK)
2426 /* Allocate a dummy window if not already done. */
2427 if (NILP (f
->menu_bar_window
))
2429 f
->menu_bar_window
= make_window ();
2430 w
= XWINDOW (f
->menu_bar_window
);
2431 XSETFRAME (w
->frame
, f
);
2432 w
->pseudo_window_p
= 1;
2435 w
= XWINDOW (f
->menu_bar_window
);
2437 /* Set window dimensions to frame dimensions and allocate or
2438 adjust glyph matrices of W. */
2439 XSETFASTINT (w
->top_line
, 0);
2440 XSETFASTINT (w
->left_col
, 0);
2441 XSETFASTINT (w
->total_lines
, FRAME_MENU_BAR_LINES (f
));
2442 XSETFASTINT (w
->total_cols
, FRAME_TOTAL_COLS (f
));
2443 allocate_matrices_for_window_redisplay (w
);
2445 #endif /* not USE_X_TOOLKIT && not USE_GTK */
2446 #endif /* HAVE_X_WINDOWS */
2449 /* Allocate/ reallocate matrices of the tool bar window. If we
2450 don't have a tool bar window yet, make one. */
2451 if (NILP (f
->tool_bar_window
))
2453 f
->tool_bar_window
= make_window ();
2454 w
= XWINDOW (f
->tool_bar_window
);
2455 XSETFRAME (w
->frame
, f
);
2456 w
->pseudo_window_p
= 1;
2459 w
= XWINDOW (f
->tool_bar_window
);
2461 XSETFASTINT (w
->top_line
, FRAME_MENU_BAR_LINES (f
));
2462 XSETFASTINT (w
->left_col
, 0);
2463 XSETFASTINT (w
->total_lines
, FRAME_TOOL_BAR_LINES (f
));
2464 XSETFASTINT (w
->total_cols
, FRAME_TOTAL_COLS (f
));
2465 allocate_matrices_for_window_redisplay (w
);
2470 /* Adjust/ allocate message buffer of frame F.
2472 Note that the message buffer is never freed. Since I could not
2473 find a free in 19.34, I assume that freeing it would be
2474 problematic in some way and don't do it either.
2476 (Implementation note: It should be checked if we can free it
2477 eventually without causing trouble). */
2480 adjust_frame_message_buffer (f
)
2483 int size
= FRAME_MESSAGE_BUF_SIZE (f
) + 1;
2485 if (FRAME_MESSAGE_BUF (f
))
2487 char *buffer
= FRAME_MESSAGE_BUF (f
);
2488 char *new_buffer
= (char *) xrealloc (buffer
, size
);
2489 FRAME_MESSAGE_BUF (f
) = new_buffer
;
2492 FRAME_MESSAGE_BUF (f
) = (char *) xmalloc (size
);
2496 /* Re-allocate buffer for decode_mode_spec on frame F. */
2499 adjust_decode_mode_spec_buffer (f
)
2502 f
->decode_mode_spec_buffer
2503 = (char *) xrealloc (f
->decode_mode_spec_buffer
,
2504 FRAME_MESSAGE_BUF_SIZE (f
) + 1);
2509 /**********************************************************************
2510 Freeing Glyph Matrices
2511 **********************************************************************/
2513 /* Free glyph memory for a frame F. F may be null. This function can
2514 be called for the same frame more than once. The root window of
2515 F may be nil when this function is called. This is the case when
2516 the function is called when F is destroyed. */
2522 if (f
&& f
->glyphs_initialized_p
)
2524 /* Block interrupt input so that we don't get surprised by an X
2525 event while we're in an inconsistent state. */
2527 f
->glyphs_initialized_p
= 0;
2529 /* Release window sub-matrices. */
2530 if (!NILP (f
->root_window
))
2531 free_window_matrices (XWINDOW (f
->root_window
));
2533 /* Free the dummy window for menu bars without X toolkit and its
2535 if (!NILP (f
->menu_bar_window
))
2537 struct window
*w
= XWINDOW (f
->menu_bar_window
);
2538 free_glyph_matrix (w
->desired_matrix
);
2539 free_glyph_matrix (w
->current_matrix
);
2540 w
->desired_matrix
= w
->current_matrix
= NULL
;
2541 f
->menu_bar_window
= Qnil
;
2544 /* Free the tool bar window and its glyph matrices. */
2545 if (!NILP (f
->tool_bar_window
))
2547 struct window
*w
= XWINDOW (f
->tool_bar_window
);
2548 free_glyph_matrix (w
->desired_matrix
);
2549 free_glyph_matrix (w
->current_matrix
);
2550 w
->desired_matrix
= w
->current_matrix
= NULL
;
2551 f
->tool_bar_window
= Qnil
;
2554 /* Release frame glyph matrices. Reset fields to zero in
2555 case we are called a second time. */
2556 if (f
->desired_matrix
)
2558 free_glyph_matrix (f
->desired_matrix
);
2559 free_glyph_matrix (f
->current_matrix
);
2560 f
->desired_matrix
= f
->current_matrix
= NULL
;
2563 /* Release glyph pools. */
2564 if (f
->desired_pool
)
2566 free_glyph_pool (f
->desired_pool
);
2567 free_glyph_pool (f
->current_pool
);
2568 f
->desired_pool
= f
->current_pool
= NULL
;
2576 /* Free glyph sub-matrices in the window tree rooted at W. This
2577 function may be called with a null pointer, and it may be called on
2578 the same tree more than once. */
2581 free_window_matrices (w
)
2586 if (!NILP (w
->hchild
))
2587 free_window_matrices (XWINDOW (w
->hchild
));
2588 else if (!NILP (w
->vchild
))
2589 free_window_matrices (XWINDOW (w
->vchild
));
2592 /* This is a leaf window. Free its memory and reset fields
2593 to zero in case this function is called a second time for
2595 free_glyph_matrix (w
->current_matrix
);
2596 free_glyph_matrix (w
->desired_matrix
);
2597 w
->current_matrix
= w
->desired_matrix
= NULL
;
2600 /* Next window on same level. */
2601 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
2606 /* Check glyph memory leaks. This function is called from
2607 shut_down_emacs. Note that frames are not destroyed when Emacs
2608 exits. We therefore free all glyph memory for all active frames
2609 explicitly and check that nothing is left allocated. */
2612 check_glyph_memory ()
2614 Lisp_Object tail
, frame
;
2616 /* Free glyph memory for all frames. */
2617 FOR_EACH_FRAME (tail
, frame
)
2618 free_glyphs (XFRAME (frame
));
2620 /* Check that nothing is left allocated. */
2621 if (glyph_matrix_count
)
2623 if (glyph_pool_count
)
2629 /**********************************************************************
2630 Building a Frame Matrix
2631 **********************************************************************/
2633 /* Most of the redisplay code works on glyph matrices attached to
2634 windows. This is a good solution most of the time, but it is not
2635 suitable for terminal code. Terminal output functions cannot rely
2636 on being able to set an arbitrary terminal window. Instead they
2637 must be provided with a view of the whole frame, i.e. the whole
2638 screen. We build such a view by constructing a frame matrix from
2639 window matrices in this section.
2641 Windows that must be updated have their must_be_update_p flag set.
2642 For all such windows, their desired matrix is made part of the
2643 desired frame matrix. For other windows, their current matrix is
2644 made part of the desired frame matrix.
2646 +-----------------+----------------+
2647 | desired | desired |
2649 +-----------------+----------------+
2652 +----------------------------------+
2654 Desired window matrices can be made part of the frame matrix in a
2655 cheap way: We exploit the fact that the desired frame matrix and
2656 desired window matrices share their glyph memory. This is not
2657 possible for current window matrices. Their glyphs are copied to
2658 the desired frame matrix. The latter is equivalent to
2659 preserve_other_columns in the old redisplay.
2661 Used glyphs counters for frame matrix rows are the result of adding
2662 up glyph lengths of the window matrices. A line in the frame
2663 matrix is enabled, if a corresponding line in a window matrix is
2666 After building the desired frame matrix, it will be passed to
2667 terminal code, which will manipulate both the desired and current
2668 frame matrix. Changes applied to the frame's current matrix have
2669 to be visible in current window matrices afterwards, of course.
2671 This problem is solved like this:
2673 1. Window and frame matrices share glyphs. Window matrices are
2674 constructed in a way that their glyph contents ARE the glyph
2675 contents needed in a frame matrix. Thus, any modification of
2676 glyphs done in terminal code will be reflected in window matrices
2679 2. Exchanges of rows in a frame matrix done by terminal code are
2680 intercepted by hook functions so that corresponding row operations
2681 on window matrices can be performed. This is necessary because we
2682 use pointers to glyphs in glyph row structures. To satisfy the
2683 assumption of point 1 above that glyphs are updated implicitly in
2684 window matrices when they are manipulated via the frame matrix,
2685 window and frame matrix must of course agree where to find the
2686 glyphs for their rows. Possible manipulations that must be
2687 mirrored are assignments of rows of the desired frame matrix to the
2688 current frame matrix and scrolling the current frame matrix. */
2690 /* Build frame F's desired matrix from window matrices. Only windows
2691 which have the flag must_be_updated_p set have to be updated. Menu
2692 bar lines of a frame are not covered by window matrices, so make
2693 sure not to touch them in this function. */
2696 build_frame_matrix (f
)
2701 /* F must have a frame matrix when this function is called. */
2702 xassert (!FRAME_WINDOW_P (f
));
2704 /* Clear all rows in the frame matrix covered by window matrices.
2705 Menu bar lines are not covered by windows. */
2706 for (i
= FRAME_TOP_MARGIN (f
); i
< f
->desired_matrix
->nrows
; ++i
)
2707 clear_glyph_row (MATRIX_ROW (f
->desired_matrix
, i
));
2709 /* Build the matrix by walking the window tree. */
2710 build_frame_matrix_from_window_tree (f
->desired_matrix
,
2711 XWINDOW (FRAME_ROOT_WINDOW (f
)));
2715 /* Walk a window tree, building a frame matrix MATRIX from window
2716 matrices. W is the root of a window tree. */
2719 build_frame_matrix_from_window_tree (matrix
, w
)
2720 struct glyph_matrix
*matrix
;
2725 if (!NILP (w
->hchild
))
2726 build_frame_matrix_from_window_tree (matrix
, XWINDOW (w
->hchild
));
2727 else if (!NILP (w
->vchild
))
2728 build_frame_matrix_from_window_tree (matrix
, XWINDOW (w
->vchild
));
2730 build_frame_matrix_from_leaf_window (matrix
, w
);
2732 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
2737 /* Add a window's matrix to a frame matrix. FRAME_MATRIX is the
2738 desired frame matrix built. W is a leaf window whose desired or
2739 current matrix is to be added to FRAME_MATRIX. W's flag
2740 must_be_updated_p determines which matrix it contributes to
2741 FRAME_MATRIX. If must_be_updated_p is non-zero, W's desired matrix
2742 is added to FRAME_MATRIX, otherwise W's current matrix is added.
2743 Adding a desired matrix means setting up used counters and such in
2744 frame rows, while adding a current window matrix to FRAME_MATRIX
2745 means copying glyphs. The latter case corresponds to
2746 preserve_other_columns in the old redisplay. */
2749 build_frame_matrix_from_leaf_window (frame_matrix
, w
)
2750 struct glyph_matrix
*frame_matrix
;
2753 struct glyph_matrix
*window_matrix
;
2754 int window_y
, frame_y
;
2755 /* If non-zero, a glyph to insert at the right border of W. */
2756 GLYPH right_border_glyph
;
2758 SET_GLYPH_FROM_CHAR (right_border_glyph
, 0);
2760 /* Set window_matrix to the matrix we have to add to FRAME_MATRIX. */
2761 if (w
->must_be_updated_p
)
2763 window_matrix
= w
->desired_matrix
;
2765 /* Decide whether we want to add a vertical border glyph. */
2766 if (!WINDOW_RIGHTMOST_P (w
))
2768 struct Lisp_Char_Table
*dp
= window_display_table (w
);
2771 SET_GLYPH_FROM_CHAR (right_border_glyph
, '|');
2773 && (gc
= DISP_BORDER_GLYPH (dp
), GLYPH_CODE_P (gc
))
2774 && GLYPH_CODE_CHAR_VALID_P (gc
))
2776 SET_GLYPH_FROM_GLYPH_CODE (right_border_glyph
, gc
);
2777 spec_glyph_lookup_face (w
, &right_border_glyph
);
2780 if (GLYPH_FACE (right_border_glyph
) <= 0)
2781 SET_GLYPH_FACE (right_border_glyph
, VERTICAL_BORDER_FACE_ID
);
2785 window_matrix
= w
->current_matrix
;
2787 /* For all rows in the window matrix and corresponding rows in the
2790 frame_y
= window_matrix
->matrix_y
;
2791 while (window_y
< window_matrix
->nrows
)
2793 struct glyph_row
*frame_row
= frame_matrix
->rows
+ frame_y
;
2794 struct glyph_row
*window_row
= window_matrix
->rows
+ window_y
;
2795 int current_row_p
= window_matrix
== w
->current_matrix
;
2797 /* Fill up the frame row with spaces up to the left margin of the
2799 fill_up_frame_row_with_spaces (frame_row
, window_matrix
->matrix_x
);
2801 /* Fill up areas in the window matrix row with spaces. */
2802 fill_up_glyph_row_with_spaces (window_row
);
2804 /* If only part of W's desired matrix has been built, and
2805 window_row wasn't displayed, use the corresponding current
2807 if (window_matrix
== w
->desired_matrix
2808 && !window_row
->enabled_p
)
2810 window_row
= w
->current_matrix
->rows
+ window_y
;
2816 /* Copy window row to frame row. */
2817 bcopy (window_row
->glyphs
[0],
2818 frame_row
->glyphs
[TEXT_AREA
] + window_matrix
->matrix_x
,
2819 window_matrix
->matrix_w
* sizeof (struct glyph
));
2823 xassert (window_row
->enabled_p
);
2825 /* Only when a desired row has been displayed, we want
2826 the corresponding frame row to be updated. */
2827 frame_row
->enabled_p
= 1;
2829 /* Maybe insert a vertical border between horizontally adjacent
2831 if (GLYPH_CHAR (right_border_glyph
) != 0)
2833 struct glyph
*border
= window_row
->glyphs
[LAST_AREA
] - 1;
2834 SET_CHAR_GLYPH_FROM_GLYPH (*border
, right_border_glyph
);
2838 /* Window row window_y must be a slice of frame row
2840 xassert (glyph_row_slice_p (window_row
, frame_row
));
2842 /* If rows are in sync, we don't have to copy glyphs because
2843 frame and window share glyphs. */
2845 strcpy (w
->current_matrix
->method
, w
->desired_matrix
->method
);
2846 add_window_display_history (w
, w
->current_matrix
->method
, 0);
2850 /* Set number of used glyphs in the frame matrix. Since we fill
2851 up with spaces, and visit leaf windows from left to right it
2852 can be done simply. */
2853 frame_row
->used
[TEXT_AREA
]
2854 = window_matrix
->matrix_x
+ window_matrix
->matrix_w
;
2862 /* Given a user-specified glyph, possibly including a Lisp-level face
2863 ID, return a glyph that has a realized face ID.
2864 This is used for glyphs displayed specially and not part of the text;
2865 for instance, vertical separators, truncation markers, etc. */
2868 spec_glyph_lookup_face (w
, glyph
)
2872 int lface_id
= GLYPH_FACE (*glyph
);
2873 /* Convert the glyph's specified face to a realized (cache) face. */
2876 int face_id
= merge_faces (XFRAME (w
->frame
),
2877 Qt
, lface_id
, DEFAULT_FACE_ID
);
2878 SET_GLYPH_FACE (*glyph
, face_id
);
2882 /* Add spaces to a glyph row ROW in a window matrix.
2884 Each row has the form:
2886 +---------+-----------------------------+------------+
2887 | left | text | right |
2888 +---------+-----------------------------+------------+
2890 Left and right marginal areas are optional. This function adds
2891 spaces to areas so that there are no empty holes between areas.
2892 In other words: If the right area is not empty, the text area
2893 is filled up with spaces up to the right area. If the text area
2894 is not empty, the left area is filled up.
2896 To be called for frame-based redisplay, only. */
2899 fill_up_glyph_row_with_spaces (row
)
2900 struct glyph_row
*row
;
2902 fill_up_glyph_row_area_with_spaces (row
, LEFT_MARGIN_AREA
);
2903 fill_up_glyph_row_area_with_spaces (row
, TEXT_AREA
);
2904 fill_up_glyph_row_area_with_spaces (row
, RIGHT_MARGIN_AREA
);
2908 /* Fill area AREA of glyph row ROW with spaces. To be called for
2909 frame-based redisplay only. */
2912 fill_up_glyph_row_area_with_spaces (row
, area
)
2913 struct glyph_row
*row
;
2916 if (row
->glyphs
[area
] < row
->glyphs
[area
+ 1])
2918 struct glyph
*end
= row
->glyphs
[area
+ 1];
2919 struct glyph
*text
= row
->glyphs
[area
] + row
->used
[area
];
2922 *text
++ = space_glyph
;
2923 row
->used
[area
] = text
- row
->glyphs
[area
];
2928 /* Add spaces to the end of ROW in a frame matrix until index UPTO is
2929 reached. In frame matrices only one area, TEXT_AREA, is used. */
2932 fill_up_frame_row_with_spaces (row
, upto
)
2933 struct glyph_row
*row
;
2936 int i
= row
->used
[TEXT_AREA
];
2937 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
];
2940 glyph
[i
++] = space_glyph
;
2942 row
->used
[TEXT_AREA
] = i
;
2947 /**********************************************************************
2948 Mirroring operations on frame matrices in window matrices
2949 **********************************************************************/
2951 /* Set frame being updated via frame-based redisplay to F. This
2952 function must be called before updates to make explicit that we are
2953 working on frame matrices or not. */
2956 set_frame_matrix_frame (f
)
2959 frame_matrix_frame
= f
;
2963 /* Make sure glyph row ROW in CURRENT_MATRIX is up to date.
2964 DESIRED_MATRIX is the desired matrix corresponding to
2965 CURRENT_MATRIX. The update is done by exchanging glyph pointers
2966 between rows in CURRENT_MATRIX and DESIRED_MATRIX. If
2967 frame_matrix_frame is non-null, this indicates that the exchange is
2968 done in frame matrices, and that we have to perform analogous
2969 operations in window matrices of frame_matrix_frame. */
2972 make_current (desired_matrix
, current_matrix
, row
)
2973 struct glyph_matrix
*desired_matrix
, *current_matrix
;
2976 struct glyph_row
*current_row
= MATRIX_ROW (current_matrix
, row
);
2977 struct glyph_row
*desired_row
= MATRIX_ROW (desired_matrix
, row
);
2978 int mouse_face_p
= current_row
->mouse_face_p
;
2980 /* Do current_row = desired_row. This exchanges glyph pointers
2981 between both rows, and does a structure assignment otherwise. */
2982 assign_row (current_row
, desired_row
);
2984 /* Enable current_row to mark it as valid. */
2985 current_row
->enabled_p
= 1;
2986 current_row
->mouse_face_p
= mouse_face_p
;
2988 /* If we are called on frame matrices, perform analogous operations
2989 for window matrices. */
2990 if (frame_matrix_frame
)
2991 mirror_make_current (XWINDOW (frame_matrix_frame
->root_window
), row
);
2995 /* W is the root of a window tree. FRAME_ROW is the index of a row in
2996 W's frame which has been made current (by swapping pointers between
2997 current and desired matrix). Perform analogous operations in the
2998 matrices of leaf windows in the window tree rooted at W. */
3001 mirror_make_current (w
, frame_row
)
3007 if (!NILP (w
->hchild
))
3008 mirror_make_current (XWINDOW (w
->hchild
), frame_row
);
3009 else if (!NILP (w
->vchild
))
3010 mirror_make_current (XWINDOW (w
->vchild
), frame_row
);
3013 /* Row relative to window W. Don't use FRAME_TO_WINDOW_VPOS
3014 here because the checks performed in debug mode there
3015 will not allow the conversion. */
3016 int row
= frame_row
- w
->desired_matrix
->matrix_y
;
3018 /* If FRAME_ROW is within W, assign the desired row to the
3019 current row (exchanging glyph pointers). */
3020 if (row
>= 0 && row
< w
->desired_matrix
->matrix_h
)
3022 struct glyph_row
*current_row
3023 = MATRIX_ROW (w
->current_matrix
, row
);
3024 struct glyph_row
*desired_row
3025 = MATRIX_ROW (w
->desired_matrix
, row
);
3027 if (desired_row
->enabled_p
)
3028 assign_row (current_row
, desired_row
);
3030 swap_glyph_pointers (desired_row
, current_row
);
3031 current_row
->enabled_p
= 1;
3035 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
3040 /* Perform row dance after scrolling. We are working on the range of
3041 lines UNCHANGED_AT_TOP + 1 to UNCHANGED_AT_TOP + NLINES (not
3042 including) in MATRIX. COPY_FROM is a vector containing, for each
3043 row I in the range 0 <= I < NLINES, the index of the original line
3044 to move to I. This index is relative to the row range, i.e. 0 <=
3045 index < NLINES. RETAINED_P is a vector containing zero for each
3046 row 0 <= I < NLINES which is empty.
3048 This function is called from do_scrolling and do_direct_scrolling. */
3051 mirrored_line_dance (matrix
, unchanged_at_top
, nlines
, copy_from
,
3053 struct glyph_matrix
*matrix
;
3054 int unchanged_at_top
, nlines
;
3058 /* A copy of original rows. */
3059 struct glyph_row
*old_rows
;
3061 /* Rows to assign to. */
3062 struct glyph_row
*new_rows
= MATRIX_ROW (matrix
, unchanged_at_top
);
3066 /* Make a copy of the original rows. */
3067 old_rows
= (struct glyph_row
*) alloca (nlines
* sizeof *old_rows
);
3068 bcopy (new_rows
, old_rows
, nlines
* sizeof *old_rows
);
3070 /* Assign new rows, maybe clear lines. */
3071 for (i
= 0; i
< nlines
; ++i
)
3073 int enabled_before_p
= new_rows
[i
].enabled_p
;
3075 xassert (i
+ unchanged_at_top
< matrix
->nrows
);
3076 xassert (unchanged_at_top
+ copy_from
[i
] < matrix
->nrows
);
3077 new_rows
[i
] = old_rows
[copy_from
[i
]];
3078 new_rows
[i
].enabled_p
= enabled_before_p
;
3080 /* RETAINED_P is zero for empty lines. */
3081 if (!retained_p
[copy_from
[i
]])
3082 new_rows
[i
].enabled_p
= 0;
3085 /* Do the same for window matrices, if MATRIX is a frame matrix. */
3086 if (frame_matrix_frame
)
3087 mirror_line_dance (XWINDOW (frame_matrix_frame
->root_window
),
3088 unchanged_at_top
, nlines
, copy_from
, retained_p
);
3092 /* Synchronize glyph pointers in the current matrix of window W with
3093 the current frame matrix. */
3096 sync_window_with_frame_matrix_rows (w
)
3099 struct frame
*f
= XFRAME (w
->frame
);
3100 struct glyph_row
*window_row
, *window_row_end
, *frame_row
;
3101 int left
, right
, x
, width
;
3103 /* Preconditions: W must be a leaf window on a tty frame. */
3104 xassert (NILP (w
->hchild
) && NILP (w
->vchild
));
3105 xassert (!FRAME_WINDOW_P (f
));
3107 left
= margin_glyphs_to_reserve (w
, 1, w
->left_margin_cols
);
3108 right
= margin_glyphs_to_reserve (w
, 1, w
->right_margin_cols
);
3109 x
= w
->current_matrix
->matrix_x
;
3110 width
= w
->current_matrix
->matrix_w
;
3112 window_row
= w
->current_matrix
->rows
;
3113 window_row_end
= window_row
+ w
->current_matrix
->nrows
;
3114 frame_row
= f
->current_matrix
->rows
+ WINDOW_TOP_EDGE_LINE (w
);
3116 for (; window_row
< window_row_end
; ++window_row
, ++frame_row
)
3118 window_row
->glyphs
[LEFT_MARGIN_AREA
]
3119 = frame_row
->glyphs
[0] + x
;
3120 window_row
->glyphs
[TEXT_AREA
]
3121 = window_row
->glyphs
[LEFT_MARGIN_AREA
] + left
;
3122 window_row
->glyphs
[LAST_AREA
]
3123 = window_row
->glyphs
[LEFT_MARGIN_AREA
] + width
;
3124 window_row
->glyphs
[RIGHT_MARGIN_AREA
]
3125 = window_row
->glyphs
[LAST_AREA
] - right
;
3130 /* Return the window in the window tree rooted in W containing frame
3131 row ROW. Value is null if none is found. */
3134 frame_row_to_window (w
, row
)
3138 struct window
*found
= NULL
;
3142 if (!NILP (w
->hchild
))
3143 found
= frame_row_to_window (XWINDOW (w
->hchild
), row
);
3144 else if (!NILP (w
->vchild
))
3145 found
= frame_row_to_window (XWINDOW (w
->vchild
), row
);
3146 else if (row
>= WINDOW_TOP_EDGE_LINE (w
)
3147 && row
< WINDOW_BOTTOM_EDGE_LINE (w
))
3150 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
3157 /* Perform a line dance in the window tree rooted at W, after
3158 scrolling a frame matrix in mirrored_line_dance.
3160 We are working on the range of lines UNCHANGED_AT_TOP + 1 to
3161 UNCHANGED_AT_TOP + NLINES (not including) in W's frame matrix.
3162 COPY_FROM is a vector containing, for each row I in the range 0 <=
3163 I < NLINES, the index of the original line to move to I. This
3164 index is relative to the row range, i.e. 0 <= index < NLINES.
3165 RETAINED_P is a vector containing zero for each row 0 <= I < NLINES
3169 mirror_line_dance (w
, unchanged_at_top
, nlines
, copy_from
, retained_p
)
3171 int unchanged_at_top
, nlines
;
3177 if (!NILP (w
->hchild
))
3178 mirror_line_dance (XWINDOW (w
->hchild
), unchanged_at_top
,
3179 nlines
, copy_from
, retained_p
);
3180 else if (!NILP (w
->vchild
))
3181 mirror_line_dance (XWINDOW (w
->vchild
), unchanged_at_top
,
3182 nlines
, copy_from
, retained_p
);
3185 /* W is a leaf window, and we are working on its current
3187 struct glyph_matrix
*m
= w
->current_matrix
;
3189 struct glyph_row
*old_rows
;
3191 /* Make a copy of the original rows of matrix m. */
3192 old_rows
= (struct glyph_row
*) alloca (m
->nrows
* sizeof *old_rows
);
3193 bcopy (m
->rows
, old_rows
, m
->nrows
* sizeof *old_rows
);
3195 for (i
= 0; i
< nlines
; ++i
)
3197 /* Frame relative line assigned to. */
3198 int frame_to
= i
+ unchanged_at_top
;
3200 /* Frame relative line assigned. */
3201 int frame_from
= copy_from
[i
] + unchanged_at_top
;
3203 /* Window relative line assigned to. */
3204 int window_to
= frame_to
- m
->matrix_y
;
3206 /* Window relative line assigned. */
3207 int window_from
= frame_from
- m
->matrix_y
;
3209 /* Is assigned line inside window? */
3210 int from_inside_window_p
3211 = window_from
>= 0 && window_from
< m
->matrix_h
;
3213 /* Is assigned to line inside window? */
3214 int to_inside_window_p
3215 = window_to
>= 0 && window_to
< m
->matrix_h
;
3217 if (from_inside_window_p
&& to_inside_window_p
)
3219 /* Enabled setting before assignment. */
3220 int enabled_before_p
;
3222 /* Do the assignment. The enabled_p flag is saved
3223 over the assignment because the old redisplay did
3225 enabled_before_p
= m
->rows
[window_to
].enabled_p
;
3226 m
->rows
[window_to
] = old_rows
[window_from
];
3227 m
->rows
[window_to
].enabled_p
= enabled_before_p
;
3229 /* If frame line is empty, window line is empty, too. */
3230 if (!retained_p
[copy_from
[i
]])
3231 m
->rows
[window_to
].enabled_p
= 0;
3233 else if (to_inside_window_p
)
3235 /* A copy between windows. This is an infrequent
3236 case not worth optimizing. */
3237 struct frame
*f
= XFRAME (w
->frame
);
3238 struct window
*root
= XWINDOW (FRAME_ROOT_WINDOW (f
));
3240 struct glyph_matrix
*m2
;
3243 w2
= frame_row_to_window (root
, frame_from
);
3244 /* ttn@surf.glug.org: when enabling menu bar using `emacs
3245 -nw', FROM_FRAME sometimes has no associated window.
3246 This check avoids a segfault if W2 is null. */
3249 m2
= w2
->current_matrix
;
3250 m2_from
= frame_from
- m2
->matrix_y
;
3251 copy_row_except_pointers (m
->rows
+ window_to
,
3252 m2
->rows
+ m2_from
);
3254 /* If frame line is empty, window line is empty, too. */
3255 if (!retained_p
[copy_from
[i
]])
3256 m
->rows
[window_to
].enabled_p
= 0;
3260 else if (from_inside_window_p
)
3264 /* If there was a copy between windows, make sure glyph
3265 pointers are in sync with the frame matrix. */
3267 sync_window_with_frame_matrix_rows (w
);
3269 /* Check that no pointers are lost. */
3273 /* Next window on same level. */
3274 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
3281 /* Check that window and frame matrices agree about their
3282 understanding where glyphs of the rows are to find. For each
3283 window in the window tree rooted at W, check that rows in the
3284 matrices of leaf window agree with their frame matrices about
3288 check_window_matrix_pointers (w
)
3293 if (!NILP (w
->hchild
))
3294 check_window_matrix_pointers (XWINDOW (w
->hchild
));
3295 else if (!NILP (w
->vchild
))
3296 check_window_matrix_pointers (XWINDOW (w
->vchild
));
3299 struct frame
*f
= XFRAME (w
->frame
);
3300 check_matrix_pointers (w
->desired_matrix
, f
->desired_matrix
);
3301 check_matrix_pointers (w
->current_matrix
, f
->current_matrix
);
3304 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
3309 /* Check that window rows are slices of frame rows. WINDOW_MATRIX is
3310 a window and FRAME_MATRIX is the corresponding frame matrix. For
3311 each row in WINDOW_MATRIX check that it's a slice of the
3312 corresponding frame row. If it isn't, abort. */
3315 check_matrix_pointers (window_matrix
, frame_matrix
)
3316 struct glyph_matrix
*window_matrix
, *frame_matrix
;
3318 /* Row number in WINDOW_MATRIX. */
3321 /* Row number corresponding to I in FRAME_MATRIX. */
3322 int j
= window_matrix
->matrix_y
;
3324 /* For all rows check that the row in the window matrix is a
3325 slice of the row in the frame matrix. If it isn't we didn't
3326 mirror an operation on the frame matrix correctly. */
3327 while (i
< window_matrix
->nrows
)
3329 if (!glyph_row_slice_p (window_matrix
->rows
+ i
,
3330 frame_matrix
->rows
+ j
))
3336 #endif /* GLYPH_DEBUG != 0 */
3340 /**********************************************************************
3341 VPOS and HPOS translations
3342 **********************************************************************/
3346 /* Translate vertical position VPOS which is relative to window W to a
3347 vertical position relative to W's frame. */
3350 window_to_frame_vpos (w
, vpos
)
3354 struct frame
*f
= XFRAME (w
->frame
);
3356 xassert (!FRAME_WINDOW_P (f
));
3357 xassert (vpos
>= 0 && vpos
<= w
->desired_matrix
->nrows
);
3358 vpos
+= WINDOW_TOP_EDGE_LINE (w
);
3359 xassert (vpos
>= 0 && vpos
<= FRAME_LINES (f
));
3364 /* Translate horizontal position HPOS which is relative to window W to
3365 a horizontal position relative to W's frame. */
3368 window_to_frame_hpos (w
, hpos
)
3372 xassert (!FRAME_WINDOW_P (XFRAME (w
->frame
)));
3373 hpos
+= WINDOW_LEFT_EDGE_COL (w
);
3377 #endif /* GLYPH_DEBUG */
3381 /**********************************************************************
3383 **********************************************************************/
3385 DEFUN ("redraw-frame", Fredraw_frame
, Sredraw_frame
, 1, 1, 0,
3386 doc
: /* Clear frame FRAME and output again what is supposed to appear on it. */)
3392 CHECK_LIVE_FRAME (frame
);
3395 /* Ignore redraw requests, if frame has no glyphs yet.
3396 (Implementation note: It still has to be checked why we are
3397 called so early here). */
3398 if (!glyphs_initialized_initially_p
)
3403 if (FRAME_MSDOS_P (f
))
3404 FRAME_TERMINAL (f
)->set_terminal_modes_hook (FRAME_TERMINAL (f
));
3407 clear_current_matrices (f
);
3409 if (FRAME_TERMCAP_P (f
))
3410 fflush (FRAME_TTY (f
)->output
);
3411 windows_or_buffers_changed
++;
3412 /* Mark all windows as inaccurate, so that every window will have
3413 its redisplay done. */
3414 mark_window_display_accurate (FRAME_ROOT_WINDOW (f
), 0);
3415 set_window_update_flags (XWINDOW (FRAME_ROOT_WINDOW (f
)), 1);
3421 /* Redraw frame F. This is nothing more than a call to the Lisp
3422 function redraw-frame. */
3429 XSETFRAME (frame
, f
);
3430 Fredraw_frame (frame
);
3434 DEFUN ("redraw-display", Fredraw_display
, Sredraw_display
, 0, 0, "",
3435 doc
: /* Clear and redisplay all visible frames. */)
3438 Lisp_Object tail
, frame
;
3440 FOR_EACH_FRAME (tail
, frame
)
3441 if (FRAME_VISIBLE_P (XFRAME (frame
)))
3442 Fredraw_frame (frame
);
3448 /* This is used when frame_garbaged is set. Call Fredraw_frame on all
3449 visible frames marked as garbaged. */
3452 redraw_garbaged_frames ()
3454 Lisp_Object tail
, frame
;
3456 FOR_EACH_FRAME (tail
, frame
)
3457 if (FRAME_VISIBLE_P (XFRAME (frame
))
3458 && FRAME_GARBAGED_P (XFRAME (frame
)))
3459 Fredraw_frame (frame
);
3464 /***********************************************************************
3466 ***********************************************************************/
3468 /* Update frame F based on the data in desired matrices.
3470 If FORCE_P is non-zero, don't let redisplay be stopped by detecting
3471 pending input. If INHIBIT_HAIRY_ID_P is non-zero, don't try
3474 Value is non-zero if redisplay was stopped due to pending input. */
3477 update_frame (f
, force_p
, inhibit_hairy_id_p
)
3480 int inhibit_hairy_id_p
;
3482 /* 1 means display has been paused because of pending input. */
3484 struct window
*root_window
= XWINDOW (f
->root_window
);
3486 if (redisplay_dont_pause
)
3488 #if PERIODIC_PREEMPTION_CHECKING
3489 else if (NILP (Vredisplay_preemption_period
))
3491 else if (!force_p
&& NUMBERP (Vredisplay_preemption_period
))
3494 double p
= XFLOATINT (Vredisplay_preemption_period
);
3497 if (detect_input_pending_ignore_squeezables ())
3504 usec
= (p
- sec
) * 1000000;
3506 EMACS_GET_TIME (tm
);
3507 EMACS_SET_SECS_USECS (preemption_period
, sec
, usec
);
3508 EMACS_ADD_TIME (preemption_next_check
, tm
, preemption_period
);
3512 if (FRAME_WINDOW_P (f
))
3514 /* We are working on window matrix basis. All windows whose
3515 flag must_be_updated_p is set have to be updated. */
3517 /* Record that we are not working on frame matrices. */
3518 set_frame_matrix_frame (NULL
);
3520 /* Update all windows in the window tree of F, maybe stopping
3521 when pending input is detected. */
3524 /* Update the menu bar on X frames that don't have toolkit
3526 if (WINDOWP (f
->menu_bar_window
))
3527 update_window (XWINDOW (f
->menu_bar_window
), 1);
3529 /* Update the tool-bar window, if present. */
3530 if (WINDOWP (f
->tool_bar_window
))
3532 struct window
*w
= XWINDOW (f
->tool_bar_window
);
3534 /* Update tool-bar window. */
3535 if (w
->must_be_updated_p
)
3539 update_window (w
, 1);
3540 w
->must_be_updated_p
= 0;
3542 /* Swap tool-bar strings. We swap because we want to
3544 tem
= f
->current_tool_bar_string
;
3545 f
->current_tool_bar_string
= f
->desired_tool_bar_string
;
3546 f
->desired_tool_bar_string
= tem
;
3551 /* Update windows. */
3552 paused_p
= update_window_tree (root_window
, force_p
);
3555 /* This flush is a performance bottleneck under X,
3556 and it doesn't seem to be necessary anyway (in general).
3557 It is necessary when resizing the window with the mouse, or
3558 at least the fringes are not redrawn in a timely manner. ++kfs */
3559 if (f
->force_flush_display_p
)
3561 FRAME_RIF (f
)->flush_display (f
);
3562 f
->force_flush_display_p
= 0;
3567 /* We are working on frame matrix basis. Set the frame on whose
3568 frame matrix we operate. */
3569 set_frame_matrix_frame (f
);
3571 /* Build F's desired matrix from window matrices. */
3572 build_frame_matrix (f
);
3574 /* Update the display */
3576 paused_p
= update_frame_1 (f
, force_p
, inhibit_hairy_id_p
);
3579 if (FRAME_TERMCAP_P (f
) || FRAME_MSDOS_P (f
))
3581 if (FRAME_TTY (f
)->termscript
)
3582 fflush (FRAME_TTY (f
)->termscript
);
3583 if (FRAME_TERMCAP_P (f
))
3584 fflush (FRAME_TTY (f
)->output
);
3587 /* Check window matrices for lost pointers. */
3589 check_window_matrix_pointers (root_window
);
3590 add_frame_display_history (f
, paused_p
);
3595 /* Reset flags indicating that a window should be updated. */
3596 set_window_update_flags (root_window
, 0);
3598 display_completed
= !paused_p
;
3604 /************************************************************************
3605 Window-based updates
3606 ************************************************************************/
3608 /* Perform updates in window tree rooted at W. FORCE_P non-zero means
3609 don't stop updating when input is pending. */
3612 update_window_tree (w
, force_p
)
3618 while (w
&& !paused_p
)
3620 if (!NILP (w
->hchild
))
3621 paused_p
|= update_window_tree (XWINDOW (w
->hchild
), force_p
);
3622 else if (!NILP (w
->vchild
))
3623 paused_p
|= update_window_tree (XWINDOW (w
->vchild
), force_p
);
3624 else if (w
->must_be_updated_p
)
3625 paused_p
|= update_window (w
, force_p
);
3627 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
3634 /* Update window W if its flag must_be_updated_p is non-zero. If
3635 FORCE_P is non-zero, don't stop updating if input is pending. */
3638 update_single_window (w
, force_p
)
3642 if (w
->must_be_updated_p
)
3644 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
3646 /* Record that this is not a frame-based redisplay. */
3647 set_frame_matrix_frame (NULL
);
3649 if (redisplay_dont_pause
)
3651 #if PERIODIC_PREEMPTION_CHECKING
3652 else if (NILP (Vredisplay_preemption_period
))
3654 else if (!force_p
&& NUMBERP (Vredisplay_preemption_period
))
3657 double p
= XFLOATINT (Vredisplay_preemption_period
);
3661 usec
= (p
- sec
) * 1000000;
3663 EMACS_GET_TIME (tm
);
3664 EMACS_SET_SECS_USECS (preemption_period
, sec
, usec
);
3665 EMACS_ADD_TIME (preemption_next_check
, tm
, preemption_period
);
3671 update_window (w
, force_p
);
3674 /* Reset flag in W. */
3675 w
->must_be_updated_p
= 0;
3679 #ifdef HAVE_WINDOW_SYSTEM
3681 /* Redraw lines from the current matrix of window W that are
3682 overlapped by other rows. YB is bottom-most y-position in W. */
3685 redraw_overlapped_rows (w
, yb
)
3690 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
3692 /* If rows overlapping others have been changed, the rows being
3693 overlapped have to be redrawn. This won't draw lines that have
3694 already been drawn in update_window_line because overlapped_p in
3695 desired rows is 0, so after row assignment overlapped_p in
3696 current rows is 0. */
3697 for (i
= 0; i
< w
->current_matrix
->nrows
; ++i
)
3699 struct glyph_row
*row
= w
->current_matrix
->rows
+ i
;
3701 if (!row
->enabled_p
)
3703 else if (row
->mode_line_p
)
3706 if (row
->overlapped_p
)
3708 enum glyph_row_area area
;
3710 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
3713 updated_area
= area
;
3714 FRAME_RIF (f
)->cursor_to (i
, 0, row
->y
,
3715 area
== TEXT_AREA
? row
->x
: 0);
3716 if (row
->used
[area
])
3717 FRAME_RIF (f
)->write_glyphs (row
->glyphs
[area
],
3719 FRAME_RIF (f
)->clear_end_of_line (-1);
3722 row
->overlapped_p
= 0;
3725 if (MATRIX_ROW_BOTTOM_Y (row
) >= yb
)
3731 /* Redraw lines from the current matrix of window W that overlap
3732 others. YB is bottom-most y-position in W. */
3735 redraw_overlapping_rows (w
, yb
)
3740 struct glyph_row
*row
;
3741 struct redisplay_interface
*rif
= FRAME_RIF (XFRAME (WINDOW_FRAME (w
)));
3743 for (i
= 0; i
< w
->current_matrix
->nrows
; ++i
)
3745 row
= w
->current_matrix
->rows
+ i
;
3747 if (!row
->enabled_p
)
3749 else if (row
->mode_line_p
)
3752 bottom_y
= MATRIX_ROW_BOTTOM_Y (row
);
3754 if (row
->overlapping_p
)
3758 if (MATRIX_ROW_OVERLAPS_PRED_P (row
) && i
> 0
3759 && !MATRIX_ROW (w
->current_matrix
, i
- 1)->overlapped_p
)
3760 overlaps
|= OVERLAPS_PRED
;
3761 if (MATRIX_ROW_OVERLAPS_SUCC_P (row
) && bottom_y
< yb
3762 && !MATRIX_ROW (w
->current_matrix
, i
+ 1)->overlapped_p
)
3763 overlaps
|= OVERLAPS_SUCC
;
3767 if (row
->used
[LEFT_MARGIN_AREA
])
3768 rif
->fix_overlapping_area (w
, row
, LEFT_MARGIN_AREA
, overlaps
);
3770 if (row
->used
[TEXT_AREA
])
3771 rif
->fix_overlapping_area (w
, row
, TEXT_AREA
, overlaps
);
3773 if (row
->used
[RIGHT_MARGIN_AREA
])
3774 rif
->fix_overlapping_area (w
, row
, RIGHT_MARGIN_AREA
, overlaps
);
3776 /* Record in neighbour rows that ROW overwrites part of
3778 if (overlaps
& OVERLAPS_PRED
)
3779 MATRIX_ROW (w
->current_matrix
, i
- 1)->overlapped_p
= 1;
3780 if (overlaps
& OVERLAPS_SUCC
)
3781 MATRIX_ROW (w
->current_matrix
, i
+ 1)->overlapped_p
= 1;
3790 #endif /* HAVE_WINDOW_SYSTEM */
3795 /* Check that no row in the current matrix of window W is enabled
3796 which is below what's displayed in the window. */
3799 check_current_matrix_flags (w
)
3802 int last_seen_p
= 0;
3803 int i
, yb
= window_text_bottom_y (w
);
3805 for (i
= 0; i
< w
->current_matrix
->nrows
- 1; ++i
)
3807 struct glyph_row
*row
= MATRIX_ROW (w
->current_matrix
, i
);
3808 if (!last_seen_p
&& MATRIX_ROW_BOTTOM_Y (row
) >= yb
)
3810 else if (last_seen_p
&& row
->enabled_p
)
3815 #endif /* GLYPH_DEBUG */
3818 /* Update display of window W. FORCE_P non-zero means that we should
3819 not stop when detecting pending input. */
3822 update_window (w
, force_p
)
3826 struct glyph_matrix
*desired_matrix
= w
->desired_matrix
;
3828 #if !PERIODIC_PREEMPTION_CHECKING
3829 int preempt_count
= baud_rate
/ 2400 + 1;
3831 extern int input_pending
;
3832 extern Lisp_Object do_mouse_tracking
;
3833 struct redisplay_interface
*rif
= FRAME_RIF (XFRAME (WINDOW_FRAME (w
)));
3835 /* Check that W's frame doesn't have glyph matrices. */
3836 xassert (FRAME_WINDOW_P (XFRAME (WINDOW_FRAME (w
))));
3839 /* Check pending input the first time so that we can quickly return. */
3840 #if !PERIODIC_PREEMPTION_CHECKING
3842 detect_input_pending_ignore_squeezables ();
3845 /* If forced to complete the update, or if no input is pending, do
3847 if (force_p
|| !input_pending
|| !NILP (do_mouse_tracking
))
3849 struct glyph_row
*row
, *end
;
3850 struct glyph_row
*mode_line_row
;
3851 struct glyph_row
*header_line_row
;
3852 int yb
, changed_p
= 0, mouse_face_overwritten_p
= 0, n_updated
;
3854 rif
->update_window_begin_hook (w
);
3855 yb
= window_text_bottom_y (w
);
3857 /* If window has a header line, update it before everything else.
3858 Adjust y-positions of other rows by the header line height. */
3859 row
= desired_matrix
->rows
;
3860 end
= row
+ desired_matrix
->nrows
- 1;
3862 if (row
->mode_line_p
)
3864 header_line_row
= row
;
3868 header_line_row
= NULL
;
3870 /* Update the mode line, if necessary. */
3871 mode_line_row
= MATRIX_MODE_LINE_ROW (desired_matrix
);
3872 if (mode_line_row
->mode_line_p
&& mode_line_row
->enabled_p
)
3874 mode_line_row
->y
= yb
;
3875 update_window_line (w
, MATRIX_ROW_VPOS (mode_line_row
,
3877 &mouse_face_overwritten_p
);
3880 /* Find first enabled row. Optimizations in redisplay_internal
3881 may lead to an update with only one row enabled. There may
3882 be also completely empty matrices. */
3883 while (row
< end
&& !row
->enabled_p
)
3886 /* Try reusing part of the display by copying. */
3887 if (row
< end
&& !desired_matrix
->no_scrolling_p
)
3889 int rc
= scrolling_window (w
, header_line_row
!= NULL
);
3892 /* All rows were found to be equal. */
3898 /* We've scrolled the display. */
3904 /* Update the rest of the lines. */
3905 for (n_updated
= 0; row
< end
&& (force_p
|| !input_pending
); ++row
)
3908 int vpos
= MATRIX_ROW_VPOS (row
, desired_matrix
);
3911 /* We'll have to play a little bit with when to
3912 detect_input_pending. If it's done too often,
3913 scrolling large windows with repeated scroll-up
3914 commands will too quickly pause redisplay. */
3915 #if PERIODIC_PREEMPTION_CHECKING
3919 EMACS_GET_TIME (tm
);
3920 EMACS_SUB_TIME (dif
, preemption_next_check
, tm
);
3921 if (EMACS_TIME_NEG_P (dif
))
3923 EMACS_ADD_TIME (preemption_next_check
, tm
, preemption_period
);
3924 if (detect_input_pending_ignore_squeezables ())
3929 if (!force_p
&& ++n_updated
% preempt_count
== 0)
3930 detect_input_pending_ignore_squeezables ();
3932 changed_p
|= update_window_line (w
, vpos
,
3933 &mouse_face_overwritten_p
);
3935 /* Mark all rows below the last visible one in the current
3936 matrix as invalid. This is necessary because of
3937 variable line heights. Consider the case of three
3938 successive redisplays, where the first displays 5
3939 lines, the second 3 lines, and the third 5 lines again.
3940 If the second redisplay wouldn't mark rows in the
3941 current matrix invalid, the third redisplay might be
3942 tempted to optimize redisplay based on lines displayed
3943 in the first redisplay. */
3944 if (MATRIX_ROW_BOTTOM_Y (row
) >= yb
)
3945 for (i
= vpos
+ 1; i
< w
->current_matrix
->nrows
- 1; ++i
)
3946 MATRIX_ROW (w
->current_matrix
, i
)->enabled_p
= 0;
3949 /* Was display preempted? */
3950 paused_p
= row
< end
;
3954 /* Update the header line after scrolling because a new header
3955 line would otherwise overwrite lines at the top of the window
3956 that can be scrolled. */
3957 if (header_line_row
&& header_line_row
->enabled_p
)
3959 header_line_row
->y
= 0;
3960 update_window_line (w
, 0, &mouse_face_overwritten_p
);
3963 /* Fix the appearance of overlapping/overlapped rows. */
3964 if (!paused_p
&& !w
->pseudo_window_p
)
3966 #ifdef HAVE_WINDOW_SYSTEM
3967 if (changed_p
&& rif
->fix_overlapping_area
)
3969 redraw_overlapped_rows (w
, yb
);
3970 redraw_overlapping_rows (w
, yb
);
3974 /* Make cursor visible at cursor position of W. */
3975 set_window_cursor_after_update (w
);
3977 #if 0 /* Check that current matrix invariants are satisfied. This is
3978 for debugging only. See the comment of check_matrix_invariants. */
3979 IF_DEBUG (check_matrix_invariants (w
));
3984 /* Remember the redisplay method used to display the matrix. */
3985 strcpy (w
->current_matrix
->method
, w
->desired_matrix
->method
);
3988 #ifdef HAVE_WINDOW_SYSTEM
3989 update_window_fringes (w
, 0);
3992 /* End the update of window W. Don't set the cursor if we
3993 paused updating the display because in this case,
3994 set_window_cursor_after_update hasn't been called, and
3995 output_cursor doesn't contain the cursor location. */
3996 rif
->update_window_end_hook (w
, !paused_p
, mouse_face_overwritten_p
);
4002 /* check_current_matrix_flags (w); */
4003 add_window_display_history (w
, w
->current_matrix
->method
, paused_p
);
4006 clear_glyph_matrix (desired_matrix
);
4012 /* Update the display of area AREA in window W, row number VPOS.
4013 AREA can be either LEFT_MARGIN_AREA or RIGHT_MARGIN_AREA. */
4016 update_marginal_area (w
, area
, vpos
)
4020 struct glyph_row
*desired_row
= MATRIX_ROW (w
->desired_matrix
, vpos
);
4021 struct redisplay_interface
*rif
= FRAME_RIF (XFRAME (WINDOW_FRAME (w
)));
4023 /* Let functions in xterm.c know what area subsequent X positions
4024 will be relative to. */
4025 updated_area
= area
;
4027 /* Set cursor to start of glyphs, write them, and clear to the end
4028 of the area. I don't think that something more sophisticated is
4029 necessary here, since marginal areas will not be the default. */
4030 rif
->cursor_to (vpos
, 0, desired_row
->y
, 0);
4031 if (desired_row
->used
[area
])
4032 rif
->write_glyphs (desired_row
->glyphs
[area
], desired_row
->used
[area
]);
4033 rif
->clear_end_of_line (-1);
4037 /* Update the display of the text area of row VPOS in window W.
4038 Value is non-zero if display has changed. */
4041 update_text_area (w
, vpos
)
4045 struct glyph_row
*current_row
= MATRIX_ROW (w
->current_matrix
, vpos
);
4046 struct glyph_row
*desired_row
= MATRIX_ROW (w
->desired_matrix
, vpos
);
4047 struct redisplay_interface
*rif
= FRAME_RIF (XFRAME (WINDOW_FRAME (w
)));
4050 /* Let functions in xterm.c know what area subsequent X positions
4051 will be relative to. */
4052 updated_area
= TEXT_AREA
;
4054 /* If rows are at different X or Y, or rows have different height,
4055 or the current row is marked invalid, write the entire line. */
4056 if (!current_row
->enabled_p
4057 || desired_row
->y
!= current_row
->y
4058 || desired_row
->ascent
!= current_row
->ascent
4059 || desired_row
->phys_ascent
!= current_row
->phys_ascent
4060 || desired_row
->phys_height
!= current_row
->phys_height
4061 || desired_row
->visible_height
!= current_row
->visible_height
4062 || current_row
->overlapped_p
4063 /* This next line is necessary for correctly redrawing
4064 mouse-face areas after scrolling and other operations.
4065 However, it causes excessive flickering when mouse is moved
4066 across the mode line. Luckily, turning it off for the mode
4067 line doesn't seem to hurt anything. -- cyd.
4068 But it is still needed for the header line. -- kfs. */
4069 || (current_row
->mouse_face_p
4070 && !(current_row
->mode_line_p
&& vpos
> 0))
4071 || current_row
->x
!= desired_row
->x
)
4073 rif
->cursor_to (vpos
, 0, desired_row
->y
, desired_row
->x
);
4075 if (desired_row
->used
[TEXT_AREA
])
4076 rif
->write_glyphs (desired_row
->glyphs
[TEXT_AREA
],
4077 desired_row
->used
[TEXT_AREA
]);
4079 /* Clear to end of window. */
4080 rif
->clear_end_of_line (-1);
4083 /* This erases the cursor. We do this here because
4084 notice_overwritten_cursor cannot easily check this, which
4085 might indicate that the whole functionality of
4086 notice_overwritten_cursor would better be implemented here.
4087 On the other hand, we need notice_overwritten_cursor as long
4088 as mouse highlighting is done asynchronously outside of
4090 if (vpos
== w
->phys_cursor
.vpos
)
4091 w
->phys_cursor_on_p
= 0;
4096 struct glyph
*current_glyph
= current_row
->glyphs
[TEXT_AREA
];
4097 struct glyph
*desired_glyph
= desired_row
->glyphs
[TEXT_AREA
];
4098 int overlapping_glyphs_p
= current_row
->contains_overlapping_glyphs_p
;
4099 int desired_stop_pos
= desired_row
->used
[TEXT_AREA
];
4100 int abort_skipping
= 0;
4102 /* If the desired row extends its face to the text area end, and
4103 unless the current row also does so at the same position,
4104 make sure we write at least one glyph, so that the face
4105 extension actually takes place. */
4106 if (MATRIX_ROW_EXTENDS_FACE_P (desired_row
)
4107 && (desired_stop_pos
< current_row
->used
[TEXT_AREA
]
4108 || (desired_stop_pos
== current_row
->used
[TEXT_AREA
]
4109 && !MATRIX_ROW_EXTENDS_FACE_P (current_row
))))
4112 stop
= min (current_row
->used
[TEXT_AREA
], desired_stop_pos
);
4116 /* Loop over glyphs that current and desired row may have
4120 int can_skip_p
= !abort_skipping
;
4122 /* Skip over glyphs that both rows have in common. These
4123 don't have to be written. We can't skip if the last
4124 current glyph overlaps the glyph to its right. For
4125 example, consider a current row of `if ' with the `f' in
4126 Courier bold so that it overlaps the ` ' to its right.
4127 If the desired row is ` ', we would skip over the space
4128 after the `if' and there would remain a pixel from the
4129 `f' on the screen. */
4130 if (overlapping_glyphs_p
&& i
> 0)
4132 struct glyph
*glyph
= ¤t_row
->glyphs
[TEXT_AREA
][i
- 1];
4135 rif
->get_glyph_overhangs (glyph
, XFRAME (w
->frame
),
4137 can_skip_p
= (right
== 0 && !abort_skipping
);
4145 && GLYPH_EQUAL_P (desired_glyph
, current_glyph
))
4147 x
+= desired_glyph
->pixel_width
;
4148 ++desired_glyph
, ++current_glyph
, ++i
;
4151 /* Consider the case that the current row contains "xxx
4152 ppp ggg" in italic Courier font, and the desired row
4153 is "xxx ggg". The character `p' has lbearing, `g'
4154 has not. The loop above will stop in front of the
4155 first `p' in the current row. If we would start
4156 writing glyphs there, we wouldn't erase the lbearing
4157 of the `p'. The rest of the lbearing problem is then
4158 taken care of by draw_glyphs. */
4159 if (overlapping_glyphs_p
4161 && i
< current_row
->used
[TEXT_AREA
]
4162 && (current_row
->used
[TEXT_AREA
]
4163 != desired_row
->used
[TEXT_AREA
]))
4167 rif
->get_glyph_overhangs (current_glyph
, XFRAME (w
->frame
),
4169 while (left
> 0 && i
> 0)
4171 --i
, --desired_glyph
, --current_glyph
;
4172 x
-= desired_glyph
->pixel_width
;
4173 left
-= desired_glyph
->pixel_width
;
4176 /* Abort the skipping algorithm if we end up before
4177 our starting point, to avoid looping (bug#1070).
4178 This can happen when the lbearing is larger than
4180 abort_skipping
= (i
< start_hpos
);
4184 /* Try to avoid writing the entire rest of the desired row
4185 by looking for a resync point. This mainly prevents
4186 mode line flickering in the case the mode line is in
4187 fixed-pitch font, which it usually will be. */
4188 if (i
< desired_row
->used
[TEXT_AREA
])
4190 int start_x
= x
, start_hpos
= i
;
4191 struct glyph
*start
= desired_glyph
;
4193 int skip_first_p
= !can_skip_p
;
4195 /* Find the next glyph that's equal again. */
4198 || !GLYPH_EQUAL_P (desired_glyph
, current_glyph
))
4201 x
+= desired_glyph
->pixel_width
;
4202 current_x
+= current_glyph
->pixel_width
;
4203 ++desired_glyph
, ++current_glyph
, ++i
;
4207 if (i
== start_hpos
|| x
!= current_x
)
4211 desired_glyph
= start
;
4215 rif
->cursor_to (vpos
, start_hpos
, desired_row
->y
, start_x
);
4216 rif
->write_glyphs (start
, i
- start_hpos
);
4221 /* Write the rest. */
4222 if (i
< desired_row
->used
[TEXT_AREA
])
4224 rif
->cursor_to (vpos
, i
, desired_row
->y
, x
);
4225 rif
->write_glyphs (desired_glyph
, desired_row
->used
[TEXT_AREA
] - i
);
4229 /* Maybe clear to end of line. */
4230 if (MATRIX_ROW_EXTENDS_FACE_P (desired_row
))
4232 /* If new row extends to the end of the text area, nothing
4233 has to be cleared, if and only if we did a write_glyphs
4234 above. This is made sure by setting desired_stop_pos
4235 appropriately above. */
4236 xassert (i
< desired_row
->used
[TEXT_AREA
]
4237 || ((desired_row
->used
[TEXT_AREA
]
4238 == current_row
->used
[TEXT_AREA
])
4239 && MATRIX_ROW_EXTENDS_FACE_P (current_row
)));
4241 else if (MATRIX_ROW_EXTENDS_FACE_P (current_row
))
4243 /* If old row extends to the end of the text area, clear. */
4244 if (i
>= desired_row
->used
[TEXT_AREA
])
4245 rif
->cursor_to (vpos
, i
, desired_row
->y
,
4246 desired_row
->pixel_width
);
4247 rif
->clear_end_of_line (-1);
4250 else if (desired_row
->pixel_width
< current_row
->pixel_width
)
4252 /* Otherwise clear to the end of the old row. Everything
4253 after that position should be clear already. */
4256 if (i
>= desired_row
->used
[TEXT_AREA
])
4257 rif
->cursor_to (vpos
, i
, desired_row
->y
,
4258 desired_row
->pixel_width
);
4260 /* If cursor is displayed at the end of the line, make sure
4261 it's cleared. Nowadays we don't have a phys_cursor_glyph
4262 with which to erase the cursor (because this method
4263 doesn't work with lbearing/rbearing), so we must do it
4265 if (vpos
== w
->phys_cursor
.vpos
4266 && (desired_row
->reversed_p
4267 ? (w
->phys_cursor
.hpos
< 0)
4268 : (w
->phys_cursor
.hpos
>= desired_row
->used
[TEXT_AREA
])))
4270 w
->phys_cursor_on_p
= 0;
4274 x
= current_row
->pixel_width
;
4275 rif
->clear_end_of_line (x
);
4284 /* Update row VPOS in window W. Value is non-zero if display has been
4288 update_window_line (w
, vpos
, mouse_face_overwritten_p
)
4290 int vpos
, *mouse_face_overwritten_p
;
4292 struct glyph_row
*current_row
= MATRIX_ROW (w
->current_matrix
, vpos
);
4293 struct glyph_row
*desired_row
= MATRIX_ROW (w
->desired_matrix
, vpos
);
4294 struct redisplay_interface
*rif
= FRAME_RIF (XFRAME (WINDOW_FRAME (w
)));
4297 /* Set the row being updated. This is important to let xterm.c
4298 know what line height values are in effect. */
4299 updated_row
= desired_row
;
4301 /* A row can be completely invisible in case a desired matrix was
4302 built with a vscroll and then make_cursor_line_fully_visible shifts
4303 the matrix. Make sure to make such rows current anyway, since
4304 we need the correct y-position, for example, in the current matrix. */
4305 if (desired_row
->mode_line_p
4306 || desired_row
->visible_height
> 0)
4308 xassert (desired_row
->enabled_p
);
4310 /* Update display of the left margin area, if there is one. */
4311 if (!desired_row
->full_width_p
4312 && !NILP (w
->left_margin_cols
))
4315 update_marginal_area (w
, LEFT_MARGIN_AREA
, vpos
);
4318 /* Update the display of the text area. */
4319 if (update_text_area (w
, vpos
))
4322 if (current_row
->mouse_face_p
)
4323 *mouse_face_overwritten_p
= 1;
4326 /* Update display of the right margin area, if there is one. */
4327 if (!desired_row
->full_width_p
4328 && !NILP (w
->right_margin_cols
))
4331 update_marginal_area (w
, RIGHT_MARGIN_AREA
, vpos
);
4334 /* Draw truncation marks etc. */
4335 if (!current_row
->enabled_p
4336 || desired_row
->y
!= current_row
->y
4337 || desired_row
->visible_height
!= current_row
->visible_height
4338 || desired_row
->cursor_in_fringe_p
!= current_row
->cursor_in_fringe_p
4339 || desired_row
->overlay_arrow_bitmap
!= current_row
->overlay_arrow_bitmap
4340 || current_row
->redraw_fringe_bitmaps_p
4341 || desired_row
->mode_line_p
!= current_row
->mode_line_p
4342 || desired_row
->exact_window_width_line_p
!= current_row
->exact_window_width_line_p
4343 || (MATRIX_ROW_CONTINUATION_LINE_P (desired_row
)
4344 != MATRIX_ROW_CONTINUATION_LINE_P (current_row
)))
4345 rif
->after_update_window_line_hook (desired_row
);
4348 /* Update current_row from desired_row. */
4349 make_current (w
->desired_matrix
, w
->current_matrix
, vpos
);
4355 /* Set the cursor after an update of window W. This function may only
4356 be called from update_window. */
4359 set_window_cursor_after_update (w
)
4362 struct frame
*f
= XFRAME (w
->frame
);
4363 struct redisplay_interface
*rif
= FRAME_RIF (f
);
4364 int cx
, cy
, vpos
, hpos
;
4366 /* Not intended for frame matrix updates. */
4367 xassert (FRAME_WINDOW_P (f
));
4369 if (cursor_in_echo_area
4370 && !NILP (echo_area_buffer
[0])
4371 /* If we are showing a message instead of the mini-buffer,
4372 show the cursor for the message instead. */
4373 && XWINDOW (minibuf_window
) == w
4374 && EQ (minibuf_window
, echo_area_window
)
4375 /* These cases apply only to the frame that contains
4376 the active mini-buffer window. */
4377 && FRAME_HAS_MINIBUF_P (f
)
4378 && EQ (FRAME_MINIBUF_WINDOW (f
), echo_area_window
))
4380 cx
= cy
= vpos
= hpos
= 0;
4382 if (cursor_in_echo_area
>= 0)
4384 /* If the mini-buffer is several lines high, find the last
4385 line that has any text on it. Note: either all lines
4386 are enabled or none. Otherwise we wouldn't be able to
4388 struct glyph_row
*row
, *last_row
;
4389 struct glyph
*glyph
;
4390 int yb
= window_text_bottom_y (w
);
4393 row
= w
->current_matrix
->rows
;
4394 while (row
->enabled_p
4395 && (last_row
== NULL
4396 || MATRIX_ROW_BOTTOM_Y (row
) <= yb
))
4398 if (row
->used
[TEXT_AREA
]
4399 && row
->glyphs
[TEXT_AREA
][0].charpos
>= 0)
4406 struct glyph
*start
= last_row
->glyphs
[TEXT_AREA
];
4407 struct glyph
*last
= start
+ last_row
->used
[TEXT_AREA
] - 1;
4409 while (last
> start
&& last
->charpos
< 0)
4412 for (glyph
= start
; glyph
< last
; ++glyph
)
4414 cx
+= glyph
->pixel_width
;
4419 vpos
= MATRIX_ROW_VPOS (last_row
, w
->current_matrix
);
4427 hpos
= w
->cursor
.hpos
;
4428 vpos
= w
->cursor
.vpos
;
4431 /* Window cursor can be out of sync for horizontally split windows. */
4432 hpos
= max (-1, hpos
); /* -1 is for when cursor is on the left fringe */
4433 hpos
= min (w
->current_matrix
->matrix_w
- 1, hpos
);
4434 vpos
= max (0, vpos
);
4435 vpos
= min (w
->current_matrix
->nrows
- 1, vpos
);
4436 rif
->cursor_to (vpos
, hpos
, cy
, cx
);
4440 /* Set WINDOW->must_be_updated_p to ON_P for all windows in the window
4441 tree rooted at W. */
4444 set_window_update_flags (w
, on_p
)
4450 if (!NILP (w
->hchild
))
4451 set_window_update_flags (XWINDOW (w
->hchild
), on_p
);
4452 else if (!NILP (w
->vchild
))
4453 set_window_update_flags (XWINDOW (w
->vchild
), on_p
);
4455 w
->must_be_updated_p
= on_p
;
4457 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
4463 /***********************************************************************
4464 Window-Based Scrolling
4465 ***********************************************************************/
4467 /* Structure describing rows in scrolling_window. */
4471 /* Number of occurrences of this row in desired and current matrix. */
4472 int old_uses
, new_uses
;
4474 /* Vpos of row in new matrix. */
4475 int new_line_number
;
4477 /* Bucket index of this row_entry in the hash table row_table. */
4480 /* The row described by this entry. */
4481 struct glyph_row
*row
;
4483 /* Hash collision chain. */
4484 struct row_entry
*next
;
4487 /* A pool to allocate row_entry structures from, and the size of the
4488 pool. The pool is reallocated in scrolling_window when we find
4489 that we need a larger one. */
4491 static struct row_entry
*row_entry_pool
;
4492 static int row_entry_pool_size
;
4494 /* Index of next free entry in row_entry_pool. */
4496 static int row_entry_idx
;
4498 /* The hash table used during scrolling, and the table's size. This
4499 table is used to quickly identify equal rows in the desired and
4502 static struct row_entry
**row_table
;
4503 static int row_table_size
;
4505 /* Vectors of pointers to row_entry structures belonging to the
4506 current and desired matrix, and the size of the vectors. */
4508 static struct row_entry
**old_lines
, **new_lines
;
4509 static int old_lines_size
, new_lines_size
;
4511 /* A pool to allocate run structures from, and its size. */
4513 static struct run
*run_pool
;
4514 static int runs_size
;
4516 /* A vector of runs of lines found during scrolling. */
4518 static struct run
**runs
;
4520 /* Add glyph row ROW to the scrolling hash table during the scrolling
4523 static INLINE
struct row_entry
*
4524 add_row_entry (w
, row
)
4526 struct glyph_row
*row
;
4528 struct row_entry
*entry
;
4529 int i
= row
->hash
% row_table_size
;
4531 entry
= row_table
[i
];
4532 while (entry
&& !row_equal_p (w
, entry
->row
, row
, 1))
4533 entry
= entry
->next
;
4537 entry
= row_entry_pool
+ row_entry_idx
++;
4539 entry
->old_uses
= entry
->new_uses
= 0;
4540 entry
->new_line_number
= 0;
4542 entry
->next
= row_table
[i
];
4543 row_table
[i
] = entry
;
4550 /* Try to reuse part of the current display of W by scrolling lines.
4551 HEADER_LINE_P non-zero means W has a header line.
4553 The algorithm is taken from Communications of the ACM, Apr78 "A
4554 Technique for Isolating Differences Between Files." It should take
4557 A short outline of the steps of the algorithm
4559 1. Skip lines equal at the start and end of both matrices.
4561 2. Enter rows in the current and desired matrix into a symbol
4562 table, counting how often they appear in both matrices.
4564 3. Rows that appear exactly once in both matrices serve as anchors,
4565 i.e. we assume that such lines are likely to have been moved.
4567 4. Starting from anchor lines, extend regions to be scrolled both
4568 forward and backward.
4572 -1 if all rows were found to be equal.
4573 0 to indicate that we did not scroll the display, or
4574 1 if we did scroll. */
4577 scrolling_window (w
, header_line_p
)
4581 struct glyph_matrix
*desired_matrix
= w
->desired_matrix
;
4582 struct glyph_matrix
*current_matrix
= w
->current_matrix
;
4583 int yb
= window_text_bottom_y (w
);
4584 int i
, j
, first_old
, first_new
, last_old
, last_new
;
4585 int nruns
, nbytes
, n
, run_idx
;
4586 struct row_entry
*entry
;
4587 struct redisplay_interface
*rif
= FRAME_RIF (XFRAME (WINDOW_FRAME (w
)));
4589 /* Skip over rows equal at the start. */
4590 for (i
= header_line_p
? 1 : 0; i
< current_matrix
->nrows
- 1; ++i
)
4592 struct glyph_row
*d
= MATRIX_ROW (desired_matrix
, i
);
4593 struct glyph_row
*c
= MATRIX_ROW (current_matrix
, i
);
4597 && !d
->redraw_fringe_bitmaps_p
4599 && MATRIX_ROW_BOTTOM_Y (c
) <= yb
4600 && MATRIX_ROW_BOTTOM_Y (d
) <= yb
4601 && row_equal_p (w
, c
, d
, 1))
4610 /* Give up if some rows in the desired matrix are not enabled. */
4611 if (!MATRIX_ROW (desired_matrix
, i
)->enabled_p
)
4614 first_old
= first_new
= i
;
4616 /* Set last_new to the index + 1 of the last enabled row in the
4619 while (i
< desired_matrix
->nrows
- 1
4620 && MATRIX_ROW (desired_matrix
, i
)->enabled_p
4621 && MATRIX_ROW_BOTTOM_Y (MATRIX_ROW (desired_matrix
, i
)) <= yb
)
4624 if (!MATRIX_ROW (desired_matrix
, i
)->enabled_p
)
4629 /* Set last_old to the index + 1 of the last enabled row in the
4630 current matrix. We don't look at the enabled flag here because
4631 we plan to reuse part of the display even if other parts are
4634 while (i
< current_matrix
->nrows
- 1)
4636 int bottom
= MATRIX_ROW_BOTTOM_Y (MATRIX_ROW (current_matrix
, i
));
4645 /* Skip over rows equal at the bottom. */
4648 while (i
- 1 > first_new
4649 && j
- 1 > first_old
4650 && MATRIX_ROW (current_matrix
, i
- 1)->enabled_p
4651 && (MATRIX_ROW (current_matrix
, i
- 1)->y
4652 == MATRIX_ROW (desired_matrix
, j
- 1)->y
)
4653 && !MATRIX_ROW (desired_matrix
, j
- 1)->redraw_fringe_bitmaps_p
4655 MATRIX_ROW (desired_matrix
, i
- 1),
4656 MATRIX_ROW (current_matrix
, j
- 1), 1))
4661 /* Nothing to do if all rows are equal. */
4662 if (last_new
== first_new
)
4665 /* Reallocate vectors, tables etc. if necessary. */
4667 if (current_matrix
->nrows
> old_lines_size
)
4669 old_lines_size
= current_matrix
->nrows
;
4670 nbytes
= old_lines_size
* sizeof *old_lines
;
4671 old_lines
= (struct row_entry
**) xrealloc (old_lines
, nbytes
);
4674 if (desired_matrix
->nrows
> new_lines_size
)
4676 new_lines_size
= desired_matrix
->nrows
;
4677 nbytes
= new_lines_size
* sizeof *new_lines
;
4678 new_lines
= (struct row_entry
**) xrealloc (new_lines
, nbytes
);
4681 n
= desired_matrix
->nrows
+ current_matrix
->nrows
;
4682 if (3 * n
> row_table_size
)
4684 row_table_size
= next_almost_prime (3 * n
);
4685 nbytes
= row_table_size
* sizeof *row_table
;
4686 row_table
= (struct row_entry
**) xrealloc (row_table
, nbytes
);
4687 bzero (row_table
, nbytes
);
4690 if (n
> row_entry_pool_size
)
4692 row_entry_pool_size
= n
;
4693 nbytes
= row_entry_pool_size
* sizeof *row_entry_pool
;
4694 row_entry_pool
= (struct row_entry
*) xrealloc (row_entry_pool
, nbytes
);
4697 if (desired_matrix
->nrows
> runs_size
)
4699 runs_size
= desired_matrix
->nrows
;
4700 nbytes
= runs_size
* sizeof *runs
;
4701 runs
= (struct run
**) xrealloc (runs
, nbytes
);
4702 nbytes
= runs_size
* sizeof *run_pool
;
4703 run_pool
= (struct run
*) xrealloc (run_pool
, nbytes
);
4706 nruns
= run_idx
= 0;
4709 /* Add rows from the current and desired matrix to the hash table
4710 row_hash_table to be able to find equal ones quickly. */
4712 for (i
= first_old
; i
< last_old
; ++i
)
4714 if (MATRIX_ROW (current_matrix
, i
)->enabled_p
)
4716 entry
= add_row_entry (w
, MATRIX_ROW (current_matrix
, i
));
4717 old_lines
[i
] = entry
;
4721 old_lines
[i
] = NULL
;
4724 for (i
= first_new
; i
< last_new
; ++i
)
4726 xassert (MATRIX_ROW_ENABLED_P (desired_matrix
, i
));
4727 entry
= add_row_entry (w
, MATRIX_ROW (desired_matrix
, i
));
4729 entry
->new_line_number
= i
;
4730 new_lines
[i
] = entry
;
4733 /* Identify moves based on lines that are unique and equal
4734 in both matrices. */
4735 for (i
= first_old
; i
< last_old
;)
4737 && old_lines
[i
]->old_uses
== 1
4738 && old_lines
[i
]->new_uses
== 1)
4741 int new_line
= old_lines
[i
]->new_line_number
;
4742 struct run
*run
= run_pool
+ run_idx
++;
4745 run
->current_vpos
= i
;
4746 run
->current_y
= MATRIX_ROW (current_matrix
, i
)->y
;
4747 run
->desired_vpos
= new_line
;
4748 run
->desired_y
= MATRIX_ROW (desired_matrix
, new_line
)->y
;
4750 run
->height
= MATRIX_ROW (current_matrix
, i
)->height
;
4752 /* Extend backward. */
4755 while (j
> first_old
4757 && old_lines
[j
] == new_lines
[k
])
4759 int h
= MATRIX_ROW (current_matrix
, j
)->height
;
4760 --run
->current_vpos
;
4761 --run
->desired_vpos
;
4764 run
->desired_y
-= h
;
4765 run
->current_y
-= h
;
4769 /* Extend forward. */
4774 && old_lines
[j
] == new_lines
[k
])
4776 int h
= MATRIX_ROW (current_matrix
, j
)->height
;
4782 /* Insert run into list of all runs. Order runs by copied
4783 pixel lines. Note that we record runs that don't have to
4784 be copied because they are already in place. This is done
4785 because we can avoid calling update_window_line in this
4787 for (j
= 0; j
< nruns
&& runs
[j
]->height
> run
->height
; ++j
)
4789 for (k
= nruns
; k
> j
; --k
)
4790 runs
[k
] = runs
[k
- 1];
4799 /* Do the moves. Do it in a way that we don't overwrite something
4800 we want to copy later on. This is not solvable in general
4801 because there is only one display and we don't have a way to
4802 exchange areas on this display. Example:
4804 +-----------+ +-----------+
4806 +-----------+ --> +-----------+
4808 +-----------+ +-----------+
4810 Instead, prefer bigger moves, and invalidate moves that would
4811 copy from where we copied to. */
4813 for (i
= 0; i
< nruns
; ++i
)
4814 if (runs
[i
]->nrows
> 0)
4816 struct run
*r
= runs
[i
];
4818 /* Copy on the display. */
4819 if (r
->current_y
!= r
->desired_y
)
4821 rif
->scroll_run_hook (w
, r
);
4823 /* Invalidate runs that copy from where we copied to. */
4824 for (j
= i
+ 1; j
< nruns
; ++j
)
4826 struct run
*p
= runs
[j
];
4828 if ((p
->current_y
>= r
->desired_y
4829 && p
->current_y
< r
->desired_y
+ r
->height
)
4830 || (p
->current_y
+ p
->height
>= r
->desired_y
4831 && (p
->current_y
+ p
->height
4832 < r
->desired_y
+ r
->height
)))
4837 /* Assign matrix rows. */
4838 for (j
= 0; j
< r
->nrows
; ++j
)
4840 struct glyph_row
*from
, *to
;
4841 int to_overlapped_p
;
4843 to
= MATRIX_ROW (current_matrix
, r
->desired_vpos
+ j
);
4844 from
= MATRIX_ROW (desired_matrix
, r
->desired_vpos
+ j
);
4845 to_overlapped_p
= to
->overlapped_p
;
4846 if (!from
->mode_line_p
&& !w
->pseudo_window_p
4847 && (to
->left_fringe_bitmap
!= from
->left_fringe_bitmap
4848 || to
->right_fringe_bitmap
!= from
->right_fringe_bitmap
4849 || to
->left_fringe_face_id
!= from
->left_fringe_face_id
4850 || to
->right_fringe_face_id
!= from
->right_fringe_face_id
4851 || to
->overlay_arrow_bitmap
!= from
->overlay_arrow_bitmap
))
4852 from
->redraw_fringe_bitmaps_p
= 1;
4853 assign_row (to
, from
);
4854 to
->enabled_p
= 1, from
->enabled_p
= 0;
4855 to
->overlapped_p
= to_overlapped_p
;
4859 /* Clear the hash table, for the next time. */
4860 for (i
= 0; i
< row_entry_idx
; ++i
)
4861 row_table
[row_entry_pool
[i
].bucket
] = NULL
;
4863 /* Value is > 0 to indicate that we scrolled the display. */
4869 /************************************************************************
4871 ************************************************************************/
4873 /* Update the desired frame matrix of frame F.
4875 FORCE_P non-zero means that the update should not be stopped by
4876 pending input. INHIBIT_HAIRY_ID_P non-zero means that scrolling
4877 should not be tried.
4879 Value is non-zero if update was stopped due to pending input. */
4882 update_frame_1 (f
, force_p
, inhibit_id_p
)
4887 /* Frame matrices to work on. */
4888 struct glyph_matrix
*current_matrix
= f
->current_matrix
;
4889 struct glyph_matrix
*desired_matrix
= f
->desired_matrix
;
4892 int preempt_count
= baud_rate
/ 2400 + 1;
4893 extern int input_pending
;
4895 xassert (current_matrix
&& desired_matrix
);
4897 if (baud_rate
!= FRAME_COST_BAUD_RATE (f
))
4898 calculate_costs (f
);
4900 if (preempt_count
<= 0)
4903 #if !PERIODIC_PREEMPTION_CHECKING
4904 if (!force_p
&& detect_input_pending_ignore_squeezables ())
4911 /* If we cannot insert/delete lines, it's no use trying it. */
4912 if (!FRAME_LINE_INS_DEL_OK (f
))
4915 /* See if any of the desired lines are enabled; don't compute for
4916 i/d line if just want cursor motion. */
4917 for (i
= 0; i
< desired_matrix
->nrows
; i
++)
4918 if (MATRIX_ROW_ENABLED_P (desired_matrix
, i
))
4921 /* Try doing i/d line, if not yet inhibited. */
4922 if (!inhibit_id_p
&& i
< desired_matrix
->nrows
)
4923 force_p
|= scrolling (f
);
4925 /* Update the individual lines as needed. Do bottom line first. */
4926 if (MATRIX_ROW_ENABLED_P (desired_matrix
, desired_matrix
->nrows
- 1))
4927 update_frame_line (f
, desired_matrix
->nrows
- 1);
4929 /* Now update the rest of the lines. */
4930 for (i
= 0; i
< desired_matrix
->nrows
- 1 && (force_p
|| !input_pending
); i
++)
4932 if (MATRIX_ROW_ENABLED_P (desired_matrix
, i
))
4934 if (FRAME_TERMCAP_P (f
))
4936 /* Flush out every so many lines.
4937 Also flush out if likely to have more than 1k buffered
4938 otherwise. I'm told that some telnet connections get
4939 really screwed by more than 1k output at once. */
4940 FILE *display_output
= FRAME_TTY (f
)->output
;
4943 int outq
= PENDING_OUTPUT_COUNT (display_output
);
4945 || (outq
> 20 && ((i
- 1) % preempt_count
== 0)))
4947 fflush (display_output
);
4948 if (preempt_count
== 1)
4950 #ifdef EMACS_OUTQSIZE
4951 if (EMACS_OUTQSIZE (0, &outq
) < 0)
4952 /* Probably not a tty. Ignore the error and reset
4954 outq
= PENDING_OUTPUT_COUNT (FRAME_TTY (f
->output
));
4957 if (baud_rate
<= outq
&& baud_rate
> 0)
4958 sleep (outq
/ baud_rate
);
4964 #if PERIODIC_PREEMPTION_CHECKING
4968 EMACS_GET_TIME (tm
);
4969 EMACS_SUB_TIME (dif
, preemption_next_check
, tm
);
4970 if (EMACS_TIME_NEG_P (dif
))
4972 EMACS_ADD_TIME (preemption_next_check
, tm
, preemption_period
);
4973 if (detect_input_pending_ignore_squeezables ())
4978 if (!force_p
&& (i
- 1) % preempt_count
== 0)
4979 detect_input_pending_ignore_squeezables ();
4982 update_frame_line (f
, i
);
4986 pause
= (i
< FRAME_LINES (f
) - 1) ? i
: 0;
4988 /* Now just clean up termcap drivers and set cursor, etc. */
4991 if ((cursor_in_echo_area
4992 /* If we are showing a message instead of the mini-buffer,
4993 show the cursor for the message instead of for the
4994 (now hidden) mini-buffer contents. */
4995 || (EQ (minibuf_window
, selected_window
)
4996 && EQ (minibuf_window
, echo_area_window
)
4997 && !NILP (echo_area_buffer
[0])))
4998 /* These cases apply only to the frame that contains
4999 the active mini-buffer window. */
5000 && FRAME_HAS_MINIBUF_P (f
)
5001 && EQ (FRAME_MINIBUF_WINDOW (f
), echo_area_window
))
5003 int top
= WINDOW_TOP_EDGE_LINE (XWINDOW (FRAME_MINIBUF_WINDOW (f
)));
5006 if (cursor_in_echo_area
< 0)
5008 /* Negative value of cursor_in_echo_area means put
5009 cursor at beginning of line. */
5015 /* Positive value of cursor_in_echo_area means put
5016 cursor at the end of the prompt. If the mini-buffer
5017 is several lines high, find the last line that has
5019 row
= FRAME_LINES (f
);
5025 if (MATRIX_ROW_ENABLED_P (current_matrix
, row
))
5027 /* Frame rows are filled up with spaces that
5028 must be ignored here. */
5029 struct glyph_row
*r
= MATRIX_ROW (current_matrix
,
5031 struct glyph
*start
= r
->glyphs
[TEXT_AREA
];
5032 struct glyph
*last
= start
+ r
->used
[TEXT_AREA
];
5035 && (last
- 1)->charpos
< 0)
5041 while (row
> top
&& col
== 0);
5043 /* Make sure COL is not out of range. */
5044 if (col
>= FRAME_CURSOR_X_LIMIT (f
))
5046 /* If we have another row, advance cursor into it. */
5047 if (row
< FRAME_LINES (f
) - 1)
5049 col
= FRAME_LEFT_SCROLL_BAR_COLS (f
);
5052 /* Otherwise move it back in range. */
5054 col
= FRAME_CURSOR_X_LIMIT (f
) - 1;
5058 cursor_to (f
, row
, col
);
5062 /* We have only one cursor on terminal frames. Use it to
5063 display the cursor of the selected window. */
5064 struct window
*w
= XWINDOW (FRAME_SELECTED_WINDOW (f
));
5065 if (w
->cursor
.vpos
>= 0
5066 /* The cursor vpos may be temporarily out of bounds
5067 in the following situation: There is one window,
5068 with the cursor in the lower half of it. The window
5069 is split, and a message causes a redisplay before
5070 a new cursor position has been computed. */
5071 && w
->cursor
.vpos
< WINDOW_TOTAL_LINES (w
))
5073 int x
= WINDOW_TO_FRAME_HPOS (w
, w
->cursor
.hpos
);
5074 int y
= WINDOW_TO_FRAME_VPOS (w
, w
->cursor
.vpos
);
5076 if (INTEGERP (w
->left_margin_cols
))
5077 x
+= XFASTINT (w
->left_margin_cols
);
5079 /* x = max (min (x, FRAME_TOTAL_COLS (f) - 1), 0); */
5080 cursor_to (f
, y
, x
);
5087 clear_desired_matrices (f
);
5092 /* Do line insertions/deletions on frame F for frame-based redisplay. */
5096 struct frame
*frame
;
5098 int unchanged_at_top
, unchanged_at_bottom
;
5101 int *old_hash
= (int *) alloca (FRAME_LINES (frame
) * sizeof (int));
5102 int *new_hash
= (int *) alloca (FRAME_LINES (frame
) * sizeof (int));
5103 int *draw_cost
= (int *) alloca (FRAME_LINES (frame
) * sizeof (int));
5104 int *old_draw_cost
= (int *) alloca (FRAME_LINES (frame
) * sizeof (int));
5106 int free_at_end_vpos
= FRAME_LINES (frame
);
5107 struct glyph_matrix
*current_matrix
= frame
->current_matrix
;
5108 struct glyph_matrix
*desired_matrix
= frame
->desired_matrix
;
5110 if (!current_matrix
)
5113 /* Compute hash codes of all the lines. Also calculate number of
5114 changed lines, number of unchanged lines at the beginning, and
5115 number of unchanged lines at the end. */
5117 unchanged_at_top
= 0;
5118 unchanged_at_bottom
= FRAME_LINES (frame
);
5119 for (i
= 0; i
< FRAME_LINES (frame
); i
++)
5121 /* Give up on this scrolling if some old lines are not enabled. */
5122 if (!MATRIX_ROW_ENABLED_P (current_matrix
, i
))
5124 old_hash
[i
] = line_hash_code (MATRIX_ROW (current_matrix
, i
));
5125 if (! MATRIX_ROW_ENABLED_P (desired_matrix
, i
))
5127 /* This line cannot be redrawn, so don't let scrolling mess it. */
5128 new_hash
[i
] = old_hash
[i
];
5129 #define INFINITY 1000000 /* Taken from scroll.c */
5130 draw_cost
[i
] = INFINITY
;
5134 new_hash
[i
] = line_hash_code (MATRIX_ROW (desired_matrix
, i
));
5135 draw_cost
[i
] = line_draw_cost (desired_matrix
, i
);
5138 if (old_hash
[i
] != new_hash
[i
])
5141 unchanged_at_bottom
= FRAME_LINES (frame
) - i
- 1;
5143 else if (i
== unchanged_at_top
)
5145 old_draw_cost
[i
] = line_draw_cost (current_matrix
, i
);
5148 /* If changed lines are few, don't allow preemption, don't scroll. */
5149 if ((!FRAME_SCROLL_REGION_OK (frame
)
5150 && changed_lines
< baud_rate
/ 2400)
5151 || unchanged_at_bottom
== FRAME_LINES (frame
))
5154 window_size
= (FRAME_LINES (frame
) - unchanged_at_top
5155 - unchanged_at_bottom
);
5157 if (FRAME_SCROLL_REGION_OK (frame
))
5158 free_at_end_vpos
-= unchanged_at_bottom
;
5159 else if (FRAME_MEMORY_BELOW_FRAME (frame
))
5160 free_at_end_vpos
= -1;
5162 /* If large window, fast terminal and few lines in common between
5163 current frame and desired frame, don't bother with i/d calc. */
5164 if (!FRAME_SCROLL_REGION_OK (frame
)
5165 && window_size
>= 18 && baud_rate
> 2400
5167 10 * scrolling_max_lines_saved (unchanged_at_top
,
5168 FRAME_LINES (frame
) - unchanged_at_bottom
,
5169 old_hash
, new_hash
, draw_cost
)))
5172 if (window_size
< 2)
5175 scrolling_1 (frame
, window_size
, unchanged_at_top
, unchanged_at_bottom
,
5176 draw_cost
+ unchanged_at_top
- 1,
5177 old_draw_cost
+ unchanged_at_top
- 1,
5178 old_hash
+ unchanged_at_top
- 1,
5179 new_hash
+ unchanged_at_top
- 1,
5180 free_at_end_vpos
- unchanged_at_top
);
5186 /* Count the number of blanks at the start of the vector of glyphs R
5187 which is LEN glyphs long. */
5190 count_blanks (r
, len
)
5196 for (i
= 0; i
< len
; ++i
)
5197 if (!CHAR_GLYPH_SPACE_P (r
[i
]))
5204 /* Count the number of glyphs in common at the start of the glyph
5205 vectors STR1 and STR2. END1 is the end of STR1 and END2 is the end
5206 of STR2. Value is the number of equal glyphs equal at the start. */
5209 count_match (str1
, end1
, str2
, end2
)
5210 struct glyph
*str1
, *end1
, *str2
, *end2
;
5212 struct glyph
*p1
= str1
;
5213 struct glyph
*p2
= str2
;
5217 && GLYPH_CHAR_AND_FACE_EQUAL_P (p1
, p2
))
5224 /* Char insertion/deletion cost vector, from term.c */
5226 extern int *char_ins_del_vector
;
5227 #define char_ins_del_cost(f) (&char_ins_del_vector[FRAME_TOTAL_COLS((f))])
5230 /* Perform a frame-based update on line VPOS in frame FRAME. */
5233 update_frame_line (f
, vpos
)
5237 struct glyph
*obody
, *nbody
, *op1
, *op2
, *np1
, *nend
;
5239 int osp
, nsp
, begmatch
, endmatch
, olen
, nlen
;
5240 struct glyph_matrix
*current_matrix
= f
->current_matrix
;
5241 struct glyph_matrix
*desired_matrix
= f
->desired_matrix
;
5242 struct glyph_row
*current_row
= MATRIX_ROW (current_matrix
, vpos
);
5243 struct glyph_row
*desired_row
= MATRIX_ROW (desired_matrix
, vpos
);
5244 int must_write_whole_line_p
;
5245 int write_spaces_p
= FRAME_MUST_WRITE_SPACES (f
);
5246 int colored_spaces_p
= (FACE_FROM_ID (f
, DEFAULT_FACE_ID
)->background
5247 != FACE_TTY_DEFAULT_BG_COLOR
);
5249 if (colored_spaces_p
)
5252 /* Current row not enabled means it has unknown contents. We must
5253 write the whole desired line in that case. */
5254 must_write_whole_line_p
= !current_row
->enabled_p
;
5255 if (must_write_whole_line_p
)
5262 obody
= MATRIX_ROW_GLYPH_START (current_matrix
, vpos
);
5263 olen
= current_row
->used
[TEXT_AREA
];
5265 /* Ignore trailing spaces, if we can. */
5266 if (!write_spaces_p
)
5267 while (olen
> 0 && CHAR_GLYPH_SPACE_P (obody
[olen
-1]))
5271 current_row
->enabled_p
= 1;
5272 current_row
->used
[TEXT_AREA
] = desired_row
->used
[TEXT_AREA
];
5274 /* If desired line is empty, just clear the line. */
5275 if (!desired_row
->enabled_p
)
5281 nbody
= desired_row
->glyphs
[TEXT_AREA
];
5282 nlen
= desired_row
->used
[TEXT_AREA
];
5283 nend
= nbody
+ nlen
;
5285 /* If display line has unknown contents, write the whole line. */
5286 if (must_write_whole_line_p
)
5288 /* Ignore spaces at the end, if we can. */
5289 if (!write_spaces_p
)
5290 while (nlen
> 0 && CHAR_GLYPH_SPACE_P (nbody
[nlen
- 1]))
5293 /* Write the contents of the desired line. */
5296 cursor_to (f
, vpos
, 0);
5297 write_glyphs (f
, nbody
, nlen
);
5300 /* Don't call clear_end_of_line if we already wrote the whole
5301 line. The cursor will not be at the right margin in that
5302 case but in the line below. */
5303 if (nlen
< FRAME_TOTAL_COLS (f
))
5305 cursor_to (f
, vpos
, nlen
);
5306 clear_end_of_line (f
, FRAME_TOTAL_COLS (f
));
5309 /* Make sure we are in the right row, otherwise cursor movement
5310 with cmgoto might use `ch' in the wrong row. */
5311 cursor_to (f
, vpos
, 0);
5313 make_current (desired_matrix
, current_matrix
, vpos
);
5317 /* Pretend trailing spaces are not there at all,
5318 unless for one reason or another we must write all spaces. */
5319 if (!write_spaces_p
)
5320 while (nlen
> 0 && CHAR_GLYPH_SPACE_P (nbody
[nlen
- 1]))
5323 /* If there's no i/d char, quickly do the best we can without it. */
5324 if (!FRAME_CHAR_INS_DEL_OK (f
))
5328 /* Find the first glyph in desired row that doesn't agree with
5329 a glyph in the current row, and write the rest from there on. */
5330 for (i
= 0; i
< nlen
; i
++)
5332 if (i
>= olen
|| !GLYPH_EQUAL_P (nbody
+ i
, obody
+ i
))
5334 /* Find the end of the run of different glyphs. */
5338 || !GLYPH_EQUAL_P (nbody
+ j
, obody
+ j
)
5339 || CHAR_GLYPH_PADDING_P (nbody
[j
])))
5342 /* Output this run of non-matching chars. */
5343 cursor_to (f
, vpos
, i
);
5344 write_glyphs (f
, nbody
+ i
, j
- i
);
5347 /* Now find the next non-match. */
5351 /* Clear the rest of the line, or the non-clear part of it. */
5354 cursor_to (f
, vpos
, nlen
);
5355 clear_end_of_line (f
, olen
);
5358 /* Make current row = desired row. */
5359 make_current (desired_matrix
, current_matrix
, vpos
);
5363 /* Here when CHAR_INS_DEL_OK != 0, i.e. we can insert or delete
5364 characters in a row. */
5368 /* If current line is blank, skip over initial spaces, if
5369 possible, and write the rest. */
5373 nsp
= count_blanks (nbody
, nlen
);
5377 cursor_to (f
, vpos
, nsp
);
5378 write_glyphs (f
, nbody
+ nsp
, nlen
- nsp
);
5381 /* Exchange contents between current_frame and new_frame. */
5382 make_current (desired_matrix
, current_matrix
, vpos
);
5386 /* Compute number of leading blanks in old and new contents. */
5387 osp
= count_blanks (obody
, olen
);
5388 nsp
= (colored_spaces_p
? 0 : count_blanks (nbody
, nlen
));
5390 /* Compute number of matching chars starting with first non-blank. */
5391 begmatch
= count_match (obody
+ osp
, obody
+ olen
,
5392 nbody
+ nsp
, nbody
+ nlen
);
5394 /* Spaces in new match implicit space past the end of old. */
5395 /* A bug causing this to be a no-op was fixed in 18.29. */
5396 if (!write_spaces_p
&& osp
+ begmatch
== olen
)
5399 while (np1
+ begmatch
< nend
&& CHAR_GLYPH_SPACE_P (np1
[begmatch
]))
5403 /* Avoid doing insert/delete char
5404 just cause number of leading spaces differs
5405 when the following text does not match. */
5406 if (begmatch
== 0 && osp
!= nsp
)
5407 osp
= nsp
= min (osp
, nsp
);
5409 /* Find matching characters at end of line */
5412 op2
= op1
+ begmatch
- min (olen
- osp
, nlen
- nsp
);
5414 && GLYPH_EQUAL_P (op1
- 1, np1
- 1))
5419 endmatch
= obody
+ olen
- op1
;
5421 /* tem gets the distance to insert or delete.
5422 endmatch is how many characters we save by doing so.
5425 tem
= (nlen
- nsp
) - (olen
- osp
);
5427 && (!FRAME_CHAR_INS_DEL_OK (f
)
5428 || endmatch
<= char_ins_del_cost (f
)[tem
]))
5431 /* nsp - osp is the distance to insert or delete.
5432 If that is nonzero, begmatch is known to be nonzero also.
5433 begmatch + endmatch is how much we save by doing the ins/del.
5437 && (!FRAME_CHAR_INS_DEL_OK (f
)
5438 || begmatch
+ endmatch
<= char_ins_del_cost (f
)[nsp
- osp
]))
5442 osp
= nsp
= min (osp
, nsp
);
5445 /* Now go through the line, inserting, writing and
5446 deleting as appropriate. */
5450 cursor_to (f
, vpos
, nsp
);
5451 delete_glyphs (f
, osp
- nsp
);
5455 /* If going to delete chars later in line
5456 and insert earlier in the line,
5457 must delete first to avoid losing data in the insert */
5458 if (endmatch
&& nlen
< olen
+ nsp
- osp
)
5460 cursor_to (f
, vpos
, nlen
- endmatch
+ osp
- nsp
);
5461 delete_glyphs (f
, olen
+ nsp
- osp
- nlen
);
5462 olen
= nlen
- (nsp
- osp
);
5464 cursor_to (f
, vpos
, osp
);
5465 insert_glyphs (f
, 0, nsp
- osp
);
5469 tem
= nsp
+ begmatch
+ endmatch
;
5470 if (nlen
!= tem
|| olen
!= tem
)
5472 if (!endmatch
|| nlen
== olen
)
5474 /* If new text being written reaches right margin, there is
5475 no need to do clear-to-eol at the end of this function
5476 (and it would not be safe, since cursor is not going to
5477 be "at the margin" after the text is done). */
5478 if (nlen
== FRAME_TOTAL_COLS (f
))
5481 /* Function write_glyphs is prepared to do nothing
5482 if passed a length <= 0. Check it here to avoid
5483 unnecessary cursor movement. */
5486 cursor_to (f
, vpos
, nsp
+ begmatch
);
5487 write_glyphs (f
, nbody
+ nsp
+ begmatch
, nlen
- tem
);
5490 else if (nlen
> olen
)
5492 /* Here, we used to have the following simple code:
5493 ----------------------------------------
5494 write_glyphs (nbody + nsp + begmatch, olen - tem);
5495 insert_glyphs (nbody + nsp + begmatch + olen - tem, nlen - olen);
5496 ----------------------------------------
5497 but it doesn't work if nbody[nsp + begmatch + olen - tem]
5498 is a padding glyph. */
5499 int out
= olen
- tem
; /* Columns to be overwritten originally. */
5502 cursor_to (f
, vpos
, nsp
+ begmatch
);
5504 /* Calculate columns we can actually overwrite. */
5505 while (CHAR_GLYPH_PADDING_P (nbody
[nsp
+ begmatch
+ out
]))
5507 write_glyphs (f
, nbody
+ nsp
+ begmatch
, out
);
5509 /* If we left columns to be overwritten, we must delete them. */
5510 del
= olen
- tem
- out
;
5512 delete_glyphs (f
, del
);
5514 /* At last, we insert columns not yet written out. */
5515 insert_glyphs (f
, nbody
+ nsp
+ begmatch
+ out
, nlen
- olen
+ del
);
5518 else if (olen
> nlen
)
5520 cursor_to (f
, vpos
, nsp
+ begmatch
);
5521 write_glyphs (f
, nbody
+ nsp
+ begmatch
, nlen
- tem
);
5522 delete_glyphs (f
, olen
- nlen
);
5528 /* If any unerased characters remain after the new line, erase them. */
5531 cursor_to (f
, vpos
, nlen
);
5532 clear_end_of_line (f
, olen
);
5535 /* Exchange contents between current_frame and new_frame. */
5536 make_current (desired_matrix
, current_matrix
, vpos
);
5541 /***********************************************************************
5542 X/Y Position -> Buffer Position
5543 ***********************************************************************/
5545 /* Determine what's under window-relative pixel position (*X, *Y).
5546 Return the object (string or buffer) that's there.
5547 Return in *POS the position in that object.
5548 Adjust *X and *Y to character positions. */
5551 buffer_posn_from_coords (w
, x
, y
, pos
, object
, dx
, dy
, width
, height
)
5554 struct display_pos
*pos
;
5555 Lisp_Object
*object
;
5557 int *width
, *height
;
5560 Lisp_Object old_current_buffer
= Fcurrent_buffer ();
5561 struct text_pos startp
;
5563 struct glyph_row
*row
;
5564 #ifdef HAVE_WINDOW_SYSTEM
5565 struct image
*img
= 0;
5569 /* We used to set current_buffer directly here, but that does the
5570 wrong thing with `face-remapping-alist' (bug#2044). */
5571 Fset_buffer (w
->buffer
);
5572 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
5573 CHARPOS (startp
) = min (ZV
, max (BEGV
, CHARPOS (startp
)));
5574 BYTEPOS (startp
) = min (ZV_BYTE
, max (BEGV_BYTE
, BYTEPOS (startp
)));
5575 start_display (&it
, w
, startp
);
5577 x0
= *x
- WINDOW_LEFT_MARGIN_WIDTH (w
);
5578 move_it_to (&it
, -1, x0
+ it
.first_visible_x
, *y
, -1,
5579 MOVE_TO_X
| MOVE_TO_Y
);
5581 Fset_buffer (old_current_buffer
);
5583 *dx
= x0
+ it
.first_visible_x
- it
.current_x
;
5584 *dy
= *y
- it
.current_y
;
5587 if (STRINGP (it
.string
))
5591 #ifdef HAVE_WINDOW_SYSTEM
5592 if (it
.what
== IT_IMAGE
)
5594 if ((img
= IMAGE_FROM_ID (it
.f
, it
.image_id
)) != NULL
5595 && !NILP (img
->spec
))
5596 *object
= img
->spec
;
5600 if (it
.vpos
< w
->current_matrix
->nrows
5601 && (row
= MATRIX_ROW (w
->current_matrix
, it
.vpos
),
5604 if (it
.hpos
< row
->used
[TEXT_AREA
])
5606 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + it
.hpos
;
5607 #ifdef HAVE_WINDOW_SYSTEM
5610 *dy
-= row
->ascent
- glyph
->ascent
;
5611 *dx
+= glyph
->slice
.x
;
5612 *dy
+= glyph
->slice
.y
;
5613 /* Image slices positions are still relative to the entire image */
5614 *width
= img
->width
;
5615 *height
= img
->height
;
5620 *width
= glyph
->pixel_width
;
5621 *height
= glyph
->ascent
+ glyph
->descent
;
5627 *height
= row
->height
;
5632 *width
= *height
= 0;
5635 /* Add extra (default width) columns if clicked after EOL. */
5636 x1
= max(0, it
.current_x
+ it
.pixel_width
- it
.first_visible_x
);
5638 it
.hpos
+= (x0
- x1
) / WINDOW_FRAME_COLUMN_WIDTH (w
);
5647 /* Value is the string under window-relative coordinates X/Y in the
5648 mode line or header line (PART says which) of window W, or nil if none.
5649 *CHARPOS is set to the position in the string returned. */
5652 mode_line_string (w
, part
, x
, y
, charpos
, object
, dx
, dy
, width
, height
)
5654 enum window_part part
;
5657 Lisp_Object
*object
;
5659 int *width
, *height
;
5661 struct glyph_row
*row
;
5662 struct glyph
*glyph
, *end
;
5664 Lisp_Object string
= Qnil
;
5666 if (part
== ON_MODE_LINE
)
5667 row
= MATRIX_MODE_LINE_ROW (w
->current_matrix
);
5669 row
= MATRIX_HEADER_LINE_ROW (w
->current_matrix
);
5671 *y
= row
- MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
5673 if (row
->mode_line_p
&& row
->enabled_p
)
5675 /* Find the glyph under X. If we find one with a string object,
5676 it's the one we were looking for. */
5677 glyph
= row
->glyphs
[TEXT_AREA
];
5678 end
= glyph
+ row
->used
[TEXT_AREA
];
5679 for (x0
= *x
; glyph
< end
&& x0
>= glyph
->pixel_width
; ++glyph
)
5680 x0
-= glyph
->pixel_width
;
5681 *x
= glyph
- row
->glyphs
[TEXT_AREA
];
5684 string
= glyph
->object
;
5685 *charpos
= glyph
->charpos
;
5686 *width
= glyph
->pixel_width
;
5687 *height
= glyph
->ascent
+ glyph
->descent
;
5688 #ifdef HAVE_WINDOW_SYSTEM
5689 if (glyph
->type
== IMAGE_GLYPH
)
5692 img
= IMAGE_FROM_ID (WINDOW_XFRAME (w
), glyph
->u
.img_id
);
5694 *object
= img
->spec
;
5695 y0
-= row
->ascent
- glyph
->ascent
;
5701 /* Add extra (default width) columns if clicked after EOL. */
5702 *x
+= x0
/ WINDOW_FRAME_COLUMN_WIDTH (w
);
5704 *height
= row
->height
;
5711 *width
= *height
= 0;
5721 /* Value is the string under window-relative coordinates X/Y in either
5722 marginal area, or nil if none. *CHARPOS is set to the position in
5723 the string returned. */
5726 marginal_area_string (w
, part
, x
, y
, charpos
, object
, dx
, dy
, width
, height
)
5728 enum window_part part
;
5731 Lisp_Object
*object
;
5733 int *width
, *height
;
5735 struct glyph_row
*row
= w
->current_matrix
->rows
;
5736 struct glyph
*glyph
, *end
;
5737 int x0
, y0
, i
, wy
= *y
;
5739 Lisp_Object string
= Qnil
;
5741 if (part
== ON_LEFT_MARGIN
)
5742 area
= LEFT_MARGIN_AREA
;
5743 else if (part
== ON_RIGHT_MARGIN
)
5744 area
= RIGHT_MARGIN_AREA
;
5748 for (i
= 0; row
->enabled_p
&& i
< w
->current_matrix
->nrows
; ++i
, ++row
)
5749 if (wy
>= row
->y
&& wy
< MATRIX_ROW_BOTTOM_Y (row
))
5752 *y
= row
- MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
5756 /* Find the glyph under X. If we find one with a string object,
5757 it's the one we were looking for. */
5758 if (area
== RIGHT_MARGIN_AREA
)
5759 x0
= ((WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
5760 ? WINDOW_LEFT_FRINGE_WIDTH (w
)
5761 : WINDOW_TOTAL_FRINGE_WIDTH (w
))
5762 + window_box_width (w
, LEFT_MARGIN_AREA
)
5763 + window_box_width (w
, TEXT_AREA
));
5765 x0
= (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
5766 ? WINDOW_LEFT_FRINGE_WIDTH (w
)
5769 glyph
= row
->glyphs
[area
];
5770 end
= glyph
+ row
->used
[area
];
5771 for (x0
= *x
- x0
; glyph
< end
&& x0
>= glyph
->pixel_width
; ++glyph
)
5772 x0
-= glyph
->pixel_width
;
5773 *x
= glyph
- row
->glyphs
[area
];
5776 string
= glyph
->object
;
5777 *charpos
= glyph
->charpos
;
5778 *width
= glyph
->pixel_width
;
5779 *height
= glyph
->ascent
+ glyph
->descent
;
5780 #ifdef HAVE_WINDOW_SYSTEM
5781 if (glyph
->type
== IMAGE_GLYPH
)
5784 img
= IMAGE_FROM_ID (WINDOW_XFRAME (w
), glyph
->u
.img_id
);
5786 *object
= img
->spec
;
5787 y0
-= row
->ascent
- glyph
->ascent
;
5788 x0
+= glyph
->slice
.x
;
5789 y0
+= glyph
->slice
.y
;
5795 /* Add extra (default width) columns if clicked after EOL. */
5796 *x
+= x0
/ WINDOW_FRAME_COLUMN_WIDTH (w
);
5798 *height
= row
->height
;
5805 *width
= *height
= 0;
5815 /***********************************************************************
5816 Changing Frame Sizes
5817 ***********************************************************************/
5822 window_change_signal (signalnum
) /* If we don't have an argument, */
5823 int signalnum
; /* some compilers complain in signal calls. */
5826 int old_errno
= errno
;
5828 struct tty_display_info
*tty
;
5830 signal (SIGWINCH
, window_change_signal
);
5831 SIGNAL_THREAD_CHECK (signalnum
);
5833 /* The frame size change obviously applies to a single
5834 termcap-controlled terminal, but we can't decide which.
5835 Therefore, we resize the frames corresponding to each tty.
5837 for (tty
= tty_list
; tty
; tty
= tty
->next
) {
5839 if (! tty
->term_initted
)
5842 /* Suspended tty frames have tty->input == NULL avoid trying to
5847 get_tty_size (fileno (tty
->input
), &width
, &height
);
5849 if (width
> 5 && height
> 2) {
5850 Lisp_Object tail
, frame
;
5852 FOR_EACH_FRAME (tail
, frame
)
5853 if (FRAME_TERMCAP_P (XFRAME (frame
)) && FRAME_TTY (XFRAME (frame
)) == tty
)
5854 /* Record the new sizes, but don't reallocate the data
5855 structures now. Let that be done later outside of the
5857 change_frame_size (XFRAME (frame
), height
, width
, 0, 1, 0);
5863 #endif /* SIGWINCH */
5866 /* Do any change in frame size that was requested by a signal. SAFE
5867 non-zero means this function is called from a place where it is
5868 safe to change frame sizes while a redisplay is in progress. */
5871 do_pending_window_change (safe
)
5874 /* If window_change_signal should have run before, run it now. */
5875 if (redisplaying_p
&& !safe
)
5878 while (delayed_size_change
)
5880 Lisp_Object tail
, frame
;
5882 delayed_size_change
= 0;
5884 FOR_EACH_FRAME (tail
, frame
)
5886 struct frame
*f
= XFRAME (frame
);
5888 if (f
->new_text_lines
!= 0 || f
->new_text_cols
!= 0)
5889 change_frame_size (f
, f
->new_text_lines
, f
->new_text_cols
,
5896 /* Change the frame height and/or width. Values may be given as zero to
5897 indicate no change is to take place.
5899 If DELAY is non-zero, then assume we're being called from a signal
5900 handler, and queue the change for later - perhaps the next
5901 redisplay. Since this tries to resize windows, we can't call it
5902 from a signal handler.
5904 SAFE non-zero means this function is called from a place where it's
5905 safe to change frame sizes while a redisplay is in progress. */
5908 change_frame_size (f
, newheight
, newwidth
, pretend
, delay
, safe
)
5909 register struct frame
*f
;
5910 int newheight
, newwidth
, pretend
, delay
, safe
;
5912 Lisp_Object tail
, frame
;
5914 if (FRAME_MSDOS_P (f
))
5916 /* On MS-DOS, all frames use the same screen, so a change in
5917 size affects all frames. Termcap now supports multiple
5919 FOR_EACH_FRAME (tail
, frame
)
5920 if (! FRAME_WINDOW_P (XFRAME (frame
)))
5921 change_frame_size_1 (XFRAME (frame
), newheight
, newwidth
,
5922 pretend
, delay
, safe
);
5925 change_frame_size_1 (f
, newheight
, newwidth
, pretend
, delay
, safe
);
5929 change_frame_size_1 (f
, newheight
, newwidth
, pretend
, delay
, safe
)
5930 register struct frame
*f
;
5931 int newheight
, newwidth
, pretend
, delay
, safe
;
5933 int new_frame_total_cols
;
5934 int count
= SPECPDL_INDEX ();
5936 /* If we can't deal with the change now, queue it for later. */
5937 if (delay
|| (redisplaying_p
&& !safe
))
5939 f
->new_text_lines
= newheight
;
5940 f
->new_text_cols
= newwidth
;
5941 delayed_size_change
= 1;
5945 /* This size-change overrides any pending one for this frame. */
5946 f
->new_text_lines
= 0;
5947 f
->new_text_cols
= 0;
5949 /* If an argument is zero, set it to the current value. */
5951 newheight
= FRAME_LINES (f
);
5953 newwidth
= FRAME_COLS (f
);
5955 /* Compute width of windows in F.
5956 This is the width of the frame without vertical scroll bars. */
5957 new_frame_total_cols
= FRAME_TOTAL_COLS_ARG (f
, newwidth
);
5959 /* Round up to the smallest acceptable size. */
5960 check_frame_size (f
, &newheight
, &newwidth
);
5962 /* If we're not changing the frame size, quit now. */
5963 /* Frame width may be unchanged but the text portion may change, for example,
5964 fullscreen and remove/add scroll bar. */
5965 if (newheight
== FRAME_LINES (f
)
5966 && newwidth
== FRAME_COLS (f
) // text portion unchanged
5967 && new_frame_total_cols
== FRAME_TOTAL_COLS (f
)) // frame width unchanged
5973 /* We only can set screen dimensions to certain values supported
5974 by our video hardware. Try to find the smallest size greater
5975 or equal to the requested dimensions. */
5976 dos_set_window_size (&newheight
, &newwidth
);
5979 if (newheight
!= FRAME_LINES (f
))
5981 if (FRAME_HAS_MINIBUF_P (f
) && !FRAME_MINIBUF_ONLY_P (f
))
5983 /* Frame has both root and mini-buffer. */
5984 XSETFASTINT (XWINDOW (FRAME_ROOT_WINDOW (f
))->top_line
,
5985 FRAME_TOP_MARGIN (f
));
5986 set_window_height (FRAME_ROOT_WINDOW (f
),
5989 - FRAME_TOP_MARGIN (f
)),
5991 XSETFASTINT (XWINDOW (FRAME_MINIBUF_WINDOW (f
))->top_line
,
5993 set_window_height (FRAME_MINIBUF_WINDOW (f
), 1, 0);
5996 /* Frame has just one top-level window. */
5997 set_window_height (FRAME_ROOT_WINDOW (f
),
5998 newheight
- FRAME_TOP_MARGIN (f
), 2);
6000 /* MSDOS frames cannot PRETEND, as they change frame size by
6001 manipulating video hardware. */
6002 if ((FRAME_TERMCAP_P (f
) && !pretend
) || FRAME_MSDOS_P (f
))
6003 FrameRows (FRAME_TTY (f
)) = newheight
;
6006 if (new_frame_total_cols
!= FRAME_TOTAL_COLS (f
))
6008 set_window_width (FRAME_ROOT_WINDOW (f
), new_frame_total_cols
, 2);
6009 if (FRAME_HAS_MINIBUF_P (f
))
6010 set_window_width (FRAME_MINIBUF_WINDOW (f
), new_frame_total_cols
, 0);
6012 /* MSDOS frames cannot PRETEND, as they change frame size by
6013 manipulating video hardware. */
6014 if ((FRAME_TERMCAP_P (f
) && !pretend
) || FRAME_MSDOS_P (f
))
6015 FrameCols (FRAME_TTY (f
)) = newwidth
;
6017 if (WINDOWP (f
->tool_bar_window
))
6018 XSETFASTINT (XWINDOW (f
->tool_bar_window
)->total_cols
, newwidth
);
6021 FRAME_LINES (f
) = newheight
;
6022 SET_FRAME_COLS (f
, newwidth
);
6025 struct window
*w
= XWINDOW (FRAME_SELECTED_WINDOW (f
));
6026 int text_area_x
, text_area_y
, text_area_width
, text_area_height
;
6028 window_box (w
, TEXT_AREA
, &text_area_x
, &text_area_y
, &text_area_width
,
6030 if (w
->cursor
.x
>= text_area_x
+ text_area_width
)
6031 w
->cursor
.hpos
= w
->cursor
.x
= 0;
6032 if (w
->cursor
.y
>= text_area_y
+ text_area_height
)
6033 w
->cursor
.vpos
= w
->cursor
.y
= 0;
6037 calculate_costs (f
);
6038 SET_FRAME_GARBAGED (f
);
6043 record_unwind_protect (Fset_buffer
, Fcurrent_buffer ());
6045 run_window_configuration_change_hook (f
);
6047 unbind_to (count
, Qnil
);
6052 /***********************************************************************
6053 Terminal Related Lisp Functions
6054 ***********************************************************************/
6056 DEFUN ("open-termscript", Fopen_termscript
, Sopen_termscript
,
6057 1, 1, "FOpen termscript file: ",
6058 doc
: /* Start writing all terminal output to FILE as well as the terminal.
6059 FILE = nil means just close any termscript file currently open. */)
6063 struct tty_display_info
*tty
;
6065 if (! FRAME_TERMCAP_P (SELECTED_FRAME ())
6066 && ! FRAME_MSDOS_P (SELECTED_FRAME ()))
6067 error ("Current frame is not on a tty device");
6071 if (tty
->termscript
!= 0)
6074 fclose (tty
->termscript
);
6077 tty
->termscript
= 0;
6081 file
= Fexpand_file_name (file
, Qnil
);
6082 tty
->termscript
= fopen (SDATA (file
), "w");
6083 if (tty
->termscript
== 0)
6084 report_file_error ("Opening termscript", Fcons (file
, Qnil
));
6090 DEFUN ("send-string-to-terminal", Fsend_string_to_terminal
,
6091 Ssend_string_to_terminal
, 1, 2, 0,
6092 doc
: /* Send STRING to the terminal without alteration.
6093 Control characters in STRING will have terminal-dependent effects.
6095 Optional parameter TERMINAL specifies the tty terminal device to use.
6096 It may be a terminal object, a frame, or nil for the terminal used by
6097 the currently selected frame. In batch mode, STRING is sent to stdout
6098 when TERMINAL is nil. */)
6101 Lisp_Object terminal
;
6103 struct terminal
*t
= get_terminal (terminal
, 1);
6106 /* ??? Perhaps we should do something special for multibyte strings here. */
6107 CHECK_STRING (string
);
6111 error ("Unknown terminal device");
6113 if (t
->type
== output_initial
)
6115 else if (t
->type
!= output_termcap
&& t
->type
!= output_msdos_raw
)
6116 error ("Device %d is not a termcap terminal device", t
->id
);
6119 struct tty_display_info
*tty
= t
->display_info
.tty
;
6122 error ("Terminal is currently suspended");
6124 if (tty
->termscript
)
6126 fwrite (SDATA (string
), 1, SBYTES (string
), tty
->termscript
);
6127 fflush (tty
->termscript
);
6131 fwrite (SDATA (string
), 1, SBYTES (string
), out
);
6138 DEFUN ("ding", Fding
, Sding
, 0, 1, 0,
6139 doc
: /* Beep, or flash the screen.
6140 Also, unless an argument is given,
6141 terminate any keyboard macro currently executing. */)
6150 ring_bell (XFRAME (selected_frame
));
6163 else if (!INTERACTIVE
) /* Stop executing a keyboard macro. */
6164 error ("Keyboard macro terminated by a command ringing the bell");
6166 ring_bell (XFRAME (selected_frame
));
6171 /***********************************************************************
6173 ***********************************************************************/
6175 DEFUN ("sleep-for", Fsleep_for
, Ssleep_for
, 1, 2, 0,
6176 doc
: /* Pause, without updating display, for SECONDS seconds.
6177 SECONDS may be a floating-point value, meaning that you can wait for a
6178 fraction of a second. Optional second arg MILLISECONDS specifies an
6179 additional wait period, in milliseconds; this may be useful if your
6180 Emacs was built without floating point support.
6181 \(Not all operating systems support waiting for a fraction of a second.) */)
6182 (seconds
, milliseconds
)
6183 Lisp_Object seconds
, milliseconds
;
6187 if (NILP (milliseconds
))
6188 XSETINT (milliseconds
, 0);
6190 CHECK_NUMBER (milliseconds
);
6191 usec
= XINT (milliseconds
) * 1000;
6194 double duration
= extract_float (seconds
);
6195 sec
= (int) duration
;
6196 usec
+= (duration
- sec
) * 1000000;
6199 #ifndef EMACS_HAS_USECS
6200 if (sec
== 0 && usec
!= 0)
6201 error ("Millisecond `sleep-for' not supported on %s", SYSTEM_TYPE
);
6204 /* Assure that 0 <= usec < 1000000. */
6207 /* We can't rely on the rounding being correct if usec is negative. */
6208 if (-1000000 < usec
)
6209 sec
--, usec
+= 1000000;
6211 sec
-= -usec
/ 1000000, usec
= 1000000 - (-usec
% 1000000);
6214 sec
+= usec
/ 1000000, usec
%= 1000000;
6216 if (sec
< 0 || (sec
== 0 && usec
== 0))
6219 wait_reading_process_output (sec
, usec
, 0, 0, Qnil
, NULL
, 0);
6225 /* This is just like wait_reading_process_output, except that
6228 TIMEOUT is number of seconds to wait (float or integer),
6229 or t to wait forever.
6230 READING is 1 if reading input.
6231 If DO_DISPLAY is >0 display process output while waiting.
6232 If DO_DISPLAY is >1 perform an initial redisplay before waiting.
6236 sit_for (timeout
, reading
, do_display
)
6237 Lisp_Object timeout
;
6238 int reading
, do_display
;
6242 swallow_events (do_display
);
6244 if ((detect_input_pending_run_timers (do_display
))
6245 || !NILP (Vexecuting_kbd_macro
))
6248 if (do_display
>= 2)
6249 redisplay_preserve_echo_area (2);
6251 if (INTEGERP (timeout
))
6253 sec
= XINT (timeout
);
6256 else if (FLOATP (timeout
))
6258 double seconds
= XFLOAT_DATA (timeout
);
6259 sec
= (int) seconds
;
6260 usec
= (int) ((seconds
- sec
) * 1000000);
6262 else if (EQ (timeout
, Qt
))
6268 wrong_type_argument (Qnumberp
, timeout
);
6270 if (sec
== 0 && usec
== 0 && !EQ (timeout
, Qt
))
6277 wait_reading_process_output (sec
, usec
, reading
? -1 : 1, do_display
,
6280 return detect_input_pending () ? Qnil
: Qt
;
6284 DEFUN ("redisplay", Fredisplay
, Sredisplay
, 0, 1, 0,
6285 doc
: /* Perform redisplay if no input is available.
6286 If optional arg FORCE is non-nil or `redisplay-dont-pause' is non-nil,
6287 perform a full redisplay even if input is available.
6288 Return t if redisplay was performed, nil otherwise. */)
6295 if ((detect_input_pending_run_timers (1)
6296 && NILP (force
) && !redisplay_dont_pause
)
6297 || !NILP (Vexecuting_kbd_macro
))
6300 count
= SPECPDL_INDEX ();
6301 if (!NILP (force
) && !redisplay_dont_pause
)
6302 specbind (Qredisplay_dont_pause
, Qt
);
6303 redisplay_preserve_echo_area (2);
6304 unbind_to (count
, Qnil
);
6310 /***********************************************************************
6311 Other Lisp Functions
6312 ***********************************************************************/
6314 /* A vector of size >= 2 * NFRAMES + 3 * NBUFFERS + 1, containing the
6315 session's frames, frame names, buffers, buffer-read-only flags, and
6316 buffer-modified-flags. */
6318 static Lisp_Object frame_and_buffer_state
;
6321 DEFUN ("frame-or-buffer-changed-p", Fframe_or_buffer_changed_p
,
6322 Sframe_or_buffer_changed_p
, 0, 1, 0,
6323 doc
: /* Return non-nil if the frame and buffer state appears to have changed.
6324 VARIABLE is a variable name whose value is either nil or a state vector
6325 that will be updated to contain all frames and buffers,
6326 aside from buffers whose names start with space,
6327 along with the buffers' read-only and modified flags. This allows a fast
6328 check to see whether buffer menus might need to be recomputed.
6329 If this function returns non-nil, it updates the internal vector to reflect
6332 If VARIABLE is nil, an internal variable is used. Users should not
6333 pass nil for VARIABLE. */)
6335 Lisp_Object variable
;
6337 Lisp_Object state
, tail
, frame
, buf
;
6338 Lisp_Object
*vecp
, *end
;
6341 if (! NILP (variable
))
6343 CHECK_SYMBOL (variable
);
6344 state
= Fsymbol_value (variable
);
6345 if (! VECTORP (state
))
6349 state
= frame_and_buffer_state
;
6351 vecp
= XVECTOR (state
)->contents
;
6352 end
= vecp
+ XVECTOR (state
)->size
;
6354 FOR_EACH_FRAME (tail
, frame
)
6358 if (!EQ (*vecp
++, frame
))
6362 if (!EQ (*vecp
++, XFRAME (frame
)->name
))
6365 /* Check that the buffer info matches. */
6366 for (tail
= Vbuffer_alist
; CONSP (tail
); tail
= XCDR (tail
))
6368 buf
= XCDR (XCAR (tail
));
6369 /* Ignore buffers that aren't included in buffer lists. */
6370 if (SREF (XBUFFER (buf
)->name
, 0) == ' ')
6374 if (!EQ (*vecp
++, buf
))
6378 if (!EQ (*vecp
++, XBUFFER (buf
)->read_only
))
6382 if (!EQ (*vecp
++, Fbuffer_modified_p (buf
)))
6387 /* Detect deletion of a buffer at the end of the list. */
6388 if (EQ (*vecp
, Qlambda
))
6391 /* Come here if we decide the data has changed. */
6393 /* Count the size we will need.
6394 Start with 1 so there is room for at least one lambda at the end. */
6396 FOR_EACH_FRAME (tail
, frame
)
6398 for (tail
= Vbuffer_alist
; CONSP (tail
); tail
= XCDR (tail
))
6400 /* Reallocate the vector if data has grown to need it,
6401 or if it has shrunk a lot. */
6402 if (! VECTORP (state
)
6403 || n
> XVECTOR (state
)->size
6404 || n
+ 20 < XVECTOR (state
)->size
/ 2)
6405 /* Add 20 extra so we grow it less often. */
6407 state
= Fmake_vector (make_number (n
+ 20), Qlambda
);
6408 if (! NILP (variable
))
6409 Fset (variable
, state
);
6411 frame_and_buffer_state
= state
;
6414 /* Record the new data in the (possibly reallocated) vector. */
6415 vecp
= XVECTOR (state
)->contents
;
6416 FOR_EACH_FRAME (tail
, frame
)
6419 *vecp
++ = XFRAME (frame
)->name
;
6421 for (tail
= Vbuffer_alist
; CONSP (tail
); tail
= XCDR (tail
))
6423 buf
= XCDR (XCAR (tail
));
6424 /* Ignore buffers that aren't included in buffer lists. */
6425 if (SREF (XBUFFER (buf
)->name
, 0) == ' ')
6428 *vecp
++ = XBUFFER (buf
)->read_only
;
6429 *vecp
++ = Fbuffer_modified_p (buf
);
6431 /* Fill up the vector with lambdas (always at least one). */
6433 while (vecp
- XVECTOR (state
)->contents
6434 < XVECTOR (state
)->size
)
6436 /* Make sure we didn't overflow the vector. */
6437 if (vecp
- XVECTOR (state
)->contents
6438 > XVECTOR (state
)->size
)
6445 /***********************************************************************
6447 ***********************************************************************/
6449 /* Initialization done when Emacs fork is started, before doing stty.
6450 Determine terminal type and set terminal_driver. Then invoke its
6451 decoding routine to set up variables in the terminal package. */
6456 char *terminal_type
;
6458 #ifdef HAVE_X_WINDOWS
6459 extern int display_arg
;
6462 /* Construct the space glyph. */
6463 space_glyph
.type
= CHAR_GLYPH
;
6464 SET_CHAR_GLYPH (space_glyph
, ' ', DEFAULT_FACE_ID
, 0);
6465 space_glyph
.charpos
= -1;
6468 cursor_in_echo_area
= 0;
6469 terminal_type
= (char *) 0;
6471 /* Now is the time to initialize this; it's used by init_sys_modes
6473 Vinitial_window_system
= Qnil
;
6475 /* SIGWINCH needs to be handled no matter what display we start
6476 with. Otherwise newly opened tty frames will not resize
6481 #endif /* CANNOT_DUMP */
6482 signal (SIGWINCH
, window_change_signal
);
6483 #endif /* SIGWINCH */
6485 /* If running as a daemon, no need to initialize any frames/terminal. */
6489 /* If the user wants to use a window system, we shouldn't bother
6490 initializing the terminal. This is especially important when the
6491 terminal is so dumb that emacs gives up before and doesn't bother
6492 using the window system.
6494 If the DISPLAY environment variable is set and nonempty,
6495 try to use X, and die with an error message if that doesn't work. */
6497 #ifdef HAVE_X_WINDOWS
6498 if (! inhibit_window_system
&& ! display_arg
)
6501 display
= getenv ("DISPLAY");
6502 display_arg
= (display
!= 0 && *display
!= 0);
6504 if (display_arg
&& !x_display_ok (display
))
6506 fprintf (stderr
, "Display %s unavailable, simulating -nw\n",
6508 inhibit_window_system
= 1;
6512 if (!inhibit_window_system
&& display_arg
6518 Vinitial_window_system
= Qx
;
6520 Vwindow_system_version
= make_number (11);
6522 #if defined (GNU_LINUX) && defined (HAVE_LIBNCURSES)
6523 /* In some versions of ncurses,
6524 tputs crashes if we have not called tgetent.
6526 { char b
[2044]; tgetent (b
, "xterm");}
6528 adjust_frame_glyphs_initially ();
6531 #endif /* HAVE_X_WINDOWS */
6534 if (!inhibit_window_system
)
6536 Vinitial_window_system
= Qw32
;
6537 Vwindow_system_version
= make_number (1);
6538 adjust_frame_glyphs_initially ();
6541 #endif /* HAVE_NTGUI */
6544 if (!inhibit_window_system
6550 Vinitial_window_system
= Qns
;
6551 Vwindow_system_version
= make_number(10);
6552 adjust_frame_glyphs_initially ();
6557 /* If no window system has been specified, try to use the terminal. */
6560 fatal ("standard input is not a tty");
6565 terminal_type
= "w32console";
6567 /* Look at the TERM variable. */
6568 terminal_type
= (char *) getenv ("TERM");
6572 #ifdef HAVE_WINDOW_SYSTEM
6573 if (! inhibit_window_system
)
6574 fprintf (stderr
, "Please set the environment variable DISPLAY or TERM (see `tset').\n");
6576 #endif /* HAVE_WINDOW_SYSTEM */
6577 fprintf (stderr
, "Please set the environment variable TERM; see `tset'.\n");
6583 struct frame
*f
= XFRAME (selected_frame
);
6585 /* Open a display on the controlling tty. */
6586 t
= init_tty (0, terminal_type
, 1); /* Errors are fatal. */
6588 /* Convert the initial frame to use the new display. */
6589 if (f
->output_method
!= output_initial
)
6591 f
->output_method
= t
->type
;
6594 t
->reference_count
++;
6595 t
->display_info
.tty
->top_frame
= selected_frame
;
6596 change_frame_size (XFRAME (selected_frame
),
6597 FrameRows (t
->display_info
.tty
),
6598 FrameCols (t
->display_info
.tty
), 0, 0, 1);
6600 /* Delete the initial terminal. */
6601 if (--initial_terminal
->reference_count
== 0
6602 && initial_terminal
->delete_terminal_hook
)
6603 (*initial_terminal
->delete_terminal_hook
) (initial_terminal
);
6605 /* Update frame parameters to reflect the new type. */
6606 Fmodify_frame_parameters
6607 (selected_frame
, Fcons (Fcons (Qtty_type
,
6608 Ftty_type (selected_frame
)), Qnil
));
6609 if (t
->display_info
.tty
->name
)
6610 Fmodify_frame_parameters (selected_frame
,
6611 Fcons (Fcons (Qtty
, build_string (t
->display_info
.tty
->name
)),
6614 Fmodify_frame_parameters (selected_frame
, Fcons (Fcons (Qtty
, Qnil
),
6619 struct frame
*sf
= SELECTED_FRAME ();
6620 int width
= FRAME_TOTAL_COLS (sf
);
6621 int height
= FRAME_LINES (sf
);
6623 unsigned int total_glyphs
= height
* (width
+ 2) * sizeof (struct glyph
);
6625 /* If these sizes are so big they cause overflow, just ignore the
6626 change. It's not clear what better we could do. */
6627 if (total_glyphs
/ sizeof (struct glyph
) / height
!= width
+ 2)
6628 fatal ("screen size %dx%d too big", width
, height
);
6631 adjust_frame_glyphs_initially ();
6632 calculate_costs (XFRAME (selected_frame
));
6634 /* Set up faces of the initial terminal frame of a dumped Emacs. */
6637 && NILP (Vinitial_window_system
))
6639 /* For the initial frame, we don't have any way of knowing what
6640 are the foreground and background colors of the terminal. */
6641 struct frame
*sf
= SELECTED_FRAME();
6643 FRAME_FOREGROUND_PIXEL (sf
) = FACE_TTY_DEFAULT_FG_COLOR
;
6644 FRAME_BACKGROUND_PIXEL (sf
) = FACE_TTY_DEFAULT_BG_COLOR
;
6645 call0 (intern ("tty-set-up-initial-frame-faces"));
6651 /***********************************************************************
6653 ***********************************************************************/
6655 DEFUN ("internal-show-cursor", Finternal_show_cursor
,
6656 Sinternal_show_cursor
, 2, 2, 0,
6657 doc
: /* Set the cursor-visibility flag of WINDOW to SHOW.
6658 WINDOW nil means use the selected window. SHOW non-nil means
6659 show a cursor in WINDOW in the next redisplay. SHOW nil means
6660 don't show a cursor. */)
6662 Lisp_Object window
, show
;
6664 /* Don't change cursor state while redisplaying. This could confuse
6666 if (!redisplaying_p
)
6669 window
= selected_window
;
6671 CHECK_WINDOW (window
);
6673 XWINDOW (window
)->cursor_off_p
= NILP (show
);
6680 DEFUN ("internal-show-cursor-p", Finternal_show_cursor_p
,
6681 Sinternal_show_cursor_p
, 0, 1, 0,
6682 doc
: /* Value is non-nil if next redisplay will display a cursor in WINDOW.
6683 WINDOW nil or omitted means report on the selected window. */)
6690 window
= selected_window
;
6692 CHECK_WINDOW (window
);
6694 w
= XWINDOW (window
);
6695 return w
->cursor_off_p
? Qnil
: Qt
;
6698 DEFUN ("last-nonminibuffer-frame", Flast_nonminibuf_frame
,
6699 Slast_nonminibuf_frame
, 0, 0, 0,
6700 doc
: /* Value is last nonminibuffer frame. */)
6703 Lisp_Object frame
= Qnil
;
6705 if (last_nonminibuf_frame
)
6706 XSETFRAME (frame
, last_nonminibuf_frame
);
6711 /***********************************************************************
6713 ***********************************************************************/
6718 defsubr (&Sredraw_frame
);
6719 defsubr (&Sredraw_display
);
6720 defsubr (&Sframe_or_buffer_changed_p
);
6721 defsubr (&Sopen_termscript
);
6723 defsubr (&Sredisplay
);
6724 defsubr (&Ssleep_for
);
6725 defsubr (&Ssend_string_to_terminal
);
6726 defsubr (&Sinternal_show_cursor
);
6727 defsubr (&Sinternal_show_cursor_p
);
6728 defsubr (&Slast_nonminibuf_frame
);
6731 defsubr (&Sdump_redisplay_history
);
6734 frame_and_buffer_state
= Fmake_vector (make_number (20), Qlambda
);
6735 staticpro (&frame_and_buffer_state
);
6737 Qdisplay_table
= intern_c_string ("display-table");
6738 staticpro (&Qdisplay_table
);
6739 Qredisplay_dont_pause
= intern_c_string ("redisplay-dont-pause");
6740 staticpro (&Qredisplay_dont_pause
);
6742 DEFVAR_INT ("baud-rate", &baud_rate
,
6743 doc
: /* *The output baud rate of the terminal.
6744 On most systems, changing this value will affect the amount of padding
6745 and the other strategic decisions made during redisplay. */);
6747 DEFVAR_BOOL ("inverse-video", &inverse_video
,
6748 doc
: /* *Non-nil means invert the entire frame display.
6749 This means everything is in inverse video which otherwise would not be. */);
6751 DEFVAR_BOOL ("visible-bell", &visible_bell
,
6752 doc
: /* *Non-nil means try to flash the frame to represent a bell.
6754 See also `ring-bell-function'. */);
6756 DEFVAR_BOOL ("no-redraw-on-reenter", &no_redraw_on_reenter
,
6757 doc
: /* *Non-nil means no need to redraw entire frame after suspending.
6758 A non-nil value is useful if the terminal can automatically preserve
6759 Emacs's frame display when you reenter Emacs.
6760 It is up to you to set this variable if your terminal can do that. */);
6762 DEFVAR_LISP ("initial-window-system", &Vinitial_window_system
,
6763 doc
: /* Name of the window system that Emacs uses for the first frame.
6764 The value is a symbol--for instance, `x' for X windows.
6765 The value is nil if Emacs is using a text-only terminal. */);
6767 DEFVAR_KBOARD ("window-system", Vwindow_system
,
6768 doc
: /* Name of window system through which the selected frame is displayed.
6769 The value is a symbol--for instance, `x' for X windows.
6770 The value is nil if the selected frame is on a text-only-terminal. */);
6772 DEFVAR_LISP ("window-system-version", &Vwindow_system_version
,
6773 doc
: /* The version number of the window system in use.
6774 For X windows, this is 11. */);
6776 DEFVAR_BOOL ("cursor-in-echo-area", &cursor_in_echo_area
,
6777 doc
: /* Non-nil means put cursor in minibuffer, at end of any message there. */);
6779 DEFVAR_LISP ("glyph-table", &Vglyph_table
,
6780 doc
: /* Table defining how to output a glyph code to the frame.
6781 If not nil, this is a vector indexed by glyph code to define the glyph.
6782 Each element can be:
6783 integer: a glyph code which this glyph is an alias for.
6784 string: output this glyph using that string (not impl. in X windows).
6785 nil: this glyph mod 524288 is the code of a character to output,
6786 and this glyph / 524288 is the face number (see `face-id') to use
6787 while outputting it. */);
6788 Vglyph_table
= Qnil
;
6790 DEFVAR_LISP ("standard-display-table", &Vstandard_display_table
,
6791 doc
: /* Display table to use for buffers that specify none.
6792 See `buffer-display-table' for more information. */);
6793 Vstandard_display_table
= Qnil
;
6795 DEFVAR_BOOL ("redisplay-dont-pause", &redisplay_dont_pause
,
6796 doc
: /* *Non-nil means update isn't paused when input is detected. */);
6797 redisplay_dont_pause
= 0;
6799 #if PERIODIC_PREEMPTION_CHECKING
6800 DEFVAR_LISP ("redisplay-preemption-period", &Vredisplay_preemption_period
,
6801 doc
: /* *The period in seconds between checking for input during redisplay.
6802 If input is detected, redisplay is pre-empted, and the input is processed.
6803 If nil, never pre-empt redisplay. */);
6804 Vredisplay_preemption_period
= make_float (0.10);
6811 Vinitial_window_system
= Qnil
;
6812 Vwindow_system_version
= Qnil
;
6816 /* arch-tag: 8d812b1f-04a2-4195-a9c4-381f8457a413
6817 (do not change this comment) */