InputMethod: Avoid needless complex conversion of key modifiers
As we only need to pass the modifiers around, rather than do anything internally with them, simply pass them around with minimal conversion.
This commit is contained in:
parent
105042ccda
commit
25942d6fcb
2 changed files with 5 additions and 33 deletions
|
@ -130,28 +130,13 @@ public:
|
|||
}
|
||||
void zwp_input_method_context_v1_modifiers_map(Resource *, wl_array *map) override
|
||||
{
|
||||
const QList<QByteArray> modifiersMap = QByteArray::fromRawData(static_cast<const char *>(map->data), map->size).split('\0');
|
||||
const auto mods = QByteArray::fromRawData(static_cast<const char *>(map->data), map->size);
|
||||
|
||||
mods.clear();
|
||||
for (const QByteArray &modifier : modifiersMap) {
|
||||
if (modifier == "Shift") {
|
||||
mods << Qt::ShiftModifier;
|
||||
} else if (modifier == "Alt") {
|
||||
mods << Qt::AltModifier;
|
||||
} else if (modifier == "Control") {
|
||||
mods << Qt::ControlModifier;
|
||||
} else if (modifier == "Mod1") {
|
||||
mods << Qt::AltModifier;
|
||||
} else if (modifier == "Mod4") {
|
||||
mods << Qt::MetaModifier;
|
||||
} else {
|
||||
mods << Qt::NoModifier;
|
||||
}
|
||||
}
|
||||
Q_EMIT q->modifiersMap(mods);
|
||||
}
|
||||
void zwp_input_method_context_v1_keysym(Resource *, uint32_t serial, uint32_t time, uint32_t sym, uint32_t state, uint32_t modifiers) override
|
||||
{
|
||||
Q_EMIT q->keysym(serial, time, sym, state == WL_KEYBOARD_KEY_STATE_PRESSED, toQtModifiers(modifiers));
|
||||
Q_EMIT q->keysym(serial, time, sym, state == WL_KEYBOARD_KEY_STATE_PRESSED, modifiers);
|
||||
}
|
||||
void zwp_input_method_context_v1_grab_keyboard(Resource *resource, uint32_t id) override
|
||||
{
|
||||
|
@ -196,19 +181,6 @@ public:
|
|||
Q_EMIT q->textDirection(serial, qtDirection);
|
||||
}
|
||||
|
||||
Qt::KeyboardModifiers toQtModifiers(uint32_t modifiers)
|
||||
{
|
||||
Qt::KeyboardModifiers ret = Qt::NoModifier;
|
||||
// if we never got the modifier map from the input method, return empty modifier
|
||||
if (mods.isEmpty()) {
|
||||
return ret;
|
||||
}
|
||||
for (int i = 0; modifiers >>= 1; ++i) {
|
||||
ret |= mods[i];
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
void zwp_input_method_context_v1_destroy(Resource *resource) override
|
||||
{
|
||||
wl_resource_destroy(resource->handle);
|
||||
|
@ -216,7 +188,6 @@ public:
|
|||
|
||||
InputMethodContextV1Interface *const q;
|
||||
QScopedPointer<InputMethodGrabV1> m_keyboardGrab;
|
||||
QVector<Qt::KeyboardModifiers> mods;
|
||||
};
|
||||
|
||||
InputMethodContextV1Interface::InputMethodContextV1Interface(InputMethodV1Interface *parent)
|
||||
|
|
|
@ -87,12 +87,13 @@ Q_SIGNALS:
|
|||
void preeditCursor(qint32 index);
|
||||
void deleteSurroundingText(qint32 index, quint32 length);
|
||||
void cursorPosition(qint32 index, qint32 anchor);
|
||||
void keysym(quint32 serial, quint32 time, quint32 sym, bool pressed, Qt::KeyboardModifiers modifiers);
|
||||
void keysym(quint32 serial, quint32 time, quint32 sym, bool pressed, quint32 modifiers);
|
||||
void key(quint32 serial, quint32 time, quint32 key, bool pressed);
|
||||
void modifiers(quint32 serial, quint32 mods_depressed, quint32 mods_latched, quint32 mods_locked, quint32 group);
|
||||
void language(quint32 serial, const QString &language);
|
||||
void textDirection(quint32 serial, Qt::LayoutDirection direction);
|
||||
void keyboardGrabRequested(InputMethodGrabV1 *keyboardGrab);
|
||||
void modifiersMap(const QByteArray &map);
|
||||
|
||||
private:
|
||||
friend class InputMethodV1Interface;
|
||||
|
|
Loading…
Reference in a new issue