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#47581: 27.1; tab-bar missed mouse clicks on MS-Windows Date: Sat, 03 Apr 2021 16:56:35 +0300 Message-ID: <83pmzbeajw.fsf@gnu.org> References: Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="4362"; mail-complaints-to="usenet@ciao.gmane.io" Cc: 47581@debbugs.gnu.org To: Ioannis Kappas , Juri Linkov Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sat Apr 03 15:57:10 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 1lSglw-0000z0-RF for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 03 Apr 2021 15:57:08 +0200 Original-Received: from localhost ([::1]:50672 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lSglv-0004N1-OK for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 03 Apr 2021 09:57:07 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:47518) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lSglp-0004Mn-Uv for bug-gnu-emacs@gnu.org; Sat, 03 Apr 2021 09:57:01 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:50960) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lSglp-0000LX-N8 for bug-gnu-emacs@gnu.org; Sat, 03 Apr 2021 09:57:01 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1lSglp-0007Qh-LI for bug-gnu-emacs@gnu.org; Sat, 03 Apr 2021 09:57: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: Sat, 03 Apr 2021 13:57:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 47581 X-GNU-PR-Package: emacs Original-Received: via spool by 47581-submit@debbugs.gnu.org id=B47581.161745821728548 (code B ref 47581); Sat, 03 Apr 2021 13:57:01 +0000 Original-Received: (at 47581) by debbugs.gnu.org; 3 Apr 2021 13:56:57 +0000 Original-Received: from localhost ([127.0.0.1]:34273 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lSglk-0007QN-QD for submit@debbugs.gnu.org; Sat, 03 Apr 2021 09:56:57 -0400 Original-Received: from eggs.gnu.org ([209.51.188.92]:54502) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lSgli-0007QB-6j for 47581@debbugs.gnu.org; Sat, 03 Apr 2021 09:56:55 -0400 Original-Received: from fencepost.gnu.org ([2001:470:142:3::e]:53575) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lSglc-0000CJ-AA; Sat, 03 Apr 2021 09:56:48 -0400 Original-Received: from 84.94.185.95.cable.012.net.il ([84.94.185.95]:2324 helo=home-c4e4a596f7) by fencepost.gnu.org with esmtpsa (TLS1.2:RSA_AES_256_CBC_SHA1:256) (Exim 4.82) (envelope-from ) id 1lSglb-0007Vy-Lz; Sat, 03 Apr 2021 09:56:48 -0400 In-Reply-To: (message from Ioannis Kappas on Sat, 3 Apr 2021 12:26:53 +0100) 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:203490 Archived-At: > From: Ioannis Kappas > Date: Sat, 3 Apr 2021 12:26:53 +0100 > > The issue appears to be due to the wrong calculation performed by the > src/xdisp.c:remember_mouse_glyph fn to identify the RECTangle location > of the glyph under the mouse cursor, when the mouse is over a tab. > > The fn calls src/windows.c:window_from_coordinates to retrieve the > window where the mouse is over, but this returns nil, resulting to a > `virtual_glyph' position calculation, which appears to dictate that > glyphs are fixed width having their width and height equal to the > smallest char width and font height of the frame respectively. > > But the tab bar glyphs are of variable size, and thus the glyph > position rectangle returned by the above function will not necessarily > correspond to the actual position of the glyph under the mouse cursor. > > Consider the following example of glyph position in a tab-bar with a > single *scratch* tab on MS-Windows. The src/xdisp.c:x_y_to_hpos_vpos > fn used elsewhere in the tab logic correctly calculates the column > HPOS as per below (e.g. the ?t glyph corresponds to column no. 7, it > is 6px wide and occupies pixels 61 to 67 in the tab row): > > | column no. | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | > | glyph | ?\s | ?* | ?s | ?c | ?r | ?a | ?t | ?c | ?h | ?* | > | width (px) | 6 | 10 | 12 | 12 | 8 | 13 | 6 | 12 | 12 | 9 | > | end pos (px) | 6 | 16 | 28 | 40 | 48 | 61 | 67 | 79 | 91 | 100 | > > and the corresponding glyph positions returned by the > src/xdisp.c:remember_mouse_glyph fn RECT on windows 10 (the fixed > width of a glyph is 9px wide): > > | column no. | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | > | glyph | ?\s | ?* | ?s | ?c | ?r | ?a | ?t | ?c | ?h | ?* | > | width (px) | 9 | 9 | 9 | 9 | 9 | 9 | 9 | 9 | 9 | 9 | > | end pos (px) | 9 | 18 | 27 | 36 | 45 | 54 | 63 | 82 | 91 | 100 | > > The above miscalculation is used by > src/w32term.c:w32_note_mouse_movement, to check if the mouse has moved > over the last glyph and thus update the last glyph position > accordingly. However, because the last glyph position check is based > on the glyph coordinates performed by src/xdisp.c:remember_mouse_glyph > `virtual_glyph' method, the glyph position does not correspond to the > actual tab glyph, and updates can be missed. Thanks, but this doesn't match my observations. First, I get a much smaller value for "virtual glyph" width: 5, not 9. (Did you look at the values in "emacs -Q" or in a session where fonts were customized?) More importantly, remember_mouse_glyph is not called at all when I click on the tab-bar buttons, it is only called when I _move_ the mouse. The decision whether we click on the same glyph or not is irrelevant to tab-bar buttons, it only cares if we click on the same _button_ as before, and that decision is made in get_tab_bar_item, which calls x_y_to_hpos_vpos, and the latter doesn't use any approximations of the glyph dimensions, it uses the actual pixel width of each glyph on display. I think the actual problem is elsewhere: in handle_tab_bar_click. It includes code that was copied from handle_tool_bar_click, and which pays attention to the value of mouse-highlight. But tab-bar buttons don't behave like tool-bar buttons in this regard: they don't respond to moving the mouse pointer to them by "activating" the button. So I think that code should be removed from handle_tab_bar_click. To wit: turn mouse-highlight off (M-x set-variable RET mouse-highlight RET nil RET), and clicks on tab-bar buttons miraculously start working with 100% reliability. Juri, why is that code present in handle_tab_bar_click? Is that just a copy/paste from handle_tool_bar_click, or is there some reason for that? I'm talking about this logic, and the comments which describe it, in handle_tab_bar_click: /* If not on the highlighted tab-bar item, and mouse-highlight is non-nil, return. This is so we generate the tab-bar button click only when the mouse button is released on the same item as where it was pressed. However, when mouse-highlight is disabled, generate the click when the button is released regardless of the highlight, since tab-bar items are not highlighted in that case. */ frame_to_window_pixel_xy (w, &x, &y); ts = get_tab_bar_item (f, x, y, &glyph, &hpos, &vpos, &prop_idx, &close_p); if (ts == -1 || (ts != 0 && !NILP (Vmouse_highlight))) return; /* When mouse-highlight is off, generate the click for the item where the button was pressed, disregarding where it was released. */ if (NILP (Vmouse_highlight) && !down_p) prop_idx = f->last_tab_bar_item;