diff options
Diffstat (limited to 'hw/xnest/Keyboard.c')
-rw-r--r-- | hw/xnest/Keyboard.c | 135 |
1 files changed, 133 insertions, 2 deletions
diff --git a/hw/xnest/Keyboard.c b/hw/xnest/Keyboard.c index ce5d57f5d..107caee90 100644 --- a/hw/xnest/Keyboard.c +++ b/hw/xnest/Keyboard.c @@ -12,6 +12,8 @@ the suitability of this software for any purpose. It is provided "as is" without express or implied warranty. */ +/* $XFree86: xc/programs/Xserver/hw/xnest/Keyboard.c,v 1.8 2001/10/28 03:34:11 tsi Exp $ */ + #define NEED_EVENTS #include "X.h" #include "Xproto.h" @@ -29,6 +31,63 @@ is" without express or implied warranty. #include "Keyboard.h" #include "Args.h" +#ifdef XKB +#include <X11/extensions/XKB.h> +#include <X11/extensions/XKBsrv.h> +#include <X11/extensions/XKBconfig.h> + +extern Bool XkbQueryExtension( +#if NeedFunctionPrototypes + Display * /* dpy */, + int * /* opcodeReturn */, + int * /* eventBaseReturn */, + int * /* errorBaseReturn */, + int * /* majorRtrn */, + int * /* minorRtrn */ +#endif +); + +extern XkbDescPtr XkbGetKeyboard( +#if NeedFunctionPrototypes + Display * /* dpy */, + unsigned int /* which */, + unsigned int /* deviceSpec */ +#endif +); + +extern Status XkbGetControls( +#if NeedFunctionPrototypes + Display * /* dpy */, + unsigned long /* which */, + XkbDescPtr /* desc */ +#endif +); + +#ifndef XKB_BASE_DIRECTORY +#define XKB_BASE_DIRECTORY "/usr/X11R6/lib/X11/xkb/" +#endif +#ifndef XKB_CONFIG_FILE +#define XKB_CONFIG_FILE "X0-config.keyboard" +#endif +#ifndef XKB_DFLT_RULES_FILE +#define XKB_DFLT_RULES_FILE "xfree86" +#endif +#ifndef XKB_DFLT_KB_LAYOUT +#define XKB_DFLT_KB_LAYOUT "us" +#endif +#ifndef XKB_DFLT_KB_MODEL +#define XKB_DFLT_KB_MODEL "pc101" +#endif +#ifndef XKB_DFLT_KB_VARIANT +#define XKB_DFLT_KB_VARIANT NULL +#endif +#ifndef XKB_DFLT_KB_OPTIONS +#define XKB_DFLT_KB_OPTIONS NULL +#endif + +extern Bool noXkbExtension; +#endif + void xnestBell(volume, pDev, ctrl, cls) int volume; DeviceIntPtr pDev; @@ -42,6 +101,7 @@ void xnestChangeKeyboardControl(pDev, ctrl) DeviceIntPtr pDev; KeybdCtrl *ctrl; { +#if 0 unsigned long value_mask; XKeyboardControl values; int i; @@ -73,6 +133,7 @@ void xnestChangeKeyboardControl(pDev, ctrl) values.led_mode = (ctrl->leds & (1 << (i - 1))) ? LedModeOn : LedModeOff; XChangeKeyboardControl(xnestDisplay, value_mask, &values); } +#endif } int xnestKeyboardProc(pDev, onoff, argc, argv) @@ -120,9 +181,9 @@ int xnestKeyboardProc(pDev, onoff, argc, argv) for (j = 0; j < 8; j++) for(i = 0; i < modifier_keymap->max_keypermod; i++) { CARD8 keycode; - if (keycode = + if ((keycode = modifier_keymap-> - modifiermap[j * modifier_keymap->max_keypermod + i]) + modifiermap[j * modifier_keymap->max_keypermod + i])) modmap[keycode] |= 1<<j; } XFreeModifiermap(modifier_keymap); @@ -132,6 +193,10 @@ int xnestKeyboardProc(pDev, onoff, argc, argv) keySyms.mapWidth = mapWidth; keySyms.map = keymap; +#ifdef XKB + if (noXkbExtension) { +XkbError: +#endif XGetKeyboardControl(xnestDisplay, &values); memmove((char *) defaultKeyboardControl.autoRepeats, @@ -139,7 +204,73 @@ int xnestKeyboardProc(pDev, onoff, argc, argv) InitKeyboardDeviceStruct(pDev, &keySyms, modmap, xnestBell, xnestChangeKeyboardControl); +#ifdef XKB + } else { + FILE *file; + XkbConfigRtrnRec config; + + XkbComponentNamesRec names; + char *rules, *model, *layout, *variants, *options; + + XkbDescPtr xkb; + int op, event, error, major, minor; + + if (XkbQueryExtension(xnestDisplay, &op, &event, &error, &major, &minor) == 0) { + ErrorF("Unable to initialize XKEYBOARD extension.\n"); + goto XkbError; + } + xkb = XkbGetKeyboard(xnestDisplay, XkbGBN_AllComponentsMask, XkbUseCoreKbd); + if (xkb == NULL || xkb->geom == NULL) { + ErrorF("Couldn't get keyboard.\n"); + goto XkbError; + } + XkbGetControls(xnestDisplay, XkbAllControlsMask, xkb); + + memset(&names, 0, sizeof(XkbComponentNamesRec)); + rules = XKB_DFLT_RULES_FILE; + model = XKB_DFLT_KB_MODEL; + layout = XKB_DFLT_KB_LAYOUT; + variants = XKB_DFLT_KB_VARIANT; + options = XKB_DFLT_KB_OPTIONS; + if (XkbInitialMap) { + if ((names.keymap = strchr(XkbInitialMap, '/')) != NULL) + ++names.keymap; + else + names.keymap = XkbInitialMap; + } + + if ((file = fopen(XKB_BASE_DIRECTORY XKB_CONFIG_FILE, "r")) != NULL) { + if (XkbCFParse(file, XkbCFDflts, xkb, &config) == 0) { + ErrorF("Error parsing config file.\n"); + fclose(file); + goto XkbError; + } + if (config.rules_file) + rules = config.rules_file; + if (config.model) + model = config.model; + if (config.layout) + layout = config.layout; + if (config.variant) + variants = config.variant; + if (config.options) + options = config.options; + + fclose(file); + } + + XkbSetRulesDflts(rules, model, layout, variants, options); + XkbInitKeyboardDeviceStruct((pointer)pDev, &names, &keySyms, modmap, + xnestBell, xnestChangeKeyboardControl); + XkbDDXChangeControls((pointer)pDev, xkb->ctrls, xkb->ctrls); + XkbFreeKeyboard(xkb, 0, False); + } +#endif +#ifdef _XSERVER64 + xfree(keymap); +#else XFree(keymap); +#endif break; case DEVICE_ON: xnestEventMask |= XNEST_KEYBOARD_EVENT_MASK; |