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>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184
diff --git a/include/X11/extensions/XKBcommon.h b/include/X11/extensions/XKBcommon.h
index 6992cbd..2881458 100644
--- a/include/X11/extensions/XKBcommon.h
+++ b/include/X11/extensions/XKBcommon.h
@@ -191,8 +191,11 @@ typedef struct _XkbcDesc {
_XFUNCPROTOBEGIN
+typedef uint32_t (*InternAtomFuncPtr)(const char *val);
+typedef const char *(*GetAtomValueFuncPtr)(uint32_t atom);
+
extern void
-XkbcInitAtoms(void);
+XkbcInitAtoms(InternAtomFuncPtr intern, GetAtomValueFuncPtr get_atom_value);
extern XkbcDescPtr
XkbcCompileKeymapFromRules(const XkbRMLVOSet *rmlvo);
diff --git a/src/atom.c b/src/atom.c
index 9ca307c..44390cf 100644
--- a/src/atom.c
+++ b/src/atom.c
@@ -81,21 +81,31 @@ SOFTWARE.
typedef struct _Node {
struct _Node *left, *right;
- Atom a;
+ CARD32 a;
unsigned int fingerPrint;
char *string;
} NodeRec, *NodePtr;
#define BAD_RESOURCE 0xe0000000
-static Atom lastAtom = None;
+static CARD32 lastAtom = None;
static NodePtr atomRoot = NULL;
static unsigned long tableLength;
static NodePtr *nodeTable = NULL;
+InternAtomFuncPtr do_intern_atom = NULL;
+GetAtomValueFuncPtr do_get_atom_value = NULL;
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)
return;
@@ -104,11 +114,14 @@ XkbcInitAtoms(void)
nodeTable[None] = NULL;
}
-static char *
-_XkbcAtomGetString(Atom atom)
+static const char *
+_XkbcAtomGetString(CARD32 atom)
{
NodePtr node;
+ if (do_get_atom_value)
+ return do_get_atom_value(atom);
+
if ((atom == None) || (atom > lastAtom))
return NULL;
if (!(node = nodeTable[atom]))
@@ -117,16 +130,17 @@ _XkbcAtomGetString(Atom atom)
}
char *
-XkbcAtomGetString(Atom atom)
+XkbcAtomGetString(CARD32 atom)
{
- char *ret = _XkbcAtomGetString(atom);
+ const char *ret = _XkbcAtomGetString(atom);
return ret ? strdup(ret) : NULL;
}
char *
-XkbcAtomText(Atom atom)
+XkbcAtomText(CARD32 atom)
{
- char *tmp, *ret;
+ const char *tmp;
+ char *ret;
tmp = _XkbcAtomGetString(atom);
if (!tmp)
@@ -140,8 +154,8 @@ XkbcAtomText(Atom atom)
return ret;
}
-static Atom
-_XkbcMakeAtom(char *string, unsigned len, Bool makeit)
+static CARD32
+_XkbcMakeAtom(const char *string, unsigned len, Bool makeit)
{
NodePtr *np;
unsigned i;
@@ -214,10 +228,12 @@ _XkbcMakeAtom(char *string, unsigned len, Bool makeit)
return None;
}
-Atom
-XkbcInternAtom(char *name, Bool onlyIfExists)
+CARD32
+XkbcInternAtom(const char *name, Bool onlyIfExists)
{
if (!name)
return None;
+ if (do_intern_atom)
+ return do_intern_atom(name);
return _XkbcMakeAtom(name, strlen(name), !onlyIfExists);
}
diff --git a/src/xkbmisc.h b/src/xkbmisc.h
index 21c970d..028e90b 100644
--- a/src/xkbmisc.h
+++ b/src/xkbmisc.h
@@ -63,15 +63,15 @@ XkbcNameMatchesPattern(char *name, char *ptrn);
/***====================================================================***/
extern char *
-XkbcAtomGetString(Atom atom);
+XkbcAtomGetString(uint32_t atom);
-extern Atom
-XkbcInternAtom(char *name, Bool onlyIfExists);
+extern uint32_t
+XkbcInternAtom(const char *name, Bool onlyIfExists);
/***====================================================================***/
extern char *
-XkbcAtomText(Atom atm);
+XkbcAtomText(uint32_t atm);
extern char *
XkbcVModIndexText(XkbcDescPtr xkb, unsigned ndx);
diff --git a/test/filecomp.c b/test/filecomp.c
index 260c151..dc20681 100644
--- a/test/filecomp.c
+++ b/test/filecomp.c
@@ -60,7 +60,7 @@ int main(int argc, char *argv[])
}
uSetErrorFile(NULL);
- XkbcInitAtoms();
+ XkbcInitAtoms(NULL, NULL);
xkb = XkbcCompileKeymapFromFile(file, name);
fclose(file);
diff --git a/test/namescomp.c b/test/namescomp.c
index 1c64419..3c34d0c 100644
--- a/test/namescomp.c
+++ b/test/namescomp.c
@@ -54,7 +54,7 @@ int main(int argc, char *argv[])
ktcsg.geometry = argv[5];
uSetErrorFile(NULL);
- XkbcInitAtoms();
+ XkbcInitAtoms(NULL, NULL);
xkb = XkbcCompileKeymapFromComponents(&ktcsg);
diff --git a/test/rulescomp.c b/test/rulescomp.c
index 8046b49..102c3e9 100644
--- a/test/rulescomp.c
+++ b/test/rulescomp.c
@@ -53,7 +53,7 @@ int main(int argc, char *argv[])
rmlvo.options = argv[5];
uSetErrorFile(NULL);
- XkbcInitAtoms();
+ XkbcInitAtoms(NULL, NULL);
xkb = XkbcCompileKeymapFromRules(&rmlvo);