Commit 2c4a045aca7c680a0315850a0e69784ac08f96a3

Daniel Stone 2010-06-21T14:22:26

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>

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);