Subject: Re: bug#16856: 24.3.50; Cursor leaves garbage in fringe

From: David Reitter <[email-masked]>
Date: Sun, 17 Jul 2016 21:41:07 +0900

On Jul 17, 2016, at 9:09 PM, Eli Zaretskii <[email-masked]> wrote:
>  "Because the cursor is drawn without limiting focus to the window
>   box, but it is removed by writing glyph and nothing into the right
>   margin, while focus is applied to the window box, parts of the
>   cursor may remain visible."
> 
> It seems to imply that drawing cursor and erasing it are implemented
> in Aquamacs by two very different code fragments?

I don’t think they’re that different.
I do not know the code there very well, otherwise I would have just fixed the problem.

Is it possible that when drawing the glyph, we call ns_focus with the rectangle returned by ns_get_glyph_string_clip_rect()?
ns_draw_window_cursor() on the other hand focuses via ns_clip_to_row().  It might do so before deleting the cursor (if that’s where the cursor is erased), but that doesn’t matter, because clipping in ns_focus probably isn’t incremental from what it looks like.

>   And if that's true, I understand
> the workaround even less: it limits the _width_ of the cursor, whereas
> the problem is clearly with its coordinates.

No, it increases the width of the clipped rectangle so that the cursor can be erased from wherever it was drawn.
But again, if the cursor type is wider than 2px (on the right hand side of the underlying glyph), we would have to widen the clip box even further.

I’m not sure what the correct solution is here.  If the bar cursor is drawn to the right of the glyph, it’s going to go into the margin or fringe.  If you prevent that even at reasonable cursors like (bar . 2), the cursor is going to look funny on the right hand side.  So, I think we have to  (A)  widen the clipping rectangle to something like max(row_width, glyph_x+glyph_w+min(2, cursor_width)), and (B)  also clip when drawing the cursor so that wide cursors don’t go into the fringe.  I think Alan’s change may have done B already.  Haven’t tested that.  (As for A, I can’t work on it right now and probably don’t know the code well enough to do this right anyway.)