Hi!

I'm writing a little program to use the additional keys on my keyboard.
It's like lineakd (http://lineakd.sf.net)

In fact, I got the following code from there:
(Stripped down to the minimum, no check and nothing...)

=============================================================================
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <X11/XKBlib.h>
#include <stdlib.h>
#include <stdio.h>

int main(int argc, char* arvg[])
{
    int base_event;
    int major_version = XkbMajorVersion;
    int minor_version = XkbMinorVersion;
    int error, reason;
    Display* dpy = XkbOpenDisplay("", &base_event, &error, &major_version, \
                                        &minor_version, &reason);
    int list[21] = {233, 234, 150, 223, 147, 148, 149, 230, 144, 153, 237, \
                        174, 176, 160, 162, 164, 146, 236, 145, 229, 178};
    int i;
    for (i = 0; i < 21; ++i) {
        XkbMapChangesRec mapChangeRec;
        XkbMessageAction xma;
        int keycode = list[i];

        XkbDescPtr xkb = XkbGetMap(dpy, XkbAllMapComponentsMask, \
                                        XkbUseCoreKbd);

        int types[1] = {XkbOneLevelIndex};
        XkbChangeTypesOfKey(xkb, keycode, 1, XkbGroup1Mask, types, 0);

        XkbResizeKeySyms(xkb, keycode, 1);

        *XkbKeySymsPtr(xkb, keycode) = 0x1008FF01 + i;
        XkbResizeKeyActions(xkb, keycode, 1);

        bzero(&mapChangeRec, sizeof(mapChangeRec));
        mapChangeRec.changed = XkbKeySymsMask | XkbKeyTypesMask;
        mapChangeRec.first_key_sym = keycode;
        mapChangeRec.num_key_syms = 1;
        mapChangeRec.first_type = 0;
        mapChangeRec.num_types = xkb->map->num_types;
        XkbChangeMap(dpy, xkb, &mapChangeRec);

        xma.type = XkbSA_ActionMessage;
        xma.flags = XkbSA_MessageOnPress;
        strcpy((char*)(xma.message), " ");

        XkbKeyActionsPtr(xkb, keycode)[0].msg = xma;

        bzero(&mapChangeRec, sizeof(mapChangeRec));
        mapChangeRec.changed = XkbKeyActionsMask;
        mapChangeRec.first_key_act = keycode;
        mapChangeRec.num_key_acts = 1;
        XkbChangeMap(dpy, xkb, &mapChangeRec);

        printf("Keycode %d set successfully\n", keycode);
    }

    return(0);
}
=============================================================================

The code sets a keysym and an action on the keys represented by the keycode.

The problem I'm having is that the code above doesn't work all the time.
It does almost always but every once in a while I get:

[linuxbox:~/ttttt]$ ./a.out
Keycode 233 set successfully
Keycode 234 set successfully
Keycode 150 set successfully
Keycode 223 set successfully
X Error of failed request:  BadValue (integer parameter out of range for
operation)
  Major opcode of failed request:  150 (XKEYBOARD)
  Minor opcode of failed request:  9 (XkbSetMap)
  Value in failed request:  0x23df0001
  Serial number of failed request:  20
  Current serial number in output stream:  21
          
I have read through a document called: "The X Keyboard Extension -
Library Specification" which seems the right place after all.
Unfortunately it didn't give me a clue why this error keeps happening...

So, if someone has an idea I'd be very grateful.

And while we're on the subject and considering the fact that I've never
programmed anything für X11 before.

So it may well be that the approach above is evil and all...

If so I'd also be glad to hear how I can do better...

So thanks in adance!

Cheers,
 Mika
 
_______________________________________________
Xpert mailing list
[EMAIL PROTECTED]
http://XFree86.Org/mailman/listinfo/xpert

Reply via email to