Tk Source Code

View Ticket
Login
2026-10-27
11:51 • Closed ticket [b164efb5]: Mouse event to wrong window (MacOS and Linux) plus 7 other changes artifact: f541b8c4 user: nemethi
2026-10-08
11:55 • Closed ticket [061f633f]: MacOS aqua: <<ContextMenu >> binding sometimes triggers for incorrect toplevel plus 7 other changes artifact: b87a2047 user: jan.nijtmans
11:49
Fix [061f633f43]: MacOS aqua: <<ContextMenu >> binding sometimes triggers for incorrect toplevel check-in: ba8c94c2 user: jan.nijtmans tags: core-8-6-branch
11:45
Fix [061f633f43]: MacOS aqua: <<ContextMenu >> binding sometimes triggers for incorrect toplevel check-in: 60a0dc77 user: jan.nijtmans tags: core-9-0-branch
11:44
Fix [061f633f43]: MacOS aqua: <<ContextMenu >> binding sometimes triggers for incorrect toplevel check-in: 3362fcc0 user: jan.nijtmans tags: trunk, main
2026-09-29
15:57 • Ticket [061f633f] MacOS aqua: <<ContextMenu >> binding sometimes triggers for incorrect toplevel status still Open with 4 other changes artifact: adc2efc6 user: serhiy.storchaka
15:24 • Ticket [b164efb5] Mouse event to wrong window (MacOS and Linux) status still Open with 3 other changes artifact: b4eb1844 user: serhiy.storchaka
15:21
Fix [061f633f43]: MacOS aqua: <<ContextMenu>> binding sometimes triggers for incorrect toplevel. Clicking with the right or middle button does not make the window the key window, so these events were sent to the widget at the same position in the toplevel which has the focus. Send them to the toplevel which was clicked. closed check-in: db5c579a user: serhiy.storchaka tags: aqua-right-click-target
2026-09-18
10:36 • New ticket [061f633f] MacOS aqua: <<ContextMenu >> binding sometimes triggers for incorrect toplevel. artifact: 1e5df267 user: SVIDevelopment

Ticket UUID: 061f633f4316dec2ff4bc4884b3d00e1edc96db8
Title: MacOS aqua: <<ContextMenu >> binding sometimes triggers for incorrect toplevel
Type: Bug Version: 9.0.2, 8.6.18, 9.0.5, 9.1b1
Submitter: SVIDevelopment Created on: 2026-09-18 10:36:52
Subsystem: (unused) Assigned To: jan.nijtmans
Priority: 5 Medium Severity: Minor
Status: Closed Last Modified: 2026-10-08 11:55:03
Resolution: Fixed Closed By: jan.nijtmans
    Closed on: 2026-10-08 11:55:03
Description:
In some cases, the ContextMenu binding triggers for the toplevel that currently has focus, instead of the toplevel underneath the mouse pointer. In the example below, when the red canvas has focus and you right-click on the blue canvas, you get the red menu. I would expect to get either the blue menu, or no menu at all.

Tested on MacOS 15.

--------------------------------------------------------------------

proc popdbg {W X Y} {
    puts "W=$W  toplevel=[winfo toplevel $W]  containing=[winfo containing $X $Y]  @ $X,$Y  focus=[focus]"
}

set toplevel1 .
wm geometry $toplevel1 400x300+650+350

set canvas1 [canvas $toplevel1.canvas1 -width 200 -height 200 -bg red]
grid $canvas1
set menu1 [menu $toplevel1.m -tearoff 0]
$menu1 add command -label "RED"
bind $canvas1 <<ContextMenu>> "popdbg %W %X %Y; tk_popup $menu1 %X %Y"

set toplevel2 [toplevel $toplevel1.top2]
wm geometry $toplevel2 300x200+200+400

set canvas2 [canvas $toplevel2.canvas2 -width 200 -height 200 -bg blue]
grid $canvas2
set menu2 [menu $toplevel2.m -tearoff 0]
$menu2 add command -label "BLUE"
bind $canvas2 <<ContextMenu>> "popdbg %W %X %Y; tk_popup $menu2 %X %Y"

--------------------------------------------------------------------------
User Comments: jan.nijtmans added on 2026-10-08 11:55:03:

Fixed [3362fcc006a9101d|here], and in core-9-0-branch and core-8-6-branch.

I tested it, it works fine.

Many thanks!


serhiy.storchaka added on 2026-09-29 15:57:06:

A right or middle click does not make the window the key window, so tkEventTarget is still the toplevel which has the focus. The event is then sent to the widget of that toplevel at the coordinates of the clicked window. A left click resets the target to the clicked toplevel, but a right or middle click does not. The same code is in 8.6 and 9.0.

Proposed fix in branch aqua-right-click-target: right and middle button events in a toplevel which is not the key window are sent to that toplevel, and the focus does not change. I could not test it, as I have no macOS.