Tk Source Code

View Ticket
Login
Ticket UUID: 869305
Title: phantom events with tk_popup
Type: Bug Version: 8.4.2, 8.6.18, 9.0.5, 9.1b1
Submitter: trott13 Created on: 2004-01-02 13:58:15
Subsystem: 13. Win Menus Assigned To: aku
Priority: 5 Medium Severity: Minor
Status: Closed Last Modified: 2026-10-20 19:32:34
Resolution: Fixed Closed By: nemethi
    Closed on: 2026-10-20 19:32:34
Description:
with Tcl/Tk 8.4.2 on Microsoft Windows Platforms 
the attached file "popup.tcl" will demonstrate 
the generation of phantom events to unterlying 
toplevel. 
 
I verified this a least for the ButtonRelease 
and BottonMotion type of events. 
 
The BottonMotion events will always be generated, 
the ButtonRelease only, if you hold Button-1 
pressed while moving around in the popup. 
 
I think these events should not be generated 
(in fact they trigger false actions in my 
programs), and in X11 they are correctly suppressed. 
 
I also checked the "tk_popup" code in 
lib/tk8.4.2/menu.tcl. Adding addional grabs there 
help in the case of the Motion Events, but the 
(most annoying) ButtonRelease keeps fooling me.
User Comments: nemethi (claiming to be Csaba Nemethi) added on 2026-10-20 19:32:34:

Serhiy, many thanks! Merged into main, core-9-0-branch, and core-8-6-branch by commits [0800b18c], [3c27418e], and [d87a23aa].


serhiy.storchaka added on 2026-09-21 19:58:49:

Still present on Windows 11 with 8.6 and 9.1: while the popup is tracked the window which posted it gets <B1-Motion> events when the pointer is dragged with the button held, and after the menu is dismissed it gets a <ButtonRelease-1> event, because the menu consumed the real release and Tk generates one for the window which had the implicit grab. To reproduce (the label shows the events received by the toplevel):

menu .m -tearoff 0
foreach i {0 1 2 3 4 5} {.m add command -label $i -command [list append m " selected $i"]}
bind . <Button-1> {set m ""; tk_popup .m %X %Y}
bind . <ButtonRelease-1> {append m " release"}
bind . <B1-Motion> {append m " motion"}
pack [label .l -textvariable m]
wm geometry . 300x300
Press button 1 in the window, drag over the menu and release on an entry: the label shows "motion ... release selected N" instead of "selected N". Click to open the menu, then click an entry: "release selected N".

Fixed on branch win-popup-phantom-events in [b8e2b73fd5]: pointer events are ignored while the native menu is tracked and the button is forgotten without an event afterwards, as with a grab on X11. The click which dismisses the menu is still delivered to the window under the pointer, as usual on Windows.


trott13 added on 2004-01-02 20:58:15:

File Added - 72045: popup.tcl

Attachments: