[FreeNX-kNX] Keymap, Keysyms, and States

Kurt Granroth freenx at granroth.org
Mon Sep 26 03:50:36 UTC 2005


Now that NX can resize the desktop and handle color depth changes and  
the like, it's now possible to start a session on a Mac and resume it  
on an x86 box ... or vice versa.  This was never possible before (for  
me, anyway).

This new-found freedom brings its own set of problems, though.  The  
main one I'm encountering now deals with the differing keymaps.  I've  
had to learn quite a bit about keycodes vs keysyms in the past few  
days and I almost have it all down, but there are some fundamental  
lacks of knowledge that are keeping me from getting it all to work  
fully.

Basically, when an NX session is started with a Macintosh client, the  
keymap that is installed is appropriate to the Macintosh.  So when  
the 'a' key is pressed, the keycode 8 and state 0x0 is sent and it's  
translated by the keymapping to keysym 0x61 'a'.  When I hold down  
the Shift key, the keycode stays 8 but the state changes to 0x1 and  
the translation for this is keysym 0x41 'A'.  So far, so good.

If, however, I start an NX session on a x86 machine, the keymap is  
very different.  The 'a' key sends a keycode of 38 to translate to  
the same keysym of 0x61.  All of the other keycodes are likewise  
different.

Now as long as I resume the session on the same architecture as the  
client that started the session, I'm fine.  If, however, I resume on  
a different architecture, then it all falls to pieces.  Say I start  
it on a Macintosh where keycode 8 is 'a' and resume on an x86  
machine.  In this case, when I press the 'a' key, keycode 38 is sent  
but according to the Mac keymap, that means ] (bracketright).  Oops!

I got around this partially but starting up a Mac session and a x86  
session and saving a "pure" keymap using 'xmodmap -pke'.  I then have  
shortcuts for "Use x86 keymap" and "Use Mac keymap" which run xmodmap  
on the right file.  This ALMOST works.

The problem is that doing this somehow screws up the state.   
Normally, when I'm not pressing any modifier keys, the state is 0x0.   
Pressing shift is 0x1, Control is 0x4, and since it's ORed together,  
Shift+Control gives me a state of 0x5.  This is what tells the keymap  
which keysym to use.  If, however, I do my resume and xmodmap trick,  
the state is completely hosed.  Not pressing any modifier keys gives  
me a state of 0x10 (or 0x12, depending on how I start and resume).   
Pressing Alt may give me a state of 0x2012 sometimes.  You can  
imagine that this wreaks havoc on the keycode to keysym translation!

Here's where my knowledge ends, unfortunately.  I have no clue what  
is changing the state much less how I can change it back?  What  
determines the state at all?

Any keymap gurus out there know the answer to that?  And if the  
answer is RTFM, just point me to the right FM and I'll continue  
figuring this out on my own (and report the results here).

Thanks!
Kurt



More information about the FreeNX-kNX mailing list