From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Eli Zaretskii Newsgroups: gmane.emacs.bugs Subject: bug#6372: 24.0.50; C-mouse-1 activates region Date: Sat, 21 Jul 2012 14:42:06 +0300 Message-ID: <83mx2t733l.fsf@gnu.org> References: <87liiujrpd.fsf@gnu.org> <8F41724E359B445C81DDA030FDFC18C6@us.oracle.com> <83hatiktul.fsf@gnu.org> <87r4sltury.fsf@gnu.org> Reply-To: Eli Zaretskii NNTP-Posting-Host: plane.gmane.org X-Trace: dough.gmane.org 1342870967 29766 80.91.229.3 (21 Jul 2012 11:42:47 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Sat, 21 Jul 2012 11:42:47 +0000 (UTC) Cc: 6372@debbugs.gnu.org To: Chong Yidong Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Sat Jul 21 13:42:46 2012 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1SsY57-0006Xl-Rt for geb-bug-gnu-emacs@m.gmane.org; Sat, 21 Jul 2012 13:42:46 +0200 Original-Received: from localhost ([::1]:50107 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SsY56-00035N-LI for geb-bug-gnu-emacs@m.gmane.org; Sat, 21 Jul 2012 07:42:44 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:55916) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SsY53-000356-S3 for bug-gnu-emacs@gnu.org; Sat, 21 Jul 2012 07:42:42 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SsY52-0001Mo-Eq for bug-gnu-emacs@gnu.org; Sat, 21 Jul 2012 07:42:41 -0400 Original-Received: from debbugs.gnu.org ([140.186.70.43]:44649) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SsY52-0001MO-Bd for bug-gnu-emacs@gnu.org; Sat, 21 Jul 2012 07:42:40 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.72) (envelope-from ) id 1SsYBC-00047D-4j for bug-gnu-emacs@gnu.org; Sat, 21 Jul 2012 07:49:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Eli Zaretskii Original-Sender: debbugs-submit-bounces@debbugs.gnu.org Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 21 Jul 2012 11:49:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 6372 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Original-Received: via spool by 6372-submit@debbugs.gnu.org id=B6372.134287131215778 (code B ref 6372); Sat, 21 Jul 2012 11:49:02 +0000 Original-Received: (at 6372) by debbugs.gnu.org; 21 Jul 2012 11:48:32 +0000 Original-Received: from localhost ([127.0.0.1]:54192 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1SsYAi-00046R-El for submit@debbugs.gnu.org; Sat, 21 Jul 2012 07:48:32 -0400 Original-Received: from mtaout22.012.net.il ([80.179.55.172]:42799) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1SsYAg-00046I-0t for 6372@debbugs.gnu.org; Sat, 21 Jul 2012 07:48:31 -0400 Original-Received: from conversion-daemon.a-mtaout22.012.net.il by a-mtaout22.012.net.il (HyperSendmail v2007.08) id <0M7I00B00DQNZV00@a-mtaout22.012.net.il> for 6372@debbugs.gnu.org; Sat, 21 Jul 2012 14:42:05 +0300 (IDT) Original-Received: from HOME-C4E4A596F7 ([87.69.210.75]) by a-mtaout22.012.net.il (HyperSendmail v2007.08) with ESMTPA id <0M7I00B5HDU3PV70@a-mtaout22.012.net.il>; Sat, 21 Jul 2012 14:42:04 +0300 (IDT) In-reply-to: <87r4sltury.fsf@gnu.org> X-012-Sender: halo1@inter.net.il X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.13 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2) X-Received-From: 140.186.70.43 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.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:62235 Archived-At: > From: Chong Yidong > Cc: Drew Adams , 6372@debbugs.gnu.org > Date: Mon, 09 Jul 2012 12:37:05 +0800 > > Eli Zaretskii writes: > > > Indeed. After the recipe, "C-h l" shows this: > > > > C-h l > > > > What do you see on GNU/Linux? Which toolkit(s) did you try it with? > > > > FWIW, in the MSDOS build the problem doesn't happen, and view-lossage > > shows just this: > > > > C-h l > > > > Any clue where could drag-mouse-1 come from? I guess we don't discard > > some events that we should. > > On GNU/Linux (both GTK build and Lucid build) I see > > C-h l Thanks. I'm sorry, but it will take someone who knows more than I do about MS-Windows messages and their processing to fix this one. I describe my findings below in the hope that someone will pick up where I left off. We track mouse events during pop-up menu by sending the WM_EMACS_TRACKPOPUPMENU message to the Emacs message pump. This message is handled by w32_wnd_proc around line 3770 of w32fns.c. There, we call TrackPopupMenu, a Windows API that displays the menu and returns the user selection of menu items. After TrackPopupMenu returns, we remove any mouse events still in the message queue, by calling PeekMessage with appropriate arguments, and return the user selection to our caller, which is w32_menu_show. The user selection returned is zero when the user closes the menu without selecting any item, by clicking outside the menu. w32_menu_show then removes any mouse events in the Emacs event queue by calling discard_mouse_events. What happens in this case, and is the reason for the bug, is that somehow the mouse click event that pops down the menu is not delivered to Emacs until _after_ w32_menu_show returns. That click is not removed by PeekMessage mentioned above, and is not discarded by discard_mouse_events. It is read by w32_wnd_proc only after all of the above processing is complete, and any memory of the menu that was popped down is gone. So Emacs processes that mouse click as a normal event, oblivious to the fact that it actually happened as part of the menu. What I don't understand here is why that mouse click is not delivered when we call PeekMessage, so that it could be discarded. It's as if Windows withholds that message from being put into the Emacs message queue. Why is that, and what can we do to be able to peek at that click message as part of menu processing and discard it, is beyond me.