From xemacs-m  Sat Mar 22 21:20:46 1997
Received: from GS213.SP.CS.CMU.EDU (GS213.SP.CS.CMU.EDU [128.2.209.183])
	by xemacs.org (8.8.5/8.8.5) with SMTP id VAA02313
	for <xemacs-beta@xemacs.org>; Sat, 22 Mar 1997 21:20:45 -0600 (CST)
Received: by GS213.SP.CS.CMU.EDU (AIX 3.2/UCB 5.64/4.03)
          id AA07324; Sat, 22 Mar 1997 22:20:42 -0500
Date: Sat, 22 Mar 1997 22:20:42 -0500
Message-Id: <9703230320.AA07324@GS213.SP.CS.CMU.EDU>
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
From: Darrell Kindred <dkindred@cmu.edu>
To: xemacs-beta@xemacs.org
Subject: hollow-cursor glitch [w/ patch]
Organization: Carnegie Mellon University School of Computer Science

[oops, left off the patch itself on the first try]

This bug exists in 19.15-b103 at least:

   Start an xemacs, and set a large default font, like this:
      -adobe-courier-medium-r-normal-*-*-240-*-*-*-*-*-*
   Type some text, and leave the cursor over a letter.
   Move another x window so that the right half of the
   cursor is obscured and XEmacs no longer has kbd focus.
   Then send that window to the back *without* giving the
   focus to XEmacs.  The hollow cursor will get a vertical
   line through the middle and no left edge.  (Alternative:
   with opaque-drag on, move the left edge of another window
   slowly from left to right over the cursor.)

The patch below fixes this.  Note: I *don't* think it's
terribly important that this get fixed in 19.15, and there's
at least some chance that I screwed it up, so I'd suggest
just applying it to 20.1.

- Darrell

--- src/redisplay-x.c.orig	Mon Mar 17 03:57:43 1997
+++ src/redisplay-x.c	Sat Mar 22 20:18:50 1997
@@ -1049,7 +1049,8 @@
     {
       int tmp_height, tmp_y;
       int bar_width = EQ (bar_cursor_value, Qt) ? 1 : 2;
-      int cursor_x;
+      int need_clipping = (cursor_start < clip_start
+			   || clip_end < cursor_start + cursor_width);
 
       /* #### This value is correct (as far as I know) because
 	 all of the times we need to draw this cursor, we will
@@ -1079,11 +1080,6 @@
 			 Qnil, Qnil, Qnil);
 	}
       
-      if (cursor)
-	cursor_x = clip_start;
-      else
-	cursor_x = cursor_start;
-      
       tmp_y = dl->ypos - bogusly_obtained_ascent_value;
       tmp_height = cursor_height;
       if (tmp_y + tmp_height > (int) (dl->ypos - dl->ascent + height))
@@ -1094,15 +1090,33 @@
 	  tmp_height = dl->ypos - dl->ascent + height - tmp_y;
 	}
       
+      if (need_clipping)
+	{
+	  XRectangle clip_box[1];
+	  clip_box[0].x = 0;
+	  clip_box[0].y = 0;
+	  clip_box[0].width = clip_end - clip_start;
+	  clip_box[0].height = tmp_height;
+	  XSetClipRectangles (dpy, gc, clip_start, tmp_y,
+			      clip_box, 1, Unsorted);
+	}
+
       if (!focus && NILP (bar_cursor_value))
 	{
-	  XDrawRectangle (dpy, x_win, gc, cursor_x, tmp_y,
+	  XDrawRectangle (dpy, x_win, gc, cursor_start, tmp_y,
 			  cursor_width - 1, tmp_height - 1);
 	}
       else if (focus && !NILP (bar_cursor_value))
 	{
-	  XDrawLine (dpy, x_win, gc, cursor_x + bar_width - 1, tmp_y,
-		     cursor_x + bar_width - 1, tmp_y + tmp_height - 1);
+	  XDrawLine (dpy, x_win, gc, cursor_start + bar_width - 1, tmp_y,
+		     cursor_start + bar_width - 1, tmp_y + tmp_height - 1);
+	}
+
+      /* Restore the GC */
+      if (need_clipping)
+	{
+	  XSetClipMask (dpy, gc, None);
+	  XSetClipOrigin (dpy, gc, 0, 0);
 	}
     }
 }

