#pragma once #include "layout/KeymapLetters.h" #include "layout/LayoutBuilder.h" #include "layout/LayoutLoader.h" #include #include #include // Builds layouts the way the app does: the built-in template filled from a // keymap, here compiled from XKB names instead of received from a compositor. // Q_INIT_RESOURCE can't be used inside a namespace. inline void initLayoutResources() { Q_INIT_RESOURCE(layouts); } namespace TestLayouts { inline Layout builtinTemplate() { initLayoutResources(); QString error; const auto layout = LayoutLoader::load(QStringLiteral(":/layouts/template.json"), &error); if (!layout) qFatal("template.json: %s", qPrintable(error)); return *layout; } inline KeymapLetters letters(const char *layout, const char *variant = nullptr) { const std::unique_ptr context( xkb_context_new(XKB_CONTEXT_NO_ENVIRONMENT_NAMES), xkb_context_unref); const xkb_rule_names names{.rules = "evdev", .model = "pc105", .layout = layout, .variant = variant, .options = nullptr}; const std::unique_ptr keymap( xkb_keymap_new_from_names(context.get(), &names, XKB_KEYMAP_COMPILE_NO_FLAGS), xkb_keymap_unref); if (!keymap) qFatal("no XKB keymap for %s", layout); return readKeymapLetters(keymap.get(), 0); } inline Layout build(const char *layout, const char *variant = nullptr) { return buildLayout(builtinTemplate(), letters(layout, variant)); } } // namespace TestLayouts