atom: describe how this odd data structure works
[platform/upstream/libxkbcommon.git] / src / context-priv.c
index 9b81c36..e3ba32d 100644 (file)
@@ -58,13 +58,7 @@ xkb_atom_lookup(struct xkb_context *ctx, const char *string)
 xkb_atom_t
 xkb_atom_intern(struct xkb_context *ctx, const char *string, size_t len)
 {
-    return atom_intern(ctx->atom_table, string, len, false);
-}
-
-xkb_atom_t
-xkb_atom_steal(struct xkb_context *ctx, char *string)
-{
-    return atom_intern(ctx->atom_table, string, strlen(string), true);
+    return atom_intern(ctx->atom_table, string, len);
 }
 
 const char *
@@ -112,7 +106,7 @@ xkb_context_get_buffer(struct xkb_context *ctx, size_t size)
 #define DEFAULT_XKB_OPTIONS NULL
 #endif
 
-const char *
+static const char *
 xkb_context_get_default_rules(struct xkb_context *ctx)
 {
     const char *env = NULL;
@@ -123,7 +117,7 @@ xkb_context_get_default_rules(struct xkb_context *ctx)
     return env ? env : DEFAULT_XKB_RULES;
 }
 
-const char *
+static const char *
 xkb_context_get_default_model(struct xkb_context *ctx)
 {
     const char *env = NULL;
@@ -134,7 +128,7 @@ xkb_context_get_default_model(struct xkb_context *ctx)
     return env ? env : DEFAULT_XKB_MODEL;
 }
 
-const char *
+static const char *
 xkb_context_get_default_layout(struct xkb_context *ctx)
 {
     const char *env = NULL;
@@ -145,11 +139,11 @@ xkb_context_get_default_layout(struct xkb_context *ctx)
     return env ? env : DEFAULT_XKB_LAYOUT;
 }
 
-const char *
+static const char *
 xkb_context_get_default_variant(struct xkb_context *ctx)
 {
     const char *env = NULL;
-    const char *layout = secure_getenv("XKB_DEFAULT_VARIANT");
+    const char *layout = secure_getenv("XKB_DEFAULT_LAYOUT");
 
     /* We don't want to inherit the variant if they haven't also set a
      * layout, since they're so closely paired. */
@@ -159,7 +153,7 @@ xkb_context_get_default_variant(struct xkb_context *ctx)
     return env ? env : DEFAULT_XKB_VARIANT;
 }
 
-const char *
+static const char *
 xkb_context_get_default_options(struct xkb_context *ctx)
 {
     const char *env = NULL;
@@ -169,3 +163,22 @@ xkb_context_get_default_options(struct xkb_context *ctx)
 
     return env ? env : DEFAULT_XKB_OPTIONS;
 }
+
+void
+xkb_context_sanitize_rule_names(struct xkb_context *ctx,
+                                struct xkb_rule_names *rmlvo)
+{
+    if (isempty(rmlvo->rules))
+        rmlvo->rules = xkb_context_get_default_rules(ctx);
+    if (isempty(rmlvo->model))
+        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);
+}