Tk Source Code

View Ticket
Login
2026-10-22
17:22 • Ticket [0c3bb74e] Without a window manager, an application keeps the implicit focus after another application takes the focus status still Closed with 3 other changes artifact: b694cdb0 user: serhiy.storchaka
2026-10-13
17:41 • Closed ticket [0c3bb74e]. artifact: 19658498 user: serhiy.storchaka
17:41 • Ticket [0c3bb74e]: 3 changes artifact: b7106bff user: serhiy.storchaka
17:18
Fix [0c3bb74e37]: without a window manager, an application keeps the implicit focus after another application takes the focus. Add the utility proc movePointerAwayFromTestArea. check-in: 561469cd user: serhiy.storchaka tags: core-8-6-branch
2026-10-12
21:12 • Ticket [0c3bb74e] Without a window manager, an application keeps the implicit focus after another application takes the focus status still Open with 3 other changes artifact: 28b56de4 user: erikleunissen
21:11 • Ticket [0c3bb74e]: 3 changes artifact: 9e9022c6 user: serhiy.storchaka
20:54 • Ticket [0c3bb74e]: 3 changes artifact: 3d5bd8aa user: erikleunissen
20:53 • Ticket [0c3bb74e]: 6 changes artifact: 13f83d9c user: erikleunissen
20:46
Fix [0c3bb74e37]: without a window manager, an application keeps the implicit focus after another application takes the focus check-in: 0f7c3be5 user: erikleunissen tags: core-9-0-branch
20:43
Fix [0c3bb74e37]: without a window manager, an application keeps the implicit focus after another application takes the focus check-in: f17f17f6 user: erikleunissen tags: trunk, main
2026-10-09
08:46 • Ticket [a4fa3ad2] event misbehavior with certain widgets when embedding status still Open with 3 other changes artifact: 1472aeed user: serhiy.storchaka
08:37
unixEmbed tests [a4fa3ad2d6]: make the focus tests independent of the previous tests. Restart the child process in the cleanup of unixEmbed-5.4 before destroying the container, so that its focused entry is not redrawn after the container is destroyed (which killed it with an X error, see [f1fe739a4f]) and its focus state does not affect the following tests. Move the pointer away in the setup of unixEmbed-5.1 to 5.4, 7.1 and 7.2, as in 8.1: without a window manager the child got the focus implicitly if its main window appeared under the pointer (see [0c3bb74e37]). check-in: f98ef68b user: serhiy.storchaka tags: x11-embed-focus-return
08:35 • New ticket [0c3bb74e] Without a window manager, an application keeps the implicit focus after another application takes the focus. artifact: a52b5ca1 user: serhiy.storchaka
08:34
Fix [0c3bb74e37]: Without a window manager, an application which got the focus implicitly, because its toplevel was under the pointer while the X focus followed the pointer, kept it after another application took the focus: the FocusOut event with detail NotifyPointer was ignored. Release the implicit focus on it, as on leaving the window. Test focus-9.1. check-in: 3f468f05 user: serhiy.storchaka tags: x11-implicit-focus-release

Ticket UUID: 0c3bb74e3777ea38ddee91ff7423a20b2e7b25c
Title: Without a window manager, an application keeps the implicit focus after another application takes the focus
Type: Bug Version: 8.6.18, 9.0.5, 9.1.0
Submitter: serhiy.storchaka Created on: 2026-10-09 08:35:43
Subsystem: 55. [focus] Assigned To: aku
Priority: 5 Medium Severity: Minor
Status: Closed Last Modified: 2026-10-22 17:22:33
Resolution: Fixed Closed By: serhiy.storchaka
    Closed on: 2026-10-13 17:41:49
Description:

Without a window manager, an application whose toplevel gets the focus implicitly, because it is under the pointer while the X focus follows the pointer (PointerRoot), keeps believing that it has the focus after another application takes it with focus -force, as long as the pointer stays there. [focus] still returns the toplevel, and key events generated for its windows go to it.

Tk takes the focus on the FocusIn event with detail NotifyPointer and releases it on a Leave event, but ignores the matching FocusOut event with detail NotifyPointer, assuming that other focus events will update the state. This is only true if the focus moves within the same application.

Tk itself sets the X focus to PointerRoot when the pointer leaves a window which got the focus implicitly, so this can happen after moving the pointer. It made unixEmbed-7.1 fail depending on which tests ran before.

Proposed fix in branch x11-implicit-focus-release, with test focus-9.1.

User Comments: serhiy.storchaka added on 2026-10-13 17:41:08:

You're right, thanks. testxfocus already kept the test off aqua, but x11 says what is meant and also excludes Wayland. Changed in main and core-9-0-branch. I also backported the fix to core-8-6-branch, with movePointerAwayFromTestArea.


erikleunissen added on 2026-10-12 21:12:33:
Oh, regarding the regression test:

Shouldn't the test constraint "unix" be "x11" ?

This to prevent that the regression test is run under Wayland or aqua.

serhiy.storchaka added on 2026-10-12 21:11:29:

Thank you for testing and merging, Erik. movePointerAwayFromTestArea is a good idea. I've already used it in branch panedwindow-sash-cursor, and will use it in new tests. It could also replace similar code in tests/unixEmbed.test and tests/focus.test.


erikleunissen added on 2026-10-12 20:53:12:
I ran the test without window manager under Xnest.

* without the fix in [3f468f0591], the test FAILS with test result: {. .}
* with the fix, the test PASSES.

On a side note:
I've seen you using the following code to move the screen pointer away from the
test area:

    event generate . <Motion> -warp 1 -x 2000 -y 2000
    controlPointerWarpTiming

To that end, I've created this utility proc:

    proc movePointerAwayFromTestArea {} {
	event generate {} <Motion> -warp 1 -x [winfo screenwidth .] \
		-y [expr {[winfo screenheight .]/2}]
	controlPointerWarpTiming
    }

The utility proc is made available to test authors through the testutils
mechanism in the domain "generic" (which is imported by default for all test 
files).

I've taken the liberty to adapt the test in branch "x11-implicit-focus-release"
to use this proc. If you agree to its usefulness, please use it for 
other/future tests also.

Thanks very much for the analysis and fix.

I've now merged the bug-fix branch into the main development branches.