Tk Source Code

View Ticket
Login
Ticket UUID: ed6c3a787d00e8b68ee6d8a15039c6c964fd1292
Title: Modal window is not restored after "show desktop" (win+d) is pressed
Type: Bug Version: 8.6
Submitter: serhiy.storchaka Created on: 2024-06-24 17:57:44
Subsystem: 68. Win Window Operations Assigned To: oehhar
Priority: 5 Medium Severity: Minor
Status: Closed Last Modified: 2026-09-15 20:06:58
Resolution: Fixed Closed By: jan.nijtmans
    Closed on: 2026-09-15 20:06:58
Description:

This issue was first reported on the Python bug tracker: https://github.com/python/cpython/issues/114422, but it is reproducible on pure Tcl/Tk. It is reproducible on Windows.

Way to reproduce the bug. Run any program in Windows and later the below script. The script will open main windows and modal dialog over it. Then press Win-d to hide all programs and show desktop. You can now switch to any program (by selecting it in the task bar or using Alt-Tab) except the Tk program.

toplevel .dialog
wm transient .dialog .
grab set .dialog


serhiy.storchaka added on 2026-09-13 20:46:49 UTC:
WmProc ignores SC_RESTORE for windows outside the grab tree, so after "show desktop" (which minimizes without WM_SYSCOMMAND) the main window cannot be restored from the taskbar. Fix on branch [win-grab-restore]: allow SC_RESTORE; the dialog is owned by the main window and is restored with it. Verified on Windows 11 with Tk 9.0.4.

User Comments: jan.nijtmans added on 2026-09-15 15:15:03:

I'm glad I can be of some help here ;-)

Merged to [b86736bbf7d63932|trunk], core-9-0-branch and core-8-6-branch

Many thanks to all!


oehhar added on 2026-09-15 05:08:32:

Thanks Csaba, If CI is clean, this may be merged. My own CI run had 0 failures.

I am on travel, back on Thursday. If nobody will merge before, I will merge on Friday.

Thanks for all, Harald


nemethi (claiming to be Csaba Nemethi) added on 2026-09-14 17:14:03:

I have applied the patch to tkWinWm.c in the main branch (i.e., trunk) and tested successfully that it works as expected.

BTW: I have also verified that Win+d and Win+m minimize the windows without making use of WM_SYSCOMMAND and SC_MINIMIZE, as correctly stated by Serhiy.


oehhar added on 2026-09-14 09:49:20:

Here is my test script from a fresh wish start typed in the console:

pack [button .b -text nofocus -command "puts nofocus"]
toplevel .t
pack [button .t.t -text close -command "destroy .t"]
grab .t.t

Patch rebased to main by commit [73e29b0c] in new branch [ed6c3a78-win-grab-restore-main].

What I observe with the test script compared to 9.0.4 release:

  • With 9.0.4, the parent Window gets totally unresponsive after a Win+D on 9.0.4. It can not be restored by Alt-Tab or the task bar icon. This changed with the patch and is IMHO an improvement.

Otherwise, the grab survives a Win+D. Pressing the "nofocus" button has no effect and the close-button gets a visual feedback, if the t child window is visible (e.g. not minimized in the taskbar). This is already the case with 9.0.4.

So, for me, this is an improvement.

I will start CI.

I would love to have another opinion if possible (Csaba?). This is a critical field, sorry. And there are so many cases.

Merge in one week or other positive feedback (if CI clean).

Thanks for all, Harald


oehhar added on 2026-09-14 08:17:27:

Serhi,

thanks for the patch of this very long standing annoyance. Highly appreciated.

I personally can imagine that there might be side effects of the patch. In addition, it is not testable.

Please give me one week to test. Then, I will merge to main.

Thanks again, Harald


oehhar added on 2024-06-24 20:02:12:

Dear Storchaka,

I can only say, that the issue is known. There are other situation where a grab is removed by Windows actions. Grab never worked reliable on Windows.

Any patches welcome!

Take care, Harald