From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Eli Zaretskii Newsgroups: gmane.emacs.bugs Subject: bug#50660: 28.0.50; Text artifacting when the cursor moves over text under mouse face that originally displayed a box Date: Fri, 15 Oct 2021 16:43:56 +0300 Message-ID: <83v91yiesj.fsf@gnu.org> References: <87czp6ysw7.fsf.ref@yahoo.com> <83pmt2xcox.fsf@gnu.org> <87lf3myhlb.fsf@yahoo.com> <87a6jzvnpq.fsf@yahoo.com> <83o88fom1k.fsf@gnu.org> <871r5bvex8.fsf@yahoo.com> <83v92mkzft.fsf@gnu.org> <87k0j0rwo3.fsf@yahoo.com> <838rzbddfa.fsf@gnu.org> <878rzbd1w5.fsf@yahoo.com> <83wnmgkmok.fsf@gnu.org> <878ryvnain.fsf@yahoo.com> <83mtnbltyp.fsf@gnu.org> <87mtnblt35.fsf@yahoo.com> <83ilxzlsck.fsf@gnu.org> <877defls2w.fsf@yahoo.com> <83fst3lrwr.fsf@gnu.org> <87o87rkczt.fsf@yahoo.com> <83czo7lqrl.fsf@gnu.org> <87h7djkayk.fsf@yahoo.com> <83bl3rli53.fsf@gnu.org> <871r4njcum.fsf@yahoo.com> Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="8744"; mail-complaints-to="usenet@ciao.gmane.io" Cc: larsi@gnus.org, 50660@debbugs.gnu.org To: Po Lu Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Fri Oct 15 15:45:37 2021 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mbNWi-00022S-1c for geb-bug-gnu-emacs@m.gmane-mx.org; Fri, 15 Oct 2021 15:45:36 +0200 Original-Received: from localhost ([::1]:51990 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mbNWg-0006wb-8T for geb-bug-gnu-emacs@m.gmane-mx.org; Fri, 15 Oct 2021 09:45:34 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:42478) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mbNWA-0006wL-Am for bug-gnu-emacs@gnu.org; Fri, 15 Oct 2021 09:45:02 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:55170) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mbNWA-0008EB-1A for bug-gnu-emacs@gnu.org; Fri, 15 Oct 2021 09:45:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1mbNW9-0000QY-SB for bug-gnu-emacs@gnu.org; Fri, 15 Oct 2021 09:45:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Eli Zaretskii Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Fri, 15 Oct 2021 13:45:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 50660 X-GNU-PR-Package: emacs Original-Received: via spool by 50660-submit@debbugs.gnu.org id=B50660.16343054471557 (code B ref 50660); Fri, 15 Oct 2021 13:45:01 +0000 Original-Received: (at 50660) by debbugs.gnu.org; 15 Oct 2021 13:44:07 +0000 Original-Received: from localhost ([127.0.0.1]:38483 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mbNVG-0000P3-PH for submit@debbugs.gnu.org; Fri, 15 Oct 2021 09:44:07 -0400 Original-Received: from eggs.gnu.org ([209.51.188.92]:40462) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mbNVD-0000ON-Q5 for 50660@debbugs.gnu.org; Fri, 15 Oct 2021 09:44:05 -0400 Original-Received: from fencepost.gnu.org ([2001:470:142:3::e]:58732) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mbNV8-0007Y8-C1; Fri, 15 Oct 2021 09:43:58 -0400 Original-Received: from [87.69.77.57] (port=3656 helo=home-c4e4a596f7) by fencepost.gnu.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mbNV7-0007g8-VH; Fri, 15 Oct 2021 09:43:58 -0400 In-Reply-To: <871r4njcum.fsf@yahoo.com> (message from Po Lu on Fri, 15 Oct 2021 09:28:17 +0800) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:217316 Archived-At: > From: Po Lu > Cc: larsi@gnus.org, 50660@debbugs.gnu.org > Date: Fri, 15 Oct 2021 09:28:17 +0800 > > @@ -28281,6 +28303,16 @@ fill_glyph_string (struct glyph_string *s, int face_id, > break; > } > > + if (s->hl == DRAW_MOUSE_FACE > + || (s->hl == DRAW_CURSOR && cursor_in_mouse_face_p (s->w))) > + { > + Mouse_HLInfo *hlinfo = MOUSE_HL_INFO (s->f); > + struct face *face > + = FACE_FROM_ID (s->f, hlinfo->mouse_face_face_id); > + s->face > + = FACE_FROM_ID (s->f, FACE_FOR_CHAR (s->f, face, > + s->first_glyph->u.ch, -1, Qnil)); > + } > s->font = s->face->font; This part doesn't look right to me: FACE_FOR_CHAR could potentially yield a face with a different font, but the glyph codes in the glyph string will reference the previous font, because get_glyph_face_and_encoding was called before the face was changed. Also, why did you not follow the more cautious code of xterm.c: > - /* What face has to be used last for the mouse face? */ > - face_id = MOUSE_HL_INFO (s->f)->mouse_face_face_id; > - face = FACE_FROM_ID_OR_NULL (s->f, face_id); > - if (face == NULL) > - face = FACE_FROM_ID (s->f, MOUSE_FACE_ID); FACE_FROM_ID can abort if the face is not in the face cache. > @@ -28620,7 +28679,67 @@ set_glyph_string_background_width (struct glyph_string *s, int start, int last_x > if (s->extends_to_end_of_line_p) > s->background_width = last_x - s->x + 1; > else > - s->background_width = s->width; > + { > + s->background_width = s->width; > +#ifdef HAVE_WINDOW_SYSTEM > + if (FRAME_WINDOW_P (s->f) > + && s->hl == DRAW_CURSOR > + && cursor_in_mouse_face_p (s->w)) > + { > + /* We will have to adjust the background width of the string > + in this situation, because the glyph's pixel_width might > + be inconsistent with the box of the mouse face, which > + leads to an ugly over-wide cursor. */ > + > + struct glyph *g = s->first_glyph; > + struct face *regular_face = FACE_FROM_ID (s->f, g->face_id); > + > + bool do_left_box_p = g->left_box_line_p; > + bool do_right_box_p = g->right_box_line_p; > + > + /* This is required because we test some parameters > + of the image slice before applying the box in > + produce_image_glyph. */ > + > + if (g->type == IMAGE_GLYPH) > + { > + if (!s->row->reversed_p) > + { > + struct image *img = IMAGE_FROM_ID (s->f, g->u.img_id); > + do_left_box_p = g->left_box_line_p && > + g->slice.img.x == 0; > + do_right_box_p = g->right_box_line_p && > + g->slice.img.x + g->slice.img.width == img->width; > + } > + else > + { > + struct image *img = IMAGE_FROM_ID (s->f, 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 from the > + offset. */ > + if (do_left_box_p) > + s->background_width -= 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) > + s->background_width -= max (0, regular_face->box_vertical_line_width); > + /* Now add the line widths from the new face. */ > + if (g->left_box_line_p) > + s->background_width += max (0, s->face->box_vertical_line_width); > + if (g->right_box_line_p) > + s->background_width += max (0, s->face->box_vertical_line_width); > + > + /* s->width is probably worth adjusting here as well. */ > + s->width = s->background_width; > + } > +#endif This looks like the same code we have elsewhere, so can't we have a function to call in both places? Also, the indentation with/without TABs seems wrong here. And finally, please always leave TWO spaces after the final period in a comment, like this: /* s->width is probably worth adjusting here as well. */ ^^^