From: Óscar Fuentes on
Simon Bachmann <ssiimmoonnbbaacchhmmaannnn(a)ffrreemmaaiill.cchh>
writes:

> I thought that that was exatly what you wanted: avoid that the
> toplevel that has the grab gets hidden by the others (just to make
> sure you understood my suggestion right: it should be "wm .t2 -topmost
> 1" in your example...).

Yeah, but it will stand in front of all other applications'
windows. This is not good. A "local topmost" would be a good interim
solution, but AFAIK this is not possible with Tk.

> AFAIK you can't avoid that a window gets "activated" when you click
> its titlebar or its icon in the taskbar.

Part of the problem comes from the fact that the window is activated
only when you use the taskbar. If you click directly on the window,
the click is ignored. This is inconsistent. No activation should take
place no matter what the user does.

> This is because the grab is
> set at "Tk level" and not at "Window manager level" (at least, that's
> what I understood from the "grab" manpage): if you click the "main"
> toplevel in the taskbar it's the window manager that gets the event
> and since it does not know nothing about the grab, it "activates" the
> window. However the window then is not truly active, since all events
> seen by the app (what happen inside) are still sent to the toplevel
> that has the grab.

The window is not "truly" active, but the user perceives it as active
as demonstrated for its decoration and the fact that it comes to the
front. This is either a bug on the window manager or in Tk's
implementation of `grab'.

> I realized that I probably did not understand you right in first
> place: you have actually three toplevels: "main" ('.'), '.t1' and
> .t2' (which should remain above the others and get all events). And
> it's '.' that causes the problem that it might hide '.t2', right?
> In that case the solution is easy: just make '.t1' transient towards '.' :
>
> wm transient .t2 .t1
> wm transient .t1 .

Sadly, my problem is more general. There are an arbitrary number of
toplevels and any of them can bring a dialog any time. Your proposal
solves the case where the user clicks on the taskbar icon of ".", but
not for the other toplevels.

As a side note, showing a tk_messageBox with -parent set to any
toplevel should be enough to demonstrate the problem. However, they
use the "topmost" trick, which demonstrates that the problem was known
to some Tk developers.

[snip]

> Hope this helps

Thanks for your analysis, Simon. I'll look at Tk's source and see how
`grab' is implemented, and then, maybe, file a bug report.

--
Oscar