Load xkb keymap information from kxkbrc config file
This is the start for adding proper support for keyboard layouts. If we have a configuration in kxkbrc the keymap is generated from that information. This allows to have different layouts and also layout switching is working (though not yet passed to Wayland clients properly). Not yet working is the global shortcut for layout switching and reconfiguring the layouts.
This commit is contained in:
parent
5caf331610
commit
2e36c4b7ca
2 changed files with 48 additions and 7 deletions
|
@ -89,13 +89,6 @@ Xkb::Xkb(InputRedirection *input)
|
|||
} else {
|
||||
xkb_context_set_log_level(m_context, XKB_LOG_LEVEL_DEBUG);
|
||||
xkb_context_set_log_fn(m_context, &xkbLogHandler);
|
||||
// load default keymap
|
||||
xkb_keymap *keymap = xkb_keymap_new_from_names(m_context, nullptr, XKB_KEYMAP_COMPILE_NO_FLAGS);
|
||||
if (keymap) {
|
||||
updateKeymap(keymap);
|
||||
} else {
|
||||
qCDebug(KWIN_XKB) << "Could not create default xkb keymap";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -106,6 +99,47 @@ Xkb::~Xkb()
|
|||
xkb_context_unref(m_context);
|
||||
}
|
||||
|
||||
void Xkb::reconfigure()
|
||||
{
|
||||
if (!m_context) {
|
||||
return;
|
||||
}
|
||||
|
||||
xkb_keymap *keymap = loadKeymapFromConfig();
|
||||
if (!keymap) {
|
||||
qCDebug(KWIN_XKB) << "Could not create xkb keymap from configuration";
|
||||
keymap = loadDefaultKeymap();
|
||||
}
|
||||
if (keymap) {
|
||||
updateKeymap(keymap);
|
||||
} else {
|
||||
qCDebug(KWIN_XKB) << "Could not create default xkb keymap";
|
||||
}
|
||||
}
|
||||
|
||||
xkb_keymap *Xkb::loadKeymapFromConfig()
|
||||
{
|
||||
// load config
|
||||
const KConfigGroup config = KSharedConfig::openConfig(QStringLiteral("kxkbrc"), KConfig::NoGlobals)->group("Layout");
|
||||
const QByteArray model = config.readEntry("Model", "pc104").toLocal8Bit();
|
||||
const QByteArray layout = config.readEntry("LayoutList", "").toLocal8Bit();
|
||||
const QByteArray options = config.readEntry("Options", "").toLocal8Bit();
|
||||
|
||||
xkb_rule_names ruleNames = {
|
||||
.rules = nullptr,
|
||||
.model = model.constData(),
|
||||
.layout = layout.constData(),
|
||||
.variant = nullptr,
|
||||
.options = options.constData()
|
||||
};
|
||||
return xkb_keymap_new_from_names(m_context, &ruleNames, XKB_KEYMAP_COMPILE_NO_FLAGS);
|
||||
}
|
||||
|
||||
xkb_keymap *Xkb::loadDefaultKeymap()
|
||||
{
|
||||
return xkb_keymap_new_from_names(m_context, nullptr, XKB_KEYMAP_COMPILE_NO_FLAGS);
|
||||
}
|
||||
|
||||
void Xkb::installKeymap(int fd, uint32_t size)
|
||||
{
|
||||
if (!m_context) {
|
||||
|
@ -321,6 +355,8 @@ void KeyboardInputRedirection::init()
|
|||
connect(waylandServer(), &QObject::destroyed, this, [this] { m_inited = false; });
|
||||
connect(workspace(), &Workspace::clientActivated, this, &KeyboardInputRedirection::update);
|
||||
connect(ScreenLocker::KSldApp::self(), &ScreenLocker::KSldApp::lockStateChanged, this, &KeyboardInputRedirection::update);
|
||||
|
||||
m_xkb->reconfigure();
|
||||
}
|
||||
|
||||
void KeyboardInputRedirection::update()
|
||||
|
|
|
@ -47,6 +47,8 @@ class Xkb
|
|||
public:
|
||||
Xkb(InputRedirection *input);
|
||||
~Xkb();
|
||||
void reconfigure();
|
||||
|
||||
void installKeymap(int fd, uint32_t size);
|
||||
void updateModifiers(uint32_t modsDepressed, uint32_t modsLatched, uint32_t modsLocked, uint32_t group);
|
||||
void updateKey(uint32_t key, InputRedirection::KeyboardKeyState state);
|
||||
|
@ -58,7 +60,10 @@ public:
|
|||
|
||||
quint32 getMods(quint32 components);
|
||||
quint32 getGroup();
|
||||
|
||||
private:
|
||||
xkb_keymap *loadKeymapFromConfig();
|
||||
xkb_keymap *loadDefaultKeymap();
|
||||
void updateKeymap(xkb_keymap *keymap);
|
||||
void createKeymapFile();
|
||||
void updateModifiers();
|
||||
|
|
Loading…
Reference in a new issue