From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Po Lu via "Bug reports for GNU Emacs, the Swiss army knife of text editors" 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: Wed, 29 Sep 2021 09:35:24 +0800 Message-ID: <87k0j0rwo3.fsf@yahoo.com> References: <87czp6ysw7.fsf.ref@yahoo.com> <831r5l5d6d.fsf@gnu.org> <87h7egy8jo.fsf@yahoo.com> <838rzs4i09.fsf@gnu.org> <87fsu06oxi.fsf@yahoo.com> <83ee9j3ju3.fsf@gnu.org> <834kaf3ets.fsf@gnu.org> <8335pz3dli.fsf@gnu.org> <87r1dj4q4m.fsf@yahoo.com> <83zgs71su7.fsf@gnu.org> <87k0jb4k5l.fsf@yahoo.com> <83sfxz1pw0.fsf@gnu.org> <87o88m14g0.fsf@yahoo.com> <83sfxyxeer.fsf@gnu.org> <87h7ee1252.fsf@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> Reply-To: Po Lu Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="29746"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) Cc: larsi@gnus.org, 50660@debbugs.gnu.org To: Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Wed Sep 29 03:36:22 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 1mVOWE-0007W5-Cj for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 29 Sep 2021 03:36:22 +0200 Original-Received: from localhost ([::1]:55954 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mVOWC-0005IL-E7 for geb-bug-gnu-emacs@m.gmane-mx.org; Tue, 28 Sep 2021 21:36:20 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:49306) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mVOVu-0005I5-22 for bug-gnu-emacs@gnu.org; Tue, 28 Sep 2021 21:36:07 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:35825) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mVOVt-0005yd-RF for bug-gnu-emacs@gnu.org; Tue, 28 Sep 2021 21:36:01 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1mVOVt-0006uy-MI for bug-gnu-emacs@gnu.org; Tue, 28 Sep 2021 21:36:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Po Lu Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 29 Sep 2021 01:36: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.163287933926563 (code B ref 50660); Wed, 29 Sep 2021 01:36:01 +0000 Original-Received: (at 50660) by debbugs.gnu.org; 29 Sep 2021 01:35:39 +0000 Original-Received: from localhost ([127.0.0.1]:47371 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mVOVX-0006uN-7Q for submit@debbugs.gnu.org; Tue, 28 Sep 2021 21:35:39 -0400 Original-Received: from sonic311-25.consmr.mail.ne1.yahoo.com ([66.163.188.206]:45659) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mVOVV-0006u6-Az for 50660@debbugs.gnu.org; Tue, 28 Sep 2021 21:35:37 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1632879331; bh=zBKbJ4kAeS8SeB2Mcb+xpqUuVIF2L39/r4Dl+Uk58jU=; h=From:To:Cc:Subject:References:Date:In-Reply-To:From:Subject:Reply-To; b=EVGICte4bbxzqfMzlN4yrJIw+luvoscPN4bN4zTuNMY1DmZLE6o08OD9/GCsz2MflDqY0gShNz7lrdDl9QyB0SMgcjPOLkcAddbQUs/O/9XuV1CswAoTbw/mmfR4PnTqvWUWGN6v+2Ur3McxwlFvhcvLBhVeq2+IttWqkDbDTHfQVcpAhy0tIkcqQpv6HeryhlsnlMXEBkTTFk8OTyv4aQBmeLi9+592Pn3lLfiQqNNr4eDayMov1q88xY9ppzDFWJ/m6D6KjiGEXamQITjCu8IdrnvViXJSWALEw909LDrJoxLf56zoUJFHQbU44AaZN38upaFJSC0lL2X9ktG0mg== X-SONIC-DKIM-SIGN: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1632879331; bh=vbyXhI7FPOVxGyxOx3h2upZUs4yhmAN2OfJxSBsWrcV=; h=X-Sonic-MF:From:To:Subject:Date:From:Subject; b=ZTzgXrOTi5l6y0UIrjMYNop9Gwm0zPdDcvZW/dctDyIwpZq5x8JWZrcOlvltNHPwCiYSRcLT4U1e9nBfYderxFWMOhhXtzuZdEQn0dK3qMUQeQ/15kJpDziXLfVGzDP4uevu+1XdYfRpAMS7z+4W4gXBzgmlFmMLxBrpaJ6NZdYqByX2u1HNkjO/zqqTP2pDbDtB/zauozL0pUyAH6YOTESidfqybYuklWJB7/1OCd2hh9gvMMiqq3u5S2kq90/9phoM/8HSpIr8ZwK+YnX4f9Gj/O7B7trP1V9z1eoD7HimZTjjd1lPg6oORLz4LSB6fSAbEB4aryj3lXS+1R2p3g== X-YMail-OSG: Ci663soVM1mXuRO3xrLhEEmEWAh6V2gGIuHypD19inv86ZkVQjaykx9RkRFOaer tsQpN3YEiyL7I1H7ZrsebCsSpoEQXOaGOSZXwkFB1kgxIcDZQWQFx7_0ZeChpIrUK92P2uHQPmg4 FgIY9IYvrJUGafletzpK7skCPK.qsMF2su6BDk.3YXRX2a41xD2rRk3nB2A_.zi1A_aZ_O.SqV0g 1kPdq2ap2F11UN9DN2xvBHZ8btDgIQ4U5qMSZhS5iSO6G6MZtKG2BoKVZ2F8K8jcFf39hLVmDckf PWK8lAFuXA86h9WPdHTERsAOGz3GDPZY_qfLSOOY9ITSKHbHEd8U8YMNvrCP80p3_jQ_evd.DyqE oAUq7Sm.pHsFwO6k34BhYDxucUFjtxUCuhTwo0_DbgPJv7qLPPPj.SO456lB4mM2tpxC9R6vdUod DcbIR58iZvD6Do7bO23wAryt7herUThT1I_8pyHwbZT1Lb3hgICS6AmwT2UQujK31bNjkf1qeKQ4 F5E9Xjt4XxSGR10MlX6uHYH72Z8.NKtBGoUb3FS3L0ZbQAi0GImlaBm64ExQk1WXPWHTF_GPQWZ. O4k6IqSvwYYNU16c9FRP.CQLmIeUVGfKKt3zm1K3cBR5l5Yn3.0zBNv9ZQ3UrNS5hcGCTBbRfpJa jQOJPstbueqQtY0czB5knOk794eYgjrXfwvbontViQf_YNfRaA6is6Va2v1Xik2JKoIx9bb2z7zp 7v.US0rwxF186iOdSyzhY8QTZG3X7FwU1xC9tF7l0iqcMOisQtkZ65hdeU9JlrGcSzNvIIx3ijBi 9kQSJhtM431ycrZVzdjmnUa.zlKei1EF5qBkzDp8Qp X-Sonic-MF: Original-Received: from sonic.gate.mail.ne1.yahoo.com by sonic311.consmr.mail.ne1.yahoo.com with HTTP; Wed, 29 Sep 2021 01:35:31 +0000 Original-Received: by kubenode508.mail-prod1.omega.sg3.yahoo.com (VZM Hermes SMTP Server) with ESMTPA ID 831b07e6fce55893d6acc38bd120bc54; Wed, 29 Sep 2021 01:35:27 +0000 (UTC) In-Reply-To: <83v92mkzft.fsf@gnu.org> (Eli Zaretskii's message of "Mon, 27 Sep 2021 14:52:54 +0300") X-Mailer: WebService/1.1.19076 mail.backend.jedi.jws.acl:role.jedi.acl.token.atz.jws.hermes.yahoo 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:215810 Archived-At: --=-=-= Content-Type: text/plain Eli Zaretskii 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 --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=fix-cursor-position.patch 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 */ --=-=-=--