* bug#6372: 24.0.50; C-mouse-1 activates region
2010-06-07 17:19 Drew Adams
@ 2012-07-08 13:41 ` Chong Yidong
2012-07-08 17:18 ` Drew Adams
2012-07-08 15:00 ` Dmitry Gutov
` (2 subsequent siblings)
3 siblings, 1 reply; 16+ messages in thread
From: Chong Yidong @ 2012-07-08 13:41 UTC (permalink / raw)
To: Drew Adams; +Cc: 6372
"Drew Adams" <drew.adams@oracle.com> writes:
> 1. Click C-mouse-1. The Buffer Menu opens.
>
> 2. Click mouse-1 outside the menu. The menu disappears, which is
> correct.
>
> But the region is activated, which is incorrect. Clicking mouse-1 here
> should simply set point, without activating the region.
FWIW, this is not reproducible on GNU/Linux. Maybe a Windows-only
issue; can someone with access to Windows check if this still happens?
^ permalink raw reply [flat|nested] 16+ messages in thread
* bug#6372: 24.0.50; C-mouse-1 activates region
2012-07-08 13:41 ` Chong Yidong
@ 2012-07-08 17:18 ` Drew Adams
2012-07-08 18:09 ` Eli Zaretskii
0 siblings, 1 reply; 16+ messages in thread
From: Drew Adams @ 2012-07-08 17:18 UTC (permalink / raw)
To: 'Chong Yidong'; +Cc: 6372
> "Drew Adams" <drew.adams@oracle.com> writes:
>
> > 1. Click C-mouse-1. The Buffer Menu opens.
> >
> > 2. Click mouse-1 outside the menu. The menu disappears, which is
> > correct.
> >
> > But the region is activated, which is incorrect. Clicking
> > mouse-1 here should simply set point, without activating the region.
>
> FWIW, this is not reproducible on GNU/Linux. Maybe a Windows-only
> issue; can someone with access to Windows check if this still happens?
Yes, the bug is still there.
I just checked in this build:
In GNU Emacs 24.1.50.1 (i386-mingw-nt5.1.2600)
of 2012-07-01 on MARVIN
Bzr revision: 108826 yamaoka@jpl.org-20120702004841-kzatmydft6dct0ry
Windowing system distributor `Microsoft Corp.', version 5.1.2600
Configured using:
`configure --with-gcc (4.6) --no-opt --enable-checking --cflags
-ID:/devel/emacs/libs/libXpm-3.5.8/include
-ID:/devel/emacs/libs/libXpm-3.5.8/src
-ID:/devel/emacs/libs/libpng-dev_1.4.3-1/include
-ID:/devel/emacs/libs/zlib-dev_1.2.5-2/include
-ID:/devel/emacs/libs/giflib-4.1.4-1/include
-ID:/devel/emacs/libs/jpeg-6b-4/include
-ID:/devel/emacs/libs/tiff-3.8.2-1/include
-ID:/devel/emacs/libs/gnutls-3.0.9/include
-ID:/devel/emacs/libs/libiconv-1.13.1-1-dev/include
-ID:/devel/emacs/libs/libxml2-2.7.8/include/libxml2'
emacs -Q
`C-mouse-1'
Move mouse outside the popped up menu, and so that some text is between the
first click and the next.
`mouse-1'
The text between the first and second clicks is selected (active region).
Thx.
^ permalink raw reply [flat|nested] 16+ messages in thread
* bug#6372: 24.0.50; C-mouse-1 activates region
2012-07-08 17:18 ` Drew Adams
@ 2012-07-08 18:09 ` Eli Zaretskii
2012-07-09 4:37 ` Chong Yidong
0 siblings, 1 reply; 16+ messages in thread
From: Eli Zaretskii @ 2012-07-08 18:09 UTC (permalink / raw)
To: Drew Adams; +Cc: 6372, cyd
> From: "Drew Adams" <drew.adams@oracle.com>
> Date: Sun, 8 Jul 2012 10:18:40 -0700
> Cc: 6372@debbugs.gnu.org
>
> > "Drew Adams" <drew.adams@oracle.com> writes:
> >
> > > 1. Click C-mouse-1. The Buffer Menu opens.
> > >
> > > 2. Click mouse-1 outside the menu. The menu disappears, which is
> > > correct.
> > >
> > > But the region is activated, which is incorrect. Clicking
> > > mouse-1 here should simply set point, without activating the region.
> >
> > FWIW, this is not reproducible on GNU/Linux. Maybe a Windows-only
> > issue; can someone with access to Windows check if this still happens?
>
> Yes, the bug is still there.
Indeed. After the recipe, "C-h l" shows this:
<C-down-mouse-1> <drag-mouse-1> 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-down-mouse-1> C-h l
Any clue where could drag-mouse-1 come from? I guess we don't discard
some events that we should.
^ permalink raw reply [flat|nested] 16+ messages in thread
* bug#6372: 24.0.50; C-mouse-1 activates region
2012-07-08 18:09 ` Eli Zaretskii
@ 2012-07-09 4:37 ` Chong Yidong
2012-07-21 11:42 ` Eli Zaretskii
0 siblings, 1 reply; 16+ messages in thread
From: Chong Yidong @ 2012-07-09 4:37 UTC (permalink / raw)
To: Eli Zaretskii; +Cc: 6372
Eli Zaretskii <eliz@gnu.org> writes:
> Indeed. After the recipe, "C-h l" shows this:
>
> <C-down-mouse-1> <drag-mouse-1> 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-down-mouse-1> 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-down-mouse-1> C-h l
^ permalink raw reply [flat|nested] 16+ messages in thread
* bug#6372: 24.0.50; C-mouse-1 activates region
2012-07-09 4:37 ` Chong Yidong
@ 2012-07-21 11:42 ` Eli Zaretskii
2012-08-08 18:39 ` Drew Adams
0 siblings, 1 reply; 16+ messages in thread
From: Eli Zaretskii @ 2012-07-21 11:42 UTC (permalink / raw)
To: Chong Yidong; +Cc: 6372
> From: Chong Yidong <cyd@gnu.org>
> Cc: Drew Adams <drew.adams@oracle.com>, 6372@debbugs.gnu.org
> Date: Mon, 09 Jul 2012 12:37:05 +0800
>
> Eli Zaretskii <eliz@gnu.org> writes:
>
> > Indeed. After the recipe, "C-h l" shows this:
> >
> > <C-down-mouse-1> <drag-mouse-1> 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-down-mouse-1> 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-down-mouse-1> 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.
^ permalink raw reply [flat|nested] 16+ messages in thread
* bug#6372: 24.0.50; C-mouse-1 activates region
2012-07-21 11:42 ` Eli Zaretskii
@ 2012-08-08 18:39 ` Drew Adams
2012-09-16 23:34 ` Drew Adams
0 siblings, 1 reply; 16+ messages in thread
From: Drew Adams @ 2012-08-08 18:39 UTC (permalink / raw)
To: 'Eli Zaretskii', 'Chong Yidong'; +Cc: 6372
ping.
> From: Eli Zaretskii Sent: Saturday, July 21, 2012 4:42 AM
> 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.
^ permalink raw reply [flat|nested] 16+ messages in thread
* bug#6372: 24.0.50; C-mouse-1 activates region
2010-06-07 17:19 Drew Adams
2012-07-08 13:41 ` Chong Yidong
@ 2012-07-08 15:00 ` Dmitry Gutov
2020-08-18 11:10 ` Stefan Kangas
2024-08-16 1:18 ` Cecilio Pardo
3 siblings, 0 replies; 16+ messages in thread
From: Dmitry Gutov @ 2012-07-08 15:00 UTC (permalink / raw)
To: cyd; +Cc: 6372
Chong Yidong <cyd@gnu.org> writes:
> "Drew Adams" <drew.adams@oracle.com> writes:
>
>> 1. Click C-mouse-1. The Buffer Menu opens.
>>
>> 2. Click mouse-1 outside the menu. The menu disappears, which is
>> correct.
>>
>> But the region is activated, which is incorrect. Clicking mouse-1 here
>> should simply set point, without activating the region.
>
> FWIW, this is not reproducible on GNU/Linux. Maybe a Windows-only
> issue; can someone with access to Windows check if this still happens?
It does happen.
And if I ctrl-click mouse-1 when the menu if open, minibuffer says
"<C-drag-mouse-1> is undefined", so looks like doing mouse-1 click when
the menu is open is registered as drag-mouse-1 event.
(I tried it in Ubuntu on an older Emacs 24 build, and that didn't happen
either).
In GNU Emacs 24.1.50.1 (i386-mingw-nt6.1.7601) of 2012-07-06.
--Dmitry
^ permalink raw reply [flat|nested] 16+ messages in thread
* bug#6372: 24.0.50; C-mouse-1 activates region
2010-06-07 17:19 Drew Adams
2012-07-08 13:41 ` Chong Yidong
2012-07-08 15:00 ` Dmitry Gutov
@ 2020-08-18 11:10 ` Stefan Kangas
2020-08-18 12:11 ` Eli Zaretskii
2024-08-16 1:18 ` Cecilio Pardo
3 siblings, 1 reply; 16+ messages in thread
From: Stefan Kangas @ 2020-08-18 11:10 UTC (permalink / raw)
To: Drew Adams; +Cc: 6372
"Drew Adams" <drew.adams@oracle.com> writes:
> emacs -Q
>
> 1. Click C-mouse-1. The Buffer Menu opens.
>
> 2. Click mouse-1 outside the menu. The menu disappears, which is
> correct.
>
> But the region is activated, which is incorrect. Clicking mouse-1 here
> should simply set point, without activating the region.
>
>
> In GNU Emacs 24.0.50.1 (i386-mingw-nt5.1.2600)
> of 2010-05-23 on G41R2F1
> Windowing system distributor `Microsoft Corp.', version 5.1.2600
> configured using `configure --with-gcc (3.4) --no-opt --cflags -Ic:/xpm/include'
That was more than 10 years ago.
I can't reproduce this on GNU/Linux, but from the discussion this looked
like a Windows-specific bug.
Since this was such a long time ago, I just wanted to ask if you (or
anyone else) can still reproduce this? Thanks.
Best regards,
Stefan Kangas
^ permalink raw reply [flat|nested] 16+ messages in thread
* bug#6372: 24.0.50; C-mouse-1 activates region
2020-08-18 11:10 ` Stefan Kangas
@ 2020-08-18 12:11 ` Eli Zaretskii
0 siblings, 0 replies; 16+ messages in thread
From: Eli Zaretskii @ 2020-08-18 12:11 UTC (permalink / raw)
To: Stefan Kangas; +Cc: 6372
> From: Stefan Kangas <stefan@marxist.se>
> Date: Tue, 18 Aug 2020 11:10:33 +0000
> Cc: 6372@debbugs.gnu.org
>
> > emacs -Q
> >
> > 1. Click C-mouse-1. The Buffer Menu opens.
> >
> > 2. Click mouse-1 outside the menu. The menu disappears, which is
> > correct.
> >
> > But the region is activated, which is incorrect. Clicking mouse-1 here
> > should simply set point, without activating the region.
> >
> >
> > In GNU Emacs 24.0.50.1 (i386-mingw-nt5.1.2600)
> > of 2010-05-23 on G41R2F1
> > Windowing system distributor `Microsoft Corp.', version 5.1.2600
> > configured using `configure --with-gcc (3.4) --no-opt --cflags -Ic:/xpm/include'
>
> That was more than 10 years ago.
>
> I can't reproduce this on GNU/Linux, but from the discussion this looked
> like a Windows-specific bug.
>
> Since this was such a long time ago, I just wanted to ask if you (or
> anyone else) can still reproduce this? Thanks.
I still see it, yes.
^ permalink raw reply [flat|nested] 16+ messages in thread
* bug#6372: 24.0.50; C-mouse-1 activates region
2010-06-07 17:19 Drew Adams
` (2 preceding siblings ...)
2020-08-18 11:10 ` Stefan Kangas
@ 2024-08-16 1:18 ` Cecilio Pardo
2024-08-18 21:47 ` Jeremy Bryant via Bug reports for GNU Emacs, the Swiss army knife of text editors
3 siblings, 1 reply; 16+ messages in thread
From: Cecilio Pardo @ 2024-08-16 1:18 UTC (permalink / raw)
To: 6372
[-- Attachment #1: Type: text/plain, Size: 258 bytes --]
This seems to happen because TrackPopupMenu returns as
soon as the WM_LBUTTONDOWN is received. That message is
correctly purged. The problem comes from the subsequent
WM_LBUTTONUP message.
This patch is not a clean solution, but keeps the problem local.
[-- Attachment #2: patch.diff --]
[-- Type: text/plain, Size: 1308 bytes --]
diff --git a/src/w32fns.c b/src/w32fns.c
index bd65aa48a14..ae33f959dd2 100644
--- a/src/w32fns.c
+++ b/src/w32fns.c
@@ -5669,9 +5669,36 @@ #define WM_TOUCH 576
0, hwnd, NULL))
{
MSG amsg;
- /* Eat any mouse messages during popupmenu */
+ bool have_lbuttondown = false;
+ /* Eat any mouse messages during popupmenu. If there is a
+ WM_LBUTTONDOWN, then we need to wait for the
+ corresponding WM_LBUTTONUP to suppress it, or it will be
+ handled elsewhere */
while (PeekMessage (&amsg, hwnd, WM_MOUSEFIRST, WM_MOUSELAST,
- PM_REMOVE));
+ PM_REMOVE))
+ {
+ if (amsg.message == WM_LBUTTONDOWN)
+ {
+ have_lbuttondown = true;
+ SetCapture(hwnd);
+ }
+ }
+
+ if (have_lbuttondown)
+ {
+ /* WM_LBUTTONUP should arrive, but we can't risk hanging
+ here if it does not, so we wait only for so long */
+ struct timespec start = current_timespec();
+ while (!PeekMessage (&amsg, hwnd, WM_LBUTTONUP, WM_LBUTTONUP,
+ PM_REMOVE))
+ {
+ if (timespectod (timespec_sub (current_timespec (),
+ start)) > 2.0 )
+ break;
+ }
+ ReleaseCapture();
+ }
+
/* Get the menu selection, if any */
if (PeekMessage (&amsg, hwnd, WM_COMMAND, WM_COMMAND, PM_REMOVE))
{
^ permalink raw reply related [flat|nested] 16+ messages in thread
* bug#6372: 24.0.50; C-mouse-1 activates region
2024-08-16 1:18 ` Cecilio Pardo
@ 2024-08-18 21:47 ` Jeremy Bryant via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-08-19 7:11 ` Cecilio Pardo
0 siblings, 1 reply; 16+ messages in thread
From: Jeremy Bryant via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2024-08-18 21:47 UTC (permalink / raw)
To: Cecilio Pardo; +Cc: 6372
Cecilio Pardo <cpardo@imayhem.com> writes:
> This seems to happen because TrackPopupMenu returns as
> soon as the WM_LBUTTONDOWN is received. That message is
> correctly purged. The problem comes from the subsequent
> WM_LBUTTONUP message.
>
> This patch is not a clean solution, but keeps the problem local.
>
>
>
> [2. text/plain; patch.diff]...
To confirm, is the bug report related to 24.0.50, a rather old version?
Have you checked if this bug is present in a recent version of Emacs?
^ permalink raw reply [flat|nested] 16+ messages in thread