keysym->keycodes weirdness, with lousy patch

Richard M Kreuter <[email protected]> Sat, 30 Oct 2004 22:06:49 -0400
Newsgroups gmane.lisp.clx.devel
Message-ID <[email protected]>
Howdy,

I found recently that #'keysym->keycodes doesn't work properly for my
configuration of XFree86 4.4 on NetBSD 2.0beta, which is configured in a
non-default way. The actual configuration is described below [1], but
the relevant thing is that this configuration changes the list of
keysyms returned in reply to +x-getkeyboardmapping+ requests, and that
the C X protocol binding doesn't actually use the contents of the reply
for determining the keycode for a keysym, whereas CLX does.

Here's the C implementation of XKeySymToKeycode in XFree86 4.4 (in
xc/lib/X11/KeyBind.c):

KeyCode
XKeysymToKeycode(dpy, ks)
    Display *dpy;
    KeySym ks;
{   
    register int i, j;

    if ((! dpy->keysyms) && (! _XKeyInitialize(dpy)))
        return (KeyCode) 0;
    for (j = 0; j < dpy->keysyms_per_keycode; j++) {
        for (i = dpy->min_keycode; i <= dpy->max_keycode; i++) {
            if (KeyCodetoKeySym(dpy, (KeyCode) i, j) == ks)
                return i;
        }
    }
    return 0;
}

_XKeyInitialize calls XGetKeyboardMapping and stashes keysyms_per_key in
dpy (among other things). So the C version of XKeysymToKeycode only
cares about how many slots there are in the keyboard mapping, and
doesn't look at the list of keysyms returned by the server.

Here's a trivial patch that modifies keysym->keycodes to do the same, in
case it's considered desirable to match what the C does. It's inelegant
to send a request to the server for every keysym slot in the mapping,
but the keyboard mapping returned by the X server just doesn't contain
the required data, and presumably there are others out there with X
servers (mis-)configured in similar ways.

--- translate.lisp	2004-10-30 21:16:51.000000000 -0400
+++ translate.lisp.orig	2003-04-03 08:39:33.000000000 -0500
@@ -558,5 +558,5 @@
     (declare (type card8 min max jmax)
 	     (type (simple-array keysym (* *)) map))
     (dotimes (j jmax)
-      (when (= keysym (keycode->keysym display i j))
+      (when (= keysym (aref map i j))
 	(push i result)))))

Regards,
Richard

[1] Starting in XFree86 4.3, the BKSP key hasn't been shiftable without
futzing with xkb. I've added an xkb "type=TWO_LEVEL" for the BKSP key,
so that it can be shifted, so that I can remap that button with
xmodmap. (This wasn't a well-informed configuration, but it does what I
want it to do, and evidently C Xlib doesn't care.) Without this
configuration, the keysym list returned by XGetKeyboardMapping looks
like this (the asdfghjkl row):

Keycode    Keysym     Keysym     Keysym     Keysym     Keysym     Keysym
 38:         97         65          0          0          0          0 
 39:        115         83          0          0          0          0 
 40:        100         68          0          0          0          0 
 41:        102         70          0          0          0          0 
 42:        103         71          0          0          0          0 
 43:        104         72          0          0          0          0 
 44:        106         74          0          0          0          0 
 45:        107         75          0          0          0          0 
 46:        108         76          0          0          0          0 

With this configuration, the keysym list looks like this (same row):

Keycode    Keysym     Keysym     Keysym     Keysym
 38:         65          0          0          0 
 39:         83          0          0          0 
 40:         68          0          0          0 
 41:         70          0          0          0 
 42:         71          0          0          0 
 43:         72          0          0          0 
 44:         74          0          0          0 
 45:         75          0          0          0 
 46:         76          0          0          0 

Anyhow, this configuration doesn't have visible untoward consequences on
programs that use the C X protocol bindings, for reasons described
above. On the other hand, if anybody knows how to make BKSP shiftable
without breaking the #'keyboard-mapping interface, I'd be glad to know
about it.

_______________________________________________
Portable-clx mailing list
[email protected]
http://lists.metacircles.com/cgi-bin/mailman/listinfo/portable-clx
cvs -d :ext:cvs.telent.net:/usr/local/src/cvs co clx  # over ssh
cvs -d :pserver:[email protected]:/cvs co clx  # anonymous