Commit 08363c58 authored by Daniel Stone's avatar Daniel Stone

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's avatarDaniel Stone <daniel@fooishbar.org>
Signed-off-by: Peter Hutterer's avatarPeter Hutterer <peter.hutterer@who-t.net>
parent 40877c66
......@@ -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,
......
......@@ -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)
{
......
......@@ -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;
......
......@@ -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:
......
......@@ -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)
......
......@@ -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*/);
......
......@@ -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)
......
......@@ -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;
}
This diff is collapsed.
......@@ -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) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment