Tk Source Code

View Ticket
Login
Ticket UUID: e2418ce5fe1bf34402a13e08b89883e2097bc2a1
Title: Pointer warp relative to the screen's root window fails if the Tk root window is withdrawn
Type: Bug Version: 9.1a0
Submitter: erikleunissen Created on: 2026-02-09 12:43:08
Subsystem: 69. Events Assigned To: nobody
Priority: 5 Medium Severity: Important
Status: Closed Last Modified: 2026-02-12 09:14:14
Resolution: Fixed Closed By: erikleunissen
    Closed on: 2026-02-12 09:14:14
Description:
A pointer warp relative to the root window of the screen[*] fails if the Tk root
window is withdrawn.

    [*] This is the window designated by "{}", which is not part of the Tk
        window hierarchy. See also the entries for "winfo pointer(x|y)",
        "winfo root(x|y)" and "event generate <Motion> -warp 1" in the respective
        manual pages.

The issue has been observed under Linux/x11, win32 and macOS/aqua (Sequoia).
It can be exercised, and visually confirmed using the script below.

The attached file "exercise.tcl" also holds this script.

Additionally, this  file holds two test cases, proposed for including in the
Tk test suite. The first test case fails, demonstrating the reported issue.
The second test case also exercises a pointer warp while the Tk root window
is withdrawn, but it does so relative to an arbitrary toplevel window. Whereas
the first test case FAILS, the second test case PASSES, showing that the issue
 only exhibits when warping relative to the root window of the screen.

-- reproducible script --

package require Tk
wm geometry . 200x200+100+100
wm deiconify .
after 10; update

# Arbitrary initial position
event generate {} <Motion> -warp 1 -x 340 -y 100
after 10; update; after 1000

puts -nonewline "Move mouse pointer while root win mapped: "
flush stdout
event generate {} <Motion> -warp 1 -x 350 -y 200
after 10; update; after 1000
if {([winfo pointerx .] == 350) && ([winfo pointery .] == 200)} {
    puts OK
} else {
    puts FAILED
}

puts -nonewline "Move mouse pointer while root win unmapped: "
flush stdout
wm withdraw .
after 10; update
event generate {} <Motion> -warp 1 -x 360 -y 300
after 10; update; after 1000
if {([winfo pointerx .] == 360) && ([winfo pointery .] == 300)} {
    puts OK
} else {
    puts FAILED
}

--
User Comments: erikleunissen added on 2026-02-12 09:14:14:
OK, thanks.

jan.nijtmans added on 2026-02-12 08:57:26:

Don't worry, I already fixed it ;-)


erikleunissen added on 2026-02-12 08:45:22:
Ah, yes. I overlooked that the proc "assert" is not a globally available proc in core-8-6. Will fix this shortly.

jan.nijtmans added on 2026-02-12 08:21:19:

This failure in on Tk 8.6 only, 9.0 and trunk appear to be fine


jan.nijtmans added on 2026-02-12 08:18:29:
> The two new non-regression tests both pass, and Github CI is also satisfied otherwise.

Hm ...
<pre>
==== bind-34.4 Pointer warp relative to the root window of the screen when the Tk root window is unmapped. (Ticket e2418ce5fe) FAILED
==== Contents of test case:

    event generate {} <Motion> -warp 1 -x 360 -y 250
    controlPointerWarpTiming
    winfo pointerxy .

---- Test setup failed:
invalid command name "assert"
---- errorInfo(setup): invalid command name "assert"
    while executing
"assert {([winfo ismapped .] == 0) && ([winfo pointerx .] == 350) && ([winfo pointery .] == 200)}"
    ("uplevel" body line 11)
    invoked from within
"uplevel 1 $setup"
---- errorCode(setup): TCL LOOKUP COMMAND assert
==== bind-34.4 FAILED



==== bind-34.5 Pointer warp relative to an arbitrary toplevel when the Tk root window is unmapped. (Ticket e2418ce5fe) FAILED
==== Contents of test case:

    event generate .one <Motion> -warp 1 -x 250 -y 100
    after 10; update
    list [expr {[winfo pointerx .one] - [winfo rootx .one]}] [expr {[winfo pointery .one] - [winfo rooty .one]}]

---- Test setup failed:
invalid command name "assert"
---- errorInfo(setup): invalid command name "assert"
    while executing
"assert {([winfo ismapped .] == 0) && ([winfo pointerx .] == 350) && ([winfo pointery .] == 200)}"
    ("uplevel" body line 14)
    invoked from within
"uplevel 1 $setup"
---- errorCode(setup): TCL LOOKUP COMMAND assert
==== bind-34.5 FAILED

</pre>

erikleunissen added on 2026-02-11 14:45:05:
Merged the bug-fix branch into trunk, core-9-0-branch and core-8-6-branch.
Closing the ticket.

jan.nijtmans added on 2026-02-11 09:43:54:
> Should a merge wait until 9.1a1 has been released?

For bug-fixes as clear and risk-less as this one: no, don't wait.

Just go ahead.

erikleunissen added on 2026-02-11 09:20:38:
The two new non-regression tests both pass, and Github CI is also satisfied otherwise.

I think that the bug-fix branch is ready for merging into the
main development branches[*].

Review by a human is welcomed.

Should a merge wait until 9.1a1 has been released?

--
[*] Target branches IMO are:
- trunk
- core-9-0-branch
- core-8-6-branch

erikleunissen added on 2026-02-09 14:28:34:
Created bug-fix branch bug-e2418ce5fe, and:
* added non-regression tests [ee6b049dd0]
* added proposed fix [8a26a9a7e7]

Attachments: