Subject: Re: bug#5908: tooltip-show breaks with multiline tip on Emacs for Windows v22.2.1

From: YAMAMOTO Mitsuharu <[email-masked]>
Date: Sat, 10 Apr 2010 07:13:32 +0900

>>>>> On Fri, 09 Apr 2010 18:58:51 +0200, Jan Djärv <[email-masked]> said:

>> I though this was a duplicate of the (still open) bug#2423.  Maybe
>> it was fixed and never closed, but I don't recall it.  (Multiline
>> tooltips still don't work the first time in GNU/Linux.)

> I have checked in a fix for multiline tooltips the first time for X.
> try_window aborts if fonts_changed_p is set, and the first time one
> loads the tip font, this is what happens.

Or maybe we could introduce a flag for try_window to ignore
fonts_changed_p, because glyph matrices are not adjusted for the
tooltip case, anyway.

				     YAMAMOTO Mitsuharu
				[email-masked]

=== modified file 'src/dispextern.h'
*** src/dispextern.h	2010-03-22 07:26:56 +0000
--- src/dispextern.h	2010-04-09 22:04:46 +0000
***************
*** 2831,2836 ****
--- 2831,2840 ----
  				       XRectangle *));
  #endif
  
+ /* Flags passed to try_window.  */
+ #define TRY_WINDOW_CHECK_MARGINS	(1 << 0)
+ #define TRY_WINDOW_IGNORE_FONTS_CHANGE	(1 << 1)
+ 
  /* Defined in fringe.c */
  
  int lookup_fringe_bitmap (Lisp_Object);

=== modified file 'src/xdisp.c'
*** src/xdisp.c	2010-04-05 15:46:29 +0000
--- src/xdisp.c	2010-04-09 22:04:15 +0000
***************
*** 13603,13609 ****
  	       = try_window_reusing_current_matrix (w)))
  	{
  	  IF_DEBUG (debug_method_add (w, "1"));
! 	  if (try_window (window, startp, 1) < 0)
  	    /* -1 means we need to scroll.
  	       0 means we need new matrices, but fonts_changed_p
  	       is set in that case, so we will detect it below.  */
--- 13603,13609 ----
  	       = try_window_reusing_current_matrix (w)))
  	{
  	  IF_DEBUG (debug_method_add (w, "1"));
! 	  if (try_window (window, startp, TRY_WINDOW_CHECK_MARGINS) < 0)
  	    /* -1 means we need to scroll.
  	       0 means we need new matrices, but fonts_changed_p
  	       is set in that case, so we will detect it below.  */
***************
*** 13954,13966 ****
     Value is 1 if successful.  It is zero if fonts were loaded during
     redisplay which makes re-adjusting glyph matrices necessary, and -1
     if point would appear in the scroll margins.
!    (We check that only if CHECK_MARGINS is nonzero.  */
  
  int
! try_window (window, pos, check_margins)
       Lisp_Object window;
       struct text_pos pos;
!      int check_margins;
  {
    struct window *w = XWINDOW (window);
    struct it it;
--- 13954,13968 ----
     Value is 1 if successful.  It is zero if fonts were loaded during
     redisplay which makes re-adjusting glyph matrices necessary, and -1
     if point would appear in the scroll margins.
!    (We check the former only if TRY_WINDOW_IGNORE_FONTS_CHANGE is
!    unset in FLAGS, and the latter only if TRY_WINDOW_CHECK_MARGINS is
!    set in FLAGS.)  */
  
  int
! try_window (window, pos, flags)
       Lisp_Object window;
       struct text_pos pos;
!      int flags;
  {
    struct window *w = XWINDOW (window);
    struct it it;
***************
*** 13982,13993 ****
      {
        if (display_line (&it))
  	last_text_row = it.glyph_row - 1;
!       if (fonts_changed_p)
  	return 0;
      }
  
    /* Don't let the cursor end in the scroll margins.  */
!   if (check_margins
        && !MINI_WINDOW_P (w))
      {
        int this_scroll_margin;
--- 13984,13995 ----
      {
        if (display_line (&it))
  	last_text_row = it.glyph_row - 1;
!       if (fonts_changed_p && !(flags & TRY_WINDOW_IGNORE_FONTS_CHANGE))
  	return 0;
      }
  
    /* Don't let the cursor end in the scroll margins.  */
!   if ((flags & TRY_WINDOW_CHECK_MARGINS)
        && !MINI_WINDOW_P (w))
      {
        int this_scroll_margin;

=== modified file 'src/xfns.c'
*** src/xfns.c	2010-03-22 07:26:56 +0000
--- src/xfns.c	2010-04-09 22:03:33 +0000
***************
*** 5196,5202 ****
    clear_glyph_matrix (w->desired_matrix);
    clear_glyph_matrix (w->current_matrix);
    SET_TEXT_POS (pos, BEGV, BEGV_BYTE);
!   try_window (FRAME_ROOT_WINDOW (f), pos, 0);
  
    /* Compute width and height of the tooltip.  */
    width = height = 0;
--- 5196,5202 ----
    clear_glyph_matrix (w->desired_matrix);
    clear_glyph_matrix (w->current_matrix);
    SET_TEXT_POS (pos, BEGV, BEGV_BYTE);
!   try_window (FRAME_ROOT_WINDOW (f), pos, TRY_WINDOW_IGNORE_FONTS_CHANGE);
  
    /* Compute width and height of the tooltip.  */
    width = height = 0;