1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
20
21 #include <config.h>
22 #include <signal.h>
23 #include <stdio.h>
24 #include <ctype.h>
25 #include <setjmp.h>
26
27 #ifdef HAVE_UNISTD_H
28 #include <unistd.h>
29 #endif
30
31 #include "lisp.h"
32 #include "termchar.h"
33 #include "termopts.h"
34
35 #include "dispextern.h"
36 #include "cm.h"
37 #include "buffer.h"
38 #include "character.h"
39 #include "keyboard.h"
40 #include "frame.h"
41 #include "termhooks.h"
42 #include "window.h"
43 #include "commands.h"
44 #include "disptab.h"
45 #include "indent.h"
46 #include "intervals.h"
47 #include "blockinput.h"
48 #include "process.h"
49
50 51
52
53 #include "syssignal.h"
54
55 #ifdef HAVE_X_WINDOWS
56 #include "xterm.h"
57 #endif
58
59 #ifdef HAVE_NTGUI
60 #include "w32term.h"
61 #endif
62
63 #ifdef HAVE_NS
64 #include "nsterm.h"
65 #endif
66
67
68
69 #include "systime.h"
70 #include <errno.h>
71
72
73
74 #ifdef HAVE_UNISTD_H
75 #include <unistd.h>
76 #endif
77
78 79 80
81
82 #ifdef __GNU_LIBRARY__
83
84 85 86
87
88 #ifdef GNU_LIBRARY_PENDING_OUTPUT_COUNT
89 #define PENDING_OUTPUT_COUNT GNU_LIBRARY_PENDING_OUTPUT_COUNT
90 #else
91 #undef PENDING_OUTPUT_COUNT
92 #define PENDING_OUTPUT_COUNT(FILE) ((FILE)->__bufp - (FILE)->__buffer)
93 #endif
94 #else
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)
98 #endif
99 #ifndef PENDING_OUTPUT_COUNT
100 #define PENDING_OUTPUT_COUNT(FILE) ((FILE)->_ptr - (FILE)->_base)
101 #endif
102 #endif
103
104 #if defined(HAVE_TERM_H) && defined (GNU_LINUX) && defined (HAVE_LIBNCURSES)
105 #include <term.h>
106 #endif
107
108 109
110
111 struct dim
112 {
113 int width;
114 int height;
115 };
116
117
118
119
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 *));
142 #if GLYPH_DEBUG
143 static int glyph_row_slice_p P_ ((struct glyph_row *, struct glyph_row *));
144 #endif
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 *,
147 struct window *));
148 static void build_frame_matrix_from_leaf_window P_ ((struct glyph_matrix *,
149 struct window *));
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,
159 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 *,
167 int));
168 static void mirror_make_current P_ ((struct window *, int));
169 void check_window_matrix_pointers P_ ((struct window *));
170 #if GLYPH_DEBUG
171 static void check_matrix_pointers P_ ((struct glyph_matrix *,
172 struct glyph_matrix *));
173 #endif
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));
187
188
189 190 191
192
193 int redisplay_dont_pause;
194
195 196 197
198 #ifdef EMACS_HAS_USECS
199 #define PERIODIC_PREEMPTION_CHECKING 1
200 #else
201 #define PERIODIC_PREEMPTION_CHECKING 0
202 #endif
203
204 #if PERIODIC_PREEMPTION_CHECKING
205
206
207
208 Lisp_Object Vredisplay_preemption_period;
209
210
211
212 static EMACS_TIME preemption_period;
213 static EMACS_TIME preemption_next_check;
214
215 #endif
216
217 218
219
220 int frame_garbaged;
221
222
223
224 int display_completed;
225
226 227
228
229 int visible_bell;
230
231
232
233 int inverse_video;
234
235
236
237 EMACS_INT baud_rate;
238
239 240
241
242 Lisp_Object Vinitial_window_system;
243
244
245
246 Lisp_Object Vwindow_system_version;
247
248 249 250 251 252 253 254 255
256
257 Lisp_Object Vglyph_table;
258
259
260
261 Lisp_Object Vstandard_display_table;
262
263 264 265
266
267 int cursor_in_echo_area;
268
269 Lisp_Object Qdisplay_table, Qredisplay_dont_pause;
270
271
272 273
274
275 Lisp_Object selected_frame;
276
277 278 279 280
281
282 struct frame *last_nonminibuf_frame;
283
284
285
286 int delayed_size_change;
287
288
289
290 static int glyphs_initialized_initially_p;
291
292
293
294 struct window *updated_window;
295
296
297
298 struct glyph_row *updated_row;
299 int updated_area;
300
301
302
303 struct glyph space_glyph;
304
305 306
307
308 int glyph_matrix_count;
309 int glyph_pool_count;
310
311 312
313
314 static struct frame *frame_matrix_frame;
315
316 317 318 319 320 321 322
323
324 int fonts_changed_p;
325
326 327
328
329 #if GLYPH_DEBUG
330
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))
335
336 337
338
339 struct redisplay_history
340 {
341 char trace[512 + 100];
342 };
343
344
345
346 #define REDISPLAY_HISTORY_SIZE 30
347
348
349
350 static struct redisplay_history redisplay_history[REDISPLAY_HISTORY_SIZE];
351
352
353
354 static int history_idx;
355
356 357
358
359 static unsigned history_tick;
360
361 static void add_frame_display_history P_ ((struct frame *, int));
362 static void add_window_display_history P_ ((struct window *, char *, int));
363
364 365 366 367
368
369 static void
370 add_window_display_history (w, msg, paused_p)
371 struct window *w;
372 char *msg;
373 int paused_p;
374 {
375 char *buf;
376
377 if (history_idx >= REDISPLAY_HISTORY_SIZE)
378 history_idx = 0;
379 buf = redisplay_history[history_idx].trace;
380 ++history_idx;
381
382 sprintf (buf, "%d: window %p (`%s')%s\n",
383 history_tick++,
384 w,
385 ((BUFFERP (w->buffer)
386 && STRINGP (XBUFFER (w->buffer)->name))
387 ? (char *) SDATA (XBUFFER (w->buffer)->name)
388 : "???"),
389 paused_p ? " ***paused***" : "");
390 strcat (buf, msg);
391 }
392
393
394 395 396
397
398 static void
399 add_frame_display_history (f, paused_p)
400 struct frame *f;
401 int paused_p;
402 {
403 char *buf;
404
405 if (history_idx >= REDISPLAY_HISTORY_SIZE)
406 history_idx = 0;
407 buf = redisplay_history[history_idx].trace;
408 ++history_idx;
409
410 sprintf (buf, "%d: update frame %p%s",
411 history_tick++,
412 f, paused_p ? " ***paused***" : "");
413 }
414
415
416 DEFUN ("dump-redisplay-history", Fdump_redisplay_history,
417 Sdump_redisplay_history, 0, 0, "",
418 doc: )
419 ()
420 {
421 int i;
422
423 for (i = history_idx - 1; i != history_idx; --i)
424 {
425 if (i < 0)
426 i = REDISPLAY_HISTORY_SIZE - 1;
427 fprintf (stderr, "%s\n", redisplay_history[i].trace);
428 }
429
430 return Qnil;
431 }
432
433
434 #else
435
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))
438
439 #endif
440
441
442 443 444
445
446 void
447 safe_bcopy (from, to, size)
448 const char *from;
449 char *to;
450 int size;
451 {
452 if (size <= 0 || from == to)
453 return;
454
455 456 457
458 if (to < from || from + size <= to)
459 bcopy (from, to, size);
460
461
462 else
463 {
464 register const char *endf = from + size;
465 register char *endt = to + size;
466
467 468 469 470 471 472
473 if (to - from < 64)
474 {
475 do
476 *--endt = *--endf;
477 while (endf != from);
478 }
479 else
480 {
481 for (;;)
482 {
483 endt -= (to - from);
484 endf -= (to - from);
485
486 if (endt < to)
487 break;
488
489 bcopy (endf, endt, to - from);
490 }
491
492 493 494
495 bcopy (from, to, endt - from);
496 }
497 }
498 }
499
500
501
502 503 504
505
506 507 508 509 510
511
512 struct glyph_matrix *
513 new_glyph_matrix (pool)
514 struct glyph_pool *pool;
515 {
516 struct glyph_matrix *result;
517
518
519 result = (struct glyph_matrix *) xmalloc (sizeof *result);
520 bzero (result, sizeof *result);
521
522 523
524 ++glyph_matrix_count;
525
526
527 result->pool = pool;
528 return result;
529 }
530
531
532 533 534 535 536 537 538 539 540 541
542
543 static void
544 free_glyph_matrix (matrix)
545 struct glyph_matrix *matrix;
546 {
547 if (matrix)
548 {
549 int i;
550
551 552
553 if (--glyph_matrix_count < 0)
554 abort ();
555
556
557 if (matrix->pool == NULL)
558 for (i = 0; i < matrix->rows_allocated; ++i)
559 xfree (matrix->rows[i].glyphs[LEFT_MARGIN_AREA]);
560
561
562 xfree (matrix->rows);
563 xfree (matrix);
564 }
565 }
566
567
568 569 570 571 572
573
574 static int
575 margin_glyphs_to_reserve (w, total_glyphs, margin)
576 struct window *w;
577 int total_glyphs;
578 Lisp_Object margin;
579 {
580 int n;
581
582 if (NUMBERP (margin))
583 {
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);
588 }
589 else
590 n = 0;
591
592 return n;
593 }
594
595
596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616
617
618 static void
619 adjust_glyph_matrix (w, matrix, x, y, dim)
620 struct window *w;
621 struct glyph_matrix *matrix;
622 int x, y;
623 struct dim dim;
624 {
625 int i;
626 int new_rows;
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;
632
633 634
635 if (w)
636 {
637 window_box (w, -1, 0, 0, &window_width, &window_height);
638
639 header_line_p = WINDOW_WANTS_HEADER_LINE_P (w);
640 header_line_changed_p = header_line_p != matrix->header_line_p;
641 }
642 matrix->header_line_p = header_line_p;
643
644 645 646 647
648 if (matrix->pool == NULL)
649 {
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);
655
656 if (!marginal_areas_changed_p
657 && !fonts_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)
664 return;
665 }
666
667
668 if (matrix->rows_allocated < dim.height)
669 {
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;
676 }
677 else
678 new_rows = 0;
679
680 681 682
683 if (matrix->pool)
684 {
685 xassert (matrix->pool->glyphs);
686
687 if (w)
688 {
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);
693 }
694 else
695 left = right = 0;
696
697 for (i = 0; i < dim.height; ++i)
698 {
699 struct glyph_row *row = &matrix->rows[i];
700
701 row->glyphs[LEFT_MARGIN_AREA]
702 = (matrix->pool->glyphs
703 + (y + i) * matrix->pool->ncolumns
704 + x);
705
706 if (w == NULL
707 || row == matrix->rows + dim.height - 1
708 || (row == matrix->rows && matrix->header_line_p))
709 {
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];
716 }
717 else
718 {
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;
725 }
726 }
727
728 matrix->left_margin_glyphs = left;
729 matrix->right_margin_glyphs = right;
730 }
731 else
732 {
733 734 735
736 if (dim.width > matrix->matrix_w
737 || new_rows
738 || header_line_changed_p
739 || marginal_areas_changed_p)
740 {
741 struct glyph_row *row = matrix->rows;
742 struct glyph_row *end = row + matrix->rows_allocated;
743
744 while (row < end)
745 {
746 row->glyphs[LEFT_MARGIN_AREA]
747 = (struct glyph *) xrealloc (row->glyphs[LEFT_MARGIN_AREA],
748 (dim.width
749 * sizeof (struct glyph)));
750
751
752 if (row == matrix->rows + dim.height - 1
753 || (row == matrix->rows && matrix->header_line_p))
754 {
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];
761 }
762 else
763 {
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;
770 }
771 ++row;
772 }
773 }
774
775 xassert (left >= 0 && right >= 0);
776 matrix->left_margin_glyphs = left;
777 matrix->right_margin_glyphs = right;
778 }
779
780
781 matrix->nrows = dim.height;
782 xassert (matrix->nrows >= 0);
783
784 if (w)
785 {
786 if (matrix == w->current_matrix)
787 {
788 789 790 791
792 if (window_width < 0)
793 window_width = window_box_width (w, -1);
794
795 796 797
798 if (!marginal_areas_changed_p
799 && !header_line_changed_p
800 && new_rows == 0
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)
805 {
806
807 for (i = 0; i < matrix->nrows && matrix->rows[i].enabled_p; ++i)
808 if (MATRIX_ROW_BOTTOM_Y (matrix->rows + i) >= window_height)
809 {
810 ++i;
811 break;
812 }
813
814 815
816 if (INTEGERP (w->window_end_vpos)
817 && XFASTINT (w->window_end_vpos) >= i)
818 w->window_end_valid = Qnil;
819
820 while (i < matrix->nrows)
821 matrix->rows[i++].enabled_p = 0;
822 }
823 else
824 {
825 for (i = 0; i < matrix->nrows; ++i)
826 matrix->rows[i].enabled_p = 0;
827 }
828 }
829 else if (matrix == w->desired_matrix)
830 {
831 832 833 834
835 for (i = 0; i < matrix->nrows; ++i)
836 matrix->rows[i].enabled_p = 0;
837 }
838 }
839
840
841
842 matrix->matrix_x = x;
843 matrix->matrix_y = y;
844 matrix->matrix_w = dim.width;
845 matrix->matrix_h = dim.height;
846
847 848
849 if (w)
850 {
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;
856 }
857 }
858
859
860 861 862 863
864
865 static void
866 reverse_rows (matrix, start, end)
867 struct glyph_matrix *matrix;
868 int start, end;
869 {
870 int i, j;
871
872 for (i = start, j = end - 1; i < j; ++i, --j)
873 {
874 875
876 struct glyph_row temp;
877 temp = matrix->rows[i];
878 matrix->rows[i] = matrix->rows[j];
879 matrix->rows[j] = temp;
880 }
881 }
882
883
884 885 886 887 888 889 890 891 892 893 894
895
896 void
897 rotate_matrix (matrix, first, last, by)
898 struct glyph_matrix *matrix;
899 int first, last, by;
900 {
901 if (by < 0)
902 {
903
904 by = -by;
905 reverse_rows (matrix, first, first + by);
906 reverse_rows (matrix, first + by, last);
907 reverse_rows (matrix, first, last);
908 }
909 else if (by > 0)
910 {
911
912 reverse_rows (matrix, last - by, last);
913 reverse_rows (matrix, first, last - by);
914 reverse_rows (matrix, first, last);
915 }
916 }
917
918
919 920 921
922
923 void
924 increment_matrix_positions (matrix, start, end, delta, delta_bytes)
925 struct glyph_matrix *matrix;
926 int start, end, delta, delta_bytes;
927 {
928
929 xassert (start >= 0 && start <= matrix->nrows);
930 xassert (end >= 0 && end <= matrix->nrows);
931 xassert (start <= end);
932
933 for (; start < end; ++start)
934 increment_row_positions (matrix->rows + start, delta, delta_bytes);
935 }
936
937
938 939 940
941
942 void
943 enable_glyph_matrix_rows (matrix, start, end, enabled_p)
944 struct glyph_matrix *matrix;
945 int start, end;
946 int enabled_p;
947 {
948 xassert (start <= end);
949 xassert (start >= 0 && start < matrix->nrows);
950 xassert (end >= 0 && end <= matrix->nrows);
951
952 for (; start < end; ++start)
953 matrix->rows[start].enabled_p = enabled_p != 0;
954 }
955
956
957 958 959 960 961 962 963 964 965
966
967 void
968 clear_glyph_matrix (matrix)
969 struct glyph_matrix *matrix;
970 {
971 if (matrix)
972 {
973 enable_glyph_matrix_rows (matrix, 0, matrix->nrows, 0);
974 matrix->no_scrolling_p = 0;
975 }
976 }
977
978
979 980 981
982
983 void
984 shift_glyph_matrix (w, matrix, start, end, dy)
985 struct window *w;
986 struct glyph_matrix *matrix;
987 int start, end, dy;
988 {
989 int min_y, max_y;
990
991 xassert (start <= end);
992 xassert (start >= 0 && start < matrix->nrows);
993 xassert (end >= 0 && end <= matrix->nrows);
994
995 min_y = WINDOW_HEADER_LINE_HEIGHT (w);
996 max_y = WINDOW_BOX_HEIGHT_NO_MODE_LINE (w);
997
998 for (; start < end; ++start)
999 {
1000 struct glyph_row *row = &matrix->rows[start];
1001
1002 row->y += dy;
1003 row->visible_height = row->height;
1004
1005 if (row->y < min_y)
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;
1009 }
1010 }
1011
1012
1013 1014 1015
1016
1017 void
1018 clear_current_matrices (f)
1019 register struct frame *f;
1020 {
1021
1022 if (f->current_matrix)
1023 clear_glyph_matrix (f->current_matrix);
1024
1025 1026 1027
1028 if (WINDOWP (f->menu_bar_window))
1029 clear_glyph_matrix (XWINDOW (f->menu_bar_window)->current_matrix);
1030
1031
1032 if (WINDOWP (f->tool_bar_window))
1033 clear_glyph_matrix (XWINDOW (f->tool_bar_window)->current_matrix);
1034
1035
1036 xassert (WINDOWP (FRAME_ROOT_WINDOW (f)));
1037 clear_window_matrices (XWINDOW (FRAME_ROOT_WINDOW (f)), 0);
1038 }
1039
1040
1041
1042
1043 void
1044 clear_desired_matrices (f)
1045 register struct frame *f;
1046 {
1047 if (f->desired_matrix)
1048 clear_glyph_matrix (f->desired_matrix);
1049
1050 if (WINDOWP (f->menu_bar_window))
1051 clear_glyph_matrix (XWINDOW (f->menu_bar_window)->desired_matrix);
1052
1053 if (WINDOWP (f->tool_bar_window))
1054 clear_glyph_matrix (XWINDOW (f->tool_bar_window)->desired_matrix);
1055
1056
1057 xassert (WINDOWP (FRAME_ROOT_WINDOW (f)));
1058 clear_window_matrices (XWINDOW (FRAME_ROOT_WINDOW (f)), 1);
1059 }
1060
1061
1062 1063
1064
1065 static void
1066 clear_window_matrices (w, desired_p)
1067 struct window *w;
1068 int desired_p;
1069 {
1070 while (w)
1071 {
1072 if (!NILP (w->hchild))
1073 {
1074 xassert (WINDOWP (w->hchild));
1075 clear_window_matrices (XWINDOW (w->hchild), desired_p);
1076 }
1077 else if (!NILP (w->vchild))
1078 {
1079 xassert (WINDOWP (w->vchild));
1080 clear_window_matrices (XWINDOW (w->vchild), desired_p);
1081 }
1082 else
1083 {
1084 if (desired_p)
1085 clear_glyph_matrix (w->desired_matrix);
1086 else
1087 {
1088 clear_glyph_matrix (w->current_matrix);
1089 w->window_end_valid = Qnil;
1090 }
1091 }
1092
1093 w = NILP (w->next) ? 0 : XWINDOW (w->next);
1094 }
1095 }
1096
1097
1098
1099 1100 1101 1102 1103
1104
1105 1106 1107
1108
1109 static struct glyph_row null_row;
1110
1111 void
1112 clear_glyph_row (row)
1113 struct glyph_row *row;
1114 {
1115 struct glyph *p[1 + LAST_AREA];
1116
1117
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];
1122
1123
1124 *row = null_row;
1125
1126
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];
1131
1132 #if 0 1133 1134 1135 1136 1137 1138
1139 bzero (p[0], (char *) p[LAST_AREA] - (char *) p[0]);
1140 #endif
1141 }
1142
1143
1144 1145
1146
1147 void
1148 blank_row (w, row, y)
1149 struct window *w;
1150 struct glyph_row *row;
1151 int y;
1152 {
1153 int min_y, max_y;
1154
1155 min_y = WINDOW_HEADER_LINE_HEIGHT (w);
1156 max_y = WINDOW_BOX_HEIGHT_NO_MODE_LINE (w);
1157
1158 clear_glyph_row (row);
1159 row->y = y;
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;
1163
1164 if (row->y < min_y)
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;
1168
1169 row->enabled_p = 1;
1170 }
1171
1172
1173 1174 1175 1176 1177
1178
1179 void
1180 increment_row_positions (row, delta, delta_bytes)
1181 struct glyph_row *row;
1182 int delta, delta_bytes;
1183 {
1184 int area, i;
1185
1186
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;
1195
1196 if (!row->enabled_p)
1197 return;
1198
1199
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;
1205
1206
1207 if (row->used[TEXT_AREA] == 0
1208 && MATRIX_ROW_DISPLAYS_TEXT_P (row))
1209 row->glyphs[TEXT_AREA]->charpos += delta;
1210 }
1211
1212
1213 #if 0
1214 1215 1216
1217
1218 static void
1219 swap_glyphs_in_rows (a, b)
1220 struct glyph_row *a, *b;
1221 {
1222 int area;
1223
1224 for (area = 0; area < LAST_AREA; ++area)
1225 {
1226
1227 int max_used = max (a->used[area], b->used[area]);
1228
1229
1230 struct glyph *glyph_a = a->glyphs[area];
1231
1232
1233 struct glyph *glyph_a_end = a->glyphs[max_used];
1234
1235
1236 struct glyph *glyph_b = b->glyphs[area];
1237
1238 while (glyph_a < glyph_a_end)
1239 {
1240 1241
1242 struct glyph temp;
1243 temp = *glyph_a;
1244 *glyph_a = *glyph_b;
1245 *glyph_b = temp;
1246 ++glyph_a;
1247 ++glyph_b;
1248 }
1249 }
1250 }
1251
1252 #endif
1253
1254
1255
1256 static INLINE void
1257 swap_glyph_pointers (a, b)
1258 struct glyph_row *a, *b;
1259 {
1260 int i;
1261 for (i = 0; i < LAST_AREA + 1; ++i)
1262 {
1263 struct glyph *temp = a->glyphs[i];
1264 a->glyphs[i] = b->glyphs[i];
1265 b->glyphs[i] = temp;
1266 }
1267 }
1268
1269
1270 1271
1272
1273 INLINE void
1274 copy_row_except_pointers (to, from)
1275 struct glyph_row *to, *from;
1276 {
1277 struct glyph *pointers[1 + LAST_AREA];
1278
1279
1280 bcopy (to->glyphs, pointers, sizeof to->glyphs);
1281
1282
1283 *to = *from;
1284
1285
1286 bcopy (pointers, to->glyphs, sizeof to->glyphs);
1287 }
1288
1289
1290 1291 1292 1293
1294
1295 void
1296 copy_glyph_row_contents (to, from, delta, delta_bytes)
1297 struct glyph_row *to, *from;
1298 int delta, delta_bytes;
1299 {
1300 int area;
1301
1302 1303
1304 copy_row_except_pointers (to, from);
1305
1306
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));
1311
1312
1313 increment_row_positions (to, delta, delta_bytes);
1314 }
1315
1316
1317 1318 1319 1320
1321
1322 static INLINE void
1323 assign_row (to, from)
1324 struct glyph_row *to, *from;
1325 {
1326 swap_glyph_pointers (to, from);
1327 copy_row_except_pointers (to, from);
1328 }
1329
1330
1331 1332 1333 1334 1335
1336
1337 #if GLYPH_DEBUG
1338
1339 static int
1340 glyph_row_slice_p (window_row, frame_row)
1341 struct glyph_row *window_row, *frame_row;
1342 {
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];
1346
1347 return (frame_glyph_start <= window_glyph_start
1348 && window_glyph_start < frame_glyph_end);
1349 }
1350
1351 #endif
1352
1353 #if 0
1354
1355 1356 1357
1358
1359 static struct glyph_row *
1360 find_glyph_row_slice (window_matrix, frame_matrix, row)
1361 struct glyph_matrix *window_matrix, *frame_matrix;
1362 int row;
1363 {
1364 int i;
1365
1366 xassert (row >= 0 && row < frame_matrix->nrows);
1367
1368 for (i = 0; i < window_matrix->nrows; ++i)
1369 if (glyph_row_slice_p (window_matrix->rows + i,
1370 frame_matrix->rows + row))
1371 break;
1372
1373 return i < window_matrix->nrows ? window_matrix->rows + i : 0;
1374 }
1375
1376 #endif
1377
1378 1379 1380 1381
1382
1383 void
1384 prepare_desired_row (row)
1385 struct glyph_row *row;
1386 {
1387 if (!row->enabled_p)
1388 {
1389 unsigned rp = row->reversed_p;
1390
1391 clear_glyph_row (row);
1392 row->enabled_p = 1;
1393 row->reversed_p = rp;
1394 }
1395 }
1396
1397
1398
1399
1400 int
1401 line_hash_code (row)
1402 struct glyph_row *row;
1403 {
1404 int hash = 0;
1405
1406 if (row->enabled_p)
1407 {
1408 struct glyph *glyph = row->glyphs[TEXT_AREA];
1409 struct glyph *end = glyph + row->used[TEXT_AREA];
1410
1411 while (glyph < end)
1412 {
1413 int c = glyph->u.ch;
1414 int face_id = glyph->face_id;
1415 if (FRAME_MUST_WRITE_SPACES (SELECTED_FRAME ()))
1416 c -= SPACEGLYPH;
1417 hash = (((hash << 4) + (hash >> 24)) & 0x0fffffff) + c;
1418 hash = (((hash << 4) + (hash >> 24)) & 0x0fffffff) + face_id;
1419 ++glyph;
1420 }
1421
1422 if (hash == 0)
1423 hash = 1;
1424 }
1425
1426 return hash;
1427 }
1428
1429
1430 1431 1432
1433
1434 static unsigned int
1435 line_draw_cost (matrix, vpos)
1436 struct glyph_matrix *matrix;
1437 int vpos;
1438 {
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];
1442 int len;
1443 Lisp_Object *glyph_table_base = GLYPH_TABLE_BASE;
1444 int glyph_table_len = GLYPH_TABLE_LENGTH;
1445
1446
1447 if (!FRAME_MUST_WRITE_SPACES (SELECTED_FRAME ()))
1448 {
1449
1450 while (end > beg && CHAR_GLYPH_SPACE_P (*(end - 1)))
1451 --end;
1452
1453
1454 if (end == beg)
1455 return 0;
1456
1457
1458 while (CHAR_GLYPH_SPACE_P (*beg))
1459 ++beg;
1460 }
1461
1462 1463
1464 if (glyph_table_base == 0)
1465 len = end - beg;
1466 else
1467 {
1468 1469
1470 len = 0;
1471 while (beg < end)
1472 {
1473 GLYPH g;
1474
1475 SET_GLYPH_FROM_CHAR_GLYPH (g, *beg);
1476
1477 if (GLYPH_INVALID_P (g)
1478 || GLYPH_SIMPLE_P (glyph_table_base, glyph_table_len, g))
1479 len += 1;
1480 else
1481 len += GLYPH_LENGTH (glyph_table_base, g);
1482
1483 ++beg;
1484 }
1485 }
1486
1487 return len;
1488 }
1489
1490
1491 1492 1493 1494 1495
1496
1497 static INLINE int
1498 row_equal_p (w, a, b, mouse_face_p)
1499 struct window *w;
1500 struct glyph_row *a, *b;
1501 int mouse_face_p;
1502 {
1503 if (a == b)
1504 return 1;
1505 else if (a->hash != b->hash)
1506 return 0;
1507 else
1508 {
1509 struct glyph *a_glyph, *b_glyph, *a_end;
1510 int area;
1511
1512 if (mouse_face_p && a->mouse_face_p != b->mouse_face_p)
1513 return 0;
1514
1515
1516 for (area = LEFT_MARGIN_AREA; area < LAST_AREA; ++area)
1517 {
1518 if (a->used[area] != b->used[area])
1519 return 0;
1520
1521 a_glyph = a->glyphs[area];
1522 a_end = a_glyph + a->used[area];
1523 b_glyph = b->glyphs[area];
1524
1525 while (a_glyph < a_end
1526 && GLYPH_EQUAL_P (a_glyph, b_glyph))
1527 ++a_glyph, ++b_glyph;
1528
1529 if (a_glyph != a_end)
1530 return 0;
1531 }
1532
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
1546 || a->x != b->x
1547
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)
1552 return 0;
1553 }
1554
1555 return 1;
1556 }
1557
1558
1559
1560 1561 1562 1563 1564
1565
1566 1567 1568
1569
1570 static struct glyph_pool *
1571 new_glyph_pool ()
1572 {
1573 struct glyph_pool *result;
1574
1575
1576 result = (struct glyph_pool *) xmalloc (sizeof *result);
1577 bzero (result, sizeof *result);
1578
1579
1580 ++glyph_pool_count;
1581
1582 return result;
1583 }
1584
1585
1586 1587 1588 1589 1590 1591
1592
1593 static void
1594 free_glyph_pool (pool)
1595 struct glyph_pool *pool;
1596 {
1597 if (pool)
1598 {
1599
1600 --glyph_pool_count;
1601 xassert (glyph_pool_count >= 0);
1602
1603 xfree (pool->glyphs);
1604 xfree (pool);
1605 }
1606 }
1607
1608
1609 1610 1611 1612 1613 1614 1615 1616
1617
1618 static int
1619 realloc_glyph_pool (pool, matrix_dim)
1620 struct glyph_pool *pool;
1621 struct dim matrix_dim;
1622 {
1623 int needed;
1624 int changed_p;
1625
1626 changed_p = (pool->glyphs == 0
1627 || matrix_dim.height != pool->nrows
1628 || matrix_dim.width != pool->ncolumns);
1629
1630
1631 needed = matrix_dim.width * matrix_dim.height;
1632 if (needed > pool->nglyphs)
1633 {
1634 int size = needed * sizeof (struct glyph);
1635
1636 if (pool->glyphs)
1637 pool->glyphs = (struct glyph *) xrealloc (pool->glyphs, size);
1638 else
1639 {
1640 pool->glyphs = (struct glyph *) xmalloc (size);
1641 bzero (pool->glyphs, size);
1642 }
1643
1644 pool->nglyphs = needed;
1645 }
1646
1647 1648 1649 1650
1651 pool->nrows = matrix_dim.height;
1652 pool->ncolumns = matrix_dim.width;
1653
1654 return changed_p;
1655 }
1656
1657
1658
1659 1660 1661
1662
1663 #if GLYPH_DEBUG
1664
1665
1666 1667 1668 1669
1670
1671 void
1672 flush_stdout ()
1673 {
1674 fflush (stdout);
1675 }
1676
1677
1678 1679 1680 1681
1682
1683 void
1684 check_matrix_pointer_lossage (matrix)
1685 struct glyph_matrix *matrix;
1686 {
1687 int i, j;
1688
1689 for (i = 0; i < matrix->nrows; ++i)
1690 for (j = 0; j < matrix->nrows; ++j)
1691 xassert (i == j
1692 || (matrix->rows[i].glyphs[TEXT_AREA]
1693 != matrix->rows[j].glyphs[TEXT_AREA]));
1694 }
1695
1696
1697
1698
1699 struct glyph_row *
1700 matrix_row (matrix, row)
1701 struct glyph_matrix *matrix;
1702 int row;
1703 {
1704 xassert (matrix && matrix->rows);
1705 xassert (row >= 0 && row < matrix->nrows);
1706
1707 1708 1709
1710 #if 0
1711 check_matrix_pointer_lossage (matrix);
1712 #endif
1713
1714 return matrix->rows + row;
1715 }
1716
1717
1718 #if 0 1719 1720
1721
1722 1723
1724
1725 static void
1726 check_matrix_invariants (w)
1727 struct window *w;
1728 {
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);
1735 int c;
1736
1737
1738 if (matrix->nrows < 2)
1739 return;
1740
1741 set_buffer_temp (buffer);
1742
1743
1744 while (MATRIX_ROW_DISPLAYS_TEXT_P (row)
1745 && MATRIX_ROW_BOTTOM_Y (row) < yb)
1746 {
1747 struct glyph_row *next = row + 1;
1748
1749 if (MATRIX_ROW_DISPLAYS_TEXT_P (row))
1750 last_text_row = row;
1751
1752
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)));
1757
1758 1759 1760
1761 if (MATRIX_ROW_END_CHARPOS (row) < BUF_ZV (current_buffer))
1762 {
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)));
1767 }
1768
1769 1770
1771 if (next->enabled_p && MATRIX_ROW_DISPLAYS_TEXT_P (next))
1772 {
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));
1779 }
1780 row = next;
1781 }
1782
1783 xassert (w->current_matrix->nrows == w->desired_matrix->nrows);
1784 xassert (w->desired_matrix->rows != NULL);
1785 set_buffer_temp (saved);
1786 }
1787
1788 #endif
1789
1790 #endif
1791
1792
1793
1794 1795 1796
1797
1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866
1867
1868 1869
1870
1871 #define NEW_LEAF_MATRIX (1 << 0)
1872
1873 1874
1875
1876 #define CHANGED_LEAF_MATRIX (1 << 1)
1877
1878 static struct dim
1879 allocate_matrices_for_frame_redisplay (window, x, y, dim_only_p,
1880 window_change_flags)
1881 Lisp_Object window;
1882 int x, y;
1883 int dim_only_p;
1884 int *window_change_flags;
1885 {
1886 struct frame *f = XFRAME (WINDOW_FRAME (XWINDOW (window)));
1887 int x0 = x, y0 = y;
1888 int wmax = 0, hmax = 0;
1889 struct dim total;
1890 struct dim dim;
1891 struct window *w;
1892 int in_horz_combination_p;
1893
1894 1895 1896 1897 1898 1899
1900 in_horz_combination_p
1901 = (!NILP (XWINDOW (window)->parent)
1902 && !NILP (XWINDOW (XWINDOW (window)->parent)->hchild));
1903
1904
1905 do
1906 {
1907 w = XWINDOW (window);
1908
1909 1910
1911 if (!NILP (w->hchild))
1912 dim = allocate_matrices_for_frame_redisplay (w->hchild, x, y,
1913 dim_only_p,
1914 window_change_flags);
1915 else if (!NILP (w->vchild))
1916 dim = allocate_matrices_for_frame_redisplay (w->vchild, x, y,
1917 dim_only_p,
1918 window_change_flags);
1919 else
1920 {
1921
1922 if (w->desired_matrix == NULL)
1923 {
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;
1927 }
1928
1929 1930
1931 dim.width = required_matrix_width (w);
1932 dim.height = required_matrix_height (w);
1933
1934
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;
1946
1947 1948 1949 1950 1951
1952 if (!dim_only_p)
1953 {
1954 adjust_glyph_matrix (w, w->desired_matrix, x, y, dim);
1955 adjust_glyph_matrix (w, w->current_matrix, x, y, dim);
1956 }
1957 }
1958
1959 1960 1961
1962 if (in_horz_combination_p)
1963 x += dim.width;
1964 else
1965 y += dim.height;
1966
1967
1968 wmax = max (wmax, dim.width);
1969 hmax = max (hmax, dim.height);
1970
1971
1972 window = w->next;
1973 }
1974 while (!NILP (window));
1975
1976 1977 1978 1979 1980 1981
1982 if (in_horz_combination_p)
1983 {
1984 total.width = x - x0;
1985 total.height = hmax;
1986 }
1987 else
1988 {
1989 total.width = wmax;
1990 total.height = y - y0;
1991 }
1992
1993 return total;
1994 }
1995
1996
1997
1998
1999 int
2000 required_matrix_height (w)
2001 struct window *w;
2002 {
2003 #ifdef HAVE_WINDOW_SYSTEM
2004 struct frame *f = XFRAME (w->frame);
2005
2006 if (FRAME_WINDOW_P (f))
2007 {
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 2013
2014 + 2
2015
2016 + 2);
2017 }
2018 #endif
2019
2020 return WINDOW_TOTAL_LINES (w);
2021 }
2022
2023
2024
2025
2026 int
2027 required_matrix_width (w)
2028 struct window *w;
2029 {
2030 #ifdef HAVE_WINDOW_SYSTEM
2031 struct frame *f = XFRAME (w->frame);
2032 if (FRAME_WINDOW_P (f))
2033 {
2034 int ch_width = FRAME_SMALLEST_CHAR_WIDTH (f);
2035 int window_pixel_width = WINDOW_TOTAL_WIDTH (w);
2036
2037
2038 return (((window_pixel_width + ch_width - 1)
2039 / ch_width) * w->ncols_scale_factor
2040
2041 + 2
2042 2043
2044 + 1 + 1);
2045 }
2046 #endif
2047
2048 return XINT (w->total_cols);
2049 }
2050
2051
2052 2053
2054
2055 static void
2056 allocate_matrices_for_window_redisplay (w)
2057 struct window *w;
2058 {
2059 while (w)
2060 {
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));
2065 else
2066 {
2067
2068 struct dim dim;
2069
2070
2071 if (w->desired_matrix == NULL)
2072 {
2073 w->desired_matrix = new_glyph_matrix (NULL);
2074 w->current_matrix = new_glyph_matrix (NULL);
2075 }
2076
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);
2081 }
2082
2083 w = NILP (w->next) ? NULL : XWINDOW (w->next);
2084 }
2085 }
2086
2087
2088 2089 2090 2091
2092
2093 void
2094 adjust_glyphs (f)
2095 struct frame *f;
2096 {
2097 2098
2099 BLOCK_INPUT;
2100
2101 if (f)
2102 adjust_frame_glyphs (f);
2103 else
2104 {
2105 Lisp_Object tail, lisp_frame;
2106
2107 FOR_EACH_FRAME (tail, lisp_frame)
2108 adjust_frame_glyphs (XFRAME (lisp_frame));
2109 }
2110
2111 UNBLOCK_INPUT;
2112 }
2113
2114
2115 2116 2117 2118 2119 2120 2121 2122 2123 2124
2125
2126 static void
2127 adjust_frame_glyphs_initially ()
2128 {
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);
2135
2136
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);
2140
2141
2142 XSETFASTINT (mini->top_line, frame_lines - 1);
2143 XSETFASTINT (mini->total_cols, frame_cols);
2144 set_window_height (root->next, 1, 0);
2145
2146 adjust_frame_glyphs (sf);
2147 glyphs_initialized_initially_p = 1;
2148 }
2149
2150
2151
2152
2153 static void
2154 adjust_frame_glyphs (f)
2155 struct frame *f;
2156 {
2157 if (FRAME_WINDOW_P (f))
2158 adjust_frame_glyphs_for_window_redisplay (f);
2159 else
2160 adjust_frame_glyphs_for_frame_redisplay (f);
2161
2162 2163
2164 adjust_frame_message_buffer (f);
2165 adjust_decode_mode_spec_buffer (f);
2166
2167 f->glyphs_initialized_p = 1;
2168 }
2169
2170 2171
2172 static int
2173 showing_window_margins_p (w)
2174 struct window *w;
2175 {
2176 while (w)
2177 {
2178 if (!NILP (w->hchild))
2179 {
2180 if (showing_window_margins_p (XWINDOW (w->hchild)))
2181 return 1;
2182 }
2183 else if (!NILP (w->vchild))
2184 {
2185 if (showing_window_margins_p (XWINDOW (w->vchild)))
2186 return 1;
2187 }
2188 else if (!NILP (w->left_margin_cols)
2189 || !NILP (w->right_margin_cols))
2190 return 1;
2191
2192 w = NILP (w->next) ? 0 : XWINDOW (w->next);
2193 }
2194 return 0;
2195 }
2196
2197
2198 2199
2200
2201 static void
2202 fake_current_matrices (window)
2203 Lisp_Object window;
2204 {
2205 struct window *w;
2206
2207 for (; !NILP (window); window = w->next)
2208 {
2209 w = XWINDOW (window);
2210
2211 if (!NILP (w->hchild))
2212 fake_current_matrices (w->hchild);
2213 else if (!NILP (w->vchild))
2214 fake_current_matrices (w->vchild);
2215 else
2216 {
2217 int i;
2218 struct frame *f = XFRAME (w->frame);
2219 struct glyph_matrix *m = w->current_matrix;
2220 struct glyph_matrix *fm = f->current_matrix;
2221
2222 xassert (m->matrix_h == WINDOW_TOTAL_LINES (w));
2223 xassert (m->matrix_w == WINDOW_TOTAL_COLS (w));
2224
2225 for (i = 0; i < m->matrix_h; ++i)
2226 {
2227 struct glyph_row *r = m->rows + i;
2228 struct glyph_row *fr = fm->rows + i + WINDOW_TOP_EDGE_LINE (w);
2229
2230 xassert (r->glyphs[TEXT_AREA] >= fr->glyphs[TEXT_AREA]
2231 && r->glyphs[LAST_AREA] <= fr->glyphs[LAST_AREA]);
2232
2233 r->enabled_p = fr->enabled_p;
2234 if (r->enabled_p)
2235 {
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]);
2241 r->mode_line_p = 0;
2242 }
2243 }
2244 }
2245 }
2246 }
2247
2248
2249 2250
2251
2252 static struct glyph_matrix *
2253 save_current_matrix (f)
2254 struct frame *f;
2255 {
2256 int i;
2257 struct glyph_matrix *saved;
2258
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);
2265
2266 for (i = 0; i < saved->nrows; ++i)
2267 {
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];
2274 }
2275
2276 return saved;
2277 }
2278
2279
2280 2281
2282
2283 static void
2284 restore_current_matrix (f, saved)
2285 struct frame *f;
2286 struct glyph_matrix *saved;
2287 {
2288 int i;
2289
2290 for (i = 0; i < saved->nrows; ++i)
2291 {
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]);
2298 }
2299
2300 xfree (saved->rows);
2301 xfree (saved);
2302 }
2303
2304
2305
2306 2307
2308
2309 static void
2310 adjust_frame_glyphs_for_frame_redisplay (f)
2311 struct frame *f;
2312 {
2313 struct dim matrix_dim;
2314 int pool_changed_p;
2315 int window_change_flags;
2316 int top_window_y;
2317
2318 if (!FRAME_LIVE_P (f))
2319 return;
2320
2321 top_window_y = FRAME_TOP_MARGIN (f);
2322
2323
2324 if (f->desired_pool == NULL)
2325 {
2326 f->desired_pool = new_glyph_pool ();
2327 f->current_pool = new_glyph_pool ();
2328 }
2329
2330
2331 if (f->desired_matrix == NULL)
2332 {
2333 f->desired_matrix = new_glyph_matrix (f->desired_pool);
2334 f->current_matrix = new_glyph_matrix (f->current_pool);
2335 }
2336
2337 2338 2339 2340 2341 2342
2343 window_change_flags = 0;
2344 matrix_dim
2345 = allocate_matrices_for_frame_redisplay (FRAME_ROOT_WINDOW (f),
2346 0, top_window_y,
2347 1,
2348 &window_change_flags);
2349
2350
2351 matrix_dim.height += top_window_y;
2352
2353
2354 pool_changed_p = realloc_glyph_pool (f->desired_pool, matrix_dim);
2355 realloc_glyph_pool (f->current_pool, matrix_dim);
2356
2357 2358
2359 if (pool_changed_p || window_change_flags)
2360 {
2361
2362 allocate_matrices_for_frame_redisplay (FRAME_ROOT_WINDOW (f),
2363 0, top_window_y, 0,
2364 &window_change_flags);
2365
2366 2367 2368
2369 xassert (matrix_dim.width == FRAME_COLS (f)
2370 && matrix_dim.height == FRAME_LINES (f));
2371
2372 2373 2374 2375 2376 2377 2378 2379 2380
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 2386 2387 2388
2389 && !showing_window_margins_p (XWINDOW (FRAME_ROOT_WINDOW (f))))
2390 {
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));
2396 }
2397 else
2398 {
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);
2402 }
2403 }
2404 }
2405
2406
2407 2408
2409
2410 static void
2411 adjust_frame_glyphs_for_window_redisplay (f)
2412 struct frame *f;
2413 {
2414 struct window *w;
2415
2416 xassert (FRAME_WINDOW_P (f) && FRAME_LIVE_P (f));
2417
2418
2419 allocate_matrices_for_window_redisplay (XWINDOW (FRAME_ROOT_WINDOW (f)));
2420
2421 #ifdef HAVE_X_WINDOWS
2422 2423
2424 #if ! defined (USE_X_TOOLKIT) && ! defined (USE_GTK)
2425 {
2426
2427 if (NILP (f->menu_bar_window))
2428 {
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;
2433 }
2434 else
2435 w = XWINDOW (f->menu_bar_window);
2436
2437 2438
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);
2444 }
2445 #endif
2446 #endif
2447
2448 #ifndef USE_GTK
2449 2450
2451 if (NILP (f->tool_bar_window))
2452 {
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;
2457 }
2458 else
2459 w = XWINDOW (f->tool_bar_window);
2460
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);
2466 #endif
2467 }
2468
2469
2470 2471 2472 2473 2474 2475 2476 2477
2478
2479 static void
2480 adjust_frame_message_buffer (f)
2481 struct frame *f;
2482 {
2483 int size = FRAME_MESSAGE_BUF_SIZE (f) + 1;
2484
2485 if (FRAME_MESSAGE_BUF (f))
2486 {
2487 char *buffer = FRAME_MESSAGE_BUF (f);
2488 char *new_buffer = (char *) xrealloc (buffer, size);
2489 FRAME_MESSAGE_BUF (f) = new_buffer;
2490 }
2491 else
2492 FRAME_MESSAGE_BUF (f) = (char *) xmalloc (size);
2493 }
2494
2495
2496
2497
2498 static void
2499 adjust_decode_mode_spec_buffer (f)
2500 struct frame *f;
2501 {
2502 f->decode_mode_spec_buffer
2503 = (char *) xrealloc (f->decode_mode_spec_buffer,
2504 FRAME_MESSAGE_BUF_SIZE (f) + 1);
2505 }
2506
2507
2508
2509 2510 2511
2512
2513 2514 2515 2516
2517
2518 void
2519 free_glyphs (f)
2520 struct frame *f;
2521 {
2522 if (f && f->glyphs_initialized_p)
2523 {
2524 2525
2526 BLOCK_INPUT;
2527 f->glyphs_initialized_p = 0;
2528
2529
2530 if (!NILP (f->root_window))
2531 free_window_matrices (XWINDOW (f->root_window));
2532
2533 2534
2535 if (!NILP (f->menu_bar_window))
2536 {
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;
2542 }
2543
2544
2545 if (!NILP (f->tool_bar_window))
2546 {
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;
2552 }
2553
2554 2555
2556 if (f->desired_matrix)
2557 {
2558 free_glyph_matrix (f->desired_matrix);
2559 free_glyph_matrix (f->current_matrix);
2560 f->desired_matrix = f->current_matrix = NULL;
2561 }
2562
2563
2564 if (f->desired_pool)
2565 {
2566 free_glyph_pool (f->desired_pool);
2567 free_glyph_pool (f->current_pool);
2568 f->desired_pool = f->current_pool = NULL;
2569 }
2570
2571 UNBLOCK_INPUT;
2572 }
2573 }
2574
2575
2576 2577 2578
2579
2580 void
2581 free_window_matrices (w)
2582 struct window *w;
2583 {
2584 while (w)
2585 {
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));
2590 else
2591 {
2592 2593 2594
2595 free_glyph_matrix (w->current_matrix);
2596 free_glyph_matrix (w->desired_matrix);
2597 w->current_matrix = w->desired_matrix = NULL;
2598 }
2599
2600
2601 w = NILP (w->next) ? 0 : XWINDOW (w->next);
2602 }
2603 }
2604
2605
2606 2607 2608 2609
2610
2611 void
2612 check_glyph_memory ()
2613 {
2614 Lisp_Object tail, frame;
2615
2616
2617 FOR_EACH_FRAME (tail, frame)
2618 free_glyphs (XFRAME (frame));
2619
2620
2621 if (glyph_matrix_count)
2622 abort ();
2623 if (glyph_pool_count)
2624 abort ();
2625 }
2626
2627
2628
2629 2630 2631
2632
2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688
2689
2690 2691 2692 2693
2694
2695 static void
2696 build_frame_matrix (f)
2697 struct frame *f;
2698 {
2699 int i;
2700
2701
2702 xassert (!FRAME_WINDOW_P (f));
2703
2704 2705
2706 for (i = FRAME_TOP_MARGIN (f); i < f->desired_matrix->nrows; ++i)
2707 clear_glyph_row (MATRIX_ROW (f->desired_matrix, i));
2708
2709
2710 build_frame_matrix_from_window_tree (f->desired_matrix,
2711 XWINDOW (FRAME_ROOT_WINDOW (f)));
2712 }
2713
2714
2715 2716
2717
2718 static void
2719 build_frame_matrix_from_window_tree (matrix, w)
2720 struct glyph_matrix *matrix;
2721 struct window *w;
2722 {
2723 while (w)
2724 {
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));
2729 else
2730 build_frame_matrix_from_leaf_window (matrix, w);
2731
2732 w = NILP (w->next) ? 0 : XWINDOW (w->next);
2733 }
2734 }
2735
2736
2737 2738 2739 2740 2741 2742 2743 2744 2745 2746
2747
2748 static void
2749 build_frame_matrix_from_leaf_window (frame_matrix, w)
2750 struct glyph_matrix *frame_matrix;
2751 struct window *w;
2752 {
2753 struct glyph_matrix *window_matrix;
2754 int window_y, frame_y;
2755
2756 GLYPH right_border_glyph;
2757
2758 SET_GLYPH_FROM_CHAR (right_border_glyph, 0);
2759
2760
2761 if (w->must_be_updated_p)
2762 {
2763 window_matrix = w->desired_matrix;
2764
2765
2766 if (!WINDOW_RIGHTMOST_P (w))
2767 {
2768 struct Lisp_Char_Table *dp = window_display_table (w);
2769 Lisp_Object gc;
2770
2771 SET_GLYPH_FROM_CHAR (right_border_glyph, '|');
2772 if (dp
2773 && (gc = DISP_BORDER_GLYPH (dp), GLYPH_CODE_P (gc))
2774 && GLYPH_CODE_CHAR_VALID_P (gc))
2775 {
2776 SET_GLYPH_FROM_GLYPH_CODE (right_border_glyph, gc);
2777 spec_glyph_lookup_face (w, &right_border_glyph);
2778 }
2779
2780 if (GLYPH_FACE (right_border_glyph) <= 0)
2781 SET_GLYPH_FACE (right_border_glyph, VERTICAL_BORDER_FACE_ID);
2782 }
2783 }
2784 else
2785 window_matrix = w->current_matrix;
2786
2787 2788
2789 window_y = 0;
2790 frame_y = window_matrix->matrix_y;
2791 while (window_y < window_matrix->nrows)
2792 {
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;
2796
2797 2798
2799 fill_up_frame_row_with_spaces (frame_row, window_matrix->matrix_x);
2800
2801
2802 fill_up_glyph_row_with_spaces (window_row);
2803
2804 2805 2806
2807 if (window_matrix == w->desired_matrix
2808 && !window_row->enabled_p)
2809 {
2810 window_row = w->current_matrix->rows + window_y;
2811 current_row_p = 1;
2812 }
2813
2814 if (current_row_p)
2815 {
2816
2817 bcopy (window_row->glyphs[0],
2818 frame_row->glyphs[TEXT_AREA] + window_matrix->matrix_x,
2819 window_matrix->matrix_w * sizeof (struct glyph));
2820 }
2821 else
2822 {
2823 xassert (window_row->enabled_p);
2824
2825 2826
2827 frame_row->enabled_p = 1;
2828
2829 2830
2831 if (GLYPH_CHAR (right_border_glyph) != 0)
2832 {
2833 struct glyph *border = window_row->glyphs[LAST_AREA] - 1;
2834 SET_CHAR_GLYPH_FROM_GLYPH (*border, right_border_glyph);
2835 }
2836
2837 #if GLYPH_DEBUG
2838 2839
2840 xassert (glyph_row_slice_p (window_row, frame_row));
2841
2842 2843
2844
2845 strcpy (w->current_matrix->method, w->desired_matrix->method);
2846 add_window_display_history (w, w->current_matrix->method, 0);
2847 #endif
2848 }
2849
2850 2851 2852
2853 frame_row->used[TEXT_AREA]
2854 = window_matrix->matrix_x + window_matrix->matrix_w;
2855
2856
2857 ++window_y;
2858 ++frame_y;
2859 }
2860 }
2861
2862 2863 2864 2865
2866
2867 void
2868 spec_glyph_lookup_face (w, glyph)
2869 struct window *w;
2870 GLYPH *glyph;
2871 {
2872 int lface_id = GLYPH_FACE (*glyph);
2873
2874 if (lface_id > 0)
2875 {
2876 int face_id = merge_faces (XFRAME (w->frame),
2877 Qt, lface_id, DEFAULT_FACE_ID);
2878 SET_GLYPH_FACE (*glyph, face_id);
2879 }
2880 }
2881
2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896
2897
2898 static void
2899 fill_up_glyph_row_with_spaces (row)
2900 struct glyph_row *row;
2901 {
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);
2905 }
2906
2907
2908 2909
2910
2911 static void
2912 fill_up_glyph_row_area_with_spaces (row, area)
2913 struct glyph_row *row;
2914 int area;
2915 {
2916 if (row->glyphs[area] < row->glyphs[area + 1])
2917 {
2918 struct glyph *end = row->glyphs[area + 1];
2919 struct glyph *text = row->glyphs[area] + row->used[area];
2920
2921 while (text < end)
2922 *text++ = space_glyph;
2923 row->used[area] = text - row->glyphs[area];
2924 }
2925 }
2926
2927
2928 2929
2930
2931 static void
2932 fill_up_frame_row_with_spaces (row, upto)
2933 struct glyph_row *row;
2934 int upto;
2935 {
2936 int i = row->used[TEXT_AREA];
2937 struct glyph *glyph = row->glyphs[TEXT_AREA];
2938
2939 while (i < upto)
2940 glyph[i++] = space_glyph;
2941
2942 row->used[TEXT_AREA] = i;
2943 }
2944
2945
2946
2947 2948 2949
2950
2951 2952 2953
2954
2955 static INLINE void
2956 set_frame_matrix_frame (f)
2957 struct frame *f;
2958 {
2959 frame_matrix_frame = f;
2960 }
2961
2962
2963 2964 2965 2966 2967 2968 2969
2970
2971 static INLINE void
2972 make_current (desired_matrix, current_matrix, row)
2973 struct glyph_matrix *desired_matrix, *current_matrix;
2974 int row;
2975 {
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;
2979
2980 2981
2982 assign_row (current_row, desired_row);
2983
2984
2985 current_row->enabled_p = 1;
2986 current_row->mouse_face_p = mouse_face_p;
2987
2988 2989
2990 if (frame_matrix_frame)
2991 mirror_make_current (XWINDOW (frame_matrix_frame->root_window), row);
2992 }
2993
2994
2995 2996 2997 2998
2999
3000 static void
3001 mirror_make_current (w, frame_row)
3002 struct window *w;
3003 int frame_row;
3004 {
3005 while (w)
3006 {
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);
3011 else
3012 {
3013 3014 3015
3016 int row = frame_row - w->desired_matrix->matrix_y;
3017
3018 3019
3020 if (row >= 0 && row < w->desired_matrix->matrix_h)
3021 {
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);
3026
3027 if (desired_row->enabled_p)
3028 assign_row (current_row, desired_row);
3029 else
3030 swap_glyph_pointers (desired_row, current_row);
3031 current_row->enabled_p = 1;
3032 }
3033 }
3034
3035 w = NILP (w->next) ? 0 : XWINDOW (w->next);
3036 }
3037 }
3038
3039
3040 3041 3042 3043 3044 3045 3046 3047 3048
3049
3050 void
3051 mirrored_line_dance (matrix, unchanged_at_top, nlines, copy_from,
3052 retained_p)
3053 struct glyph_matrix *matrix;
3054 int unchanged_at_top, nlines;
3055 int *copy_from;
3056 char *retained_p;
3057 {
3058
3059 struct glyph_row *old_rows;
3060
3061
3062 struct glyph_row *new_rows = MATRIX_ROW (matrix, unchanged_at_top);
3063
3064 int i;
3065
3066
3067 old_rows = (struct glyph_row *) alloca (nlines * sizeof *old_rows);
3068 bcopy (new_rows, old_rows, nlines * sizeof *old_rows);
3069
3070
3071 for (i = 0; i < nlines; ++i)
3072 {
3073 int enabled_before_p = new_rows[i].enabled_p;
3074
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;
3079
3080
3081 if (!retained_p[copy_from[i]])
3082 new_rows[i].enabled_p = 0;
3083 }
3084
3085
3086 if (frame_matrix_frame)
3087 mirror_line_dance (XWINDOW (frame_matrix_frame->root_window),
3088 unchanged_at_top, nlines, copy_from, retained_p);
3089 }
3090
3091
3092 3093
3094
3095 static void
3096 sync_window_with_frame_matrix_rows (w)
3097 struct window *w;
3098 {
3099 struct frame *f = XFRAME (w->frame);
3100 struct glyph_row *window_row, *window_row_end, *frame_row;
3101 int left, right, x, width;
3102
3103
3104 xassert (NILP (w->hchild) && NILP (w->vchild));
3105 xassert (!FRAME_WINDOW_P (f));
3106
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;
3111
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);
3115
3116 for (; window_row < window_row_end; ++window_row, ++frame_row)
3117 {
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;
3126 }
3127 }
3128
3129
3130 3131
3132
3133 struct window *
3134 frame_row_to_window (w, row)
3135 struct window *w;
3136 int row;
3137 {
3138 struct window *found = NULL;
3139
3140 while (w && !found)
3141 {
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))
3148 found = w;
3149
3150 w = NILP (w->next) ? 0 : XWINDOW (w->next);
3151 }
3152
3153 return found;
3154 }
3155
3156
3157 3158 3159 3160 3161 3162 3163 3164 3165 3166
3167
3168 static void
3169 mirror_line_dance (w, unchanged_at_top, nlines, copy_from, retained_p)
3170 struct window *w;
3171 int unchanged_at_top, nlines;
3172 int *copy_from;
3173 char *retained_p;
3174 {
3175 while (w)
3176 {
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);
3183 else
3184 {
3185 3186
3187 struct glyph_matrix *m = w->current_matrix;
3188 int i, sync_p = 0;
3189 struct glyph_row *old_rows;
3190
3191
3192 old_rows = (struct glyph_row *) alloca (m->nrows * sizeof *old_rows);
3193 bcopy (m->rows, old_rows, m->nrows * sizeof *old_rows);
3194
3195 for (i = 0; i < nlines; ++i)
3196 {
3197
3198 int frame_to = i + unchanged_at_top;
3199
3200
3201 int frame_from = copy_from[i] + unchanged_at_top;
3202
3203
3204 int window_to = frame_to - m->matrix_y;
3205
3206
3207 int window_from = frame_from - m->matrix_y;
3208
3209
3210 int from_inside_window_p
3211 = window_from >= 0 && window_from < m->matrix_h;
3212
3213
3214 int to_inside_window_p
3215 = window_to >= 0 && window_to < m->matrix_h;
3216
3217 if (from_inside_window_p && to_inside_window_p)
3218 {
3219
3220 int enabled_before_p;
3221
3222 3223 3224
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;
3228
3229
3230 if (!retained_p[copy_from[i]])
3231 m->rows[window_to].enabled_p = 0;
3232 }
3233 else if (to_inside_window_p)
3234 {
3235 3236
3237 struct frame *f = XFRAME (w->frame);
3238 struct window *root = XWINDOW (FRAME_ROOT_WINDOW (f));
3239 struct window *w2;
3240 struct glyph_matrix *m2;
3241 int m2_from;
3242
3243 w2 = frame_row_to_window (root, frame_from);
3244 3245 3246
3247 if (w2)
3248 {
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);
3253
3254
3255 if (!retained_p[copy_from[i]])
3256 m->rows[window_to].enabled_p = 0;
3257 }
3258 sync_p = 1;
3259 }
3260 else if (from_inside_window_p)
3261 sync_p = 1;
3262 }
3263
3264 3265
3266 if (sync_p)
3267 sync_window_with_frame_matrix_rows (w);
3268
3269
3270 CHECK_MATRIX (m);
3271 }
3272
3273
3274 w = NILP (w->next) ? 0 : XWINDOW (w->next);
3275 }
3276 }
3277
3278
3279 #if GLYPH_DEBUG
3280
3281 3282 3283 3284 3285
3286
3287 void
3288 check_window_matrix_pointers (w)
3289 struct window *w;
3290 {
3291 while (w)
3292 {
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));
3297 else
3298 {
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);
3302 }
3303
3304 w = NILP (w->next) ? 0 : XWINDOW (w->next);
3305 }
3306 }
3307
3308
3309 3310 3311 3312
3313
3314 static void
3315 check_matrix_pointers (window_matrix, frame_matrix)
3316 struct glyph_matrix *window_matrix, *frame_matrix;
3317 {
3318
3319 int i = 0;
3320
3321
3322 int j = window_matrix->matrix_y;
3323
3324 3325 3326
3327 while (i < window_matrix->nrows)
3328 {
3329 if (!glyph_row_slice_p (window_matrix->rows + i,
3330 frame_matrix->rows + j))
3331 abort ();
3332 ++i, ++j;
3333 }
3334 }
3335
3336 #endif
3337
3338
3339
3340 3341 3342
3343
3344 #if GLYPH_DEBUG
3345
3346 3347
3348
3349 static int
3350 window_to_frame_vpos (w, vpos)
3351 struct window *w;
3352 int vpos;
3353 {
3354 struct frame *f = XFRAME (w->frame);
3355
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));
3360 return vpos;
3361 }
3362
3363
3364 3365
3366
3367 static int
3368 window_to_frame_hpos (w, hpos)
3369 struct window *w;
3370 int hpos;
3371 {
3372 xassert (!FRAME_WINDOW_P (XFRAME (w->frame)));
3373 hpos += WINDOW_LEFT_EDGE_COL (w);
3374 return hpos;
3375 }
3376
3377 #endif
3378
3379
3380
3381 3382 3383
3384
3385 DEFUN ("redraw-frame", Fredraw_frame, Sredraw_frame, 1, 1, 0,
3386 doc: )
3387 (frame)
3388 Lisp_Object frame;
3389 {
3390 struct frame *f;
3391
3392 CHECK_LIVE_FRAME (frame);
3393 f = XFRAME (frame);
3394
3395 3396 3397
3398 if (!glyphs_initialized_initially_p)
3399 return Qnil;
3400
3401 update_begin (f);
3402 #ifdef MSDOS
3403 if (FRAME_MSDOS_P (f))
3404 FRAME_TERMINAL (f)->set_terminal_modes_hook (FRAME_TERMINAL (f));
3405 #endif
3406 clear_frame (f);
3407 clear_current_matrices (f);
3408 update_end (f);
3409 if (FRAME_TERMCAP_P (f))
3410 fflush (FRAME_TTY (f)->output);
3411 windows_or_buffers_changed++;
3412 3413
3414 mark_window_display_accurate (FRAME_ROOT_WINDOW (f), 0);
3415 set_window_update_flags (XWINDOW (FRAME_ROOT_WINDOW (f)), 1);
3416 f->garbaged = 0;
3417 return Qnil;
3418 }
3419
3420
3421 3422
3423
3424 void
3425 redraw_frame (f)
3426 struct frame *f;
3427 {
3428 Lisp_Object frame;
3429 XSETFRAME (frame, f);
3430 Fredraw_frame (frame);
3431 }
3432
3433
3434 DEFUN ("redraw-display", Fredraw_display, Sredraw_display, 0, 0, "",
3435 doc: )
3436 ()
3437 {
3438 Lisp_Object tail, frame;
3439
3440 FOR_EACH_FRAME (tail, frame)
3441 if (FRAME_VISIBLE_P (XFRAME (frame)))
3442 Fredraw_frame (frame);
3443
3444 return Qnil;
3445 }
3446
3447
3448 3449
3450
3451 void
3452 redraw_garbaged_frames ()
3453 {
3454 Lisp_Object tail, frame;
3455
3456 FOR_EACH_FRAME (tail, frame)
3457 if (FRAME_VISIBLE_P (XFRAME (frame))
3458 && FRAME_GARBAGED_P (XFRAME (frame)))
3459 Fredraw_frame (frame);
3460 }
3461
3462
3463
3464 3465 3466
3467
3468 3469 3470 3471 3472 3473 3474
3475
3476 int
3477 update_frame (f, force_p, inhibit_hairy_id_p)
3478 struct frame *f;
3479 int force_p;
3480 int inhibit_hairy_id_p;
3481 {
3482
3483 int paused_p;
3484 struct window *root_window = XWINDOW (f->root_window);
3485
3486 if (redisplay_dont_pause)
3487 force_p = 1;
3488 #if PERIODIC_PREEMPTION_CHECKING
3489 else if (NILP (Vredisplay_preemption_period))
3490 force_p = 1;
3491 else if (!force_p && NUMBERP (Vredisplay_preemption_period))
3492 {
3493 EMACS_TIME tm;
3494 double p = XFLOATINT (Vredisplay_preemption_period);
3495 int sec, usec;
3496
3497 if (detect_input_pending_ignore_squeezables ())
3498 {
3499 paused_p = 1;
3500 goto do_pause;
3501 }
3502
3503 sec = (int) p;
3504 usec = (p - sec) * 1000000;
3505
3506 EMACS_GET_TIME (tm);
3507 EMACS_SET_SECS_USECS (preemption_period, sec, usec);
3508 EMACS_ADD_TIME (preemption_next_check, tm, preemption_period);
3509 }
3510 #endif
3511
3512 if (FRAME_WINDOW_P (f))
3513 {
3514 3515
3516
3517
3518 set_frame_matrix_frame (NULL);
3519
3520 3521
3522 update_begin (f);
3523
3524 3525
3526 if (WINDOWP (f->menu_bar_window))
3527 update_window (XWINDOW (f->menu_bar_window), 1);
3528
3529
3530 if (WINDOWP (f->tool_bar_window))
3531 {
3532 struct window *w = XWINDOW (f->tool_bar_window);
3533
3534
3535 if (w->must_be_updated_p)
3536 {
3537 Lisp_Object tem;
3538
3539 update_window (w, 1);
3540 w->must_be_updated_p = 0;
3541
3542 3543
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;
3547 }
3548 }
3549
3550
3551
3552 paused_p = update_window_tree (root_window, force_p);
3553 update_end (f);
3554
3555 3556 3557 3558
3559 if (f->force_flush_display_p)
3560 {
3561 FRAME_RIF (f)->flush_display (f);
3562 f->force_flush_display_p = 0;
3563 }
3564 }
3565 else
3566 {
3567 3568
3569 set_frame_matrix_frame (f);
3570
3571
3572 build_frame_matrix (f);
3573
3574
3575 update_begin (f);
3576 paused_p = update_frame_1 (f, force_p, inhibit_hairy_id_p);
3577 update_end (f);
3578
3579 if (FRAME_TERMCAP_P (f) || FRAME_MSDOS_P (f))
3580 {
3581 if (FRAME_TTY (f)->termscript)
3582 fflush (FRAME_TTY (f)->termscript);
3583 if (FRAME_TERMCAP_P (f))
3584 fflush (FRAME_TTY (f)->output);
3585 }
3586
3587
3588 #if GLYPH_DEBUG
3589 check_window_matrix_pointers (root_window);
3590 add_frame_display_history (f, paused_p);
3591 #endif
3592 }
3593
3594 do_pause:
3595
3596 set_window_update_flags (root_window, 0);
3597
3598 display_completed = !paused_p;
3599 return paused_p;
3600 }
3601
3602
3603
3604 3605 3606
3607
3608 3609
3610
3611 static int
3612 update_window_tree (w, force_p)
3613 struct window *w;
3614 int force_p;
3615 {
3616 int paused_p = 0;
3617
3618 while (w && !paused_p)
3619 {
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);
3626
3627 w = NILP (w->next) ? 0 : XWINDOW (w->next);
3628 }
3629
3630 return paused_p;
3631 }
3632
3633
3634 3635
3636
3637 void
3638 update_single_window (w, force_p)
3639 struct window *w;
3640 int force_p;
3641 {
3642 if (w->must_be_updated_p)
3643 {
3644 struct frame *f = XFRAME (WINDOW_FRAME (w));
3645
3646
3647 set_frame_matrix_frame (NULL);
3648
3649 if (redisplay_dont_pause)
3650 force_p = 1;
3651 #if PERIODIC_PREEMPTION_CHECKING
3652 else if (NILP (Vredisplay_preemption_period))
3653 force_p = 1;
3654 else if (!force_p && NUMBERP (Vredisplay_preemption_period))
3655 {
3656 EMACS_TIME tm;
3657 double p = XFLOATINT (Vredisplay_preemption_period);
3658 int sec, usec;
3659
3660 sec = (int) p;
3661 usec = (p - sec) * 1000000;
3662
3663 EMACS_GET_TIME (tm);
3664 EMACS_SET_SECS_USECS (preemption_period, sec, usec);
3665 EMACS_ADD_TIME (preemption_next_check, tm, preemption_period);
3666 }
3667 #endif
3668
3669
3670 update_begin (f);
3671 update_window (w, force_p);
3672 update_end (f);
3673
3674
3675 w->must_be_updated_p = 0;
3676 }
3677 }
3678
3679 #ifdef HAVE_WINDOW_SYSTEM
3680
3681 3682
3683
3684 static void
3685 redraw_overlapped_rows (w, yb)
3686 struct window *w;
3687 int yb;
3688 {
3689 int i;
3690 struct frame *f = XFRAME (WINDOW_FRAME (w));
3691
3692 3693 3694 3695 3696
3697 for (i = 0; i < w->current_matrix->nrows; ++i)
3698 {
3699 struct glyph_row *row = w->current_matrix->rows + i;
3700
3701 if (!row->enabled_p)
3702 break;
3703 else if (row->mode_line_p)
3704 continue;
3705
3706 if (row->overlapped_p)
3707 {
3708 enum glyph_row_area area;
3709
3710 for (area = LEFT_MARGIN_AREA; area < LAST_AREA; ++area)
3711 {
3712 updated_row = row;
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],
3718 row->used[area]);
3719 FRAME_RIF (f)->clear_end_of_line (-1);
3720 }
3721
3722 row->overlapped_p = 0;
3723 }
3724
3725 if (MATRIX_ROW_BOTTOM_Y (row) >= yb)
3726 break;
3727 }
3728 }
3729
3730
3731 3732
3733
3734 static void
3735 redraw_overlapping_rows (w, yb)
3736 struct window *w;
3737 int yb;
3738 {
3739 int i, bottom_y;
3740 struct glyph_row *row;
3741 struct redisplay_interface *rif = FRAME_RIF (XFRAME (WINDOW_FRAME (w)));
3742
3743 for (i = 0; i < w->current_matrix->nrows; ++i)
3744 {
3745 row = w->current_matrix->rows + i;
3746
3747 if (!row->enabled_p)
3748 break;
3749 else if (row->mode_line_p)
3750 continue;
3751
3752 bottom_y = MATRIX_ROW_BOTTOM_Y (row);
3753
3754 if (row->overlapping_p)
3755 {
3756 int overlaps = 0;
3757
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;
3764
3765 if (overlaps)
3766 {
3767 if (row->used[LEFT_MARGIN_AREA])
3768 rif->fix_overlapping_area (w, row, LEFT_MARGIN_AREA, overlaps);
3769
3770 if (row->used[TEXT_AREA])
3771 rif->fix_overlapping_area (w, row, TEXT_AREA, overlaps);
3772
3773 if (row->used[RIGHT_MARGIN_AREA])
3774 rif->fix_overlapping_area (w, row, RIGHT_MARGIN_AREA, overlaps);
3775
3776 3777
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;
3782 }
3783 }
3784
3785 if (bottom_y >= yb)
3786 break;
3787 }
3788 }
3789
3790 #endif
3791
3792
3793 #ifdef GLYPH_DEBUG
3794
3795 3796
3797
3798 void
3799 check_current_matrix_flags (w)
3800 struct window *w;
3801 {
3802 int last_seen_p = 0;
3803 int i, yb = window_text_bottom_y (w);
3804
3805 for (i = 0; i < w->current_matrix->nrows - 1; ++i)
3806 {
3807 struct glyph_row *row = MATRIX_ROW (w->current_matrix, i);
3808 if (!last_seen_p && MATRIX_ROW_BOTTOM_Y (row) >= yb)
3809 last_seen_p = 1;
3810 else if (last_seen_p && row->enabled_p)
3811 abort ();
3812 }
3813 }
3814
3815 #endif
3816
3817
3818 3819
3820
3821 static int
3822 update_window (w, force_p)
3823 struct window *w;
3824 int force_p;
3825 {
3826 struct glyph_matrix *desired_matrix = w->desired_matrix;
3827 int paused_p;
3828 #if !PERIODIC_PREEMPTION_CHECKING
3829 int preempt_count = baud_rate / 2400 + 1;
3830 #endif
3831 extern int input_pending;
3832 extern Lisp_Object do_mouse_tracking;
3833 struct redisplay_interface *rif = FRAME_RIF (XFRAME (WINDOW_FRAME (w)));
3834 #if GLYPH_DEBUG
3835
3836 xassert (FRAME_WINDOW_P (XFRAME (WINDOW_FRAME (w))));
3837 #endif
3838
3839
3840 #if !PERIODIC_PREEMPTION_CHECKING
3841 if (!force_p)
3842 detect_input_pending_ignore_squeezables ();
3843 #endif
3844
3845 3846
3847 if (force_p || !input_pending || !NILP (do_mouse_tracking))
3848 {
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;
3853
3854 rif->update_window_begin_hook (w);
3855 yb = window_text_bottom_y (w);
3856
3857 3858
3859 row = desired_matrix->rows;
3860 end = row + desired_matrix->nrows - 1;
3861
3862 if (row->mode_line_p)
3863 {
3864 header_line_row = row;
3865 ++row;
3866 }
3867 else
3868 header_line_row = NULL;
3869
3870
3871 mode_line_row = MATRIX_MODE_LINE_ROW (desired_matrix);
3872 if (mode_line_row->mode_line_p && mode_line_row->enabled_p)
3873 {
3874 mode_line_row->y = yb;
3875 update_window_line (w, MATRIX_ROW_VPOS (mode_line_row,
3876 desired_matrix),
3877 &mouse_face_overwritten_p);
3878 }
3879
3880 3881 3882
3883 while (row < end && !row->enabled_p)
3884 ++row;
3885
3886
3887 if (row < end && !desired_matrix->no_scrolling_p)
3888 {
3889 int rc = scrolling_window (w, header_line_row != NULL);
3890 if (rc < 0)
3891 {
3892
3893 paused_p = 0;
3894 goto set_cursor;
3895 }
3896 else if (rc > 0)
3897 {
3898
3899 force_p = 1;
3900 changed_p = 1;
3901 }
3902 }
3903
3904
3905 for (n_updated = 0; row < end && (force_p || !input_pending); ++row)
3906 if (row->enabled_p)
3907 {
3908 int vpos = MATRIX_ROW_VPOS (row, desired_matrix);
3909 int i;
3910
3911 3912 3913 3914
3915 #if PERIODIC_PREEMPTION_CHECKING
3916 if (!force_p)
3917 {
3918 EMACS_TIME tm, dif;
3919 EMACS_GET_TIME (tm);
3920 EMACS_SUB_TIME (dif, preemption_next_check, tm);
3921 if (EMACS_TIME_NEG_P (dif))
3922 {
3923 EMACS_ADD_TIME (preemption_next_check, tm, preemption_period);
3924 if (detect_input_pending_ignore_squeezables ())
3925 break;
3926 }
3927 }
3928 #else
3929 if (!force_p && ++n_updated % preempt_count == 0)
3930 detect_input_pending_ignore_squeezables ();
3931 #endif
3932 changed_p |= update_window_line (w, vpos,
3933 &mouse_face_overwritten_p);
3934
3935 3936 3937 3938 3939 3940 3941 3942 3943
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;
3947 }
3948
3949
3950 paused_p = row < end;
3951
3952 set_cursor:
3953
3954 3955 3956
3957 if (header_line_row && header_line_row->enabled_p)
3958 {
3959 header_line_row->y = 0;
3960 update_window_line (w, 0, &mouse_face_overwritten_p);
3961 }
3962
3963
3964 if (!paused_p && !w->pseudo_window_p)
3965 {
3966 #ifdef HAVE_WINDOW_SYSTEM
3967 if (changed_p && rif->fix_overlapping_area)
3968 {
3969 redraw_overlapped_rows (w, yb);
3970 redraw_overlapping_rows (w, yb);
3971 }
3972 #endif
3973
3974
3975 set_window_cursor_after_update (w);
3976
3977 #if 0 3978
3979 IF_DEBUG (check_matrix_invariants (w));
3980 #endif
3981 }
3982
3983 #if GLYPH_DEBUG
3984
3985 strcpy (w->current_matrix->method, w->desired_matrix->method);
3986 #endif
3987
3988 #ifdef HAVE_WINDOW_SYSTEM
3989 update_window_fringes (w, 0);
3990 #endif
3991
3992 3993 3994 3995
3996 rif->update_window_end_hook (w, !paused_p, mouse_face_overwritten_p);
3997 }
3998 else
3999 paused_p = 1;
4000
4001 #if GLYPH_DEBUG
4002
4003 add_window_display_history (w, w->current_matrix->method, paused_p);
4004 #endif
4005
4006 clear_glyph_matrix (desired_matrix);
4007
4008 return paused_p;
4009 }
4010
4011
4012 4013
4014
4015 static void
4016 update_marginal_area (w, area, vpos)
4017 struct window *w;
4018 int area, vpos;
4019 {
4020 struct glyph_row *desired_row = MATRIX_ROW (w->desired_matrix, vpos);
4021 struct redisplay_interface *rif = FRAME_RIF (XFRAME (WINDOW_FRAME (w)));
4022
4023 4024
4025 updated_area = area;
4026
4027 4028 4029
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);
4034 }
4035
4036
4037 4038
4039
4040 static int
4041 update_text_area (w, vpos)
4042 struct window *w;
4043 int vpos;
4044 {
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)));
4048 int changed_p = 0;
4049
4050 4051
4052 updated_area = TEXT_AREA;
4053
4054 4055
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 4064 4065 4066 4067 4068
4069 || (current_row->mouse_face_p
4070 && !(current_row->mode_line_p && vpos > 0))
4071 || current_row->x != desired_row->x)
4072 {
4073 rif->cursor_to (vpos, 0, desired_row->y, desired_row->x);
4074
4075 if (desired_row->used[TEXT_AREA])
4076 rif->write_glyphs (desired_row->glyphs[TEXT_AREA],
4077 desired_row->used[TEXT_AREA]);
4078
4079
4080 rif->clear_end_of_line (-1);
4081 changed_p = 1;
4082
4083 4084 4085 4086 4087 4088 4089
4090 if (vpos == w->phys_cursor.vpos)
4091 w->phys_cursor_on_p = 0;
4092 }
4093 else
4094 {
4095 int stop, i, x;
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;
4101
4102 4103 4104 4105
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))))
4110 --desired_stop_pos;
4111
4112 stop = min (current_row->used[TEXT_AREA], desired_stop_pos);
4113 i = 0;
4114 x = desired_row->x;
4115
4116 4117
4118 while (i < stop)
4119 {
4120 int can_skip_p = !abort_skipping;
4121
4122 4123 4124 4125 4126 4127 4128 4129
4130 if (overlapping_glyphs_p && i > 0)
4131 {
4132 struct glyph *glyph = ¤t_row->glyphs[TEXT_AREA][i - 1];
4133 int left, right;
4134
4135 rif->get_glyph_overhangs (glyph, XFRAME (w->frame),
4136 &left, &right);
4137 can_skip_p = (right == 0 && !abort_skipping);
4138 }
4139
4140 if (can_skip_p)
4141 {
4142 int start_hpos = i;
4143
4144 while (i < stop
4145 && GLYPH_EQUAL_P (desired_glyph, current_glyph))
4146 {
4147 x += desired_glyph->pixel_width;
4148 ++desired_glyph, ++current_glyph, ++i;
4149 }
4150
4151 4152 4153 4154 4155 4156 4157 4158
4159 if (overlapping_glyphs_p
4160 && i > 0
4161 && i < current_row->used[TEXT_AREA]
4162 && (current_row->used[TEXT_AREA]
4163 != desired_row->used[TEXT_AREA]))
4164 {
4165 int left, right;
4166
4167 rif->get_glyph_overhangs (current_glyph, XFRAME (w->frame),
4168 &left, &right);
4169 while (left > 0 && i > 0)
4170 {
4171 --i, --desired_glyph, --current_glyph;
4172 x -= desired_glyph->pixel_width;
4173 left -= desired_glyph->pixel_width;
4174 }
4175
4176 4177 4178 4179
4180 abort_skipping = (i < start_hpos);
4181 }
4182 }
4183
4184 4185 4186 4187
4188 if (i < desired_row->used[TEXT_AREA])
4189 {
4190 int start_x = x, start_hpos = i;
4191 struct glyph *start = desired_glyph;
4192 int current_x = x;
4193 int skip_first_p = !can_skip_p;
4194
4195
4196 while (i < stop
4197 && (skip_first_p
4198 || !GLYPH_EQUAL_P (desired_glyph, current_glyph))
4199 && x == current_x)
4200 {
4201 x += desired_glyph->pixel_width;
4202 current_x += current_glyph->pixel_width;
4203 ++desired_glyph, ++current_glyph, ++i;
4204 skip_first_p = 0;
4205 }
4206
4207 if (i == start_hpos || x != current_x)
4208 {
4209 i = start_hpos;
4210 x = start_x;
4211 desired_glyph = start;
4212 break;
4213 }
4214
4215 rif->cursor_to (vpos, start_hpos, desired_row->y, start_x);
4216 rif->write_glyphs (start, i - start_hpos);
4217 changed_p = 1;
4218 }
4219 }
4220
4221
4222 if (i < desired_row->used[TEXT_AREA])
4223 {
4224 rif->cursor_to (vpos, i, desired_row->y, x);
4225 rif->write_glyphs (desired_glyph, desired_row->used[TEXT_AREA] - i);
4226 changed_p = 1;
4227 }
4228
4229
4230 if (MATRIX_ROW_EXTENDS_FACE_P (desired_row))
4231 {
4232 4233 4234 4235
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)));
4240 }
4241 else if (MATRIX_ROW_EXTENDS_FACE_P (current_row))
4242 {
4243
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);
4248 changed_p = 1;
4249 }
4250 else if (desired_row->pixel_width < current_row->pixel_width)
4251 {
4252 4253
4254 int x;
4255
4256 if (i >= desired_row->used[TEXT_AREA])
4257 rif->cursor_to (vpos, i, desired_row->y,
4258 desired_row->pixel_width);
4259
4260 4261 4262 4263 4264
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])))
4269 {
4270 w->phys_cursor_on_p = 0;
4271 x = -1;
4272 }
4273 else
4274 x = current_row->pixel_width;
4275 rif->clear_end_of_line (x);
4276 changed_p = 1;
4277 }
4278 }
4279
4280 return changed_p;
4281 }
4282
4283
4284 4285
4286
4287 static int
4288 update_window_line (w, vpos, mouse_face_overwritten_p)
4289 struct window *w;
4290 int vpos, *mouse_face_overwritten_p;
4291 {
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)));
4295 int changed_p = 0;
4296
4297 4298
4299 updated_row = desired_row;
4300
4301 4302 4303 4304
4305 if (desired_row->mode_line_p
4306 || desired_row->visible_height > 0)
4307 {
4308 xassert (desired_row->enabled_p);
4309
4310
4311 if (!desired_row->full_width_p
4312 && !NILP (w->left_margin_cols))
4313 {
4314 changed_p = 1;
4315 update_marginal_area (w, LEFT_MARGIN_AREA, vpos);
4316 }
4317
4318
4319 if (update_text_area (w, vpos))
4320 {
4321 changed_p = 1;
4322 if (current_row->mouse_face_p)
4323 *mouse_face_overwritten_p = 1;
4324 }
4325
4326
4327 if (!desired_row->full_width_p
4328 && !NILP (w->right_margin_cols))
4329 {
4330 changed_p = 1;
4331 update_marginal_area (w, RIGHT_MARGIN_AREA, vpos);
4332 }
4333
4334
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);
4346 }
4347
4348
4349 make_current (w->desired_matrix, w->current_matrix, vpos);
4350 updated_row = NULL;
4351 return changed_p;
4352 }
4353
4354
4355 4356
4357
4358 static void
4359 set_window_cursor_after_update (w)
4360 struct window *w;
4361 {
4362 struct frame *f = XFRAME (w->frame);
4363 struct redisplay_interface *rif = FRAME_RIF (f);
4364 int cx, cy, vpos, hpos;
4365
4366
4367 xassert (FRAME_WINDOW_P (f));
4368
4369 if (cursor_in_echo_area
4370 && !NILP (echo_area_buffer[0])
4371 4372
4373 && XWINDOW (minibuf_window) == w
4374 && EQ (minibuf_window, echo_area_window)
4375 4376
4377 && FRAME_HAS_MINIBUF_P (f)
4378 && EQ (FRAME_MINIBUF_WINDOW (f), echo_area_window))
4379 {
4380 cx = cy = vpos = hpos = 0;
4381
4382 if (cursor_in_echo_area >= 0)
4383 {
4384 4385 4386 4387
4388 struct glyph_row *row, *last_row;
4389 struct glyph *glyph;
4390 int yb = window_text_bottom_y (w);
4391
4392 last_row = NULL;
4393 row = w->current_matrix->rows;
4394 while (row->enabled_p
4395 && (last_row == NULL
4396 || MATRIX_ROW_BOTTOM_Y (row) <= yb))
4397 {
4398 if (row->used[TEXT_AREA]
4399 && row->glyphs[TEXT_AREA][0].charpos >= 0)
4400 last_row = row;
4401 ++row;
4402 }
4403
4404 if (last_row)
4405 {
4406 struct glyph *start = last_row->glyphs[TEXT_AREA];
4407 struct glyph *last = start + last_row->used[TEXT_AREA] - 1;
4408
4409 while (last > start && last->charpos < 0)
4410 --last;
4411
4412 for (glyph = start; glyph < last; ++glyph)
4413 {
4414 cx += glyph->pixel_width;
4415 ++hpos;
4416 }
4417
4418 cy = last_row->y;
4419 vpos = MATRIX_ROW_VPOS (last_row, w->current_matrix);
4420 }
4421 }
4422 }
4423 else
4424 {
4425 cx = w->cursor.x;
4426 cy = w->cursor.y;
4427 hpos = w->cursor.hpos;
4428 vpos = w->cursor.vpos;
4429 }
4430
4431
4432 hpos = max (-1, hpos);
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);
4437 }
4438
4439
4440 4441
4442
4443 void
4444 set_window_update_flags (w, on_p)
4445 struct window *w;
4446 int on_p;
4447 {
4448 while (w)
4449 {
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);
4454 else
4455 w->must_be_updated_p = on_p;
4456
4457 w = NILP (w->next) ? 0 : XWINDOW (w->next);
4458 }
4459 }
4460
4461
4462
4463 4464 4465
4466
4467
4468
4469 struct row_entry
4470 {
4471
4472 int old_uses, new_uses;
4473
4474
4475 int new_line_number;
4476
4477
4478 int bucket;
4479
4480
4481 struct glyph_row *row;
4482
4483
4484 struct row_entry *next;
4485 };
4486
4487 4488 4489
4490
4491 static struct row_entry *row_entry_pool;
4492 static int row_entry_pool_size;
4493
4494
4495
4496 static int row_entry_idx;
4497
4498 4499 4500
4501
4502 static struct row_entry **row_table;
4503 static int row_table_size;
4504
4505 4506
4507
4508 static struct row_entry **old_lines, **new_lines;
4509 static int old_lines_size, new_lines_size;
4510
4511
4512
4513 static struct run *run_pool;
4514 static int runs_size;
4515
4516
4517
4518 static struct run **runs;
4519
4520 4521
4522
4523 static INLINE struct row_entry *
4524 add_row_entry (w, row)
4525 struct window *w;
4526 struct glyph_row *row;
4527 {
4528 struct row_entry *entry;
4529 int i = row->hash % row_table_size;
4530
4531 entry = row_table[i];
4532 while (entry && !row_equal_p (w, entry->row, row, 1))
4533 entry = entry->next;
4534
4535 if (entry == NULL)
4536 {
4537 entry = row_entry_pool + row_entry_idx++;
4538 entry->row = row;
4539 entry->old_uses = entry->new_uses = 0;
4540 entry->new_line_number = 0;
4541 entry->bucket = i;
4542 entry->next = row_table[i];
4543 row_table[i] = entry;
4544 }
4545
4546 return entry;
4547 }
4548
4549
4550 4551 4552 4553 4554 4555 4556 4557 4558 4559 4560 4561 4562 4563 4564 4565 4566 4567 4568 4569 4570 4571 4572 4573 4574
4575
4576 static int
4577 scrolling_window (w, header_line_p)
4578 struct window *w;
4579 int header_line_p;
4580 {
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)));
4588
4589
4590 for (i = header_line_p ? 1 : 0; i < current_matrix->nrows - 1; ++i)
4591 {
4592 struct glyph_row *d = MATRIX_ROW (desired_matrix, i);
4593 struct glyph_row *c = MATRIX_ROW (current_matrix, i);
4594
4595 if (c->enabled_p
4596 && d->enabled_p
4597 && !d->redraw_fringe_bitmaps_p
4598 && c->y == d->y
4599 && MATRIX_ROW_BOTTOM_Y (c) <= yb
4600 && MATRIX_ROW_BOTTOM_Y (d) <= yb
4601 && row_equal_p (w, c, d, 1))
4602 {
4603 assign_row (c, d);
4604 d->enabled_p = 0;
4605 }
4606 else
4607 break;
4608 }
4609
4610
4611 if (!MATRIX_ROW (desired_matrix, i)->enabled_p)
4612 return -1;
4613
4614 first_old = first_new = i;
4615
4616 4617
4618 i = first_new + 1;
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)
4622 ++i;
4623
4624 if (!MATRIX_ROW (desired_matrix, i)->enabled_p)
4625 return 0;
4626
4627 last_new = i;
4628
4629 4630 4631 4632
4633 i = first_old + 1;
4634 while (i < current_matrix->nrows - 1)
4635 {
4636 int bottom = MATRIX_ROW_BOTTOM_Y (MATRIX_ROW (current_matrix, i));
4637 if (bottom <= yb)
4638 ++i;
4639 if (bottom >= yb)
4640 break;
4641 }
4642
4643 last_old = i;
4644
4645
4646 i = last_new;
4647 j = last_old;
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
4654 && row_equal_p (w,
4655 MATRIX_ROW (desired_matrix, i - 1),
4656 MATRIX_ROW (current_matrix, j - 1), 1))
4657 --i, --j;
4658 last_new = i;
4659 last_old = j;
4660
4661
4662 if (last_new == first_new)
4663 return 0;
4664
4665
4666
4667 if (current_matrix->nrows > old_lines_size)
4668 {
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);
4672 }
4673
4674 if (desired_matrix->nrows > new_lines_size)
4675 {
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);
4679 }
4680
4681 n = desired_matrix->nrows + current_matrix->nrows;
4682 if (3 * n > row_table_size)
4683 {
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);
4688 }
4689
4690 if (n > row_entry_pool_size)
4691 {
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);
4695 }
4696
4697 if (desired_matrix->nrows > runs_size)
4698 {
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);
4704 }
4705
4706 nruns = run_idx = 0;
4707 row_entry_idx = 0;
4708
4709 4710
4711
4712 for (i = first_old; i < last_old; ++i)
4713 {
4714 if (MATRIX_ROW (current_matrix, i)->enabled_p)
4715 {
4716 entry = add_row_entry (w, MATRIX_ROW (current_matrix, i));
4717 old_lines[i] = entry;
4718 ++entry->old_uses;
4719 }
4720 else
4721 old_lines[i] = NULL;
4722 }
4723
4724 for (i = first_new; i < last_new; ++i)
4725 {
4726 xassert (MATRIX_ROW_ENABLED_P (desired_matrix, i));
4727 entry = add_row_entry (w, MATRIX_ROW (desired_matrix, i));
4728 ++entry->new_uses;
4729 entry->new_line_number = i;
4730 new_lines[i] = entry;
4731 }
4732
4733 4734
4735 for (i = first_old; i < last_old;)
4736 if (old_lines[i]
4737 && old_lines[i]->old_uses == 1
4738 && old_lines[i]->new_uses == 1)
4739 {
4740 int j, k;
4741 int new_line = old_lines[i]->new_line_number;
4742 struct run *run = run_pool + run_idx++;
4743
4744
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;
4749 run->nrows = 1;
4750 run->height = MATRIX_ROW (current_matrix, i)->height;
4751
4752
4753 j = i - 1;
4754 k = new_line - 1;
4755 while (j > first_old
4756 && k > first_new
4757 && old_lines[j] == new_lines[k])
4758 {
4759 int h = MATRIX_ROW (current_matrix, j)->height;
4760 --run->current_vpos;
4761 --run->desired_vpos;
4762 ++run->nrows;
4763 run->height += h;
4764 run->desired_y -= h;
4765 run->current_y -= h;
4766 --j, --k;
4767 }
4768
4769
4770 j = i + 1;
4771 k = new_line + 1;
4772 while (j < last_old
4773 && k < last_new
4774 && old_lines[j] == new_lines[k])
4775 {
4776 int h = MATRIX_ROW (current_matrix, j)->height;
4777 ++run->nrows;
4778 run->height += h;
4779 ++j, ++k;
4780 }
4781
4782 4783 4784 4785 4786
4787 for (j = 0; j < nruns && runs[j]->height > run->height; ++j)
4788 ;
4789 for (k = nruns; k > j; --k)
4790 runs[k] = runs[k - 1];
4791 runs[j] = run;
4792 ++nruns;
4793
4794 i += run->nrows;
4795 }
4796 else
4797 ++i;
4798
4799 4800 4801 4802 4803 4804 4805 4806 4807 4808 4809 4810 4811
4812
4813 for (i = 0; i < nruns; ++i)
4814 if (runs[i]->nrows > 0)
4815 {
4816 struct run *r = runs[i];
4817
4818
4819 if (r->current_y != r->desired_y)
4820 {
4821 rif->scroll_run_hook (w, r);
4822
4823
4824 for (j = i + 1; j < nruns; ++j)
4825 {
4826 struct run *p = runs[j];
4827
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)))
4833 p->nrows = 0;
4834 }
4835 }
4836
4837
4838 for (j = 0; j < r->nrows; ++j)
4839 {
4840 struct glyph_row *from, *to;
4841 int to_overlapped_p;
4842
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;
4856 }
4857 }
4858
4859
4860 for (i = 0; i < row_entry_idx; ++i)
4861 row_table[row_entry_pool[i].bucket] = NULL;
4862
4863
4864 return nruns;
4865 }
4866
4867
4868
4869 4870 4871
4872
4873 4874 4875 4876 4877 4878 4879
4880
4881 static int
4882 update_frame_1 (f, force_p, inhibit_id_p)
4883 struct frame *f;
4884 int force_p;
4885 int inhibit_id_p;
4886 {
4887
4888 struct glyph_matrix *current_matrix = f->current_matrix;
4889 struct glyph_matrix *desired_matrix = f->desired_matrix;
4890 int i;
4891 int pause;
4892 int preempt_count = baud_rate / 2400 + 1;
4893 extern int input_pending;
4894
4895 xassert (current_matrix && desired_matrix);
4896
4897 if (baud_rate != FRAME_COST_BAUD_RATE (f))
4898 calculate_costs (f);
4899
4900 if (preempt_count <= 0)
4901 preempt_count = 1;
4902
4903 #if !PERIODIC_PREEMPTION_CHECKING
4904 if (!force_p && detect_input_pending_ignore_squeezables ())
4905 {
4906 pause = 1;
4907 goto do_pause;
4908 }
4909 #endif
4910
4911
4912 if (!FRAME_LINE_INS_DEL_OK (f))
4913 inhibit_id_p = 1;
4914
4915 4916
4917 for (i = 0; i < desired_matrix->nrows; i++)
4918 if (MATRIX_ROW_ENABLED_P (desired_matrix, i))
4919 break;
4920
4921
4922 if (!inhibit_id_p && i < desired_matrix->nrows)
4923 force_p |= scrolling (f);
4924
4925
4926 if (MATRIX_ROW_ENABLED_P (desired_matrix, desired_matrix->nrows - 1))
4927 update_frame_line (f, desired_matrix->nrows - 1);
4928
4929
4930 for (i = 0; i < desired_matrix->nrows - 1 && (force_p || !input_pending); i++)
4931 {
4932 if (MATRIX_ROW_ENABLED_P (desired_matrix, i))
4933 {
4934 if (FRAME_TERMCAP_P (f))
4935 {
4936 4937 4938 4939
4940 FILE *display_output = FRAME_TTY (f)->output;
4941 if (display_output)
4942 {
4943 int outq = PENDING_OUTPUT_COUNT (display_output);
4944 if (outq > 900
4945 || (outq > 20 && ((i - 1) % preempt_count == 0)))
4946 {
4947 fflush (display_output);
4948 if (preempt_count == 1)
4949 {
4950 #ifdef EMACS_OUTQSIZE
4951 if (EMACS_OUTQSIZE (0, &outq) < 0)
4952 4953
4954 outq = PENDING_OUTPUT_COUNT (FRAME_TTY (f->output));
4955 #endif
4956 outq *= 10;
4957 if (baud_rate <= outq && baud_rate > 0)
4958 sleep (outq / baud_rate);
4959 }
4960 }
4961 }
4962 }
4963
4964 #if PERIODIC_PREEMPTION_CHECKING
4965 if (!force_p)
4966 {
4967 EMACS_TIME tm, dif;
4968 EMACS_GET_TIME (tm);
4969 EMACS_SUB_TIME (dif, preemption_next_check, tm);
4970 if (EMACS_TIME_NEG_P (dif))
4971 {
4972 EMACS_ADD_TIME (preemption_next_check, tm, preemption_period);
4973 if (detect_input_pending_ignore_squeezables ())
4974 break;
4975 }
4976 }
4977 #else
4978 if (!force_p && (i - 1) % preempt_count == 0)
4979 detect_input_pending_ignore_squeezables ();
4980 #endif
4981
4982 update_frame_line (f, i);
4983 }
4984 }
4985
4986 pause = (i < FRAME_LINES (f) - 1) ? i : 0;
4987
4988
4989 if (!pause)
4990 {
4991 if ((cursor_in_echo_area
4992 4993 4994
4995 || (EQ (minibuf_window, selected_window)
4996 && EQ (minibuf_window, echo_area_window)
4997 && !NILP (echo_area_buffer[0])))
4998 4999
5000 && FRAME_HAS_MINIBUF_P (f)
5001 && EQ (FRAME_MINIBUF_WINDOW (f), echo_area_window))
5002 {
5003 int top = WINDOW_TOP_EDGE_LINE (XWINDOW (FRAME_MINIBUF_WINDOW (f)));
5004 int row, col;
5005
5006 if (cursor_in_echo_area < 0)
5007 {
5008 5009
5010 row = top;
5011 col = 0;
5012 }
5013 else
5014 {
5015 5016 5017 5018
5019 row = FRAME_LINES (f);
5020 do
5021 {
5022 --row;
5023 col = 0;
5024
5025 if (MATRIX_ROW_ENABLED_P (current_matrix, row))
5026 {
5027 5028
5029 struct glyph_row *r = MATRIX_ROW (current_matrix,
5030 row);
5031 struct glyph *start = r->glyphs[TEXT_AREA];
5032 struct glyph *last = start + r->used[TEXT_AREA];
5033
5034 while (last > start
5035 && (last - 1)->charpos < 0)
5036 --last;
5037
5038 col = last - start;
5039 }
5040 }
5041 while (row > top && col == 0);
5042
5043
5044 if (col >= FRAME_CURSOR_X_LIMIT (f))
5045 {
5046
5047 if (row < FRAME_LINES (f) - 1)
5048 {
5049 col = FRAME_LEFT_SCROLL_BAR_COLS (f);
5050 row++;
5051 }
5052
5053 else
5054 col = FRAME_CURSOR_X_LIMIT (f) - 1;
5055 }
5056 }
5057
5058 cursor_to (f, row, col);
5059 }
5060 else
5061 {
5062 5063
5064 struct window *w = XWINDOW (FRAME_SELECTED_WINDOW (f));
5065 if (w->cursor.vpos >= 0
5066 5067 5068 5069 5070
5071 && w->cursor.vpos < WINDOW_TOTAL_LINES (w))
5072 {
5073 int x = WINDOW_TO_FRAME_HPOS (w, w->cursor.hpos);
5074 int y = WINDOW_TO_FRAME_VPOS (w, w->cursor.vpos);
5075
5076 if (INTEGERP (w->left_margin_cols))
5077 x += XFASTINT (w->left_margin_cols);
5078
5079
5080 cursor_to (f, y, x);
5081 }
5082 }
5083 }
5084
5085 do_pause:
5086
5087 clear_desired_matrices (f);
5088 return pause;
5089 }
5090
5091
5092
5093
5094 int
5095 scrolling (frame)
5096 struct frame *frame;
5097 {
5098 int unchanged_at_top, unchanged_at_bottom;
5099 int window_size;
5100 int changed_lines;
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));
5105 register int i;
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;
5109
5110 if (!current_matrix)
5111 abort ();
5112
5113 5114 5115
5116 changed_lines = 0;
5117 unchanged_at_top = 0;
5118 unchanged_at_bottom = FRAME_LINES (frame);
5119 for (i = 0; i < FRAME_LINES (frame); i++)
5120 {
5121
5122 if (!MATRIX_ROW_ENABLED_P (current_matrix, i))
5123 return 0;
5124 old_hash[i] = line_hash_code (MATRIX_ROW (current_matrix, i));
5125 if (! MATRIX_ROW_ENABLED_P (desired_matrix, i))
5126 {
5127
5128 new_hash[i] = old_hash[i];
5129 #define INFINITY 1000000
5130 draw_cost[i] = INFINITY;
5131 }
5132 else
5133 {
5134 new_hash[i] = line_hash_code (MATRIX_ROW (desired_matrix, i));
5135 draw_cost[i] = line_draw_cost (desired_matrix, i);
5136 }
5137
5138 if (old_hash[i] != new_hash[i])
5139 {
5140 changed_lines++;
5141 unchanged_at_bottom = FRAME_LINES (frame) - i - 1;
5142 }
5143 else if (i == unchanged_at_top)
5144 unchanged_at_top++;
5145 old_draw_cost[i] = line_draw_cost (current_matrix, i);
5146 }
5147
5148
5149 if ((!FRAME_SCROLL_REGION_OK (frame)
5150 && changed_lines < baud_rate / 2400)
5151 || unchanged_at_bottom == FRAME_LINES (frame))
5152 return 1;
5153
5154 window_size = (FRAME_LINES (frame) - unchanged_at_top
5155 - unchanged_at_bottom);
5156
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;
5161
5162 5163
5164 if (!FRAME_SCROLL_REGION_OK (frame)
5165 && window_size >= 18 && baud_rate > 2400
5166 && (window_size >=
5167 10 * scrolling_max_lines_saved (unchanged_at_top,
5168 FRAME_LINES (frame) - unchanged_at_bottom,
5169 old_hash, new_hash, draw_cost)))
5170 return 0;
5171
5172 if (window_size < 2)
5173 return 0;
5174
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);
5181
5182 return 0;
5183 }
5184
5185
5186 5187
5188
5189 static int
5190 count_blanks (r, len)
5191 struct glyph *r;
5192 int len;
5193 {
5194 int i;
5195
5196 for (i = 0; i < len; ++i)
5197 if (!CHAR_GLYPH_SPACE_P (r[i]))
5198 break;
5199
5200 return i;
5201 }
5202
5203
5204 5205 5206
5207
5208 static int
5209 count_match (str1, end1, str2, end2)
5210 struct glyph *str1, *end1, *str2, *end2;
5211 {
5212 struct glyph *p1 = str1;
5213 struct glyph *p2 = str2;
5214
5215 while (p1 < end1
5216 && p2 < end2
5217 && GLYPH_CHAR_AND_FACE_EQUAL_P (p1, p2))
5218 ++p1, ++p2;
5219
5220 return p1 - str1;
5221 }
5222
5223
5224
5225
5226 extern int *char_ins_del_vector;
5227 #define char_ins_del_cost(f) (&char_ins_del_vector[FRAME_TOTAL_COLS((f))])
5228
5229
5230
5231
5232 static void
5233 update_frame_line (f, vpos)
5234 struct frame *f;
5235 int vpos;
5236 {
5237 struct glyph *obody, *nbody, *op1, *op2, *np1, *nend;
5238 int tem;
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);
5248
5249 if (colored_spaces_p)
5250 write_spaces_p = 1;
5251
5252 5253
5254 must_write_whole_line_p = !current_row->enabled_p;
5255 if (must_write_whole_line_p)
5256 {
5257 obody = 0;
5258 olen = 0;
5259 }
5260 else
5261 {
5262 obody = MATRIX_ROW_GLYPH_START (current_matrix, vpos);
5263 olen = current_row->used[TEXT_AREA];
5264
5265
5266 if (!write_spaces_p)
5267 while (olen > 0 && CHAR_GLYPH_SPACE_P (obody[olen-1]))
5268 olen--;
5269 }
5270
5271 current_row->enabled_p = 1;
5272 current_row->used[TEXT_AREA] = desired_row->used[TEXT_AREA];
5273
5274
5275 if (!desired_row->enabled_p)
5276 {
5277 nlen = 0;
5278 goto just_erase;
5279 }
5280
5281 nbody = desired_row->glyphs[TEXT_AREA];
5282 nlen = desired_row->used[TEXT_AREA];
5283 nend = nbody + nlen;
5284
5285
5286 if (must_write_whole_line_p)
5287 {
5288
5289 if (!write_spaces_p)
5290 while (nlen > 0 && CHAR_GLYPH_SPACE_P (nbody[nlen - 1]))
5291 --nlen;
5292
5293
5294 if (nlen)
5295 {
5296 cursor_to (f, vpos, 0);
5297 write_glyphs (f, nbody, nlen);
5298 }
5299
5300 5301 5302
5303 if (nlen < FRAME_TOTAL_COLS (f))
5304 {
5305 cursor_to (f, vpos, nlen);
5306 clear_end_of_line (f, FRAME_TOTAL_COLS (f));
5307 }
5308 else
5309 5310
5311 cursor_to (f, vpos, 0);
5312
5313 make_current (desired_matrix, current_matrix, vpos);
5314 return;
5315 }
5316
5317 5318
5319 if (!write_spaces_p)
5320 while (nlen > 0 && CHAR_GLYPH_SPACE_P (nbody[nlen - 1]))
5321 nlen--;
5322
5323
5324 if (!FRAME_CHAR_INS_DEL_OK (f))
5325 {
5326 int i, j;
5327
5328 5329
5330 for (i = 0; i < nlen; i++)
5331 {
5332 if (i >= olen || !GLYPH_EQUAL_P (nbody + i, obody + i))
5333 {
5334
5335 j = i + 1;
5336 while (j < nlen
5337 && (j >= olen
5338 || !GLYPH_EQUAL_P (nbody + j, obody + j)
5339 || CHAR_GLYPH_PADDING_P (nbody[j])))
5340 ++j;
5341
5342
5343 cursor_to (f, vpos, i);
5344 write_glyphs (f, nbody + i, j - i);
5345 i = j - 1;
5346
5347
5348 }
5349 }
5350
5351
5352 if (olen > nlen)
5353 {
5354 cursor_to (f, vpos, nlen);
5355 clear_end_of_line (f, olen);
5356 }
5357
5358
5359 make_current (desired_matrix, current_matrix, vpos);
5360 return;
5361 }
5362
5363 5364
5365
5366 if (!olen)
5367 {
5368 5369
5370 if (write_spaces_p)
5371 nsp = 0;
5372 else
5373 nsp = count_blanks (nbody, nlen);
5374
5375 if (nlen > nsp)
5376 {
5377 cursor_to (f, vpos, nsp);
5378 write_glyphs (f, nbody + nsp, nlen - nsp);
5379 }
5380
5381
5382 make_current (desired_matrix, current_matrix, vpos);
5383 return;
5384 }
5385
5386
5387 osp = count_blanks (obody, olen);
5388 nsp = (colored_spaces_p ? 0 : count_blanks (nbody, nlen));
5389
5390
5391 begmatch = count_match (obody + osp, obody + olen,
5392 nbody + nsp, nbody + nlen);
5393
5394
5395
5396 if (!write_spaces_p && osp + begmatch == olen)
5397 {
5398 np1 = nbody + nsp;
5399 while (np1 + begmatch < nend && CHAR_GLYPH_SPACE_P (np1[begmatch]))
5400 ++begmatch;
5401 }
5402
5403 5404 5405
5406 if (begmatch == 0 && osp != nsp)
5407 osp = nsp = min (osp, nsp);
5408
5409
5410 op1 = obody + olen;
5411 np1 = nbody + nlen;
5412 op2 = op1 + begmatch - min (olen - osp, nlen - nsp);
5413 while (op1 > op2
5414 && GLYPH_EQUAL_P (op1 - 1, np1 - 1))
5415 {
5416 op1--;
5417 np1--;
5418 }
5419 endmatch = obody + olen - op1;
5420
5421 5422 5423
5424
5425 tem = (nlen - nsp) - (olen - osp);
5426 if (endmatch && tem
5427 && (!FRAME_CHAR_INS_DEL_OK (f)
5428 || endmatch <= char_ins_del_cost (f)[tem]))
5429 endmatch = 0;
5430
5431 5432 5433 5434
5435
5436 if (nsp != osp
5437 && (!FRAME_CHAR_INS_DEL_OK (f)
5438 || begmatch + endmatch <= char_ins_del_cost (f)[nsp - osp]))
5439 {
5440 begmatch = 0;
5441 endmatch = 0;
5442 osp = nsp = min (osp, nsp);
5443 }
5444
5445 5446
5447
5448 if (osp > nsp)
5449 {
5450 cursor_to (f, vpos, nsp);
5451 delete_glyphs (f, osp - nsp);
5452 }
5453 else if (nsp > osp)
5454 {
5455 5456 5457
5458 if (endmatch && nlen < olen + nsp - osp)
5459 {
5460 cursor_to (f, vpos, nlen - endmatch + osp - nsp);
5461 delete_glyphs (f, olen + nsp - osp - nlen);
5462 olen = nlen - (nsp - osp);
5463 }
5464 cursor_to (f, vpos, osp);
5465 insert_glyphs (f, 0, nsp - osp);
5466 }
5467 olen += nsp - osp;
5468
5469 tem = nsp + begmatch + endmatch;
5470 if (nlen != tem || olen != tem)
5471 {
5472 if (!endmatch || nlen == olen)
5473 {
5474 5475 5476 5477
5478 if (nlen == FRAME_TOTAL_COLS (f))
5479 olen = 0;
5480
5481 5482 5483
5484 if (nlen - tem > 0)
5485 {
5486 cursor_to (f, vpos, nsp + begmatch);
5487 write_glyphs (f, nbody + nsp + begmatch, nlen - tem);
5488 }
5489 }
5490 else if (nlen > olen)
5491 {
5492 5493 5494 5495 5496 5497 5498
5499 int out = olen - tem;
5500 int del;
5501
5502 cursor_to (f, vpos, nsp + begmatch);
5503
5504
5505 while (CHAR_GLYPH_PADDING_P (nbody[nsp + begmatch + out]))
5506 out--;
5507 write_glyphs (f, nbody + nsp + begmatch, out);
5508
5509
5510 del = olen - tem - out;
5511 if (del > 0)
5512 delete_glyphs (f, del);
5513
5514
5515 insert_glyphs (f, nbody + nsp + begmatch + out, nlen - olen + del);
5516 olen = nlen;
5517 }
5518 else if (olen > nlen)
5519 {
5520 cursor_to (f, vpos, nsp + begmatch);
5521 write_glyphs (f, nbody + nsp + begmatch, nlen - tem);
5522 delete_glyphs (f, olen - nlen);
5523 olen = nlen;
5524 }
5525 }
5526
5527 just_erase:
5528
5529 if (olen > nlen)
5530 {
5531 cursor_to (f, vpos, nlen);
5532 clear_end_of_line (f, olen);
5533 }
5534
5535
5536 make_current (desired_matrix, current_matrix, vpos);
5537 }
5538
5539
5540
5541 5542 5543
5544
5545 5546 5547 5548
5549
5550 Lisp_Object
5551 buffer_posn_from_coords (w, x, y, pos, object, dx, dy, width, height)
5552 struct window *w;
5553 int *x, *y;
5554 struct display_pos *pos;
5555 Lisp_Object *object;
5556 int *dx, *dy;
5557 int *width, *height;
5558 {
5559 struct it it;
5560 Lisp_Object old_current_buffer = Fcurrent_buffer ();
5561 struct text_pos startp;
5562 Lisp_Object string;
5563 struct glyph_row *row;
5564 #ifdef HAVE_WINDOW_SYSTEM
5565 struct image *img = 0;
5566 #endif
5567 int x0, x1;
5568
5569 5570
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);
5576
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);
5580
5581 Fset_buffer (old_current_buffer);
5582
5583 *dx = x0 + it.first_visible_x - it.current_x;
5584 *dy = *y - it.current_y;
5585
5586 string = w->buffer;
5587 if (STRINGP (it.string))
5588 string = it.string;
5589 *pos = it.current;
5590
5591 #ifdef HAVE_WINDOW_SYSTEM
5592 if (it.what == IT_IMAGE)
5593 {
5594 if ((img = IMAGE_FROM_ID (it.f, it.image_id)) != NULL
5595 && !NILP (img->spec))
5596 *object = img->spec;
5597 }
5598 #endif
5599
5600 if (it.vpos < w->current_matrix->nrows
5601 && (row = MATRIX_ROW (w->current_matrix, it.vpos),
5602 row->enabled_p))
5603 {
5604 if (it.hpos < row->used[TEXT_AREA])
5605 {
5606 struct glyph *glyph = row->glyphs[TEXT_AREA] + it.hpos;
5607 #ifdef HAVE_WINDOW_SYSTEM
5608 if (img)
5609 {
5610 *dy -= row->ascent - glyph->ascent;
5611 *dx += glyph->slice.x;
5612 *dy += glyph->slice.y;
5613
5614 *width = img->width;
5615 *height = img->height;
5616 }
5617 else
5618 #endif
5619 {
5620 *width = glyph->pixel_width;
5621 *height = glyph->ascent + glyph->descent;
5622 }
5623 }
5624 else
5625 {
5626 *width = 0;
5627 *height = row->height;
5628 }
5629 }
5630 else
5631 {
5632 *width = *height = 0;
5633 }
5634
5635
5636 x1 = max(0, it.current_x + it.pixel_width - it.first_visible_x);
5637 if (x0 > x1)
5638 it.hpos += (x0 - x1) / WINDOW_FRAME_COLUMN_WIDTH (w);
5639
5640 *x = it.hpos;
5641 *y = it.vpos;
5642
5643 return string;
5644 }
5645
5646
5647 5648 5649
5650
5651 Lisp_Object
5652 mode_line_string (w, part, x, y, charpos, object, dx, dy, width, height)
5653 struct window *w;
5654 enum window_part part;
5655 int *x, *y;
5656 int *charpos;
5657 Lisp_Object *object;
5658 int *dx, *dy;
5659 int *width, *height;
5660 {
5661 struct glyph_row *row;
5662 struct glyph *glyph, *end;
5663 int x0, y0;
5664 Lisp_Object string = Qnil;
5665
5666 if (part == ON_MODE_LINE)
5667 row = MATRIX_MODE_LINE_ROW (w->current_matrix);
5668 else
5669 row = MATRIX_HEADER_LINE_ROW (w->current_matrix);
5670 y0 = *y - row->y;
5671 *y = row - MATRIX_FIRST_TEXT_ROW (w->current_matrix);
5672
5673 if (row->mode_line_p && row->enabled_p)
5674 {
5675 5676
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];
5682 if (glyph < end)
5683 {
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)
5690 {
5691 struct image *img;
5692 img = IMAGE_FROM_ID (WINDOW_XFRAME (w), glyph->u.img_id);
5693 if (img != NULL)
5694 *object = img->spec;
5695 y0 -= row->ascent - glyph->ascent;
5696 }
5697 #endif
5698 }
5699 else
5700 {
5701
5702 *x += x0 / WINDOW_FRAME_COLUMN_WIDTH (w);
5703 *width = 0;
5704 *height = row->height;
5705 }
5706 }
5707 else
5708 {
5709 *x = 0;
5710 x0 = 0;
5711 *width = *height = 0;
5712 }
5713
5714 *dx = x0;
5715 *dy = y0;
5716
5717 return string;
5718 }
5719
5720
5721 5722 5723
5724
5725 Lisp_Object
5726 marginal_area_string (w, part, x, y, charpos, object, dx, dy, width, height)
5727 struct window *w;
5728 enum window_part part;
5729 int *x, *y;
5730 int *charpos;
5731 Lisp_Object *object;
5732 int *dx, *dy;
5733 int *width, *height;
5734 {
5735 struct glyph_row *row = w->current_matrix->rows;
5736 struct glyph *glyph, *end;
5737 int x0, y0, i, wy = *y;
5738 int area;
5739 Lisp_Object string = Qnil;
5740
5741 if (part == ON_LEFT_MARGIN)
5742 area = LEFT_MARGIN_AREA;
5743 else if (part == ON_RIGHT_MARGIN)
5744 area = RIGHT_MARGIN_AREA;
5745 else
5746 abort ();
5747
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))
5750 break;
5751 y0 = *y - row->y;
5752 *y = row - MATRIX_FIRST_TEXT_ROW (w->current_matrix);
5753
5754 if (row->enabled_p)
5755 {
5756 5757
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));
5764 else
5765 x0 = (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w)
5766 ? WINDOW_LEFT_FRINGE_WIDTH (w)
5767 : 0);
5768
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];
5774 if (glyph < end)
5775 {
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)
5782 {
5783 struct image *img;
5784 img = IMAGE_FROM_ID (WINDOW_XFRAME (w), glyph->u.img_id);
5785 if (img != NULL)
5786 *object = img->spec;
5787 y0 -= row->ascent - glyph->ascent;
5788 x0 += glyph->slice.x;
5789 y0 += glyph->slice.y;
5790 }
5791 #endif
5792 }
5793 else
5794 {
5795
5796 *x += x0 / WINDOW_FRAME_COLUMN_WIDTH (w);
5797 *width = 0;
5798 *height = row->height;
5799 }
5800 }
5801 else
5802 {
5803 x0 = 0;
5804 *x = 0;
5805 *width = *height = 0;
5806 }
5807
5808 *dx = x0;
5809 *dy = y0;
5810
5811 return string;
5812 }
5813
5814
5815 5816 5817
5818
5819 #ifdef SIGWINCH
5820
5821 SIGTYPE
5822 window_change_signal (signalnum)
5823 int signalnum;
5824 {
5825 int width, height;
5826 int old_errno = errno;
5827
5828 struct tty_display_info *tty;
5829
5830 signal (SIGWINCH, window_change_signal);
5831 SIGNAL_THREAD_CHECK (signalnum);
5832
5833 5834 5835 5836
5837 for (tty = tty_list; tty; tty = tty->next) {
5838
5839 if (! tty->term_initted)
5840 continue;
5841
5842 5843
5844 if (!tty->input)
5845 continue;
5846
5847 get_tty_size (fileno (tty->input), &width, &height);
5848
5849 if (width > 5 && height > 2) {
5850 Lisp_Object tail, frame;
5851
5852 FOR_EACH_FRAME (tail, frame)
5853 if (FRAME_TERMCAP_P (XFRAME (frame)) && FRAME_TTY (XFRAME (frame)) == tty)
5854 5855 5856
5857 change_frame_size (XFRAME (frame), height, width, 0, 1, 0);
5858 }
5859 }
5860
5861 errno = old_errno;
5862 }
5863 #endif
5864
5865
5866 5867 5868
5869
5870 void
5871 do_pending_window_change (safe)
5872 int safe;
5873 {
5874
5875 if (redisplaying_p && !safe)
5876 return;
5877
5878 while (delayed_size_change)
5879 {
5880 Lisp_Object tail, frame;
5881
5882 delayed_size_change = 0;
5883
5884 FOR_EACH_FRAME (tail, frame)
5885 {
5886 struct frame *f = XFRAME (frame);
5887
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,
5890 0, 0, safe);
5891 }
5892 }
5893 }
5894
5895
5896 5897 5898 5899 5900 5901 5902 5903 5904 5905
5906
5907 void
5908 change_frame_size (f, newheight, newwidth, pretend, delay, safe)
5909 register struct frame *f;
5910 int newheight, newwidth, pretend, delay, safe;
5911 {
5912 Lisp_Object tail, frame;
5913
5914 if (FRAME_MSDOS_P (f))
5915 {
5916 5917 5918
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);
5923 }
5924 else
5925 change_frame_size_1 (f, newheight, newwidth, pretend, delay, safe);
5926 }
5927
5928 static void
5929 change_frame_size_1 (f, newheight, newwidth, pretend, delay, safe)
5930 register struct frame *f;
5931 int newheight, newwidth, pretend, delay, safe;
5932 {
5933 int new_frame_total_cols;
5934 int count = SPECPDL_INDEX ();
5935
5936
5937 if (delay || (redisplaying_p && !safe))
5938 {
5939 f->new_text_lines = newheight;
5940 f->new_text_cols = newwidth;
5941 delayed_size_change = 1;
5942 return;
5943 }
5944
5945
5946 f->new_text_lines = 0;
5947 f->new_text_cols = 0;
5948
5949
5950 if (newheight == 0)
5951 newheight = FRAME_LINES (f);
5952 if (newwidth == 0)
5953 newwidth = FRAME_COLS (f);
5954
5955 5956
5957 new_frame_total_cols = FRAME_TOTAL_COLS_ARG (f, newwidth);
5958
5959
5960 check_frame_size (f, &newheight, &newwidth);
5961
5962
5963 5964
5965 if (newheight == FRAME_LINES (f)
5966 && newwidth == FRAME_COLS (f) 5967 && new_frame_total_cols == FRAME_TOTAL_COLS (f)) 5968 return;
5969
5970 BLOCK_INPUT;
5971
5972 #ifdef MSDOS
5973 5974 5975
5976 dos_set_window_size (&newheight, &newwidth);
5977 #endif
5978
5979 if (newheight != FRAME_LINES (f))
5980 {
5981 if (FRAME_HAS_MINIBUF_P (f) && !FRAME_MINIBUF_ONLY_P (f))
5982 {
5983
5984 XSETFASTINT (XWINDOW (FRAME_ROOT_WINDOW (f))->top_line,
5985 FRAME_TOP_MARGIN (f));
5986 set_window_height (FRAME_ROOT_WINDOW (f),
5987 (newheight
5988 - 1
5989 - FRAME_TOP_MARGIN (f)),
5990 2);
5991 XSETFASTINT (XWINDOW (FRAME_MINIBUF_WINDOW (f))->top_line,
5992 newheight - 1);
5993 set_window_height (FRAME_MINIBUF_WINDOW (f), 1, 0);
5994 }
5995 else
5996
5997 set_window_height (FRAME_ROOT_WINDOW (f),
5998 newheight - FRAME_TOP_MARGIN (f), 2);
5999
6000 6001
6002 if ((FRAME_TERMCAP_P (f) && !pretend) || FRAME_MSDOS_P (f))
6003 FrameRows (FRAME_TTY (f)) = newheight;
6004 }
6005
6006 if (new_frame_total_cols != FRAME_TOTAL_COLS (f))
6007 {
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);
6011
6012 6013
6014 if ((FRAME_TERMCAP_P (f) && !pretend) || FRAME_MSDOS_P (f))
6015 FrameCols (FRAME_TTY (f)) = newwidth;
6016
6017 if (WINDOWP (f->tool_bar_window))
6018 XSETFASTINT (XWINDOW (f->tool_bar_window)->total_cols, newwidth);
6019 }
6020
6021 FRAME_LINES (f) = newheight;
6022 SET_FRAME_COLS (f, newwidth);
6023
6024 {
6025 struct window *w = XWINDOW (FRAME_SELECTED_WINDOW (f));
6026 int text_area_x, text_area_y, text_area_width, text_area_height;
6027
6028 window_box (w, TEXT_AREA, &text_area_x, &text_area_y, &text_area_width,
6029 &text_area_height);
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;
6034 }
6035
6036 adjust_glyphs (f);
6037 calculate_costs (f);
6038 SET_FRAME_GARBAGED (f);
6039 f->resized_p = 1;
6040
6041 UNBLOCK_INPUT;
6042
6043 record_unwind_protect (Fset_buffer, Fcurrent_buffer ());
6044
6045 run_window_configuration_change_hook (f);
6046
6047 unbind_to (count, Qnil);
6048 }
6049
6050
6051
6052 6053 6054
6055
6056 DEFUN ("open-termscript", Fopen_termscript, Sopen_termscript,
6057 1, 1, "FOpen termscript file: ",
6058 doc: 6059 )
6060 (file)
6061 Lisp_Object file;
6062 {
6063 struct tty_display_info *tty;
6064
6065 if (! FRAME_TERMCAP_P (SELECTED_FRAME ())
6066 && ! FRAME_MSDOS_P (SELECTED_FRAME ()))
6067 error ("Current frame is not on a tty device");
6068
6069 tty = CURTTY ();
6070
6071 if (tty->termscript != 0)
6072 {
6073 BLOCK_INPUT;
6074 fclose (tty->termscript);
6075 UNBLOCK_INPUT;
6076 }
6077 tty->termscript = 0;
6078
6079 if (! NILP (file))
6080 {
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));
6085 }
6086 return Qnil;
6087 }
6088
6089
6090 DEFUN ("send-string-to-terminal", Fsend_string_to_terminal,
6091 Ssend_string_to_terminal, 1, 2, 0,
6092 doc: 6093 6094 6095 6096 6097 6098 )
6099 (string, terminal)
6100 Lisp_Object string;
6101 Lisp_Object terminal;
6102 {
6103 struct terminal *t = get_terminal (terminal, 1);
6104 FILE *out;
6105
6106
6107 CHECK_STRING (string);
6108 BLOCK_INPUT;
6109
6110 if (!t)
6111 error ("Unknown terminal device");
6112
6113 if (t->type == output_initial)
6114 out = stdout;
6115 else if (t->type != output_termcap && t->type != output_msdos_raw)
6116 error ("Device %d is not a termcap terminal device", t->id);
6117 else
6118 {
6119 struct tty_display_info *tty = t->display_info.tty;
6120
6121 if (! tty->output)
6122 error ("Terminal is currently suspended");
6123
6124 if (tty->termscript)
6125 {
6126 fwrite (SDATA (string), 1, SBYTES (string), tty->termscript);
6127 fflush (tty->termscript);
6128 }
6129 out = tty->output;
6130 }
6131 fwrite (SDATA (string), 1, SBYTES (string), out);
6132 fflush (out);
6133 UNBLOCK_INPUT;
6134 return Qnil;
6135 }
6136
6137
6138 DEFUN ("ding", Fding, Sding, 0, 1, 0,
6139 doc: 6140 6141 )
6142 (arg)
6143 Lisp_Object arg;
6144 {
6145 if (!NILP (arg))
6146 {
6147 if (noninteractive)
6148 putchar (07);
6149 else
6150 ring_bell (XFRAME (selected_frame));
6151 }
6152 else
6153 bitch_at_user ();
6154
6155 return Qnil;
6156 }
6157
6158 void
6159 bitch_at_user ()
6160 {
6161 if (noninteractive)
6162 putchar (07);
6163 else if (!INTERACTIVE)
6164 error ("Keyboard macro terminated by a command ringing the bell");
6165 else
6166 ring_bell (XFRAME (selected_frame));
6167 }
6168
6169
6170
6171 6172 6173
6174
6175 DEFUN ("sleep-for", Fsleep_for, Ssleep_for, 1, 2, 0,
6176 doc: 6177 6178 6179 6180 6181 )
6182 (seconds, milliseconds)
6183 Lisp_Object seconds, milliseconds;
6184 {
6185 int sec, usec;
6186
6187 if (NILP (milliseconds))
6188 XSETINT (milliseconds, 0);
6189 else
6190 CHECK_NUMBER (milliseconds);
6191 usec = XINT (milliseconds) * 1000;
6192
6193 {
6194 double duration = extract_float (seconds);
6195 sec = (int) duration;
6196 usec += (duration - sec) * 1000000;
6197 }
6198
6199 #ifndef EMACS_HAS_USECS
6200 if (sec == 0 && usec != 0)
6201 error ("Millisecond `sleep-for' not supported on %s", SYSTEM_TYPE);
6202 #endif
6203
6204
6205 if (usec < 0)
6206 {
6207
6208 if (-1000000 < usec)
6209 sec--, usec += 1000000;
6210 else
6211 sec -= -usec / 1000000, usec = 1000000 - (-usec % 1000000);
6212 }
6213 else
6214 sec += usec / 1000000, usec %= 1000000;
6215
6216 if (sec < 0 || (sec == 0 && usec == 0))
6217 return Qnil;
6218
6219 wait_reading_process_output (sec, usec, 0, 0, Qnil, NULL, 0);
6220
6221 return Qnil;
6222 }
6223
6224
6225 6226 6227 6228 6229 6230 6231 6232 6233
6234
6235 Lisp_Object
6236 sit_for (timeout, reading, do_display)
6237 Lisp_Object timeout;
6238 int reading, do_display;
6239 {
6240 int sec, usec;
6241
6242 swallow_events (do_display);
6243
6244 if ((detect_input_pending_run_timers (do_display))
6245 || !NILP (Vexecuting_kbd_macro))
6246 return Qnil;
6247
6248 if (do_display >= 2)
6249 redisplay_preserve_echo_area (2);
6250
6251 if (INTEGERP (timeout))
6252 {
6253 sec = XINT (timeout);
6254 usec = 0;
6255 }
6256 else if (FLOATP (timeout))
6257 {
6258 double seconds = XFLOAT_DATA (timeout);
6259 sec = (int) seconds;
6260 usec = (int) ((seconds - sec) * 1000000);
6261 }
6262 else if (EQ (timeout, Qt))
6263 {
6264 sec = 0;
6265 usec = 0;
6266 }
6267 else
6268 wrong_type_argument (Qnumberp, timeout);
6269
6270 if (sec == 0 && usec == 0 && !EQ (timeout, Qt))
6271 return Qt;
6272
6273 #ifdef SIGIO
6274 gobble_input (0);
6275 #endif
6276
6277 wait_reading_process_output (sec, usec, reading ? -1 : 1, do_display,
6278 Qnil, NULL, 0);
6279
6280 return detect_input_pending () ? Qnil : Qt;
6281 }
6282
6283
6284 DEFUN ("redisplay", Fredisplay, Sredisplay, 0, 1, 0,
6285 doc: 6286 6287 6288 )
6289 (force)
6290 Lisp_Object force;
6291 {
6292 int count;
6293
6294 swallow_events (1);
6295 if ((detect_input_pending_run_timers (1)
6296 && NILP (force) && !redisplay_dont_pause)
6297 || !NILP (Vexecuting_kbd_macro))
6298 return Qnil;
6299
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);
6305 return Qt;
6306 }
6307
6308
6309
6310 6311 6312
6313
6314 6315 6316
6317
6318 static Lisp_Object frame_and_buffer_state;
6319
6320
6321 DEFUN ("frame-or-buffer-changed-p", Fframe_or_buffer_changed_p,
6322 Sframe_or_buffer_changed_p, 0, 1, 0,
6323 doc: 6324 6325 6326 6327 6328 6329 6330 6331 6332 6333 )
6334 (variable)
6335 Lisp_Object variable;
6336 {
6337 Lisp_Object state, tail, frame, buf;
6338 Lisp_Object *vecp, *end;
6339 int n;
6340
6341 if (! NILP (variable))
6342 {
6343 CHECK_SYMBOL (variable);
6344 state = Fsymbol_value (variable);
6345 if (! VECTORP (state))
6346 goto changed;
6347 }
6348 else
6349 state = frame_and_buffer_state;
6350
6351 vecp = XVECTOR (state)->contents;
6352 end = vecp + XVECTOR (state)->size;
6353
6354 FOR_EACH_FRAME (tail, frame)
6355 {
6356 if (vecp == end)
6357 goto changed;
6358 if (!EQ (*vecp++, frame))
6359 goto changed;
6360 if (vecp == end)
6361 goto changed;
6362 if (!EQ (*vecp++, XFRAME (frame)->name))
6363 goto changed;
6364 }
6365
6366 for (tail = Vbuffer_alist; CONSP (tail); tail = XCDR (tail))
6367 {
6368 buf = XCDR (XCAR (tail));
6369
6370 if (SREF (XBUFFER (buf)->name, 0) == ' ')
6371 continue;
6372 if (vecp == end)
6373 goto changed;
6374 if (!EQ (*vecp++, buf))
6375 goto changed;
6376 if (vecp == end)
6377 goto changed;
6378 if (!EQ (*vecp++, XBUFFER (buf)->read_only))
6379 goto changed;
6380 if (vecp == end)
6381 goto changed;
6382 if (!EQ (*vecp++, Fbuffer_modified_p (buf)))
6383 goto changed;
6384 }
6385 if (vecp == end)
6386 goto changed;
6387
6388 if (EQ (*vecp, Qlambda))
6389 return Qnil;
6390
6391
6392 changed:
6393 6394
6395 n = 1;
6396 FOR_EACH_FRAME (tail, frame)
6397 n += 2;
6398 for (tail = Vbuffer_alist; CONSP (tail); tail = XCDR (tail))
6399 n += 3;
6400 6401
6402 if (! VECTORP (state)
6403 || n > XVECTOR (state)->size
6404 || n + 20 < XVECTOR (state)->size / 2)
6405
6406 {
6407 state = Fmake_vector (make_number (n + 20), Qlambda);
6408 if (! NILP (variable))
6409 Fset (variable, state);
6410 else
6411 frame_and_buffer_state = state;
6412 }
6413
6414
6415 vecp = XVECTOR (state)->contents;
6416 FOR_EACH_FRAME (tail, frame)
6417 {
6418 *vecp++ = frame;
6419 *vecp++ = XFRAME (frame)->name;
6420 }
6421 for (tail = Vbuffer_alist; CONSP (tail); tail = XCDR (tail))
6422 {
6423 buf = XCDR (XCAR (tail));
6424
6425 if (SREF (XBUFFER (buf)->name, 0) == ' ')
6426 continue;
6427 *vecp++ = buf;
6428 *vecp++ = XBUFFER (buf)->read_only;
6429 *vecp++ = Fbuffer_modified_p (buf);
6430 }
6431
6432 *vecp++ = Qlambda;
6433 while (vecp - XVECTOR (state)->contents
6434 < XVECTOR (state)->size)
6435 *vecp++ = Qlambda;
6436
6437 if (vecp - XVECTOR (state)->contents
6438 > XVECTOR (state)->size)
6439 abort ();
6440 return Qt;
6441 }
6442
6443
6444
6445 6446 6447
6448
6449 6450 6451
6452
6453 void
6454 init_display ()
6455 {
6456 char *terminal_type;
6457
6458 #ifdef HAVE_X_WINDOWS
6459 extern int display_arg;
6460 #endif
6461
6462
6463 space_glyph.type = CHAR_GLYPH;
6464 SET_CHAR_GLYPH (space_glyph, ' ', DEFAULT_FACE_ID, 0);
6465 space_glyph.charpos = -1;
6466
6467 inverse_video = 0;
6468 cursor_in_echo_area = 0;
6469 terminal_type = (char *) 0;
6470
6471 6472
6473 Vinitial_window_system = Qnil;
6474
6475 6476 6477
6478 #ifdef SIGWINCH
6479 #ifndef CANNOT_DUMP
6480 if (initialized)
6481 #endif
6482 signal (SIGWINCH, window_change_signal);
6483 #endif
6484
6485
6486 if (IS_DAEMON)
6487 return;
6488
6489 6490 6491 6492 6493 6494 6495
6496
6497 #ifdef HAVE_X_WINDOWS
6498 if (! inhibit_window_system && ! display_arg)
6499 {
6500 char *display;
6501 display = getenv ("DISPLAY");
6502 display_arg = (display != 0 && *display != 0);
6503
6504 if (display_arg && !x_display_ok (display))
6505 {
6506 fprintf (stderr, "Display %s unavailable, simulating -nw\n",
6507 display);
6508 inhibit_window_system = 1;
6509 }
6510 }
6511
6512 if (!inhibit_window_system && display_arg
6513 #ifndef CANNOT_DUMP
6514 && initialized
6515 #endif
6516 )
6517 {
6518 Vinitial_window_system = Qx;
6519 #ifdef HAVE_X11
6520 Vwindow_system_version = make_number (11);
6521 #endif
6522 #if defined (GNU_LINUX) && defined (HAVE_LIBNCURSES)
6523 6524 6525
6526 { char b[2044]; tgetent (b, "xterm");}
6527 #endif
6528 adjust_frame_glyphs_initially ();
6529 return;
6530 }
6531 #endif
6532
6533 #ifdef HAVE_NTGUI
6534 if (!inhibit_window_system)
6535 {
6536 Vinitial_window_system = Qw32;
6537 Vwindow_system_version = make_number (1);
6538 adjust_frame_glyphs_initially ();
6539 return;
6540 }
6541 #endif
6542
6543 #ifdef HAVE_NS
6544 if (!inhibit_window_system
6545 #ifndef CANNOT_DUMP
6546 && initialized
6547 #endif
6548 )
6549 {
6550 Vinitial_window_system = Qns;
6551 Vwindow_system_version = make_number(10);
6552 adjust_frame_glyphs_initially ();
6553 return;
6554 }
6555 #endif
6556
6557
6558 if (! isatty (0))
6559 {
6560 fatal ("standard input is not a tty");
6561 exit (1);
6562 }
6563
6564 #ifdef WINDOWSNT
6565 terminal_type = "w32console";
6566 #else
6567
6568 terminal_type = (char *) getenv ("TERM");
6569 #endif
6570 if (!terminal_type)
6571 {
6572 #ifdef HAVE_WINDOW_SYSTEM
6573 if (! inhibit_window_system)
6574 fprintf (stderr, "Please set the environment variable DISPLAY or TERM (see `tset').\n");
6575 else
6576 #endif
6577 fprintf (stderr, "Please set the environment variable TERM; see `tset'.\n");
6578 exit (1);
6579 }
6580
6581 {
6582 struct terminal *t;
6583 struct frame *f = XFRAME (selected_frame);
6584
6585
6586 t = init_tty (0, terminal_type, 1);
6587
6588
6589 if (f->output_method != output_initial)
6590 abort ();
6591 f->output_method = t->type;
6592 f->terminal = t;
6593
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);
6599
6600
6601 if (--initial_terminal->reference_count == 0
6602 && initial_terminal->delete_terminal_hook)
6603 (*initial_terminal->delete_terminal_hook) (initial_terminal);
6604
6605
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)),
6612 Qnil));
6613 else
6614 Fmodify_frame_parameters (selected_frame, Fcons (Fcons (Qtty, Qnil),
6615 Qnil));
6616 }
6617
6618 {
6619 struct frame *sf = SELECTED_FRAME ();
6620 int width = FRAME_TOTAL_COLS (sf);
6621 int height = FRAME_LINES (sf);
6622
6623 unsigned int total_glyphs = height * (width + 2) * sizeof (struct glyph);
6624
6625 6626
6627 if (total_glyphs / sizeof (struct glyph) / height != width + 2)
6628 fatal ("screen size %dx%d too big", width, height);
6629 }
6630
6631 adjust_frame_glyphs_initially ();
6632 calculate_costs (XFRAME (selected_frame));
6633
6634
6635 if (initialized
6636 && !noninteractive
6637 && NILP (Vinitial_window_system))
6638 {
6639 6640
6641 struct frame *sf = SELECTED_FRAME();
6642
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"));
6646 }
6647 }
6648
6649
6650
6651 6652 6653
6654
6655 DEFUN ("internal-show-cursor", Finternal_show_cursor,
6656 Sinternal_show_cursor, 2, 2, 0,
6657 doc: 6658 6659 6660 )
6661 (window, show)
6662 Lisp_Object window, show;
6663 {
6664 6665
6666 if (!redisplaying_p)
6667 {
6668 if (NILP (window))
6669 window = selected_window;
6670 else
6671 CHECK_WINDOW (window);
6672
6673 XWINDOW (window)->cursor_off_p = NILP (show);
6674 }
6675
6676 return Qnil;
6677 }
6678
6679
6680 DEFUN ("internal-show-cursor-p", Finternal_show_cursor_p,
6681 Sinternal_show_cursor_p, 0, 1, 0,
6682 doc: 6683 )
6684 (window)
6685 Lisp_Object window;
6686 {
6687 struct window *w;
6688
6689 if (NILP (window))
6690 window = selected_window;
6691 else
6692 CHECK_WINDOW (window);
6693
6694 w = XWINDOW (window);
6695 return w->cursor_off_p ? Qnil : Qt;
6696 }
6697
6698 DEFUN ("last-nonminibuffer-frame", Flast_nonminibuf_frame,
6699 Slast_nonminibuf_frame, 0, 0, 0,
6700 doc: )
6701 ()
6702 {
6703 Lisp_Object frame = Qnil;
6704
6705 if (last_nonminibuf_frame)
6706 XSETFRAME (frame, last_nonminibuf_frame);
6707
6708 return frame;
6709 }
6710
6711 6712 6713
6714
6715 void
6716 syms_of_display ()
6717 {
6718 defsubr (&Sredraw_frame);
6719 defsubr (&Sredraw_display);
6720 defsubr (&Sframe_or_buffer_changed_p);
6721 defsubr (&Sopen_termscript);
6722 defsubr (&Sding);
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);
6729
6730 #if GLYPH_DEBUG
6731 defsubr (&Sdump_redisplay_history);
6732 #endif
6733
6734 frame_and_buffer_state = Fmake_vector (make_number (20), Qlambda);
6735 staticpro (&frame_and_buffer_state);
6736
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);
6741
6742 DEFVAR_INT ("baud-rate", &baud_rate,
6743 doc: 6744 6745 );
6746
6747 DEFVAR_BOOL ("inverse-video", &inverse_video,
6748 doc: 6749 );
6750
6751 DEFVAR_BOOL ("visible-bell", &visible_bell,
6752 doc: 6753 6754 );
6755
6756 DEFVAR_BOOL ("no-redraw-on-reenter", &no_redraw_on_reenter,
6757 doc: 6758 6759 6760 );
6761
6762 DEFVAR_LISP ("initial-window-system", &Vinitial_window_system,
6763 doc: 6764 6765 );
6766
6767 DEFVAR_KBOARD ("window-system", Vwindow_system,
6768 doc: 6769 6770 );
6771
6772 DEFVAR_LISP ("window-system-version", &Vwindow_system_version,
6773 doc: 6774 );
6775
6776 DEFVAR_BOOL ("cursor-in-echo-area", &cursor_in_echo_area,
6777 doc: );
6778
6779 DEFVAR_LISP ("glyph-table", &Vglyph_table,
6780 doc: 6781 6782 6783 6784 6785 6786 6787 );
6788 Vglyph_table = Qnil;
6789
6790 DEFVAR_LISP ("standard-display-table", &Vstandard_display_table,
6791 doc: 6792 );
6793 Vstandard_display_table = Qnil;
6794
6795 DEFVAR_BOOL ("redisplay-dont-pause", &redisplay_dont_pause,
6796 doc: );
6797 redisplay_dont_pause = 0;
6798
6799 #if PERIODIC_PREEMPTION_CHECKING
6800 DEFVAR_LISP ("redisplay-preemption-period", &Vredisplay_preemption_period,
6801 doc: 6802 6803 );
6804 Vredisplay_preemption_period = make_float (0.10);
6805 #endif
6806
6807 #ifdef CANNOT_DUMP
6808 if (noninteractive)
6809 #endif
6810 {
6811 Vinitial_window_system = Qnil;
6812 Vwindow_system_version = Qnil;
6813 }
6814 }
6815
6816 6817