xmodmap patch to vnc 3.3.3

Grant McDorman grant.mcdorman "at" cedara.com
Wed, 20 Mar 2002 16:22:14 +0000

[Copied to the VNC list since this should be archived, and distributed to
the world.]

Background: Marius is using a VNC server on a *nix system, and has a non-US
(Norwegian?) keyboard. He wishes to change the keyboard layout so that the
'Aring' key, when pressed, acts as the 's' key. The standard X method of
changing this does not work.

Analysis: This is a deficiency, at best; at worst, it's a bug.

VNC in general sends keystrokes as key names (due to its Unix heritage,
these are the names used in Unix, referred to as keysyms).

The Unix VNC server has a compiled-in list of a basic set of key names; this
is, essentially, the U.S. 'qwerty' keyboard.

If you press a key on the viewer that's not in the static list, the VNC
server looks for a key definition, locally, that when pressed will
correspond to the key name. It then uses that definition, suitably modifed
by the Shift/Shift Lock keys, to report the key to the Unix applications.

As a result, it is impossible to redefine the key completely - the physical
key name (in this case Aring) must be present on the logical key.

In detail, the first time you press the 'aring' key Xvnc will add a key
mapping that assigns keycode 91, say, to 'aring'. Subsequently, it will
search its mappings when you press the 'aring' key, and find that entry #91
contains 'aring'. It will then send code 91 to the application - which will
use the *same* entry to translate it back to a key name: that is, 'aring'.

If you remap 'aring' to 's':
  xmodmap -e 'keysym aring = s'
this changes entry #91 to contain only 's'. As a result, when Xvnc searches
its mappings for 'aring', it won't find it - and will create a *new*

However, since the VNC server (and all X servers, in fact) allow multiple
key definitions for each physical key, there is a trick you can use to get
the effect you want.

The first two definitions on the key are the normal state, and the shifted
state. The second two are for the 'AltGraph' or "Mode Switch" key, in
combination with the shift key. Subsequent definitions are possible but
usually serve no pratical purpose.

However, since Xvnc uses the key definition when *any* of the set of
mappings correspond to the physical key, you should be able to do this trick:
  xmodmap -e 'keycode 127 = s S aring'
Then, Xvnc will find this mapping for when the viewer sends the aring key;
since the 'aring' key name appears as the _third_ symbol the application
(and you) will see 's' (or 'S') when you press the key.

Of course, if you're using a 'mode switch' type key you'll have to extend
the mapping to five entries; but it should still work.

(original message follows)

According to Marius Kotsbak:
> On Wed, 2002-03-20 at 16:44, Grant McDorman wrote:
> > According to Marius Kotsbak:
> > > On Wed, 2002-03-20 at 16:02, Grant McDorman wrote:
> > > > According to Marius:
> > > > > Grant McDorman wrote:
> > > I am NOT using xmodmap with keycodes myself, just keysyms. The keycodes
> > > are preconfigured for vnc (havent't changed anything in vnc), just as
> > > normal X session.
> > >
> > > The opposite work though, i can use keysym "s = aring" and i get the
> > > norwegian character "aring" when i press s. But mapping from the
> > > aring-button to s is impossible. xmodmap does not complain, but it has
> > > no effect.
> > >
> > > Could it be that vnc is not handling keycodes outside the US keyboard
> > > right?
> >
> > VNC doesn't include non-U.S. keysyms in its static keymap. Any keysym
> > it receives outside of this static keymap is dynamically added.
> >
> > What happens is the VNC client sends the keysym. If the server finds it
> > its keymap, it uses that; otherwise, it creates a new entry which, of
> > course, maps the incoming keysym to itself.
> >
> > I'm not sure how one could manage to remap a keysym outside the static
> > keymap at startup. However, to see if it works, try this: Press your
> > key; then do 'xmodmap -e "keysym aring = s"'.
> As I said; I have tried exactly that one. It is accepted, but has no
> effect.
> >
> > I'll look at the source for 3.3.3 and see if there is something that can
> > cooked up.
> >
> > --
> >
> > Grant McDorman <grant.mcdorman "at" cedara.com>, Sr. Software Design
> > Cedara Software Corp.  <URL:http://www.cedara.com>
> >   (formerly I.S.G. Technologies Inc.)
> > Mississauga, Ontario, Canada
> >


Grant McDorman <grant.mcdorman "at" cedara.com>, Sr. Software Design Consultant
Cedara Software Corp.  <URL:http://www.cedara.com>
  (formerly I.S.G. Technologies Inc.)
Mississauga, Ontario, Canada

[demime 0.97b removed an attachment of type application/pgp-signature]
To unsubscribe, mail majordomo "at" uk.research.att.com with the line:
'unsubscribe vnc-list' in the message BODY
See also: http://www.uk.research.att.com/vnc/intouch.html