emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: address@hidden: Re: mode-line redisplay bug]


From: Jason Rumney
Subject: Re: address@hidden: Re: mode-line redisplay bug]
Date: Sat, 08 Oct 2005 22:26:59 +0100
User-agent: Gnus/5.11 (Gnus v5.11) Emacs/22.0.50 (windows-nt)

Jason Rumney <address@hidden> writes:

> On GNU/Linux:
>
> The highlit area flickers. On W32 it flickers once when the tooltip
> pops up, but on X, it flickers constantly. I remember fixing something
> like this on W32 years ago, it was in the code that detected mouse
> movement - movement events were being sent for zero movement when
> inside track-mouse forms. But my recollection is that the same bug did
> not appear on X at the time, so even though the code appeared to be
> the same, I did not try to apply my fix to the X code.

I have looked at this and narrowed down the changes I made to
w32term.c. Looking at the code again, I am sure that my changes should
be applied to xterm.c as well, but applying them does not seem to make
any difference to the flickering. It probably needs an X expert to
look at it as I may have some misunderstanding here.

In note_mouse_movement, which is called from handle_one_xevent in
response to several types of event, we check the event's mouse position
against last_mouse_glyph, to limit the number of events we pass
through to lisp.

last_mouse_glyph is updated in XTmouse_position, nowhere else as far
as I can tell. XTmouse_position is installed as mouse_position_hook.
As far as I can tell, it is called only when do_mouse_tracking is
non-nil (in keyboard.c), or when the functions mouse-position and
mouse-pixel-position (both in frame.c) are explicitly called.

This means that last_mouse_glyph normally won't get updated, so it
doesn't serve the purpose that we use it for.

I fixed this in w32term.c by factoring out the code that updates
last_mouse_glyph from w32_mouse_position (the equivalent of
XTmouse_position) into a new function remember_mouse_glyph, and call
it from note_mouse_movement when we notice the glyph has changed, to
ensure it is always up to date.

Having done that, I also noticed the following code from
XTmouse_position:

      /* Arrange for the division in FRAME_PIXEL_X_TO_COL etc. to
         round down even for negative values.  */
      if (gx < 0)
        gx -= width - 1;
      if (gy < 0)
        gy -= height - 1;

      gx = (gx + width - 1) / width * width;
      gy = (gy + height - 1) / height * height;

      last_mouse_glyph.width  = width;
      last_mouse_glyph.height = height;
      last_mouse_glyph.x = gx;
      last_mouse_glyph.y = gy;

gx and gy are initially the position of the mouse. We are trying to
find the rectangle around the glyph under the mouse here.

On Windows, I found that this code returns the rectangle of a glyph
diagonally adjacent to the glyph we want. I am not sure if I am
missing something about the way X co-ordinates work, but I think the
two lines that round gx and gy should be simply:

      gx = gx / width * width;
      gy = gy / height * height;



Here is the full patch adapted to xterm.c. As I said, it does not seem
to have any effect, so it needs someone more familiar with X to look
at it further:

3584a3585,3586
> static void remember_mouse_glyph P_ ((struct frame *, int, int));
> 
3609a3612,3613
>       /* Remember which glyph we're now on.  */
>       remember_mouse_glyph (frame, event->x, event->y);
3679a3684,3724
> /* Remember which glyph the mouse is over.
>  */
> static void
> remember_mouse_glyph (f1, win_x, win_y)
>      FRAME_PTR f1;
>      int win_x, win_y;
> {
>   int width, height, gx, gy;
> 
>   /* Try getting the rectangle of the actual glyph.  */
>   if (!glyph_rect (f1, win_x, win_y, &last_mouse_glyph))
>     {
>       /* If there is no glyph under the mouse, then we divide the screen
>        into a grid of the smallest glyph in the frame, and use that
>        as our "glyph".  */
>       width = FRAME_SMALLEST_CHAR_WIDTH (f1);
>       height = FRAME_SMALLEST_FONT_HEIGHT (f1);
>       gx = win_x;
>       gy = win_y;
> 
>       /* Arrange for the division in FRAME_PIXEL_X_TO_COL etc. to
>        round down even for negative values.  */
>       if (gx < 0)
>       gx -= width - 1;
>       if (gy < 0)
>       gy -= height - 1;
> #if 0
>       gx = (gx + width - 1) / width * width;
>       gy = (gy + height - 1) / height * height;
> #else
>       gx = gx / width * width;
>       gy = gy / width * width;
> #endif
>       last_mouse_glyph.width  = width;
>       last_mouse_glyph.height = height;
>       last_mouse_glyph.x = gx;
>       last_mouse_glyph.y = gy;
>     }
> }
> 
> 
3866,3891c3911
<           int width, height, gx, gy;
<           XRectangle rect;
< 
<           if (glyph_rect (f1, win_x, win_y, &rect))
<             last_mouse_glyph = rect;
<           else
<             {
<               width = FRAME_SMALLEST_CHAR_WIDTH (f1);
<               height = FRAME_SMALLEST_FONT_HEIGHT (f1);
<               gx = win_x;
<               gy = win_y;
< 
<               /* Arrange for the division in FRAME_PIXEL_X_TO_COL etc. to
<                  round down even for negative values.  */
<               if (gx < 0)
<                 gx -= width - 1;
<               if (gy < 0)
<                 gy -= height - 1;
<               gx = (gx + width - 1) / width * width;
<               gy = (gy + height - 1) / height * height;
< 
<               last_mouse_glyph.width  = width;
<               last_mouse_glyph.height = height;
<               last_mouse_glyph.x = gx;
<               last_mouse_glyph.y = gy;
<             }
---
>           remember_mouse_glyph (f1, win_x, win_y);

reply via email to

[Prev in Thread] Current Thread [Next in Thread]