XKB_EXPORT char *
xkb_map_get_as_string(struct xkb_keymap *keymap)
{
- return xkb_keymap_get_as_string(keymap);
+ return xkb_keymap_get_as_string(keymap, XKB_KEYMAP_FORMAT_TEXT_V1);
}
XKB_EXPORT struct xkb_keymap *
}
XKB_EXPORT char *
-xkb_keymap_get_as_string(struct xkb_keymap *keymap)
+xkb_keymap_get_as_string(struct xkb_keymap *keymap,
+ enum xkb_keymap_format format)
{
bool ok;
struct buf buf = { NULL, 0, 0 };
+ if (format == XKB_KEYMAP_USE_ORIGINAL_FORMAT)
+ format = keymap->format;
+
+ if (format != XKB_KEYMAP_FORMAT_TEXT_V1) {
+ log_err(keymap->ctx,
+ "Trying to get a keymap as a string in an unsupported format (%d)\n",
+ format);
+ return NULL;
+ }
+
ok = (check_write_buf(&buf, "xkb_keymap {\n") &&
write_keycodes(keymap, &buf) &&
write_types(keymap, &buf) &&
#include "text.h"
struct xkb_keymap *
-xkb_keymap_new(struct xkb_context *ctx)
+xkb_keymap_new(struct xkb_context *ctx,
+ enum xkb_keymap_format format,
+ enum xkb_keymap_compile_flags flags)
{
struct xkb_keymap *keymap;
keymap->refcnt = 1;
keymap->ctx = xkb_context_ref(ctx);
+ keymap->format = format;
+ keymap->flags = flags;
+
return keymap;
}
int refcnt;
enum xkb_keymap_compile_flags flags;
+ enum xkb_keymap_format format;
unsigned int enabled_ctrls;
}
struct xkb_keymap *
-xkb_keymap_new(struct xkb_context *ctx);
+xkb_keymap_new(struct xkb_context *ctx,
+ enum xkb_keymap_format format,
+ enum xkb_keymap_compile_flags);
#endif
#include "rules.h"
static struct xkb_keymap *
-compile_keymap_file(struct xkb_context *ctx, XkbFile *file)
+compile_keymap_file(struct xkb_context *ctx, XkbFile *file,
+ enum xkb_keymap_format format,
+ enum xkb_keymap_compile_flags flags)
{
struct xkb_keymap *keymap;
- keymap = xkb_keymap_new(ctx);
+ keymap = xkb_keymap_new(ctx, format, flags);
if (!keymap)
goto err;
return NULL;
}
- keymap = compile_keymap_file(ctx, file);
+ keymap = compile_keymap_file(ctx, file, XKB_KEYMAP_FORMAT_TEXT_V1, flags);
FreeXkbFile(file);
return keymap;
}
return NULL;
}
- keymap = compile_keymap_file(ctx, file);
+ keymap = compile_keymap_file(ctx, file, format, flags);
FreeXkbFile(file);
return keymap;
}
return NULL;
}
- keymap = compile_keymap_file(ctx, xkb_file);
+ keymap = compile_keymap_file(ctx, xkb_file, format, flags);
FreeXkbFile(xkb_file);
return keymap;
}
goto err_ctx;
}
- dump = xkb_keymap_get_as_string(keymap);
+ dump = xkb_keymap_get_as_string(keymap, XKB_KEYMAP_FORMAT_TEXT_V1);
if (!dump) {
fprintf(stderr, "Couldn't get the keymap string\n");
goto err_map;
keymap = test_compile_string(ctx, original);
assert(keymap);
- dump = xkb_keymap_get_as_string(keymap);
+ dump = xkb_keymap_get_as_string(keymap, XKB_KEYMAP_USE_ORIGINAL_FORMAT);
assert(dump);
if (!streq(original, dump)) {
xkb_keymap_new_from_file(context, file, format, flags)
#define xkb_map_new_from_string(context, string, format, flags) \
xkb_keymap_new_from_string(context, string, format, flags)
-#define xkb_map_get_as_string(keymap) xkb_keymap_get_as_string(keymap)
+#define xkb_map_get_as_string(keymap) \
+ xkb_keymap_get_as_string(keymap, XKB_KEYMAP_FORMAT_TEXT_V1)
#define xkb_map_ref(keymap) xkb_keymap_ref(keymap)
#define xkb_map_unref(keymap) xkb_keymap_unref(keymap)
void
xkb_keymap_unref(struct xkb_keymap *keymap);
+/* See xkb_keymap_get_as_string(). */
+#define XKB_KEYMAP_USE_ORIGINAL_FORMAT ((enum xkb_keymap_format) -1)
+
/**
* @brief Get the compiled keymap as a string.
*
- * @returns The compiled keymap as a NUL-terminated string, or NULL if
- * unsuccessful.
+ * @param keymap The keymap to get as a string.
+ * @param format The keymap format to use for the string. You can pass
+ * in the special value XKB_KEYMAP_USE_ORIGINAL_FORMAT to use the format
+ * from which the keymap was originally created.
+ *
+ * @returns The keymap as a NUL-terminated string, or NULL if unsuccessful.
*
* The returned string may be fed back into xkb_map_new_from_string() to get
* the exact same keymap (possibly in another process, etc.).
* by the caller.
*/
char *
-xkb_keymap_get_as_string(struct xkb_keymap *keymap);
+xkb_keymap_get_as_string(struct xkb_keymap *keymap,
+ enum xkb_keymap_format format);
/** @} */