Add environment overrides for default RMLVO You can now set default values in the environment, as well as a context option to ignore the environment, e.g. for tests. 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 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232
diff --git a/configure.ac b/configure.ac
index a0fcfe6..f795510 100644
--- a/configure.ac
+++ b/configure.ac
@@ -114,6 +114,26 @@ AC_ARG_WITH([default_layout],
AC_DEFINE_UNQUOTED([DEFAULT_XKB_LAYOUT], ["$DEFAULT_XKB_LAYOUT"],
[Default XKB layout])
+AC_ARG_WITH([default_variant],
+ [AS_HELP_STRING([--with-default-variant=<path>],
+ [Default XKB variant (default: (none))])],
+ [DEFAULT_XKB_VARIANT="$withval"],
+ [DEFAULT_XKB_VARAINT=])
+if ! test "x$DEFAULT_XKB_VARIANT" = x; then
+ AC_DEFINE_UNQUOTED([DEFAULT_XKB_VARIANT], ["$DEFAULT_XKB_VARIANT"],
+ [Default XKB variant])
+fi
+
+AC_ARG_WITH([default_options],
+ [AS_HELP_STRING([--with-default-options=<path>],
+ [Default XKB options (default: (none))])],
+ [DEFAULT_XKB_OPTIONS="$withval"],
+ [DEFAULT_XKB_OPTIONS=])
+if ! test "x$DEFAULT_XKB_OPTIONS" = x; then
+ AC_DEFINE_UNQUOTED([DEFAULT_XKB_OPTIONS], ["$DEFAULT_XKB_OPTIONS"],
+ [Default XKB options])
+fi
+
AC_CONFIG_FILES([
Makefile
xkbcommon-uninstalled.pc
diff --git a/src/context.c b/src/context.c
index 2dd8ea9..8d56487 100644
--- a/src/context.c
+++ b/src/context.c
@@ -44,6 +44,8 @@ struct xkb_context {
int log_verbosity;
void *user_data;
+ struct xkb_rule_names names_dflt;
+
darray(char *) includes;
darray(char *) failed_includes;
@@ -52,6 +54,8 @@ struct xkb_context {
/* Buffer for the *Text() functions. */
char text_buffer[2048];
size_t text_next;
+
+ unsigned int use_environment_names : 1;
};
/**
@@ -271,6 +275,14 @@ log_verbosity(const char *verbosity) {
return 0;
}
+#ifndef DEFAULT_XKB_VARIANT
+#define DEFAULT_XKB_VARIANT NULL
+#endif
+
+#ifndef DEFAULT_XKB_OPTIONS
+#define DEFAULT_XKB_OPTIONS NULL
+#endif
+
/**
* Create a new context.
*/
@@ -305,6 +317,8 @@ xkb_context_new(enum xkb_context_flags flags)
return NULL;
}
+ ctx->use_environment_names = !(flags & XKB_CONTEXT_NO_ENVIRONMENT_NAMES);
+
ctx->atom_table = atom_table_new();
if (!ctx->atom_table) {
xkb_context_unref(ctx);
@@ -418,3 +432,61 @@ xkb_context_get_buffer(struct xkb_context *ctx, size_t size)
return rtrn;
}
+
+const char *
+xkb_context_get_default_rules(struct xkb_context *ctx)
+{
+ const char *env = NULL;
+
+ if (ctx->use_environment_names)
+ env = getenv("XKB_DEFAULT_RULES");
+
+ return env ? env : DEFAULT_XKB_RULES;
+}
+
+const char *
+xkb_context_get_default_model(struct xkb_context *ctx)
+{
+ const char *env = NULL;
+
+ if (ctx->use_environment_names)
+ env = getenv("XKB_DEFAULT_MODEL");
+
+ return env ? env : DEFAULT_XKB_MODEL;
+}
+
+const char *
+xkb_context_get_default_layout(struct xkb_context *ctx)
+{
+ const char *env = NULL;
+
+ if (ctx->use_environment_names)
+ env = getenv("XKB_DEFAULT_LAYOUT");
+
+ return env ? env : DEFAULT_XKB_LAYOUT;
+}
+
+const char *
+xkb_context_get_default_variant(struct xkb_context *ctx)
+{
+ const char *env = NULL;
+ const char *layout = getenv("XKB_DEFAULT_VARIANT");
+
+ /* We don't want to inherit the variant if they haven't also set a
+ * layout, since they're so closely paired. */
+ if (layout && ctx->use_environment_names)
+ env = getenv("XKB_DEFAULT_VARIANT");
+
+ return env ? env : DEFAULT_XKB_VARIANT;
+}
+
+const char *
+xkb_context_get_default_options(struct xkb_context *ctx)
+{
+ const char *env = NULL;
+
+ if (ctx->use_environment_names)
+ env = getenv("XKB_DEFAULT_OPTIONS");
+
+ return env ? env : DEFAULT_XKB_OPTIONS;
+}
diff --git a/src/context.h b/src/context.h
index 2f94988..7c061a0 100644
--- a/src/context.h
+++ b/src/context.h
@@ -77,6 +77,21 @@ xkb_log(struct xkb_context *ctx, enum xkb_log_level level,
xkb_log_cond_level((ctx), (level), __VA_ARGS__); \
} while (0)
+const char *
+xkb_context_get_default_rules(struct xkb_context *ctx);
+
+const char *
+xkb_context_get_default_model(struct xkb_context *ctx);
+
+const char *
+xkb_context_get_default_layout(struct xkb_context *ctx);
+
+const char *
+xkb_context_get_default_variant(struct xkb_context *ctx);
+
+const char *
+xkb_context_get_default_options(struct xkb_context *ctx);
+
/*
* The format is not part of the argument list in order to avoid the
* "ISO C99 requires rest arguments to be used" warning when only the
diff --git a/src/keymap.c b/src/keymap.c
index 8404c03..b468f94 100644
--- a/src/keymap.c
+++ b/src/keymap.c
@@ -153,13 +153,24 @@ xkb_keymap_new_from_names(struct xkb_context *ctx,
return NULL;
}
- rmlvo = *rmlvo_in;
+ if (rmlvo_in)
+ rmlvo = *rmlvo_in;
+ else
+ memset(&rmlvo, 0, sizeof(rmlvo));
+
if (isempty(rmlvo.rules))
- rmlvo.rules = DEFAULT_XKB_RULES;
+ rmlvo.rules = xkb_context_get_default_rules(ctx);
if (isempty(rmlvo.model))
- rmlvo.model = DEFAULT_XKB_MODEL;
- if (isempty(rmlvo.layout))
- rmlvo.layout = DEFAULT_XKB_LAYOUT;
+ rmlvo.model = xkb_context_get_default_model(ctx);
+ /* Layout and variant are tied together, so don't try to use one from
+ * the caller and one from the environment. */
+ if (isempty(rmlvo.layout)) {
+ rmlvo.layout = xkb_context_get_default_layout(ctx);
+ rmlvo.variant = xkb_context_get_default_variant(ctx);
+ }
+ /* Options can be empty, so respect that if passed in. */
+ if (rmlvo.options == NULL)
+ rmlvo.options = xkb_context_get_default_options(ctx);
keymap = xkb_keymap_new(ctx, format, flags);
if (!keymap)
diff --git a/test/rmlvo-to-kccgst.c b/test/rmlvo-to-kccgst.c
index bba2bde..bab725d 100644
--- a/test/rmlvo-to-kccgst.c
+++ b/test/rmlvo-to-kccgst.c
@@ -61,13 +61,6 @@ main(int argc, char *argv[])
}
}
- 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;
-
ctx = test_get_context(0);
if (!ctx) {
fprintf(stderr, "Failed to get xkb context\n");
diff --git a/xkbcommon/xkbcommon.h b/xkbcommon/xkbcommon.h
index 1756948..cdc021b 100644
--- a/xkbcommon/xkbcommon.h
+++ b/xkbcommon/xkbcommon.h
@@ -417,7 +417,9 @@ xkb_keysym_to_utf32(xkb_keysym_t keysym);
/** Flags for context creation. */
enum xkb_context_flags {
/** Create this context with an empty include path. */
- XKB_CONTEXT_NO_DEFAULT_INCLUDES = (1 << 0)
+ XKB_CONTEXT_NO_DEFAULT_INCLUDES = (1 << 0),
+ /** Don't take RMLVO names from the environment. */
+ XKB_CONTEXT_NO_ENVIRONMENT_NAMES = (1 << 1),
};
/**