From: dhami@cs.ubc.ca (Mandeep S Dhami)
Newsgroups: comp.lang.tcl
Subject: Re: Can't get tk to work correctly with tvtwm
Date: 6 Oct 1992 01:02:29 -0700
Organization: Computer Science, University of B.C., Vancouver, B.C., Canada
NNTP-Posting-Host: valhalla.cs.ubc.ca
Keywords: tkMenu Tk Tcl tvtwm virtual window manager


It has been some time since I did something with wish/tvtwm, but I did have
the same problem some 4 months ago! I am appending all the relevant postings
form that thread. I know I did miss some, but hope it helps anyway. 

BTW, The last posting (which is missed here) mentioned of major differences
between tvtwm and tk which implied (big) changes in tk for compatability. It
was also mentioned that this was on the Bug/Todo list and was expected to be
fixed in some later release (of tk). I don't know if the last posting fixes
those problems (I know I am not specific about the problem, but I do not
recall it exactly and I lost the file! But I hope whoever posted it last
time, does it again).

Mandeep.
__________________________________________________________________
"I'm very brave generally," he went on in a low voice:
"only to-day I happen to have a headache."
                                      -- Lewis Carroll
__________________________________________________________________

Appended Material:
------------------
In article <1992May2.065010.29040@cs.ubc.ca> dhami@cs.ubc.ca (Mandeep S Dhami) writes:
>I have just started programming with tk (and tcl), so this
>is really a novice quiestion (I unpacked wish yeterday! though
>I used "some" expect earlier).

Not really.  It's something that's easily overlooked, especially if
you weren't the one who installed tvtwm on your system.

>When I am in window 0, it behaves correctly. When I am in say
>window 1 or 2, instead of producing menus/submenus along left-
>bottom/rightbottom of last menu, they are produced fulshed along
>the right margin of the *screen*. [etc.]

I haven't played with tvtwm in a while, but here's part of the README
from the tvtwm.pl7 distribution that seems to point out the problem:

-----
Side note:  With tvtwm createing it's "virtual" root window, many
programs that try to look for the root window (editres, xwd, xsetroot) will
not work as expected.  To fix many of these problems, there is a vroot.h
header file that has been made available by Andreas Stolcke
<stolcke@ICSI.Berkeley.EDU>, which redefines all of the standard X macros
for the root window (RootWindow(), RootWindowOfScreen(), and
DefaultRootWindow()).  Most programs can be fixed by including the header
file after Xlib.h in the source code.
-----

Lo and behold, Tk uses all three library functions mentioned above.
It would seem that you should:

[a] FTP vroot.h from various places, including:
	gatekeeper.dec.com:/.1/X11/R4-contrib/vroot.h
[b] add '#include "vroot.h"' after '#include <X11/Xlib.h>' in:
	tk.h  tkConfig.h  tkInt.h
[c] recompile Tk/wish
--
-----------------------------------------------------------------------------
Adrian Ho, He With The Embarrassingly *Dead* Passion ** Phone: (510) 642-5563
System Manager, CFD Lab, ME Dept, UC Berkeley * adrianho@barkley.berkeley.edu
Maintainer, Tcl/Tk Contrib Archive ---- barkley.berkeley.edu [128.32.142.237]

*****

In article <1992May5.232649.26879@cs.ubc.ca>, dhami@cs.ubc.ca (Mandeep S Dhami) writes:
|> 
|> Thanks to Adrian Ho for pointing out that:
|> > Side note:  With tvtwm createing it's "virtual" root window, many
|> > programs that try to look for the root window (editres, xwd, xsetroot) will
|> > not work as expected.  To fix many of these problems, there is a vroot.h
|> > header file that has been made available by Andreas Stolcke
|> > <stolcke@ICSI.Berkeley.EDU>, which redefines all of the standard X macros
|> > for the root window (RootWindow(), RootWindowOfScreen(), and
|> > DefaultRootWindow()).  Most programs can be fixed by including the header
|> > file after Xlib.h in the source code.
|> 
|> I ftp'ed vroot.h and recompiled the code (I did it for 1.4 copy
|> as I did not want to screw up my 2.0 copy!). It does not seem to
|> make any difference. It still has the same behavior. (for any one 
|> else interested in vroot.h, just add protection for multiple
|> inclusion in the header file as the standard one does not, rest works
|> without any problem on SonOS 4.1).
|> 
|> Any other sugestions?

First, a clarification.  The vroot.h header only deals with the problem
of finding the root window, which is usually only an issue for programs
that try to manipulate the root window (like setting the background).

vroot.h does not and cannot deal with the problem of interpreting
window positions.  Virtual window manager introduce an ambiguity into
any position spec in terms of (x,y) coordinates, because those coordinates
could be interpreted relative to the virtual root or relative to the
physical display.  As far as I know there is no general way for dealing
with this, and the ICCCM doesn't offers any help in this regard.

If tvtwm's README file is correct, however, it uses a heuristic to
distinguish the two cases:

   USPosition vs. PPosition - When a window has USPosition hints
   set, the window will be positioned at that exact pixel location.
   When PPosition hints are set, the window will be positioned at 
   the pixel location plus the current offset of the Virtual Desktop.
   For example, if the desktop has been panned to +200+500 and 
   a window is mapped with PPosition +100+100, the window will be
   positioned at +300+600 on the desktop.

So it should be possible to go into the Tk code and make sure that
menu positions are interpreted relative to the physical screen.

Hope this helps.

-- 
Andreas Stolcke					stolcke@icsi.berkeley.edu
International Computer Science Institute	stolcke@ucbicsi.bitnet
1947 Center St., Suite 600, Berkeley, CA 94704	(510) 642-4274 ext. 126

*****

In article <u785jINNmjf@agate.berkeley.edu>, I wrote:
|> If tvtwm's README file is correct, however, it uses a heuristic to
|> distinguish the two cases:
|> 
|>    USPosition vs. PPosition - When a window has USPosition hints
|>    set, the window will be positioned at that exact pixel location.
|>    When PPosition hints are set, the window will be positioned at 
|>    the pixel location plus the current offset of the Virtual Desktop.
|>    For example, if the desktop has been panned to +200+500 and 
|>    a window is mapped with PPosition +100+100, the window will be
|>    positioned at +300+600 on the desktop.
|> 
|> So it should be possible to go into the Tk code and make sure that
|> menu positions are interpreted relative to the physical screen.

Before anybody starts hacking away, what the tvtwm documentation doesn't tell
you is that the PPosition hint for relative positioning is only used if

1 - The window is a child of the virtual root (so you do have a need for
    vroot.h).
2 - You enable UsePPosition "on" in your .tvtwmrc.

-- 
Andreas Stolcke					stolcke@icsi.berkeley.edu
International Computer Science Institute	stolcke@ucbicsi.bitnet
1947 Center St., Suite 600, Berkeley, CA 94704	(510) 642-4274 ext. 126

*****

The following patch may be of use to tvtwm users.

In a limited way it fixes the problem of menus opening up in the wrong place
on the virtual tvtwm screen.  It's limited in that the current physical
origin of the screen must be an integer multiple of physical screen widths
and physical screen heights from the origin of the virtual screen.  I believe
most people (around here anyway) use tvtwm in this manner so it shouldn't be
much of a limitation.

The patch is for the Tk 2.1 version of tkMenu.c

To apply the patch:
  patch tkMenu.c <tkMenu.patch

The patch (tkMenu.patch) :

*** tkMenu.c.orig	Mon Jun  8 01:31:59 1992
--- tkMenu.c	Fri Jul  3 05:24:00 1992
***************
*** 432,438 ****
      register Menu *menuPtr = (Menu *) clientData;
      register MenuEntry *mePtr;
      int result = TCL_OK;
!     int length, type;
      char c;
  
      if (argc < 2) {
--- 432,438 ----
      register Menu *menuPtr = (Menu *) clientData;
      register MenuEntry *mePtr;
      int result = TCL_OK;
!     int length, type, wos, hos;
      char c;
  
      if (argc < 2) {
***************
*** 734,741 ****
  	 * on-screen.
  	 */
  
! 	tmp = WidthOfScreen(Tk_Screen(menuPtr->tkwin))
! 		- Tk_Width(menuPtr->tkwin);
  	if (x > tmp) {
  	    x = tmp;
  	}
--- 734,749 ----
  	 * on-screen.
  	 */
  
! 	wos = WidthOfScreen(Tk_Screen(menuPtr->tkwin));
! 	if (x > 0) {
! 	  x = x % wos;
! 	  if (x == 0) {
! 	    x = wos;
! 	  }
! 	} else {
! 	  x = x % wos;
! 	}  
! 	tmp = wos - Tk_Width(menuPtr->tkwin);
  	if (x > tmp) {
  	    x = tmp;
  	}
***************
*** 742,749 ****
  	if (x < 0) {
  	    x = 0;
  	}
! 	tmp = HeightOfScreen(Tk_Screen(menuPtr->tkwin))
! 		- Tk_Height(menuPtr->tkwin);
  	if (y > tmp) {
  	    y = tmp;
  	}
--- 750,758 ----
  	if (x < 0) {
  	    x = 0;
  	}
! 	hos = HeightOfScreen(Tk_Screen(menuPtr->tkwin));
! 	y = y % hos;
! 	tmp = hos - Tk_Height(menuPtr->tkwin);
  	if (y > tmp) {
  	    y = tmp;
  	}


*****

Newsgroups: comp.lang.tcl