all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Po Lu via "Bug reports for GNU Emacs, the Swiss army knife of text editors" <bug-gnu-emacs@gnu.org>
To: Eli Zaretskii <eliz@gnu.org>
Cc: larsi@gnus.org, 50660@debbugs.gnu.org
Subject: bug#50660: 28.0.50; Text artifacting when the cursor moves over text under mouse face that originally displayed a box
Date: Wed, 29 Sep 2021 09:35:24 +0800	[thread overview]
Message-ID: <87k0j0rwo3.fsf@yahoo.com> (raw)
In-Reply-To: <83v92mkzft.fsf@gnu.org> (Eli Zaretskii's message of "Mon, 27 Sep 2021 14:52:54 +0300")

[-- Attachment #1: Type: text/plain, Size: 297 bytes --]

Eli Zaretskii <eliz@gnu.org> writes:

> I think I'm still a bit confused.  Can you show the patch you have
> where you see these problems with erase_phys_cursor?

Thanks, but I think I've already solved the problem.  Can you try the
attached patch and see if there are any problems with it?  TIA


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: fix-cursor-position.patch --]
[-- Type: text/x-patch, Size: 6669 bytes --]

diff --git a/src/dispnew.c b/src/dispnew.c
index 0c31319917..f58e1d28e4 100644
--- a/src/dispnew.c
+++ b/src/dispnew.c
@@ -3848,6 +3848,10 @@ gui_update_window_end (struct window *w, bool cursor_on_p,
 				w->output_cursor.hpos, w->output_cursor.vpos,
 				w->output_cursor.x, w->output_cursor.y);
 
+      if (cursor_in_mouse_face_p (w)
+	  && cursor_on_p)
+	mouse_face_overwritten_p = 1;
+
       if (draw_window_fringes (w, true))
 	{
 	  if (WINDOW_RIGHT_DIVIDER_WIDTH (w))
diff --git a/src/xdisp.c b/src/xdisp.c
index 2e72f6b591..f542b3f526 100644
--- a/src/xdisp.c
+++ b/src/xdisp.c
@@ -1179,7 +1179,9 @@ #define face_after_it_pos(IT)  face_before_or_after_it_pos (IT, false)
 static Lisp_Object get_it_property (struct it *, Lisp_Object);
 static Lisp_Object calc_line_height_property (struct it *, Lisp_Object,
 					      struct font *, int, bool);
-
+static void get_cursor_offset_for_mouse_face (struct window *w,
+					      struct glyph_row *row,
+					      int *offset)
 #endif /* HAVE_WINDOW_SYSTEM */
 
 static void produce_special_glyphs (struct it *, enum display_element_type);
@@ -31741,6 +31743,10 @@ erase_phys_cursor (struct window *w)
   Mouse_HLInfo *hlinfo = MOUSE_HL_INFO (f);
   int hpos = w->phys_cursor.hpos;
   int vpos = w->phys_cursor.vpos;
+#ifdef HAVE_WINDOW_SYSTEM
+  int mouse_delta = 0;
+  int phys_x = w->phys_cursor.x;
+#endif
   bool mouse_face_here_p = false;
   struct glyph_matrix *active_glyphs = w->current_matrix;
   struct glyph_row *cursor_row;
@@ -31810,6 +31816,14 @@ erase_phys_cursor (struct window *w)
       && cursor_row->used[TEXT_AREA] > hpos && hpos >= 0)
     mouse_face_here_p = true;
 
+#ifdef HAVE_WINDOW_SYSTEM
+  if (mouse_face_here_p)
+    {
+      get_cursor_offset_for_mouse_face (w, cursor_row, &mouse_delta);
+      w->phys_cursor.x += mouse_delta;
+    }
+#endif
+
   /* Maybe clear the display under the cursor.  */
   if (w->phys_cursor_type == HOLLOW_BOX_CURSOR)
     {
@@ -31845,6 +31859,9 @@ erase_phys_cursor (struct window *w)
   draw_phys_cursor_glyph (w, cursor_row, hl);
 
  mark_cursor_off:
+#ifdef HAVE_WINDOW_SYSTEM
+  w->phys_cursor.x = phys_x;
+#endif
   w->phys_cursor_on_p = false;
   w->phys_cursor_type = NO_CURSOR;
 }
@@ -32081,6 +32098,9 @@ show_mouse_face (Mouse_HLInfo *hlinfo, enum draw_glyphs_face draw)
       && hlinfo->mouse_face_end_row < w->current_matrix->nrows)
     {
       bool phys_cursor_on_p = w->phys_cursor_on_p;
+#ifdef HAVE_WINDOW_SYSTEM
+      int mouse_off = 0;
+#endif
       struct glyph_row *row, *first, *last;
 
       first = MATRIX_ROW (w->current_matrix, hlinfo->mouse_face_beg_row);
@@ -32154,6 +32174,12 @@ show_mouse_face (Mouse_HLInfo *hlinfo, enum draw_glyphs_face draw)
 	      row->mouse_face_p
 		= draw == DRAW_MOUSE_FACE || draw == DRAW_IMAGE_RAISED;
 	    }
+#ifdef HAVE_WINDOW_SYSTEM
+	  if (MATRIX_ROW_VPOS (row, w->current_matrix)
+	      == w->phys_cursor.vpos && !w->pseudo_window_p
+	      && draw == DRAW_MOUSE_FACE)
+	    get_cursor_offset_for_mouse_face (w, row, &mouse_off);
+#endif
 	}
 
       /* When we've written over the cursor, arrange for it to
@@ -32163,6 +32189,7 @@ show_mouse_face (Mouse_HLInfo *hlinfo, enum draw_glyphs_face draw)
 	{
 #ifdef HAVE_WINDOW_SYSTEM
 	  int hpos = w->phys_cursor.hpos;
+	  int old_phys_cursor_x = w->phys_cursor.x;
 
 	  /* When the window is hscrolled, cursor hpos can legitimately be
 	     out of bounds, but we draw the cursor at the corresponding
@@ -32174,7 +32201,9 @@ show_mouse_face (Mouse_HLInfo *hlinfo, enum draw_glyphs_face draw)
 
 	  block_input ();
 	  display_and_set_cursor (w, true, hpos, w->phys_cursor.vpos,
-				  w->phys_cursor.x, w->phys_cursor.y);
+				  w->phys_cursor.x + mouse_off,
+				  w->phys_cursor.y);
+	  w->phys_cursor.x = old_phys_cursor_x;
 	  unblock_input ();
 #endif	/* HAVE_WINDOW_SYSTEM */
 	}
@@ -35926,4 +35955,89 @@ cancel_hourglass (void)
     }
 }
 
+#ifdef HAVE_WINDOW_SYSTEM
+/* Get the offset to apply before drawing phys_cursor, and return it
+   in OFFSET, if ROW has something currently under mouse face. */
+static void
+get_cursor_offset_for_mouse_face (struct window *w, struct glyph_row *row,
+				  int *offset)
+{
+  if (row->mode_line_p)
+    return;
+  block_input ();
+
+  struct frame *f = WINDOW_XFRAME (w);
+  Mouse_HLInfo *hlinfo = MOUSE_HL_INFO (f);
+  struct glyph *start, *end;
+  struct face *mouse_face = FACE_FROM_ID (f, hlinfo->mouse_face_face_id);
+  int hpos = w->phys_cursor.hpos;
+  end = &row->glyphs[TEXT_AREA][hpos];
+
+  if (!row->reversed_p)
+    {
+      if (MATRIX_ROW_VPOS (row, w->current_matrix) ==
+ 	  hlinfo->mouse_face_beg_row)
+	start = &row->glyphs[TEXT_AREA][hlinfo->mouse_face_beg_col];
+      else
+	start = row->glyphs[TEXT_AREA];
+    }
+  else
+    {
+      if (MATRIX_ROW_VPOS (row, w->current_matrix) ==
+	  hlinfo->mouse_face_end_row)
+	start = &row->glyphs[TEXT_AREA][hlinfo->mouse_face_end_col];
+      else
+	start = &row->glyphs[TEXT_AREA][row->used[TEXT_AREA] - 1];
+    }
+
+  /* Calculate an offset to correct phys_cursor x if we are
+     drawing the cursor in the mouse face. */
+
+  for (; start != end; row->reversed_p ?
+	 --start : ++start)
+    {
+      struct glyph *g = start;
+      struct face *mouse = mouse_face;
+      struct face *regular_face = FACE_FROM_ID (f, g->face_id);
+
+      bool do_left_box_p = g->left_box_line_p;
+      bool do_right_box_p = g->right_box_line_p;
+
+      if (row->reversed_p && g->type == IMAGE_GLYPH)
+	{
+	  struct image *img = IMAGE_FROM_ID (WINDOW_XFRAME (w),
+					     g->u.img_id);
+	  do_left_box_p = g->left_box_line_p &&
+	    g->slice.img.x + g->slice.img.width == img->width;
+	  do_right_box_p = g->right_box_line_p &&
+	    g->slice.img.x == 0;
+	}
+      else if (g->type == IMAGE_GLYPH)
+	{
+	  struct image *img = IMAGE_FROM_ID (WINDOW_XFRAME (w),
+					     g->u.img_id);
+	  do_left_box_p = g->left_box_line_p &&
+	    g->slice.img.x + g->slice.img.width == img->width;
+	  do_right_box_p = g->right_box_line_p &&
+	    g->slice.img.x == 0;
+	}
+
+      /* If the glyph has a left box line, subtract it the
+	 offset. */
+      if (do_left_box_p)
+        *offset -= max (0, regular_face->box_vertical_line_width);
+      /* Likewise with the right box line, as there may be a
+	 box there as well. */
+      if (do_right_box_p)
+        *offset -= max (0, regular_face->box_vertical_line_width);
+      /* Now we add the line widths from the new face. */
+      if (g->left_box_line_p)
+	*offset += max (0, mouse->box_vertical_line_width);
+      if (g->right_box_line_p)
+        *offset += max (0, mouse->box_vertical_line_width);
+    }
+
+  unblock_input ();
+}
+#endif
 #endif /* HAVE_WINDOW_SYSTEM */

  reply	other threads:[~2021-09-29  1:35 UTC|newest]

Thread overview: 83+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <87czp6ysw7.fsf.ref@yahoo.com>
2021-09-18 12:23 ` bug#50660: 28.0.50; Text artifacting when the cursor moves over text under mouse face that originally displayed a box Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2021-09-18 13:48   ` Lars Ingebrigtsen
2021-09-19  0:33     ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2021-09-19  5:47       ` Eli Zaretskii
2021-09-19 13:55         ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2021-09-19 15:13           ` Lars Ingebrigtsen
2021-09-19 17:01           ` Eli Zaretskii
2021-09-20  1:00             ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2021-09-20  5:19               ` Eli Zaretskii
2021-09-20  5:34                 ` Eli Zaretskii
2021-09-20  8:02                   ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2021-09-20  7:07                 ` Eli Zaretskii
2021-09-20  7:34                   ` Eli Zaretskii
2021-09-20  8:18                     ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2021-09-20  9:47                       ` Eli Zaretskii
2021-09-20 10:27                         ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2021-09-20 10:51                           ` Eli Zaretskii
2021-09-20 11:08                             ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2021-09-20 12:07                               ` Eli Zaretskii
2021-09-20 12:36                               ` Eli Zaretskii
2021-09-21  0:38                                 ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2021-09-21  6:11                                   ` Eli Zaretskii
2021-09-21  7:34                                     ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2021-09-21  8:45                                       ` Eli Zaretskii
2021-09-21  9:20                                         ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2021-09-21  9:37                                           ` Eli Zaretskii
2021-09-21  9:45                                             ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2021-09-21 10:17                                               ` Eli Zaretskii
2021-09-21 10:41                                                 ` Eli Zaretskii
2021-09-21 12:26                                                   ` Eli Zaretskii
2021-09-20 11:09                             ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2021-09-21 12:46                             ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2021-09-21 13:10                               ` Eli Zaretskii
2021-09-21 13:36                                 ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2021-09-21 13:47                                   ` Eli Zaretskii
2021-09-23 23:53                                     ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2021-09-24  6:47                                       ` Eli Zaretskii
2021-09-26  6:46                                       ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2021-09-26  7:04                                         ` Eli Zaretskii
2021-09-26  9:56                                           ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2021-09-27 11:52                                             ` Eli Zaretskii
2021-09-29  1:35                                               ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors [this message]
2021-10-02  8:43                                                 ` Eli Zaretskii
2021-10-02  9:46                                                   ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2021-10-02 12:52                                                   ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2021-10-14  8:58                                                     ` Eli Zaretskii
2021-10-14 10:52                                                       ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2021-10-14 11:11                                                         ` Robert Pluim
2021-10-14 11:25                                                           ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2021-10-14 11:35                                                         ` Eli Zaretskii
2021-10-14 11:54                                                           ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2021-10-14 12:10                                                             ` Eli Zaretskii
2021-10-14 12:16                                                               ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2021-10-14 12:20                                                                 ` Eli Zaretskii
2021-10-14 12:27                                                                   ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2021-10-14 12:44                                                                     ` Eli Zaretskii
2021-10-14 13:11                                                                       ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2021-10-14 15:51                                                                         ` Eli Zaretskii
2021-10-15  1:28                                                                           ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2021-10-15 13:43                                                                             ` Eli Zaretskii
2021-10-16  0:18                                                                               ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2021-10-16  6:09                                                                                 ` Eli Zaretskii
2021-10-16  6:16                                                                                   ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2021-10-16  6:28                                                                                     ` Eli Zaretskii
2021-10-16  6:39                                                                                       ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2021-10-16  7:00                                                                                         ` Eli Zaretskii
2021-10-16  7:13                                                                                           ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2021-10-16  7:26                                                                                             ` Eli Zaretskii
2021-10-16  7:52                                                                                               ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2021-10-16 10:10                                                                                                 ` Eli Zaretskii
2021-10-16 12:12                                                                                                   ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2021-10-16 12:25                                                                                                     ` Eli Zaretskii
2021-10-16 12:36                                                                                                       ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2021-10-16 12:45                                                                                                         ` Eli Zaretskii
2021-10-16 13:18                                                                                                           ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2021-10-16 13:46                                                                                                             ` Eli Zaretskii
2021-10-17  0:32                                                                                                               ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2021-10-17 12:15                                                                                                                 ` Eli Zaretskii
2021-10-17 12:39                                                                                                                   ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2021-09-20  8:02                 ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2021-09-20  6:33               ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2021-09-19  0:50     ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2021-09-19 15:10       ` Lars Ingebrigtsen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87k0j0rwo3.fsf@yahoo.com \
    --to=bug-gnu-emacs@gnu.org \
    --cc=50660@debbugs.gnu.org \
    --cc=eliz@gnu.org \
    --cc=larsi@gnus.org \
    --cc=luangruo@yahoo.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.