summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Stone <daniel@fooishbar.org>2008-12-26 18:38:25 +1100
committerDaniel Stone <daniel@fooishbar.org>2009-01-22 15:08:51 +1100
commit08363c5830bdea34012dcd954b45ccfdc79a3a7e (patch)
tree67475a96ca4c23bcacb626b02eb4ab2f8602a742
parent40877c6680863bd6a8475f2bb0c54df55bcf0b0e (diff)
Input: Overhaul keyboard initialisation process
XkbInitKeyboardDeviceStruct is now the only valid keyboard initialisation: all the details are hidden behind here. This now makes it impossible to supply a core keymap at startup. If dev->key is valid, dev->key->xkbInfo->desc is also valid. Signed-off-by: Daniel Stone <daniel@fooishbar.org> Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
-rw-r--r--Xi/exevents.c11
-rw-r--r--dix/devices.c159
-rw-r--r--hw/kdrive/src/kinput.c19
-rw-r--r--hw/vfb/InitInput.c16
-rw-r--r--hw/xfree86/common/xf86Module.h2
-rw-r--r--include/input.h16
-rw-r--r--include/xkbsrv.h33
-rw-r--r--xkb/ddxLoad.c33
-rw-r--r--xkb/xkbInit.c476
-rw-r--r--xkb/xkbUtils.c6
10 files changed, 220 insertions, 551 deletions
diff --git a/Xi/exevents.c b/Xi/exevents.c
index 1802b1859..323bc8d41 100644
--- a/Xi/exevents.c
+++ b/Xi/exevents.c
@@ -191,7 +191,6 @@ CopyKeyClass(DeviceIntPtr device, DeviceIntPtr master)
{
static DeviceIntPtr lastMapNotifyDevice = NULL;
KeyClassPtr mk, dk; /* master, device */
- BOOL sendNotify = FALSE;
int i;
if (device == master)
@@ -240,14 +239,8 @@ CopyKeyClass(DeviceIntPtr device, DeviceIntPtr master)
for (i = 0; i < 8; i++)
mk->modifierKeyCount[i] = dk->modifierKeyCount[i];
- if (dk->xkbInfo && dk->xkbInfo->desc) {
- if (!mk->xkbInfo || !mk->xkbInfo->desc) {
- XkbInitDevice(master);
- XkbFinishDeviceInit(master);
- }
- if (!XkbCopyKeymap(dk->xkbInfo->desc, mk->xkbInfo->desc, True))
- FatalError("Couldn't pivot keymap from device to core!\n");
- }
+ if (!XkbCopyKeymap(dk->xkbInfo->desc, mk->xkbInfo->desc, True))
+ FatalError("Couldn't pivot keymap from device to core!\n");
if (lastMapNotifyDevice != master) {
SendMappingNotify(master, MappingKeyboard,
diff --git a/dix/devices.c b/dix/devices.c
index 9d6651d48..6748e487d 100644
--- a/dix/devices.c
+++ b/dix/devices.c
@@ -483,54 +483,24 @@ CoreKeyboardCtl(DeviceIntPtr pDev, KeybdCtrl *ctrl)
static int
CoreKeyboardProc(DeviceIntPtr pDev, int what)
{
- CARD8 *modMap;
- KeySymsRec keySyms;
- XkbComponentNamesRec names;
- ClassesPtr classes;
+ XkbRMLVOSet rmlvo;
switch (what) {
case DEVICE_INIT:
- if (!(classes = xcalloc(1, sizeof(ClassesRec))))
- {
- ErrorF("[dix] Could not allocate device classes.\n");
- return BadAlloc;
- }
-
- keySyms.minKeyCode = 8;
- keySyms.maxKeyCode = 255;
- keySyms.mapWidth = 4;
- keySyms.map = (KeySym *)xcalloc(sizeof(KeySym),
- (keySyms.maxKeyCode -
- keySyms.minKeyCode + 1) *
- keySyms.mapWidth);
- if (!keySyms.map) {
- ErrorF("[dix] Couldn't allocate core keymap\n");
- xfree(classes);
- return BadAlloc;
- }
-
- modMap = xcalloc(1, MAP_LENGTH);
- if (!modMap) {
- ErrorF("[dix] Couldn't allocate core modifier map\n");
- xfree(classes);
- return BadAlloc;
- }
-
- bzero(&names, sizeof(names));
- XkbInitKeyboardDeviceStruct(pDev, &names, &keySyms, modMap,
- CoreKeyboardBell, CoreKeyboardCtl);
+ XkbGetRulesDflts(&rmlvo);
+ InitKeyboardDeviceStruct(pDev, &rmlvo, CoreKeyboardBell,
+ CoreKeyboardCtl);
+ return Success;
- xfree(keySyms.map);
- xfree(modMap);
- break;
+ case DEVICE_ON:
+ case DEVICE_OFF:
+ return Success;
case DEVICE_CLOSE:
- break;
-
- default:
- break;
+ return Success;
}
- return Success;
+
+ return BadMatch;
}
/**
@@ -1102,73 +1072,7 @@ SetKeySymsMap(KeySymsPtr dst, KeySymsPtr src)
return TRUE;
}
-static Bool
-InitModMap(KeyClassPtr keyc)
-{
- int i, j;
- CARD8 keysPerModifier[8];
- CARD8 mask;
-
- keyc->maxKeysPerModifier = 0;
- for (i = 0; i < 8; i++)
- keysPerModifier[i] = 0;
- for (i = 8; i < MAP_LENGTH; i++)
- {
- for (j = 0, mask = 1; j < 8; j++, mask <<= 1)
- {
- if (mask & keyc->modifierMap[i])
- {
- if (++keysPerModifier[j] > keyc->maxKeysPerModifier)
- keyc->maxKeysPerModifier = keysPerModifier[j];
- }
- }
- }
- keyc->modifierKeyMap = xcalloc(8, keyc->maxKeysPerModifier);
- if (!keyc->modifierKeyMap && keyc->maxKeysPerModifier)
- return (FALSE);
- for (i = 0; i < 8; i++)
- keysPerModifier[i] = 0;
- for (i = 8; i < MAP_LENGTH; i++)
- {
- for (j = 0, mask = 1; j < 8; j++, mask <<= 1)
- {
- if (mask & keyc->modifierMap[i])
- {
- keyc->modifierKeyMap[(j*keyc->maxKeysPerModifier) +
- keysPerModifier[j]] = i;
- keysPerModifier[j]++;
- }
- }
- }
- return TRUE;
-}
-
-Bool
-InitKeyClassDeviceStruct(DeviceIntPtr dev, KeySymsPtr pKeySyms, CARD8 pModifiers[])
-{
- KeyClassPtr keyc;
-
- keyc = xcalloc(1, sizeof(KeyClassRec));
- if (!keyc)
- return FALSE;
- keyc->curKeySyms.minKeyCode = pKeySyms->minKeyCode;
- keyc->curKeySyms.maxKeyCode = pKeySyms->maxKeyCode;
- if (pModifiers)
- memmove((char *)keyc->modifierMap, (char *)pModifiers, MAP_LENGTH);
- if (!SetKeySymsMap(&keyc->curKeySyms, pKeySyms) || !InitModMap(keyc))
- {
- xfree(keyc->curKeySyms.map);
- xfree(keyc->modifierKeyMap);
- xfree(keyc);
- return FALSE;
- }
- dev->key = keyc;
- dev->key->xkbInfo= NULL;
- XkbInitDevice(dev);
- return TRUE;
-}
-
-Bool
+_X_EXPORT Bool
InitButtonClassDeviceStruct(DeviceIntPtr dev, int numButtons,
CARD8 *map)
{
@@ -1349,30 +1253,7 @@ InitFocusClassDeviceStruct(DeviceIntPtr dev)
return TRUE;
}
-Bool
-InitKbdFeedbackClassDeviceStruct(DeviceIntPtr dev, BellProcPtr bellProc,
- KbdCtrlProcPtr controlProc)
-{
- KbdFeedbackPtr feedc;
-
- feedc = (KbdFeedbackPtr)xalloc(sizeof(KbdFeedbackClassRec));
- if (!feedc)
- return FALSE;
- feedc->BellProc = bellProc;
- feedc->CtrlProc = controlProc;
- defaultKeyboardControl.autoRepeat = TRUE;
- feedc->ctrl = defaultKeyboardControl;
- feedc->ctrl.id = 0;
- if ((feedc->next = dev->kbdfeed) != 0)
- feedc->ctrl.id = dev->kbdfeed->ctrl.id + 1;
- dev->kbdfeed = feedc;
- feedc->xkb_sli= NULL;
- XkbFinishDeviceInit(dev);
- (*dev->kbdfeed->CtrlProc)(dev,&dev->kbdfeed->ctrl);
- return TRUE;
-}
-
-Bool
+_X_EXPORT Bool
InitPtrFeedbackClassDeviceStruct(DeviceIntPtr dev, PtrCtrlProcPtr controlProc)
{
PtrFeedbackPtr feedc;
@@ -1517,19 +1398,7 @@ InitPointerDeviceStruct(DevicePtr device, CARD8 *map, int numButtons,
InitPtrFeedbackClassDeviceStruct(dev, controlProc));
}
-Bool
-InitKeyboardDeviceStruct(DevicePtr device, KeySymsPtr pKeySyms,
- CARD8 pModifiers[], BellProcPtr bellProc,
- KbdCtrlProcPtr controlProc)
-{
- DeviceIntPtr dev = (DeviceIntPtr)device;
-
- return(InitKeyClassDeviceStruct(dev, pKeySyms, pModifiers) &&
- InitFocusClassDeviceStruct(dev) &&
- InitKbdFeedbackClassDeviceStruct(dev, bellProc, controlProc));
-}
-
-void
+_X_EXPORT void
SendMappingNotify(DeviceIntPtr pDev, unsigned request, unsigned firstKeyCode,
unsigned count, ClientPtr client)
{
diff --git a/hw/kdrive/src/kinput.c b/hw/kdrive/src/kinput.c
index 670cc372f..92f5216e5 100644
--- a/hw/kdrive/src/kinput.c
+++ b/hw/kdrive/src/kinput.c
@@ -746,7 +746,7 @@ KdKeyboardProc(DeviceIntPtr pDevice, int onoff)
DevicePtr pDev = (DevicePtr)pDevice;
KdKeyboardInfo *ki;
Atom xiclass;
- XkbComponentNamesRec names;
+ XkbRMLVOSet rmlvo;
if (!pDev)
return BadImplementation;
@@ -795,16 +795,13 @@ KdKeyboardProc(DeviceIntPtr pDevice, int onoff)
KdInitModMap(ki);
KdInitAutoRepeats(ki);
- memset(&names, 0, sizeof(XkbComponentNamesRec));
-
- XkbSetRulesDflts (ki->xkbRules, ki->xkbModel, ki->xkbLayout,
- ki->xkbVariant, ki->xkbOptions);
-
- ret = XkbInitKeyboardDeviceStruct (pDevice,
- &names,
- &ki->keySyms,
- ki->modmap,
- KdBell, KdKbdCtrl);
+ memset(&rmlvo, 0, sizeof(rmlvo));
+ rmlvo.rules = ki->xkbRules;
+ rmlvo.model = ki->xkbModel;
+ rmlvo.layout = ki->xkbLayout;
+ rmlvo.variant = ki->xkbVariant;
+ rmlvo.options = ki->xkbOptions;
+ ret = InitKeyboardDeviceStruct (pDevice, &rmlvo, KdBell, KdKbdCtrl);
if (!ret) {
ErrorF("Couldn't initialise keyboard %s\n", ki->name);
return BadImplementation;
diff --git a/hw/vfb/InitInput.c b/hw/vfb/InitInput.c
index d2abfc242..e53ac4b29 100644
--- a/hw/vfb/InitInput.c
+++ b/hw/vfb/InitInput.c
@@ -259,21 +259,19 @@ GetLK201Mappings(KeySymsPtr pKeySyms, CARD8 *pModMap)
static int
vfbKeybdProc(DeviceIntPtr pDevice, int onoff)
{
- KeySymsRec keySyms;
- CARD8 modMap[MAP_LENGTH];
DevicePtr pDev = (DevicePtr)pDevice;
+ XkbRMLVOSet rmlvo;
switch (onoff)
{
- case DEVICE_INIT:
- GetLK201Mappings(&keySyms, modMap);
- InitKeyboardDeviceStruct(pDev, &keySyms, modMap,
- (BellProcPtr)NoopDDA, (KbdCtrlProcPtr)NoopDDA);
- break;
- case DEVICE_ON:
+ case DEVICE_INIT:
+ XkbGetRulesDflts(&rmlvo);
+ InitKeyboardDeviceStruct(pDevice, &rmlvo, NULL, NULL);
+ break;
+ case DEVICE_ON:
pDev->on = TRUE;
break;
- case DEVICE_OFF:
+ case DEVICE_OFF:
pDev->on = FALSE;
break;
case DEVICE_CLOSE:
diff --git a/hw/xfree86/common/xf86Module.h b/hw/xfree86/common/xf86Module.h
index e6960c84d..cbba3edde 100644
--- a/hw/xfree86/common/xf86Module.h
+++ b/hw/xfree86/common/xf86Module.h
@@ -83,7 +83,7 @@ typedef enum {
*/
#define ABI_ANSIC_VERSION SET_ABI_VERSION(0, 4)
#define ABI_VIDEODRV_VERSION SET_ABI_VERSION(5, 0)
-#define ABI_XINPUT_VERSION SET_ABI_VERSION(4, 0)
+#define ABI_XINPUT_VERSION SET_ABI_VERSION(5, 0)
#define ABI_EXTENSION_VERSION SET_ABI_VERSION(2, 0)
#define ABI_FONT_VERSION SET_ABI_VERSION(0, 6)
diff --git a/include/input.h b/include/input.h
index cf546e076..db75f6c78 100644
--- a/include/input.h
+++ b/include/input.h
@@ -53,6 +53,7 @@ SOFTWARE.
#include <X11/Xmd.h>
#include <X11/Xproto.h>
#include "window.h" /* for WindowPtr */
+#include "xkbrules.h"
#define DEVICE_INIT 0
#define DEVICE_ON 1
@@ -268,11 +269,6 @@ extern _X_EXPORT Bool SetKeySymsMap(
KeySymsPtr /*dst*/,
KeySymsPtr /*src*/);
-extern _X_EXPORT Bool InitKeyClassDeviceStruct(
- DeviceIntPtr /*device*/,
- KeySymsPtr /*pKeySyms*/,
- CARD8 /*pModifiers*/[]);
-
extern _X_EXPORT Bool InitButtonClassDeviceStruct(
DeviceIntPtr /*device*/,
int /*numButtons*/,
@@ -304,11 +300,6 @@ typedef void (*KbdCtrlProcPtr)(
DeviceIntPtr /*device*/,
KeybdCtrl * /*ctrl*/);
-extern _X_EXPORT Bool InitKbdFeedbackClassDeviceStruct(
- DeviceIntPtr /*device*/,
- BellProcPtr /*bellProc*/,
- KbdCtrlProcPtr /*controlProc*/);
-
typedef void (*PtrCtrlProcPtr)(
DeviceIntPtr /*device*/,
PtrCtrl * /*ctrl*/);
@@ -363,9 +354,8 @@ extern _X_EXPORT Bool InitPointerDeviceStruct(
int /*numAxes*/);
extern _X_EXPORT Bool InitKeyboardDeviceStruct(
- DevicePtr /*device*/,
- KeySymsPtr /*pKeySyms*/,
- CARD8 /*pModifiers*/[],
+ DeviceIntPtr /*device*/,
+ XkbRMLVOSet * /*rmlvo*/,
BellProcPtr /*bellProc*/,
KbdCtrlProcPtr /*controlProc*/);
diff --git a/include/xkbsrv.h b/include/xkbsrv.h
index af87d8fa5..a28967c22 100644
--- a/include/xkbsrv.h
+++ b/include/xkbsrv.h
@@ -54,6 +54,7 @@ THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include <X11/extensions/XKBproto.h>
#include "xkbstr.h"
+#include "xkbrules.h"
#include "inputstr.h"
typedef struct _XkbInterest {
@@ -870,31 +871,18 @@ extern _X_EXPORT void XkbClearAllLatchesAndLocks(
XkbEventCausePtr /* cause */
);
+extern _X_EXPORT void XkbGetRulesDflts(
+ XkbRMLVOSet * /* rmlvo */
+);
+
extern _X_EXPORT void XkbSetRulesDflts(
- char * /* rulesFile */,
- char * /* model */,
- char * /* layout */,
- char * /* variant */,
- char * /* options */
+ XkbRMLVOSet * /* rmlvo */
);
extern _X_EXPORT void XkbDeleteRulesDflts(
void
);
-extern _X_EXPORT void XkbInitDevice(
- DeviceIntPtr /* pXDev */
-);
-
-extern _X_EXPORT Bool XkbInitKeyboardDeviceStruct(
- DeviceIntPtr /* pXDev */,
- XkbComponentNamesPtr /* pNames */,
- KeySymsPtr /* pSyms */,
- CARD8 /* pMods */[],
- BellProcPtr /* bellProc */,
- KbdCtrlProcPtr /* ctrlProc */
-);
-
extern _X_EXPORT int SProcXkbDispatch(
ClientPtr /* client */
);
@@ -922,10 +910,6 @@ extern _X_EXPORT Status XkbChangeKeycodeRange(
XkbChangesPtr /* changes */
);
-extern _X_EXPORT int XkbFinishDeviceInit(
- DeviceIntPtr /* pXDev */
-);
-
extern _X_EXPORT void XkbFreeSrvLedInfo(
XkbSrvLedInfoPtr /* sli */
);
@@ -1021,6 +1005,11 @@ extern _X_EXPORT Bool XkbDDXNamesFromRules(
XkbComponentNamesPtr /* names */
);
+extern _X_EXPORT XkbDescPtr XkbCompileKeymap(
+ DeviceIntPtr /* dev */,
+ XkbRMLVOSet * /* rmlvo */
+);
+
_XFUNCPROTOEND
#define XkbAtomGetString(s) NameForAtom(s)
diff --git a/xkb/ddxLoad.c b/xkb/ddxLoad.c
index b4ac53593..c24b2cc2f 100644
--- a/xkb/ddxLoad.c
+++ b/xkb/ddxLoad.c
@@ -428,3 +428,36 @@ XkbRF_RulesPtr rules;
return complete;
}
+
+XkbDescPtr
+XkbCompileKeymap(DeviceIntPtr dev, XkbRMLVOSet *rmlvo)
+{
+ XkbComponentNamesRec kccgst;
+ XkbRF_VarDefsRec mlvo;
+ XkbDescPtr xkb;
+ char name[PATH_MAX];
+
+ if (!dev || !rmlvo) {
+ LogMessage(X_ERROR, "XKB: No device or RMLVO specified\n");
+ return NULL;
+ }
+
+ mlvo.model = rmlvo->model;
+ mlvo.layout = rmlvo->layout;
+ mlvo.variant = rmlvo->variant;
+ mlvo.options = rmlvo->options;
+
+ /* XDNFR already logs for us. */
+ if (!XkbDDXNamesFromRules(dev, rmlvo->rules, &mlvo, &kccgst))
+ return NULL;
+
+ /* XDLKBN too, but it might return 0 as well as allocating. */
+ if (!XkbDDXLoadKeymapByNames(dev, &kccgst, XkmAllIndicesMask, 0, &xkb, name,
+ PATH_MAX)) {
+ if (xkb)
+ XkbFreeKeyboard(xkb, 0, TRUE);
+ return NULL;
+ }
+
+ return xkb;
+}
diff --git a/xkb/xkbInit.c b/xkb/xkbInit.c
index e800482ac..d85fbd4e4 100644
--- a/xkb/xkbInit.c
+++ b/xkb/xkbInit.c
@@ -93,36 +93,35 @@ char * XkbBaseDirectory= XKB_BASE_DIRECTORY;
char * XkbBinDirectory= XKB_BIN_DIRECTORY;
static int XkbWantAccessX= 0;
-static Bool rulesDefined= False;
-static char * XkbRulesFile= NULL;
+static char * XkbRulesDflt= NULL;
static char * XkbModelDflt= NULL;
static char * XkbLayoutDflt= NULL;
static char * XkbVariantDflt= NULL;
static char * XkbOptionsDflt= NULL;
+static char * XkbRulesUsed= NULL;
static char * XkbModelUsed= NULL;
static char * XkbLayoutUsed= NULL;
static char * XkbVariantUsed= NULL;
static char * XkbOptionsUsed= NULL;
-static XkbDescPtr xkb_cached_map = NULL;
-
static Bool XkbWantRulesProp= XKB_DFLT_RULES_PROP;
/***====================================================================***/
-static char *
-XkbGetRulesDflts(XkbRF_VarDefsPtr defs)
+void
+XkbGetRulesDflts(XkbRMLVOSet *rmlvo)
{
- if (XkbModelDflt) defs->model= XkbModelDflt;
- else defs->model= XKB_DFLT_MODEL;
- if (XkbLayoutDflt) defs->layout= XkbLayoutDflt;
- else defs->layout= XKB_DFLT_LAYOUT;
- if (XkbVariantDflt) defs->variant= XkbVariantDflt;
- else defs->variant= XKB_DFLT_VARIANT;
- if (XkbOptionsDflt) defs->options= XkbOptionsDflt;
- else defs->options= XKB_DFLT_OPTIONS;
- return (rulesDefined?XkbRulesFile:XKB_DFLT_RULES);
+ if (XkbRulesDflt) rmlvo->rules = XkbRulesDflt;
+ else rmlvo->rules = XKB_DFLT_RULES;
+ if (XkbModelDflt) rmlvo->model= XkbModelDflt;
+ else rmlvo->model= XKB_DFLT_MODEL;
+ if (XkbLayoutDflt) rmlvo->layout= XkbLayoutDflt;
+ else rmlvo->layout= XKB_DFLT_LAYOUT;
+ if (XkbVariantDflt) rmlvo->variant= XkbVariantDflt;
+ else rmlvo->variant= XKB_DFLT_VARIANT;
+ if (XkbOptionsDflt) rmlvo->options= XkbOptionsDflt;
+ else rmlvo->options= XKB_DFLT_OPTIONS;
}
static Bool
@@ -132,9 +131,7 @@ int len,out;
Atom name;
char * pval;
- if (rulesDefined && (!XkbRulesFile))
- return False;
- len= (XkbRulesFile?strlen(XkbRulesFile):strlen(XKB_DFLT_RULES));
+ len= (XkbRulesUsed?strlen(XkbRulesUsed):0);
len+= (XkbModelUsed?strlen(XkbModelUsed):0);
len+= (XkbLayoutUsed?strlen(XkbLayoutUsed):0);
len+= (XkbVariantUsed?strlen(XkbVariantUsed):0);
@@ -156,12 +153,9 @@ char * pval;
return True;
}
out= 0;
- if (XkbRulesFile) {
- strcpy(&pval[out],XkbRulesFile);
- out+= strlen(XkbRulesFile);
- } else {
- strcpy(&pval[out],XKB_DFLT_RULES);
- out+= strlen(XKB_DFLT_RULES);
+ if (XkbRulesUsed) {
+ strcpy(&pval[out],XkbRulesUsed);
+ out+= strlen(XkbRulesUsed);
}
pval[out++]= '\0';
if (XkbModelUsed) {
@@ -195,71 +189,55 @@ char * pval;
}
static void
-XkbSetRulesUsed(XkbRF_VarDefsPtr defs)
+XkbSetRulesUsed(XkbRMLVOSet *rmlvo)
{
+ if (XkbRulesUsed)
+ _XkbFree(XkbRulesUsed);
+ XkbRulesUsed= (rmlvo->rules?_XkbDupString(rmlvo->rules):NULL);
if (XkbModelUsed)
_XkbFree(XkbModelUsed);
- XkbModelUsed= (defs->model?_XkbDupString(defs->model):NULL);
+ XkbModelUsed= (rmlvo->model?_XkbDupString(rmlvo->model):NULL);
if (XkbLayoutUsed)
_XkbFree(XkbLayoutUsed);
- XkbLayoutUsed= (defs->layout?_XkbDupString(defs->layout):NULL);
+ XkbLayoutUsed= (rmlvo->layout?_XkbDupString(rmlvo->layout):NULL);
if (XkbVariantUsed)
_XkbFree(XkbVariantUsed);
- XkbVariantUsed= (defs->variant?_XkbDupString(defs->variant):NULL);
+ XkbVariantUsed= (rmlvo->variant?_XkbDupString(rmlvo->variant):NULL);
if (XkbOptionsUsed)
_XkbFree(XkbOptionsUsed);
- XkbOptionsUsed= (defs->options?_XkbDupString(defs->options):NULL);
+ XkbOptionsUsed= (rmlvo->options?_XkbDupString(rmlvo->options):NULL);
if (XkbWantRulesProp)
QueueWorkProc(XkbWriteRulesProp,NULL,NULL);
return;
}
-/**
- * Set the default RMLVO for the next device to be initialised.
- * If a parameter is NULL, the previous setting will be used. Use empty
- * strings if you want to delete a previous setting.
- *
- * If @rulesFile is NULL and no previous @rulesFile has been set, the
- * built-in default is chosen as default.
- */
void
-XkbSetRulesDflts(char *rulesFile,char *model,char *layout,
- char *variant,char *options)
+XkbSetRulesDflts(XkbRMLVOSet *rmlvo)
{
- if (!rulesFile && !XkbRulesFile)
- {
- LogMessage(X_WARNING, "[xkb] No rule given, and no previous rule "
- "defined. Defaulting to '%s'.\n",
- XKB_DFLT_RULES);
- rulesFile = XKB_DFLT_RULES;
+ if (rmlvo->rules) {
+ if (XkbRulesDflt)
+ _XkbFree(XkbRulesDflt);
+ XkbRulesDflt= _XkbDupString(rmlvo->rules);
}
-
- if (rulesFile) {
- if (XkbRulesFile)
- _XkbFree(XkbRulesFile);
- XkbRulesFile= _XkbDupString(rulesFile);
- rulesDefined= True;
- }
-
- if (model) {
+ if (rmlvo->model) {
if (XkbModelDflt)
_XkbFree(XkbModelDflt);
- XkbModelDflt= _XkbDupString(model);
+ XkbModelDflt= _XkbDupString(rmlvo->model);
}
- if (layout) {
+ if (rmlvo->layout) {
if (XkbLayoutDflt)
_XkbFree(XkbLayoutDflt);
- XkbLayoutDflt= _XkbDupString(layout);
+ XkbLayoutDflt= _XkbDupString(rmlvo->layout);
}
- if (variant) {
+ if (rmlvo->variant) {
if (XkbVariantDflt)
_XkbFree(XkbVariantDflt);
- XkbVariantDflt= _XkbDupString(variant);
+ XkbVariantDflt= _XkbDupString(rmlvo->variant);
}
- if (options) {
+ if (rmlvo->options) {
if (XkbOptionsDflt)
_XkbFree(XkbOptionsDflt);
- XkbOptionsDflt= _XkbDupString(options);
+ XkbOptionsDflt= _XkbDupString(rmlvo->options);
}
return;
}
@@ -267,8 +245,8 @@ XkbSetRulesDflts(char *rulesFile,char *model,char *layout,
void
XkbDeleteRulesDflts(void)
{
- _XkbFree(XkbRulesFile);
- XkbRulesFile = NULL;
+ _XkbFree(XkbRulesDflt);
+ XkbRulesDflt = NULL;
_XkbFree(XkbModelDflt);
XkbModelDflt = NULL;
_XkbFree(XkbLayoutDflt);
@@ -277,9 +255,6 @@ XkbDeleteRulesDflts(void)
XkbVariantDflt = NULL;
_XkbFree(XkbOptionsDflt);
XkbOptionsDflt = NULL;
-
- XkbFreeKeyboard(xkb_cached_map, XkbAllComponentsMask, True);
- xkb_cached_map = NULL;
}
/***====================================================================***/
@@ -467,292 +442,123 @@ XkbControlsPtr ctrls;
return Success;
}
-void
-XkbInitDevice(DeviceIntPtr pXDev)
+_X_EXPORT Bool
+InitKeyboardDeviceStruct(DeviceIntPtr dev, XkbRMLVOSet *rmlvo,
+ BellProcPtr bell_func, KbdCtrlProcPtr ctrl_func)
{
-int i;
-XkbSrvInfoPtr xkbi;
-XkbChangesRec changes;
-unsigned check;
-XkbEventCauseRec cause;
-
- bzero(&changes,sizeof(XkbChangesRec));
- pXDev->key->xkbInfo= xkbi= _XkbTypedCalloc(1,XkbSrvInfoRec);
- if ( xkbi ) {
- XkbDescPtr xkb;
+ int i;
+ unsigned int check;
+ XkbSrvInfoPtr xkbi;
+ XkbDescPtr xkb;
+ XkbSrvLedInfoPtr sli;
+ XkbChangesRec changes;
+ XkbEventCauseRec cause;
+
+ if (dev->key || dev->kbdfeed || !rmlvo)
+ return False;
- if (xkb_cached_map) {
- xkbi->desc = xkb_cached_map;
- xkb_cached_map = NULL;
- }
- else {
- xkbi->desc= XkbAllocKeyboard();
- if (!xkbi->desc)
- FatalError("Couldn't allocate keyboard description\n");
- xkbi->desc->min_key_code = pXDev->key->curKeySyms.minKeyCode;
- xkbi->desc->max_key_code = pXDev->key->curKeySyms.maxKeyCode;
- }
- xkb= xkbi->desc;
- if (xkb->min_key_code == 0)
- xkb->min_key_code = pXDev->key->curKeySyms.minKeyCode;
- if (xkb->max_key_code == 0)
- xkb->max_key_code = pXDev->key->curKeySyms.maxKeyCode;
- if ((pXDev->key->curKeySyms.minKeyCode!=xkbi->desc->min_key_code)||
- (pXDev->key->curKeySyms.maxKeyCode!=xkbi->desc->max_key_code)) {
- /* 12/9/95 (ef) -- XXX! Maybe we should try to fix up one or */
- /* the other here, but for now just complain */
- /* can't just update the core range without */
- /* reallocating the KeySymsRec (pain) */
- ErrorF("[xkb] Internal Error!! XKB and core keymap have different range\n");
- }
- if (XkbAllocClientMap(xkb,XkbAllClientInfoMask,0)!=Success)
- FatalError("Couldn't allocate client map in XkbInitDevice\n");
- i= XkbNumKeys(xkb)/3+1;
- if (XkbAllocServerMap(xkb,XkbAllServerInfoMask,i)!=Success)
- FatalError("Couldn't allocate server map in XkbInitDevice\n");
-
- xkbi->dfltPtrDelta=1;
- xkbi->device = pXDev;
-
- XkbInitSemantics(xkb);
- XkbInitNames(xkbi);
- XkbInitRadioGroups(xkbi);
-
- /* 12/31/94 (ef) -- XXX! Should check if state loaded from file */
- bzero(&xkbi->state,sizeof(XkbStateRec));
-
- XkbInitControls(pXDev,xkbi);
-
- if (xkb->defined & XkmSymbolsMask)
- memcpy(pXDev->key->modifierMap, xkb->map->modmap,
- xkb->max_key_code + 1);
- else
- memcpy(xkb->map->modmap, pXDev->key->modifierMap,
- xkb->max_key_code + 1);
-
- XkbInitIndicatorMap(xkbi);
-
- XkbDDXInitDevice(pXDev);
-
- if (xkb->defined & XkmSymbolsMask)
- XkbUpdateCoreDescription(pXDev, True);
- else
- XkbUpdateKeyTypesFromCore(pXDev, xkb->min_key_code,
- XkbNumKeys(xkb), &changes);
-
- XkbSetCauseUnknown(&cause);
- XkbUpdateActions(pXDev,xkb->min_key_code, XkbNumKeys(xkb),&changes,
- &check,&cause);
- /* For sanity. The first time the connection
- * is opened, the client side min and max are set
- * using QueryMinMaxKeyCodes() which grabs them
- * from pXDev.
- */
- pXDev->key->curKeySyms.minKeyCode = xkb->min_key_code;
- pXDev->key->curKeySyms.maxKeyCode = xkb->max_key_code;
+ memset(&changes, 0, sizeof(changes));
+ XkbSetCauseUnknown(&cause);
+
+ dev->key = xcalloc(1, sizeof(*dev->key));
+ if (!dev->key) {
+ ErrorF("XKB: Failed to allocate key class\n");
+ return False;
}
- return;
-}
-#if MAP_LENGTH > XkbMaxKeyCount
-#undef XkbMaxKeyCount
-#define XkbMaxKeyCount MAP_LENGTH
-#endif
+ dev->kbdfeed = xcalloc(1, sizeof(*dev->kbdfeed));
+ if (!dev->kbdfeed) {
+ ErrorF("XKB: Failed to allocate key feedback class\n");
+ goto unwind_key;
+ }
-Bool
-XkbInitKeyboardDeviceStruct(
- DeviceIntPtr dev,
- XkbComponentNamesPtr names,
- KeySymsPtr pSymsIn,
- CARD8 pModsIn[],
- void (*bellProc)(
- int /*percent*/,
- DeviceIntPtr /*device*/,
- pointer /*ctrl*/,
- int),
- void (*ctrlProc)(
- DeviceIntPtr /*device*/,
- KeybdCtrl * /*ctrl*/))
-{
-KeySymsRec tmpSyms,*pSyms;
-CARD8 tmpMods[XkbMaxLegalKeyCode+1],*pMods;
-char name[PATH_MAX],*rules;
-Bool ok=False;
-XkbRF_VarDefsRec defs;
-XkbDescPtr xkb;
-
- if ((dev->key!=NULL)||(dev->kbdfeed!=NULL))
- return False;
- pSyms= pSymsIn;
- pMods= pModsIn;
- bzero(&defs,sizeof(XkbRF_VarDefsRec));
- rules= XkbGetRulesDflts(&defs);
-
- /*
- * The strings are duplicated because it is not guaranteed that
- * they are allocated, or that they are allocated for every server
- * generation. Eventually they will be freed at the end of this
- * function.
- */
- names->keymap = NULL;
- if (names->keycodes) names->keycodes = _XkbDupString(names->keycodes);
- if (names->types) names->types = _XkbDupString(names->types);
- if (names->compat) names->compat = _XkbDupString(names->compat);
- if (names->geometry) names->geometry = _XkbDupString(names->geometry);
- if (names->symbols) names->symbols = _XkbDupString(names->symbols);
-
- if (defs.model && defs.layout && rules) {
- XkbComponentNamesRec rNames;
- bzero(&rNames,sizeof(XkbComponentNamesRec));
- if (XkbDDXNamesFromRules(dev,rules,&defs,&rNames)) {
- if (rNames.keycodes) {
- if (!names->keycodes)
- names->keycodes = rNames.keycodes;
- else
- _XkbFree(rNames.keycodes);
- }
- if (rNames.types) {
- if (!names->types)
- names->types = rNames.types;
- else _XkbFree(rNames.types);
- }
- if (rNames.compat) {
- if (!names->compat)
- names->compat = rNames.compat;
- else _XkbFree(rNames.compat);
- }
- if (rNames.symbols) {
- if (!names->symbols)
- names->symbols = rNames.symbols;
- else _XkbFree(rNames.symbols);
- }
- if (rNames.geometry) {
- if (!names->geometry)
- names->geometry = rNames.geometry;
- else _XkbFree(rNames.geometry);
- }
- XkbSetRulesUsed(&defs);
- }
+ xkbi = xcalloc(1, sizeof(*xkbi));
+ if (!xkbi) {
+ ErrorF("XKB: Failed to allocate XKB info\n");
+ goto unwind_kbdfeed;
+ }
+ dev->key->xkbInfo = xkbi;
+
+ xkb = XkbCompileKeymap(dev, rmlvo);
+ if (!xkb) {
+ ErrorF("XKB: Failed to compile keymap\n");
+ goto unwind_info;
}
+ xkbi->desc = xkb;
- ok = (Bool) XkbDDXLoadKeymapByNames(dev,names,XkmAllIndicesMask,0,
- &xkb,name,PATH_MAX);
+ if (xkb->min_key_code == 0)
+ xkb->min_key_code = 8;
+ if (xkb->max_key_code == 0)
+ xkb->max_key_code = 255;
- if (ok && (xkb!=NULL)) {
- KeyCode minKC,maxKC;
+ i = XkbNumKeys(xkb) / 3 + 1;
+ if (XkbAllocClientMap(xkb, XkbAllClientInfoMask, 0) != Success)
+ goto unwind_desc;
+ if (XkbAllocServerMap(xkb, XkbAllServerInfoMask, i) != Success)
+ goto unwind_desc;
- minKC= xkb->min_key_code;
- maxKC= xkb->max_key_code;
- if (XkbIsLegalKeycode(minKC)&&XkbIsLegalKeycode(maxKC)&&(minKC<=maxKC)&&
- ((minKC!=pSyms->minKeyCode)||(maxKC!=pSyms->maxKeyCode))) {
- if (xkb->map!=NULL) {
- KeySym *inSym,*outSym;
- int width= pSymsIn->mapWidth;
+ xkbi->dfltPtrDelta = 1;
+ xkbi->device = dev;
- tmpSyms.minKeyCode= minKC;
- tmpSyms.maxKeyCode= maxKC;
+ XkbInitSemantics(xkb);
+ XkbInitNames(xkbi);
+ XkbInitRadioGroups(xkbi);
- if (minKC<pSymsIn->minKeyCode)
- minKC= pSymsIn->minKeyCode;
- if (maxKC>pSymsIn->maxKeyCode)
- maxKC= pSymsIn->maxKeyCode;
+ XkbInitControls(dev, xkbi);
- tmpSyms.mapWidth= width;
- tmpSyms.map= _XkbTypedCalloc(width*XkbNumKeys(xkb),KeySym);
- inSym= &pSymsIn->map[(minKC-pSymsIn->minKeyCode)*width];
- outSym= &tmpSyms.map[(minKC-tmpSyms.minKeyCode)*width];
- memcpy(outSym,inSym,((maxKC-minKC+1)*width)*sizeof(KeySym));
- pSyms= &tmpSyms;
- }
- if ((xkb->map!=NULL)&&(xkb->map->modmap!=NULL)) {
- bzero(tmpMods,XkbMaxKeyCount);
- memcpy(tmpMods,xkb->map->modmap,maxKC+1);
- pMods= tmpMods;
- }
- }
- /* Store the map here so we can pick it back up in XkbInitDevice.
- * Sigh. */
- xkb_cached_map = xkb;
- }
- else {
- LogMessage(X_WARNING, "Couldn't load XKB keymap, falling back to pre-XKB keymap\n");
- }
- ok= InitKeyboardDeviceStruct((DevicePtr)dev,pSyms,pMods,bellProc,ctrlProc);
- xkb_cached_map = NULL;
- if ((pSyms==&tmpSyms)&&(pSyms->map!=NULL)) {
- _XkbFree(pSyms->map);
- pSyms->map= NULL;
- }
-
- if (names->keycodes) _XkbFree(names->keycodes);
- names->keycodes = NULL;
- if (names->types) _XkbFree(names->types);
- names->types = NULL;
- if (names->compat) _XkbFree(names->compat);
- names->compat = NULL;
- if (names->geometry) _XkbFree(names->geometry);
- names->geometry = NULL;
- if (names->symbols) _XkbFree(names->symbols);
- names->symbols = NULL;
-
- return ok;
-}
+ /* XXX: Doesn't XUCD make this redundant? */
+ memcpy(dev->key->modifierMap, xkb->map->modmap, xkb->max_key_code + 1);
-/***====================================================================***/
+ XkbInitIndicatorMap(xkbi);
- /*
- * InitKeyClassDeviceStruct initializes the key class before it
- * initializes the keyboard feedback class for a device.
- * UpdateActions can't set up the correct autorepeat for keyboard
- * initialization because the keyboard feedback isn't created yet.
- * Instead, UpdateActions notes the "correct" autorepeat in the
- * SrvInfo structure and InitKbdFeedbackClass calls UpdateAutoRepeat
- * to apply the computed autorepeat once the feedback class exists.
- *
- * DIX will apply the changed autorepeat, so there's no need to
- * do so here. This function returns True if both RepeatKeys and
- * the core protocol autorepeat ctrls are set (i.e. should use
- * software autorepeat), false otherwise.
- *
- * This function also computes the autorepeat accelerators for the
- * default indicator feedback.
- */
-int
-XkbFinishDeviceInit(DeviceIntPtr pXDev)
-{
-XkbSrvInfoPtr xkbi;
-XkbDescPtr xkb;
-int softRepeat;
-XkbSrvLedInfoPtr sli;
+ XkbDDXInitDevice(dev);
- xkbi = NULL;
- if (pXDev && pXDev->key && pXDev->key->xkbInfo && pXDev->kbdfeed) {
- xkbi= pXDev->key->xkbInfo;
- xkb= xkbi->desc;
- /* If we come from DeepCopyDeviceClasses, the CtrlProc was already set
- * to XkbDDXKeybdCtrlProc, overwriting it leads to happy recursion.
- */
- if (pXDev->kbdfeed && pXDev->kbdfeed->CtrlProc != XkbDDXKeybdCtrlProc) {
- xkbi->kbdProc= pXDev->kbdfeed->CtrlProc;
- pXDev->kbdfeed->CtrlProc= XkbDDXKeybdCtrlProc;
- }
- if (pXDev->kbdfeed->ctrl.autoRepeat)
- xkb->ctrls->enabled_ctrls|= XkbRepeatKeysMask;
- softRepeat= (xkb->ctrls->enabled_ctrls&XkbRepeatKeysMask)!=0;
- if (pXDev->kbdfeed) {
- memcpy(pXDev->kbdfeed->ctrl.autoRepeats,
- xkb->ctrls->per_key_repeat,XkbPerKeyBitArraySize);
- softRepeat= softRepeat&&pXDev->kbdfeed->ctrl.autoRepeat;
- }
- }
- else softRepeat= 0;
- sli= XkbFindSrvLedInfo(pXDev,XkbDfltXIClass,XkbDfltXIId,0);
- if (sli && xkbi)
- XkbCheckIndicatorMaps(xkbi->device,sli,XkbAllIndicatorsMask);
- else DebugF("[xkb] No indicator feedback in XkbFinishInit (shouldn't happen)!\n");
- return softRepeat;
+ XkbUpdateCoreDescription(dev, True);
+
+ XkbUpdateActions(dev, xkb->min_key_code, XkbNumKeys(xkb), &changes,
+ &check, &cause);
+ dev->key->curKeySyms.minKeyCode = xkb->min_key_code;
+ dev->key->curKeySyms.maxKeyCode = xkb->max_key_code;
+
+ InitFocusClassDeviceStruct(dev);
+
+ xkbi->kbdProc = ctrl_func;
+ dev->kbdfeed->CtrlProc = XkbDDXKeybdCtrlProc;
+
+ dev->kbdfeed->ctrl = defaultKeyboardControl;
+ if (dev->kbdfeed->ctrl.autoRepeat)
+ xkb->ctrls->enabled_ctrls |= XkbRepeatKeysMask;
+
+ memcpy(dev->kbdfeed->ctrl.autoRepeats, xkb->ctrls->per_key_repeat,
+ XkbPerKeyBitArraySize);
+
+ sli = XkbFindSrvLedInfo(dev, XkbDfltXIClass, XkbDfltXIId, 0);
+ if (sli)
+ XkbCheckIndicatorMaps(dev, sli, XkbAllIndicatorsMask);
+ else
+ DebugF("XKB: No indicator feedback in XkbFinishInit!\n");
+
+ dev->kbdfeed->CtrlProc(dev,&dev->kbdfeed->ctrl);
+
+ XkbSetRulesDflts(rmlvo);
+ XkbSetRulesUsed(rmlvo);
+
+ return TRUE;
+
+unwind_desc:
+ XkbFreeKeyboard(xkb, 0, TRUE);
+unwind_info:
+ xfree(xkbi);
+unwind_kbdfeed:
+ xfree(dev->kbdfeed);
+unwind_key:
+ xfree(dev->key);
+ return FALSE;
}
+
+/***====================================================================***/
+
/*
* Be very careful about what does and doesn't get freed by this
* function. To reduce fragmentation, XkbInitDevice allocates a
diff --git a/xkb/xkbUtils.c b/xkb/xkbUtils.c
index abfd6fb97..c7a6d99d0 100644
--- a/xkb/xkbUtils.c
+++ b/xkb/xkbUtils.c
@@ -382,10 +382,6 @@ int maxNumberOfGroups;
else if (resize) {
keyc->curKeySyms.minKeyCode= xkb->min_key_code;
keyc->curKeySyms.maxKeyCode= xkb->max_key_code;
- tmp= keyc->curKeySyms.mapWidth*_XkbCoreNumKeys(keyc);
- keyc->curKeySyms.map= _XkbTypedRealloc(keyc->curKeySyms.map,tmp,KeySym);
- if (!keyc->curKeySyms.map)
- FatalError("Couldn't allocate keysyms\n");
first= firstCommon= xkb->min_key_code;
last= lastCommon= xkb->max_key_code;
}
@@ -622,8 +618,6 @@ XkbEventCauseRec cause;
XkbChangesRec changes;
unsigned check;
- if (kbd->key->xkbInfo==NULL)
- XkbInitDevice(kbd);
bzero(&changes,sizeof(XkbChangesRec));
check= 0;
if (request==MappingKeyboard) {