]> code.delx.au - gnu-emacs/blobdiff - src/dispnew.c
(dump_glyph_row, dump_glyph_matrix, Fdump_glyph_matrix)
[gnu-emacs] / src / dispnew.c
index f16933b69b312bf4c2437cfd084c8ef132779733..9c96da4b804c6ffd454a2483d68925e5901ba1cc 100644 (file)
@@ -120,6 +120,9 @@ struct dim
 \f
 /* Function prototypes.  */
 
+static struct glyph_matrix *save_frame_matrix P_ ((struct glyph_matrix *));
+static void restore_frame_matrix P_ ((struct glyph_matrix *, struct glyph_matrix *));
+static void fake_current_matrices P_ ((Lisp_Object));
 static void redraw_overlapping_rows P_ ((struct window *, int));
 static void redraw_overlapped_rows P_ ((struct window *, int));
 static int count_blanks P_ ((struct glyph *, int));
@@ -550,6 +553,7 @@ adjust_glyph_matrix (w, matrix, x, y, dim)
       if (!marginal_areas_changed_p
          && !fonts_changed_p
          && !header_line_changed_p
+         && matrix->window_left_x == XFASTINT (w->left)
          && matrix->window_top_y == XFASTINT (w->top)
          && matrix->window_height == window_height
          && matrix->window_vscroll == w->vscroll
@@ -686,6 +690,7 @@ adjust_glyph_matrix (w, matrix, x, y, dim)
          upper window).  Invalidate all rows that are no longer part
          of the window.  */
       if (!marginal_areas_changed_p
+         && matrix->window_left_x == XFASTINT (w->left)
          && matrix->window_top_y == XFASTINT (w->top)
          && matrix->window_width == window_box_width (w, -1))
        {
@@ -721,6 +726,7 @@ adjust_glyph_matrix (w, matrix, x, y, dim)
      was last adjusted.  This is used to optimize redisplay above.  */
   if (w)
     {
+      matrix->window_left_x = XFASTINT (w->left);
       matrix->window_top_y = XFASTINT (w->top);
       matrix->window_height = window_height;
       matrix->window_width = window_width;
@@ -1998,6 +2004,110 @@ adjust_frame_glyphs (f)
 }
 
 
+/* In the window tree with root W, build current matrices of leaf
+   windows from the frame's current matrix.  */
+
+static void
+fake_current_matrices (window)
+     Lisp_Object window;
+{
+  struct window *w;
+      
+  for (; !NILP (window); window = w->next)
+    {
+      w = XWINDOW (window);
+      
+      if (!NILP (w->hchild))
+       fake_current_matrices (w->hchild);
+      else if (!NILP (w->vchild))
+       fake_current_matrices (w->vchild);
+      else
+       {
+         int i;
+         struct frame *f = XFRAME (w->frame);
+         struct glyph_matrix *m = w->current_matrix;
+         struct glyph_matrix *fm = f->current_matrix;
+
+         xassert (m->matrix_h == XFASTINT (w->height));
+         xassert (m->matrix_w == XFASTINT (w->width));
+         
+         for (i = 0; i < m->matrix_h; ++i)
+           {
+             struct glyph_row *r = m->rows + i;
+             struct glyph_row *fr = fm->rows + i + XFASTINT (w->top);
+
+             xassert (r->glyphs[TEXT_AREA] >= fr->glyphs[TEXT_AREA]
+                      && r->glyphs[LAST_AREA] <= fr->glyphs[LAST_AREA]);
+
+             r->enabled_p = fr->enabled_p;
+             if (r->enabled_p)
+               {
+                 r->used[LEFT_MARGIN_AREA] = m->left_margin_glyphs;
+                 r->used[RIGHT_MARGIN_AREA] = m->right_margin_glyphs;
+                 r->used[TEXT_AREA] = (m->matrix_w
+                                       - r->used[LEFT_MARGIN_AREA]
+                                       - r->used[RIGHT_MARGIN_AREA]);
+                 r->mode_line_p = 0;
+                 r->inverse_p = fr->inverse_p;
+               }
+           }
+       }
+    }
+}
+
+
+/* Return a glyph matrix that holds of copy of the glyph contents
+   of frame matrix M.  */
+
+static struct glyph_matrix *
+save_frame_matrix (m)
+     struct glyph_matrix *m;
+{
+  struct glyph_matrix *copy;
+  int i;
+
+  copy = (struct glyph_matrix *) xmalloc (sizeof *copy);
+  *copy = *m;
+  copy->rows = (struct glyph_row *) xmalloc (m->nrows * sizeof (*copy->rows));
+
+  for (i = 0; i < copy->nrows; ++i)
+    {
+      struct glyph_row *from = m->rows + i;
+      struct glyph_row *to = copy->rows + i;
+      size_t nbytes = from->used[TEXT_AREA] * sizeof (struct glyph);
+      to->glyphs[TEXT_AREA] = (struct glyph *) xmalloc (nbytes);
+      bcopy (from->glyphs[TEXT_AREA], to->glyphs[TEXT_AREA], nbytes);
+      to->used[TEXT_AREA] = from->used[TEXT_AREA];
+    }
+  
+  return copy;
+}
+
+
+/* Restore the glyph contents of frame matrix M from the copy COPY,
+   made by save_frame_matrix.  Free memory allocated for COPY.  */
+
+static void
+restore_frame_matrix (m, copy)
+     struct glyph_matrix *m, *copy;
+{
+  int i;
+  
+  for (i = 0; i < copy->nrows; ++i)
+    {
+      struct glyph_row *from = copy->rows + i;
+      struct glyph_row *to = m->rows + i;
+      size_t nbytes = from->used[TEXT_AREA] * sizeof (struct glyph);
+      bcopy (from->glyphs[TEXT_AREA], to->glyphs[TEXT_AREA], nbytes);
+      to->used[TEXT_AREA] = from->used[TEXT_AREA];
+      xfree (from->glyphs[TEXT_AREA]);
+    }
+
+  xfree (copy->rows);
+  xfree (copy);
+}
+
+
 /* Allocate/reallocate glyph matrices of a single frame F for
    frame-based redisplay.  */
 
@@ -2033,7 +2143,7 @@ adjust_frame_glyphs_for_frame_redisplay (f)
       f->desired_matrix = new_glyph_matrix (f->desired_pool);
       f->current_matrix = new_glyph_matrix (f->current_pool);
     }
-      
+  
   /* Compute window glyph matrices.  (This takes the mini-buffer
      window into account).  The result is the size of the frame glyph
      matrix needed.  The variable window_change_flags is set to a bit
@@ -2071,12 +2181,31 @@ adjust_frame_glyphs_for_frame_redisplay (f)
   
       /* Resize frame matrices.  */
       adjust_glyph_matrix (NULL, f->desired_matrix, 0, 0, matrix_dim);
-      adjust_glyph_matrix (NULL, f->current_matrix, 0, 0, matrix_dim);
 
-      /* Since location and size of sub-matrices within the pool may
-        have changed, and current matrices don't have meaningful
-        contents anymore, mark the frame garbaged.  */
-      SET_FRAME_GARBAGED (f);
+      /* Pointers to glyph memory in glyph rows are exchanged during
+        the update phase of redisplay, which means in general that a
+        frame's current matrix consists of pointers into both the
+        desired and current glyph pool of the frame.  Adjusting a
+        matrix sets the frame matrix up so that pointers are all into
+        the same pool.  If we want to preserve glyph contents of the
+        current matrix over a call to adjust_glyph_matrix, we must
+        make a copy of the current glyphs, and restore the current
+        matrix' contents from that copy.  */
+      if (display_completed
+         && !FRAME_GARBAGED_P (f)
+         && matrix_dim.width == f->current_matrix->matrix_w
+         && matrix_dim.height == f->current_matrix->matrix_h)
+       {
+         struct glyph_matrix *saved = save_frame_matrix (f->current_matrix);
+         adjust_glyph_matrix (NULL, f->current_matrix, 0, 0, matrix_dim);
+         restore_frame_matrix (f->current_matrix, saved);
+         fake_current_matrices (FRAME_ROOT_WINDOW (f));
+       }
+      else
+       {
+         adjust_glyph_matrix (NULL, f->current_matrix, 0, 0, matrix_dim);
+         SET_FRAME_GARBAGED (f);
+       }
     }
 }
 
@@ -3177,8 +3306,10 @@ direct_output_for_insert (g)
       || !display_completed
       /* Give up if buffer appears in two places.  */
       || buffer_shared > 1
-      /* Give up if w is mini-buffer and a message is being displayed there */
-      || (MINI_WINDOW_P (w) && !NILP (echo_area_buffer[0]))
+      /* Give up if currently displaying a message instead of the
+        minibuffer contents.  */
+      || (EQ (selected_window, minibuf_window)
+         && EQ (minibuf_window, echo_area_window))
       /* Give up for hscrolled mini-buffer because display of the prompt
         is handled specially there (see display_line).  */
       || (MINI_WINDOW_P (w) && XFASTINT (w->hscroll))
@@ -3763,6 +3894,7 @@ update_window (w, force_p)
   int paused_p;
   int preempt_count = baud_rate / 2400 + 1;
   extern int input_pending;
+  extern Lisp_Object do_mouse_tracking;
 #if GLYPH_DEBUG
   struct frame *f = XFRAME (WINDOW_FRAME (w));
   extern struct frame *updating_frame;
@@ -3780,12 +3912,12 @@ update_window (w, force_p)
 
   /* If forced to complete the update, or if no input is pending, do
      the update.  */
-  if (force_p || !input_pending)
+  if (force_p || !input_pending || !NILP (do_mouse_tracking))
     {
       struct glyph_row *row, *end;
       struct glyph_row *mode_line_row;
       struct glyph_row *header_line_row = NULL;
-      int yb, changed_p = 0, mouse_face_overwritten_p = 0;
+      int yb, changed_p = 0, mouse_face_overwritten_p = 0, n_updated;
 
       rif->update_window_begin_hook (w);
       yb = window_text_bottom_y (w);
@@ -3840,7 +3972,7 @@ update_window (w, force_p)
        }
 
       /* Update the rest of the lines.  */
-      for (; row < end && (force_p || !input_pending); ++row)
+      for (n_updated = 0; row < end && (force_p || !input_pending); ++row)
        if (row->enabled_p)
          {
            int vpos = MATRIX_ROW_VPOS (row, desired_matrix);
@@ -3850,7 +3982,7 @@ update_window (w, force_p)
               detect_input_pending.  If it's done too often,
               scrolling large windows with repeated scroll-up
               commands will too quickly pause redisplay.  */
-           if (!force_p && vpos % preempt_count == 0)
+           if (!force_p && ++n_updated % preempt_count == 0)
              detect_input_pending ();
 
            changed_p |= update_window_line (w, vpos,