Return-Path: owner-exmh-users@sunlabs
Return-Path: <owner-exmh-users@sunlabs>
Received: from sunlabs.eng.sun.com by sage.Eng.Sun.COM (5.x/SMI-SVR4)
	id AA29977; Thu, 17 Oct 1996 08:45:03 -0700
Received: filtered by sunlabs.eng.sun.com (SunLabs-1.2)
	id IAA20840; Thu, 17 Oct 1996 08:28:58 -0700
Received: from Eng.Sun.COM by sunlabs.eng.sun.com (SunLabs-1.2)
	id IAA20835; Thu, 17 Oct 1996 08:28:55 -0700
Received: from venus.Sun.COM by Eng.Sun.COM (SMI-8.6/SMI-5.3)
	id IAA24154; Thu, 17 Oct 1996 08:27:37 -0700
Received: from crdems.ge.com (crdems.GE.COM [192.35.44.5]) by venus.Sun.COM (SMI-8.6/mail.byaddr) with SMTP id IAA23719 for <exmh-users@sunlabs.eng.sun.com>; Thu, 17 Oct 1996 08:27:13 -0700
Received: from cobweb.crd.ge.com by crdems.ge.com (5.65/GE 1.77) id AA12328; Thu, 17 Oct 96 11:16:56 -0400
Received: by cobweb.crd.ge.com (5.x/GE-CRD Standard Sendmail Version S1.5)id AA07474; Thu, 17 Oct 1996 11:16:54 -0400
Message-Id: <9610171516.AA07474@cobweb.crd.ge.com>
From: kennykb@cobweb.crd.ge.com (Kevin Kenny)
To: John Haxby <jch@hazel.pwd.hp.com>
Cc: kennykb@cobweb.crd.ge.com (Kevin Kenny), hdevore@crow.bmc.com,
        exmh-users@sunlabs.Eng.Sun.COM
Subject: Re: Alt != Meta ? 
In-Reply-To: jch@hazel.pwd.hp.com's message of Thu, 17 Oct 96 09:40:26 +0100.     <199610170854.AA064822443@paloalto.access.hp.com> 
X-Face: 5*Bwl\0iY*1'W~D~c2foEA#,\H[\j3:fTgL0QDgl'0/_fV8X|GO>!b`fdiNc{Ioj6u7a{qq 1h+JHjg)m(|axb2m&0{I9cl5lQ9OeK\vdx=Ca]v9No,e'd~rIQ'ei,%J!^+@w|2/fLdXMKEOIh85kr plx|`3lxhu#KWB;}OjDeAg^
X-Uri: http://ce-toolkit.crd.ge.com/people/kennykb.html
Mime-Version: 1.0
Date: Thu, 17 Oct 96 15:16:54 -0500
Sender: owner-exmh-users@sunlabs.Eng.Sun.COM
Precedence: bulk
Content-Type: text/plain; charset=us-ascii
Content-Length: 3642


jch@hazel.pwd.hp.com said:
> However, I don't think that Tk is to blame here.  Empricially,  it 
> would seem that the *keycode* is used for the modifier, not  the 
> *keysym*.

A light begins to dawn.  The default keysyms that Hummingbird uses in
eXceed are what's broken.  My copy of Exceed came out of the box with:
> $ xmodmap -pke | grep Meta
> keycode  16 = Alt_L Meta_L
> keycode  74 = Alt_R Meta_R

Now the only problem with Tk is that it doesn't perform gracefully
in a non-X11 environment because -

- It can't deal with a paucity of shift keys.  It needs Alt
  to work the menu accelerators and Meta to drive the default
  widget bindings.  (Losing Alt is perhaps acceptable because
  F10 can be used to work the menus.  Losing Meta is obnoxious
  -- and the PC keyboard has no Meta key!  Moreover, I can't just
  do `xmodmap' on Windows.)

- Likewise, it can't deal with a paucity of mouse buttons.  It's
  difficult to run most Tk applications with a two-button mouse, and
  nearly impossible with a one-button mouse.

Does anyone know if there's a way to make Tk see a Meta key under Windoze?

Given my new understanding, I offer the attached procedure for your
consideration.  It attempts to repair the keybindings to something
reasonable.

proc do_x_setup {} {

    # Set a pleasanter bell sound 

    set xset {xset b 100 880 120}
    set xmodmap {xmodmap}

    # turn on repeat on the BackSpace and Tab keys -- off by default on some
    # terminals.  Also find out whether the terminal has <Alt>, <Meta>,
    # both, or neither.  If any key is trying to be both at the same
    # time (!) make it Meta.

    set keytab [exec xmodmap -pke]
    foreach line [split $keytab \n] {
	set keycode [lindex $line 1]
	set keysyms [lrange $line 3 end]
	if {[lsearch -regexp $keysyms {^(BackSpace|Tab)$}] >= 0} {
	    lappend xset r $keycode
	} elseif {[set index [lsearch -regexp $keysyms {^Meta}]] >= 0} {
	    set metakeys([lindex $keysyms $index]) $keycode
	} elseif {[set index [lsearch -regexp $keysyms {^Alt}]] >= 0} {
	    set altkeys([lindex $keysyms $index]) $keycode
	}
    }

    # If there isn't any Meta key, remap Alt to be Meta.  That way, the
    # PC keyboard works with Tk.

    if {![info exists metakeys]} {
	foreach keysym [array names altkeys] {
	    set keycode $altkeys($keysym)
	    regsub {^Alt} $keysym Meta keysym
	    set metakeys($keysym) $keycode
	}
	unset altkeys
    }

    # Assign Meta to Mod1, and Alt to Mod2.  Clean up any multiple
    # keysyms that may be attached to the Mod1 and Mod2 keys.

    if [info exists metakeys] {
	foreach keysym [array names metakeys] {
	    lappend xmodmap -e [list keycode $metakeys($keysym) = $keysym]
	}
	lappend xmodmap -e [list clear mod1] \
		-e [linsert [array names metakeys] 0 add mod1 =]
    }
    if [info exists altkeys] {
	foreach keysym [array names altkeys] {
	    lappend xmodmap -e [list keycode $altkeys($keysym) = $keysym]
	}
	lappend xmodmap -e [list clear mod2] \
		-e [linsert [array names altkeys] 0 add mod2 =]
    }

    # CapsLock and Control are interchanged on Tektronix terminals.

    if [string match [winfo server .] {X11R0 Tektronix, Inc. 5*}] {
	lappend xmodmap -e "keycode 28 = Caps_Lock" \
		-e "keycode 25 = Control_L" \
		-e "clear lock " \
		-e "add lock = Caps_Lock" \
		-e "clear control" \
		-e "add control = Control_L Control_R"
    }

    puts stderr $xset
    eval exec $xset
    puts stderr $xmodmap
    eval exec $xmodmap
}

--
73 de ke9tv/2, Kevin KENNY   GE Corporate Research & Development
kennykb@crd.ge.com           P. O. Box 8, Room KWC273
                             Schenectady, New York 12301-0008 USA


