Allow external atom databases
Allow people to plug in an external atom database (e.g. the X server's), so we don't have to migrate our own atoms over later. We are a bit over-keen on atoms at the moment, so it does pollute the atom database a bit though. Signed-off-by: Daniel Stone <daniel@fooishbar.org>master
parent
15b0db5492
commit
2c4a045aca
|
@ -191,8 +191,11 @@ typedef struct _XkbcDesc {
|
||||||
|
|
||||||
_XFUNCPROTOBEGIN
|
_XFUNCPROTOBEGIN
|
||||||
|
|
||||||
|
typedef uint32_t (*InternAtomFuncPtr)(const char *val);
|
||||||
|
typedef const char *(*GetAtomValueFuncPtr)(uint32_t atom);
|
||||||
|
|
||||||
extern void
|
extern void
|
||||||
XkbcInitAtoms(void);
|
XkbcInitAtoms(InternAtomFuncPtr intern, GetAtomValueFuncPtr get_atom_value);
|
||||||
|
|
||||||
extern XkbcDescPtr
|
extern XkbcDescPtr
|
||||||
XkbcCompileKeymapFromRules(const XkbRMLVOSet *rmlvo);
|
XkbcCompileKeymapFromRules(const XkbRMLVOSet *rmlvo);
|
||||||
|
|
42
src/atom.c
42
src/atom.c
|
@ -81,21 +81,31 @@ SOFTWARE.
|
||||||
|
|
||||||
typedef struct _Node {
|
typedef struct _Node {
|
||||||
struct _Node *left, *right;
|
struct _Node *left, *right;
|
||||||
Atom a;
|
CARD32 a;
|
||||||
unsigned int fingerPrint;
|
unsigned int fingerPrint;
|
||||||
char *string;
|
char *string;
|
||||||
} NodeRec, *NodePtr;
|
} NodeRec, *NodePtr;
|
||||||
|
|
||||||
#define BAD_RESOURCE 0xe0000000
|
#define BAD_RESOURCE 0xe0000000
|
||||||
|
|
||||||
static Atom lastAtom = None;
|
static CARD32 lastAtom = None;
|
||||||
static NodePtr atomRoot = NULL;
|
static NodePtr atomRoot = NULL;
|
||||||
static unsigned long tableLength;
|
static unsigned long tableLength;
|
||||||
static NodePtr *nodeTable = NULL;
|
static NodePtr *nodeTable = NULL;
|
||||||
|
InternAtomFuncPtr do_intern_atom = NULL;
|
||||||
|
GetAtomValueFuncPtr do_get_atom_value = NULL;
|
||||||
|
|
||||||
void
|
void
|
||||||
XkbcInitAtoms(void)
|
XkbcInitAtoms(InternAtomFuncPtr intern, GetAtomValueFuncPtr get_atom_value)
|
||||||
{
|
{
|
||||||
|
if (intern && get_atom_value) {
|
||||||
|
if (do_intern_atom && do_get_atom_value)
|
||||||
|
return;
|
||||||
|
do_intern_atom = intern;
|
||||||
|
do_get_atom_value = get_atom_value;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (nodeTable)
|
if (nodeTable)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
@ -104,11 +114,14 @@ XkbcInitAtoms(void)
|
||||||
nodeTable[None] = NULL;
|
nodeTable[None] = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static char *
|
static const char *
|
||||||
_XkbcAtomGetString(Atom atom)
|
_XkbcAtomGetString(CARD32 atom)
|
||||||
{
|
{
|
||||||
NodePtr node;
|
NodePtr node;
|
||||||
|
|
||||||
|
if (do_get_atom_value)
|
||||||
|
return do_get_atom_value(atom);
|
||||||
|
|
||||||
if ((atom == None) || (atom > lastAtom))
|
if ((atom == None) || (atom > lastAtom))
|
||||||
return NULL;
|
return NULL;
|
||||||
if (!(node = nodeTable[atom]))
|
if (!(node = nodeTable[atom]))
|
||||||
|
@ -117,16 +130,17 @@ _XkbcAtomGetString(Atom atom)
|
||||||
}
|
}
|
||||||
|
|
||||||
char *
|
char *
|
||||||
XkbcAtomGetString(Atom atom)
|
XkbcAtomGetString(CARD32 atom)
|
||||||
{
|
{
|
||||||
char *ret = _XkbcAtomGetString(atom);
|
const char *ret = _XkbcAtomGetString(atom);
|
||||||
return ret ? strdup(ret) : NULL;
|
return ret ? strdup(ret) : NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
char *
|
char *
|
||||||
XkbcAtomText(Atom atom)
|
XkbcAtomText(CARD32 atom)
|
||||||
{
|
{
|
||||||
char *tmp, *ret;
|
const char *tmp;
|
||||||
|
char *ret;
|
||||||
|
|
||||||
tmp = _XkbcAtomGetString(atom);
|
tmp = _XkbcAtomGetString(atom);
|
||||||
if (!tmp)
|
if (!tmp)
|
||||||
|
@ -140,8 +154,8 @@ XkbcAtomText(Atom atom)
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static Atom
|
static CARD32
|
||||||
_XkbcMakeAtom(char *string, unsigned len, Bool makeit)
|
_XkbcMakeAtom(const char *string, unsigned len, Bool makeit)
|
||||||
{
|
{
|
||||||
NodePtr *np;
|
NodePtr *np;
|
||||||
unsigned i;
|
unsigned i;
|
||||||
|
@ -214,10 +228,12 @@ _XkbcMakeAtom(char *string, unsigned len, Bool makeit)
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
|
|
||||||
Atom
|
CARD32
|
||||||
XkbcInternAtom(char *name, Bool onlyIfExists)
|
XkbcInternAtom(const char *name, Bool onlyIfExists)
|
||||||
{
|
{
|
||||||
if (!name)
|
if (!name)
|
||||||
return None;
|
return None;
|
||||||
|
if (do_intern_atom)
|
||||||
|
return do_intern_atom(name);
|
||||||
return _XkbcMakeAtom(name, strlen(name), !onlyIfExists);
|
return _XkbcMakeAtom(name, strlen(name), !onlyIfExists);
|
||||||
}
|
}
|
||||||
|
|
|
@ -63,15 +63,15 @@ XkbcNameMatchesPattern(char *name, char *ptrn);
|
||||||
/***====================================================================***/
|
/***====================================================================***/
|
||||||
|
|
||||||
extern char *
|
extern char *
|
||||||
XkbcAtomGetString(Atom atom);
|
XkbcAtomGetString(uint32_t atom);
|
||||||
|
|
||||||
extern Atom
|
extern uint32_t
|
||||||
XkbcInternAtom(char *name, Bool onlyIfExists);
|
XkbcInternAtom(const char *name, Bool onlyIfExists);
|
||||||
|
|
||||||
/***====================================================================***/
|
/***====================================================================***/
|
||||||
|
|
||||||
extern char *
|
extern char *
|
||||||
XkbcAtomText(Atom atm);
|
XkbcAtomText(uint32_t atm);
|
||||||
|
|
||||||
extern char *
|
extern char *
|
||||||
XkbcVModIndexText(XkbcDescPtr xkb, unsigned ndx);
|
XkbcVModIndexText(XkbcDescPtr xkb, unsigned ndx);
|
||||||
|
|
|
@ -60,7 +60,7 @@ int main(int argc, char *argv[])
|
||||||
}
|
}
|
||||||
|
|
||||||
uSetErrorFile(NULL);
|
uSetErrorFile(NULL);
|
||||||
XkbcInitAtoms();
|
XkbcInitAtoms(NULL, NULL);
|
||||||
|
|
||||||
xkb = XkbcCompileKeymapFromFile(file, name);
|
xkb = XkbcCompileKeymapFromFile(file, name);
|
||||||
fclose(file);
|
fclose(file);
|
||||||
|
|
|
@ -54,7 +54,7 @@ int main(int argc, char *argv[])
|
||||||
ktcsg.geometry = argv[5];
|
ktcsg.geometry = argv[5];
|
||||||
|
|
||||||
uSetErrorFile(NULL);
|
uSetErrorFile(NULL);
|
||||||
XkbcInitAtoms();
|
XkbcInitAtoms(NULL, NULL);
|
||||||
|
|
||||||
xkb = XkbcCompileKeymapFromComponents(&ktcsg);
|
xkb = XkbcCompileKeymapFromComponents(&ktcsg);
|
||||||
|
|
||||||
|
|
|
@ -53,7 +53,7 @@ int main(int argc, char *argv[])
|
||||||
rmlvo.options = argv[5];
|
rmlvo.options = argv[5];
|
||||||
|
|
||||||
uSetErrorFile(NULL);
|
uSetErrorFile(NULL);
|
||||||
XkbcInitAtoms();
|
XkbcInitAtoms(NULL, NULL);
|
||||||
|
|
||||||
xkb = XkbcCompileKeymapFromRules(&rmlvo);
|
xkb = XkbcCompileKeymapFromRules(&rmlvo);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue