1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23: #include <config.h>
24: #include <signal.h>
25: #include <stdio.h>
26: #include <ctype.h>
27:
28: #ifdef HAVE_UNISTD_H
29: #include <unistd.h>
30: #endif
31:
32: #include "lisp.h"
33: #include "termchar.h"
34: #include "termopts.h"
35: #include "termhooks.h"
36:
37: #include "dispextern.h"
38: #include "cm.h"
39: #include "buffer.h"
40: #include "charset.h"
41: #include "keyboard.h"
42: #include "frame.h"
43: #include "window.h"
44: #include "commands.h"
45: #include "disptab.h"
46: #include "indent.h"
47: #include "intervals.h"
48: #include "blockinput.h"
49: #include "process.h"
50:
51:
52:
53:
54: #include "syssignal.h"
55:
56: #ifdef HAVE_X_WINDOWS
57: #include "xterm.h"
58: #endif
59:
60: #ifdef HAVE_NTGUI
61: #include "w32term.h"
62: #endif
63:
64: #ifdef MAC_OS
65: #include "macterm.h"
66: #endif
67:
68:
69:
70: #include "systime.h"
71: #include <errno.h>
72:
73:
74:
75: #ifdef HAVE_UNISTD_H
76: #include <unistd.h>
77: #endif
78:
79:
80:
81:
82:
83: #ifdef __GNU_LIBRARY__
84:
85:
86:
87:
88:
89: #ifdef GNU_LIBRARY_PENDING_OUTPUT_COUNT
90: #define PENDING_OUTPUT_COUNT GNU_LIBRARY_PENDING_OUTPUT_COUNT
91: #else
92: #undef PENDING_OUTPUT_COUNT
93: #define PENDING_OUTPUT_COUNT(FILE) ((FILE)->__bufp - (FILE)->__buffer)
94: #endif
95: #else
96: #if !defined (PENDING_OUTPUT_COUNT) && HAVE_STDIO_EXT_H && HAVE___FPENDING
97: #include <stdio_ext.h>
98: #define PENDING_OUTPUT_COUNT(FILE) __fpending (FILE)
99: #endif
100: #ifndef PENDING_OUTPUT_COUNT
101: #define PENDING_OUTPUT_COUNT(FILE) ((FILE)->_ptr - (FILE)->_base)
102: #endif
103: #endif
104:
105: #if defined(HAVE_TERM_H) && defined (GNU_LINUX) && defined (HAVE_LIBNCURSES)
106: #include <term.h>
107: #endif
108: ^L
109:
110:
111:
112: struct dim
113: {
114: int width;
115: int height;
116: };
117:
118: ^L
119:
120:
121: static struct glyph_matrix *save_current_matrix P_ ((struct frame *));
122: static void restore_current_matrix P_ ((struct frame *, struct glyph_matrix *));
123: static int showing_window_margins_p P_ ((struct window *));
124: static void fake_current_matrices P_ ((Lisp_Object));
125: static void redraw_overlapping_rows P_ ((struct window *, int));
126: static void redraw_overlapped_rows P_ ((struct window *, int));
127: static int count_blanks P_ ((struct glyph *, int));
128: static int count_match P_ ((struct glyph *, struct glyph *,
129: struct glyph *, struct glyph *));
130: static unsigned line_draw_cost P_ ((struct glyph_matrix *, int));
131: static void update_frame_line P_ ((struct frame *, int));
132: static struct dim allocate_matrices_for_frame_redisplay
133: P_ ((Lisp_Object, int, int, int, int *));
134: static void allocate_matrices_for_window_redisplay P_ ((struct window *));
135: static int realloc_glyph_pool P_ ((struct glyph_pool *, struct dim));
136: static void adjust_frame_glyphs P_ ((struct frame *));
137: struct glyph_matrix *new_glyph_matrix P_ ((struct glyph_pool *));
138: static void free_glyph_matrix P_ ((struct glyph_matrix *));
139: static void adjust_glyph_matrix P_ ((struct window *, struct glyph_matrix *,
140: int, int, struct dim));
141: static void change_frame_size_1 P_ ((struct frame *, int, int, int, int, int));
142: static void swap_glyph_pointers P_ ((struct glyph_row *, struct glyph_row *));
143: #if GLYPH_DEBUG
144: static int glyph_row_slice_p P_ ((struct glyph_row *, struct glyph_row *));
145: #endif
146: static void fill_up_frame_row_with_spaces P_ ((struct glyph_row *, int));
147: static void build_frame_matrix_from_window_tree P_ ((struct glyph_matrix *,
148: struct window *));
149: static void build_frame_matrix_from_leaf_window P_ ((struct glyph_matrix *,
150: struct window *));
151: static struct glyph_pool *new_glyph_pool P_ ((void));
152: static void free_glyph_pool P_ ((struct glyph_pool *));
153: static void adjust_frame_glyphs_initially P_ ((void));
154: static void adjust_frame_message_buffer P_ ((struct frame *));
155: static void adjust_decode_mode_spec_buffer P_ ((struct frame *));
156: static void fill_up_glyph_row_with_spaces P_ ((struct glyph_row *));
157: static void build_frame_matrix P_ ((struct frame *));
158: void clear_current_matrices P_ ((struct frame *));
159: void scroll_glyph_matrix_range P_ ((struct glyph_matrix *, int, int,
160: int, int));
161: static void clear_window_matrices P_ ((struct window *, int));
162: static void fill_up_glyph_row_area_with_spaces P_ ((struct glyph_row *, int));
163: static int scrolling_window P_ ((struct window *, int));
164: static int update_window_line P_ ((struct window *, int, int *));
165: static void update_marginal_area P_ ((struct window *, int, int));
166: static int update_text_area P_ ((struct window *, int));
167: static void make_current P_ ((struct glyph_matrix *, struct glyph_matrix *,
168: int));
169: static void mirror_make_current P_ ((struct window *, int));
170: void check_window_matrix_pointers P_ ((struct window *));
171: #if GLYPH_DEBUG
172: static void check_matrix_pointers P_ ((struct glyph_matrix *,
173: struct glyph_matrix *));
174: #endif
175: static void mirror_line_dance P_ ((struct window *, int, int, int *, char *));
176: static int update_window_tree P_ ((struct window *, int));
177: static int update_window P_ ((struct window *, int));
178: static int update_frame_1 P_ ((struct frame *, int, int));
179: static void set_window_cursor_after_update P_ ((struct window *));
180: static int row_equal_p P_ ((struct window *, struct glyph_row *,
181: struct glyph_row *, int));
182: static void adjust_frame_glyphs_for_window_redisplay P_ ((struct frame *));
183: static void adjust_frame_glyphs_for_frame_redisplay P_ ((struct frame *));
184: static void reverse_rows P_ ((struct glyph_matrix *, int, int));
185: static int margin_glyphs_to_reserve P_ ((struct window *, int, Lisp_Object));
186: static void sync_window_with_frame_matrix_rows P_ ((struct window *));
187: struct window *frame_row_to_window P_ ((struct window *, int));
188:
189: ^L
190:
191:
192:
193:
194: int redisplay_dont_pause;
195:
196:
197:
198:
199: #ifdef EMACS_HAS_USECS
200: #define PERIODIC_PREEMPTION_CHECKING 1
201: #else
202: #define PERIODIC_PREEMPTION_CHECKING 0
203: #endif
204:
205: #if PERIODIC_PREEMPTION_CHECKING
206:
207:
208:
209: Lisp_Object Vredisplay_preemption_period;
210:
211:
212:
213: static EMACS_TIME preemption_period;
214: static EMACS_TIME preemption_next_check;
215:
216: #endif
217:
218:
219:
220:
221: int frame_garbaged;
222:
223:
224:
225: int display_completed;
226:
227:
228:
229:
230: int visible_bell;
231:
232:
233:
234: int inverse_video;
235:
236:
237:
238: EMACS_INT baud_rate;
239:
240:
241:
242:
243: Lisp_Object Vwindow_system;
244:
245:
246:
247: Lisp_Object Vwindow_system_version;
248:
249:
250:
251:
252:
253:
254:
255:
256:
257:
258: Lisp_Object Vglyph_table;
259:
260:
261:
262: Lisp_Object Vstandard_display_table;
263:
264:
265:
266:
267:
268: int cursor_in_echo_area;
269:
270: Lisp_Object Qdisplay_table, Qredisplay_dont_pause;
271:
272: ^L
273:
274:
275:
276: Lisp_Object selected_frame;
277:
278:
279:
280:
281:
282:
283: struct frame *last_nonminibuf_frame;
284:
285:
286:
287: FILE *termscript;
288:
289:
290:
291: struct cm Wcm;
292:
293:
294:
295: int delayed_size_change;
296:
297:
298:
299: static int glyphs_initialized_initially_p;
300:
301:
302:
303: struct window *updated_window;
304:
305:
306:
307: struct glyph_row *updated_row;
308: int updated_area;
309:
310:
311:
312: struct glyph space_glyph;
313:
314:
315:
316:
317:
318: int redisplay_performed_directly_p;
319:
320:
321:
322:
323: int glyph_matrix_count;
324: int glyph_pool_count;
325:
326:
327:
328:
329: static struct frame *frame_matrix_frame;
330:
331:
332:
333:
334: struct redisplay_interface *rif;
335:
336:
337:
338:
339:
340:
341:
342: int fonts_changed_p;
343:
344:
345:
346:
347: #if GLYPH_DEBUG
348:
349: static int window_to_frame_vpos P_ ((struct window *, int));
350: static int window_to_frame_hpos P_ ((struct window *, int));
351: #define WINDOW_TO_FRAME_VPOS(W, VPOS) window_to_frame_vpos ((W), (VPOS))
352: #define WINDOW_TO_FRAME_HPOS(W, HPOS) window_to_frame_hpos ((W), (HPOS))
353:
354:
355:
356:
357: struct redisplay_history
358: {
359: char trace[512 + 100];
360: };
361:
362:
363:
364: #define REDISPLAY_HISTORY_SIZE 30
365:
366:
367:
368: static struct redisplay_history redisplay_history[REDISPLAY_HISTORY_SIZE];
369:
370:
371:
372: static int history_idx;
373:
374:
375:
376:
377: static unsigned history_tick;
378:
379: static void add_frame_display_history P_ ((struct frame *, int));
380: static void add_window_display_history P_ ((struct window *, char *, int));
381: ^L
382:
383:
384:
385:
386:
387: static void
388: add_window_display_history (w, msg, paused_p)
389: struct window *w;
390: char *msg;
391: int paused_p;
392: {
393: char *buf;
394:
395: if (history_idx >= REDISPLAY_HISTORY_SIZE)
396: history_idx = 0;
397: buf = redisplay_history[history_idx].trace;
398: ++history_idx;
399:
400: sprintf (buf, "%d: window %p (`%s')%s\n",
401: history_tick++,
402: w,
403: ((BUFFERP (w->buffer)
404: && STRINGP (XBUFFER (w->buffer)->name))
405: ? (char *) SDATA (XBUFFER (w->buffer)->name)
406: : "???"),
407: paused_p ? " ***paused***" : "");
408: strcat (buf, msg);
409: }
410:
411:
412:
413:
414:
415:
416: static void
417: add_frame_display_history (f, paused_p)
418: struct frame *f;
419: int paused_p;
420: {
421: char *buf;
422:
423: if (history_idx >= REDISPLAY_HISTORY_SIZE)
424: history_idx = 0;
425: buf = redisplay_history[history_idx].trace;
426: ++history_idx;
427:
428: sprintf (buf, "%d: update frame %p%s",
429: history_tick++,
430: f, paused_p ? " ***paused***" : "");
431: }
432:
433:
434: DEFUN ("dump-redisplay-history", Fdump_redisplay_history,
435: Sdump_redisplay_history, 0, 0, "",
436: doc: )
437: ()
438: {
439: int i;
440:
441: for (i = history_idx - 1; i != history_idx; --i)
442: {
443: if (i < 0)
444: i = REDISPLAY_HISTORY_SIZE - 1;
445: fprintf (stderr, "%s\n", redisplay_history[i].trace);
446: }
447:
448: return Qnil;
449: }
450:
451:
452: #else
453:
454: #define WINDOW_TO_FRAME_VPOS(W, VPOS) ((VPOS) + WINDOW_TOP_EDGE_LINE (W))
455: #define WINDOW_TO_FRAME_HPOS(W, HPOS) ((HPOS) + WINDOW_LEFT_EDGE_COL (W))
456:
457: #endif
458:
459:
460:
461:
462:
463:
464: void
465: safe_bcopy (from, to, size)
466: const char *from;
467: char *to;
468: int size;
469: {
470: if (size <= 0 || from == to)
471: return;
472:
473:
474:
475:
476: if (to < from || from + size <= to)
477: bcopy (from, to, size);
478:
479:
480: else
481: {
482: register const char *endf = from + size;
483: register char *endt = to + size;
484:
485:
486:
487:
488:
489:
490:
491: if (to - from < 64)
492: {
493: do
494: *--endt = *--endf;
495: while (endf != from);
496: }
497: else
498: {
499: for (;;)
500: {
501: endt -= (to - from);
502: endf -= (to - from);
503:
504: if (endt < to)
505: break;
506:
507: bcopy (endf, endt, to - from);
508: }
509:
510:
511:
512:
513: bcopy (from, to, endt - from);
514: }
515: }
516: }
517:
518:
519: ^L
520:
521:
522:
523:
524:
525:
526:
527:
528:
529:
530: struct glyph_matrix *
531: new_glyph_matrix (pool)
532: struct glyph_pool *pool;
533: {
534: struct glyph_matrix *result;
535:
536:
537: result = (struct glyph_matrix *) xmalloc (sizeof *result);
538: bzero (result, sizeof *result);
539:
540:
541:
542: ++glyph_matrix_count;
543:
544:
545: result->pool = pool;
546: return result;
547: }
548:
549:
550:
551:
552:
553:
554:
555:
556:
557:
558:
559:
560:
561: static void
562: free_glyph_matrix (matrix)
563: struct glyph_matrix *matrix;
564: {
565: if (matrix)
566: {
567: int i;
568:
569:
570:
571: if (--glyph_matrix_count < 0)
572: abort ();
573:
574:
575: if (matrix->pool == NULL)
576: for (i = 0; i < matrix->rows_allocated; ++i)
577: xfree (matrix->rows