Last portion of fix for bug #16051 with redisplay loops.
authorEli Zaretskii <eliz@gnu.org>
Mon, 23 Dec 2013 19:24:25 +0000 (21:24 +0200)
committerEli Zaretskii <eliz@gnu.org>
Mon, 23 Dec 2013 19:24:25 +0000 (21:24 +0200)
 src/xdisp.c (redisplay_tool_bar): Modify the tool-bar-lines frame parameter
 only when the new size is different from the old one, and the new
 size can be achieved given the frame height.

src/ChangeLog
src/xdisp.c

index e1df65b..818ff27 100644 (file)
@@ -5,6 +5,9 @@
        redisplay_tool_bar does.  Improve and fix commentary.
        (hscroll_window_tree): Don't assume w->cursor.vpos is within the
        limits of the glyph matrices.  (Bug#16051)
+       (redisplay_tool_bar): Modify the tool-bar-lines frame parameter
+       only when the new size is different from the old one, and the new
+       size can be achieved given the frame height.
 
 2013-12-23  Jan Djärv  <jan.h.d@swipnet.se>
 
index 9a3c27f..1c157c7 100644 (file)
@@ -12289,18 +12289,35 @@ redisplay_tool_bar (struct frame *f)
 
          if (change_height_p)
            {
+             /* Current size of the tool-bar window in canonical line
+                units.  */
+             int old_lines = WINDOW_TOTAL_LINES (w);
+             /* Required size of the tool-bar window in canonical
+                line units. */
              int new_lines = ((new_height + FRAME_LINE_HEIGHT (f) - 1)
                               / FRAME_LINE_HEIGHT (f));
-
-             XSETFRAME (frame, f);
-             Fmodify_frame_parameters (frame,
-                                       list1 (Fcons (Qtool_bar_lines,
-                                                     make_number (new_lines))));
-             /* Always do that now.  */
-             clear_glyph_matrix (w->desired_matrix);
-             f->n_tool_bar_rows = nrows;
-             f->fonts_changed = 1;
-             return 1;
+             /* Maximum size of the tool-bar window in canonical line
+                units that this frame can allow. */
+             int max_lines =
+               WINDOW_TOTAL_LINES (XWINDOW (FRAME_ROOT_WINDOW (f))) - 1;
+
+             /* Don't try to change the tool-bar window size and set
+                the fonts_changed flag unless really necessary.  That
+                flag causes redisplay to give up and retry
+                redisplaying the frame from scratch, so setting it
+                unnecessarily can lead to nasty redisplay loops.  */
+             if (new_lines <= max_lines
+                 && eabs (new_lines - old_lines) >= 1)
+               {
+                 XSETFRAME (frame, f);
+                 Fmodify_frame_parameters (frame,
+                                           list1 (Fcons (Qtool_bar_lines,
+                                                         make_number (new_lines))));
+                 clear_glyph_matrix (w->desired_matrix);
+                 f->n_tool_bar_rows = nrows;
+                 f->fonts_changed = 1;
+                 return 1;
+               }
            }
        }
     }