Fixed: Tk main window stealing focus from console at startup

Filip Konvička filip.konvicka.removethisantispamtoken at logis.cz
Tue Sep 12 12:17:38 CEST 2006


Hi all,

this is a problem that bothered me for quite a long time. The first call 
to the Tk libraries within a Windows console application causes that the 
console application loses focus. Focus goes to the (hidden) main Tk 
window. (My console app only uses the TclODBC library, so it is 
otherwise a non-GUI app.)

To prevent this, the Tcl command

   wm attributes . -disabled 1

can be used at application startup. It seems that it does not affect 
regular windows (like the Browser). The Oz syntax to call this is

   {TkSend wm(attributes '.' '-disabled' 1)}

I don't know whether this problem exists on non-Windows platforms as 
well, and I have not tested this approach there.

However, I attach a patch to the TkInit.oz initialization script for 
anyone interested (this does the job, so you don't need to call the 
command yourself).

In case that this is Windows-specific, the command could perhaps be 
injected into mozart/platform/wish/winMain.cc instead of TkInit.oz 
(there already is one similar command in winMain.cc, "wm withdraw .", 
which hides the main window).

Cheers,
Filip
-------------- next part --------------
Index: share/lib/wp/TkInit.oz
===================================================================
RCS file: /services/mozart/CVS/mozart/share/lib/wp/TkInit.oz,v
retrieving revision 1.6
diff -u -r1.6 TkInit.oz
--- share/lib/wp/TkInit.oz	30 Apr 2003 22:05:03 -0000	1.6
+++ share/lib/wp/TkInit.oz	12 Sep 2006 09:58:58 -0000
@@ -21,7 +21,10 @@
 %%% of this file, and for a DISCLAIMER OF ALL
 %%% WARRANTIES.
 %%%
-
+% prevent the main window from stealing focus on startup:
+'
+wm attributes . -disabled 1
+'#
 % make sure
 '
 fconfigure stdout -translation {auto lf}


More information about the mozart-users mailing list