Compile keyboard description from XKB rules, too XkbcCompileKeymapFromRules can be used to generate a XkbDescPtr from XKB rules instead of using components. The previous XkbcCompileKeymap has been renamed to XkbcCompileKeymapFromComponents.
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
diff --git a/include/X11/extensions/XKBcommon.h b/include/X11/extensions/XKBcommon.h
index 80a5e46..2ed590d 100644
--- a/include/X11/extensions/XKBcommon.h
+++ b/include/X11/extensions/XKBcommon.h
@@ -67,7 +67,10 @@ typedef struct _XkbcDesc {
_XFUNCPROTOBEGIN
extern XkbcDescPtr
-XkbcCompileKeymap(XkbComponentNamesPtr ktcsg);
+XkbcCompileKeymapFromRules(const char *rules, XkbRF_VarDefsPtr defs);
+
+extern XkbcDescPtr
+XkbcCompileKeymapFromComponents(XkbComponentNamesPtr ktcsg);
extern char *
XkbcKeysymToString(KeySym ks);
diff --git a/src/xkbcomp/xkbcomp.c b/src/xkbcomp/xkbcomp.c
index e8c2fb8..68f50a4 100644
--- a/src/xkbcomp/xkbcomp.c
+++ b/src/xkbcomp/xkbcomp.c
@@ -24,12 +24,18 @@ sale, use or other dealings in this Software without prior written
authorization from the authors.
*/
+#include <limits.h>
#include "X11/extensions/XKBcommon.h"
#include <X11/extensions/XKM.h>
+#include "XKBcommonint.h"
#include "xkbcomp.h"
#include "parseutils.h"
#include "utils.h"
+#ifndef DFLT_XKB_CONFIG_ROOT
+#define DFLT_XKB_CONFIG_ROOT "/usr/share/X11/xkb"
+#endif
+
static int
XkbFileFromComponents(const XkbComponentNamesPtr ktcsg, XkbFile **file)
{
@@ -60,8 +66,71 @@ XkbFileFromComponents(const XkbComponentNamesPtr ktcsg, XkbFile **file)
return 1;
}
+static XkbComponentNamesPtr
+XkbComponentsFromRules(const char *rulesPath, const XkbRF_VarDefsPtr defs)
+{
+ XkbRF_RulesPtr rules;
+ XkbComponentNamesPtr names = NULL;
+
+ if (!(rules = XkbcRF_Load((char *)rulesPath, NULL, False, True))) {
+ ERROR("Failed to load XKB rules \"%s\"\n", rulesPath);
+ goto fail;
+ }
+
+ if (!(names = _XkbTypedCalloc(1, XkbComponentNamesRec))) {
+ ERROR("Failed to allocate XKB components\n");
+ goto unwind_rules;
+ }
+
+ if (!XkbcRF_GetComponents(rules, defs, names))
+ ERROR("No components returned from XKB rules \"%s\"\n", rulesPath);
+
+unwind_rules:
+ XkbcRF_Free(rules, True);
+fail:
+ return names;
+}
+
+XkbcDescPtr
+XkbcCompileKeymapFromRules(const char *rules, XkbRF_VarDefsPtr defs)
+{
+ char rulesPath[PATH_MAX];
+ int pathlen;
+ XkbComponentNamesPtr names;
+ XkbcDescPtr xkb;
+
+ if (!rules)
+ return NULL;
+
+ pathlen = snprintf(rulesPath, sizeof(rulesPath),
+ DFLT_XKB_CONFIG_ROOT "/rules/%s", rules);
+ if (pathlen >= sizeof(rulesPath)) {
+ ERROR("XKB rules path truncated\n");
+ return NULL;
+ }
+
+ names = XkbComponentsFromRules(rulesPath, defs);
+ if (!names) {
+ ERROR("Failed to generate XKB components from rules \"%s\"\n",
+ rules);
+ return NULL;
+ }
+
+ xkb = XkbcCompileKeymapFromComponents(names);
+
+ _XkbFree(names->keymap);
+ _XkbFree(names->keycodes);
+ _XkbFree(names->types);
+ _XkbFree(names->compat);
+ _XkbFree(names->symbols);
+ _XkbFree(names->geometry);
+ _XkbFree(names);
+
+ return xkb;
+}
+
XkbcDescPtr
-XkbcCompileKeymap(XkbComponentNamesPtr ktcsg)
+XkbcCompileKeymapFromComponents(XkbComponentNamesPtr ktcsg)
{
XkbFile *file, *mapToUse;
XkbcDescPtr xkb;