Commit 04253fb2eb4500d331971a2a345af1f48ca42493

Daniel Stone 2012-08-03T02:51:10

Add support for default rules/model/layout Right now it just comes from build-time, but eventually this should be sourced from configuration files at runtime too. Signed-off-by: Daniel Stone <daniel@fooishbar.org>

diff --git a/configure.ac b/configure.ac
index b5a83bc..12db771 100644
--- a/configure.ac
+++ b/configure.ac
@@ -97,6 +97,29 @@ AC_ARG_WITH([xkb_config_root],
     [XKBCONFIGROOT="$xkb_base"])
 AC_SUBST([XKBCONFIGROOT])
 
+AC_ARG_WITH([default_rules],
+    [AS_HELP_STRING([--with-default-rules=<path>],
+        [Default XKB ruleset (default: evdev)])],
+    [DEFAULT_XKB_RULES="$withval"],
+    [DEFAULT_XKB_RULES="evdev"])
+AC_DEFINE_UNQUOTED([DEFAULT_XKB_RULES], ["$DEFAULT_XKB_RULES"],
+                   [Default XKB ruleset])
+
+AC_ARG_WITH([default_model],
+    [AS_HELP_STRING([--with-default-model=<path>],
+        [Default XKB model (default: pc105)])],
+    [DEFAULT_XKB_MODEL="$withval"],
+    [DEFAULT_XKB_MODEL="pc105"])
+AC_DEFINE_UNQUOTED([DEFAULT_XKB_MODEL], ["$DEFAULT_XKB_MODEL"],
+                   [Default XKB model])
+
+AC_ARG_WITH([default_layout],
+    [AS_HELP_STRING([--with-default-layout=<path>],
+        [Default XKB layout (default: us)])],
+    [DEFAULT_XKB_LAYOUT="$withval"],
+    [DEFAULT_XKB_LAYOUT="us"])
+AC_DEFINE_UNQUOTED([DEFAULT_XKB_LAYOUT], ["$DEFAULT_XKB_LAYOUT"],
+                   [Default XKB layout])
 
 AC_CONFIG_FILES([
     Makefile
diff --git a/src/xkbcomp/xkbcomp.c b/src/xkbcomp/xkbcomp.c
index 2932ba3..b18cd70 100644
--- a/src/xkbcomp/xkbcomp.c
+++ b/src/xkbcomp/xkbcomp.c
@@ -246,21 +246,24 @@ xkb_map_new_from_kccgst(struct xkb_context *ctx,
 
 XKB_EXPORT struct xkb_keymap *
 xkb_map_new_from_names(struct xkb_context *ctx,
-                       const struct xkb_rule_names *rmlvo,
+                       const struct xkb_rule_names *rmlvo_in,
                        enum xkb_map_compile_flags flags)
 {
     struct xkb_component_names *kkctgs;
     struct xkb_keymap *keymap;
+    struct xkb_rule_names rmlvo = *rmlvo_in;
 
-    if (!rmlvo || ISEMPTY(rmlvo->rules) || ISEMPTY(rmlvo->layout)) {
-        log_err(ctx, "rules and layout required to generate XKB keymap\n");
-        return NULL;
-    }
+    if (ISEMPTY(rmlvo.rules))
+        rmlvo.rules = DEFAULT_XKB_RULES;
+    if (ISEMPTY(rmlvo.model))
+        rmlvo.model = DEFAULT_XKB_MODEL;
+    if (ISEMPTY(rmlvo.layout))
+        rmlvo.layout = DEFAULT_XKB_LAYOUT;
 
-    kkctgs = xkb_components_from_rules(ctx, rmlvo);
+    kkctgs = xkb_components_from_rules(ctx, &rmlvo);
     if (!kkctgs) {
         log_err(ctx, "failed to generate XKB components from rules \"%s\"\n",
-                rmlvo->rules);
+                rmlvo.rules);
         return NULL;
     }
 
diff --git a/test/rulescomp.c b/test/rulescomp.c
index e2f4aec..30c0df8 100644
--- a/test/rulescomp.c
+++ b/test/rulescomp.c
@@ -100,7 +100,6 @@ int main(int argc, char *argv[])
     assert(test_rmlvo(ctx, "evdev",      "pc105",  "us",  "intl",  ""));
     assert(test_rmlvo(ctx, "evdev",      "pc105",  "us",  "intl",  "grp:alts_toggle"));
 
-    assert(!test_rmlvo(ctx, "",          "",       "",    "",      ""));
     assert(!test_rmlvo(ctx, "base",      "",       "",    "",      ""));
     assert(!test_rmlvo(ctx, "base",      "pc105",  "",    "",      ""));
     assert(!test_rmlvo(ctx, "badrules",  "",       "us",  "",      ""));