Fix the key code of key events when control is pressed
Change-Id: I51a57a32d8263e663a48dac15881d685359bc91d Reviewed-by: Jan Arne Petersen <jan.petersen@kdab.com> Reviewed-by: Pier Luigi Fiorini <pierluigi.fiorini@hawaiios.org>
This commit is contained in:
parent
c32b30362d
commit
f213a7d54e
@ -335,8 +335,9 @@ void QWaylandTextInput::zwp_text_input_v2_keysym(uint32_t time, uint32_t sym, ui
|
||||
Qt::KeyboardModifiers qtModifiers = modifiersToQtModifiers(modifiers);
|
||||
|
||||
QEvent::Type type = QWaylandXkb::toQtEventType(state);
|
||||
const QString &text = QWaylandXkb::textFromKeysym(sym, qtModifiers);
|
||||
int qtkey = QWaylandXkb::keysymToQtKey(sym, qtModifiers, text);
|
||||
QString text;
|
||||
int qtkey;
|
||||
std::tie(qtkey, text) = QWaylandXkb::keysymToQtKey(sym, qtModifiers);
|
||||
|
||||
QWindowSystemInterface::handleKeyEvent(QGuiApplication::focusWindow(),
|
||||
time, type, qtkey, qtModifiers, text);
|
||||
|
@ -707,8 +707,7 @@ void QWaylandInputDevice::Keyboard::keyboard_key(uint32_t serial, uint32_t time,
|
||||
|
||||
Qt::KeyboardModifiers modifiers = mParent->modifiers();
|
||||
|
||||
text = QWaylandXkb::textFromKeysym(sym, modifiers);
|
||||
qtkey = QWaylandXkb::keysymToQtKey(sym, modifiers, text);
|
||||
std::tie(qtkey, text) = QWaylandXkb::keysymToQtKey(sym, modifiers);
|
||||
|
||||
sendKey(window->window(), time, type, qtkey, modifiers, code, sym, mNativeModifiers, text);
|
||||
#else
|
||||
|
@ -293,8 +293,13 @@ static xkb_keysym_t toKeysymFromTable(uint32_t key)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int QWaylandXkb::keysymToQtKey(xkb_keysym_t keysym, Qt::KeyboardModifiers &modifiers, const QString &text)
|
||||
std::pair<int, QString> QWaylandXkb::keysymToQtKey(xkb_keysym_t keysym, Qt::KeyboardModifiers &modifiers)
|
||||
{
|
||||
QString text;
|
||||
uint utf32 = xkb_keysym_to_utf32(keysym);
|
||||
if (utf32)
|
||||
text = QString::fromUcs4(&utf32, 1);
|
||||
|
||||
int code = 0;
|
||||
|
||||
if (keysym >= XKB_KEY_F1 && keysym <= XKB_KEY_F35) {
|
||||
@ -316,7 +321,13 @@ int QWaylandXkb::keysymToQtKey(xkb_keysym_t keysym, Qt::KeyboardModifiers &modif
|
||||
code = lookupKeysym(keysym);
|
||||
}
|
||||
|
||||
return code;
|
||||
// Map control + letter to proper text
|
||||
if (utf32 >= 'A' && utf32 <= '~' && (modifiers & Qt::ControlModifier)) {
|
||||
utf32 &= ~0x60;
|
||||
text = QString::fromUcs4(&utf32, 1);
|
||||
}
|
||||
|
||||
return { code, text };
|
||||
}
|
||||
|
||||
Qt::KeyboardModifiers QWaylandXkb::modifiers(struct xkb_state *state)
|
||||
@ -342,22 +353,6 @@ QEvent::Type QWaylandXkb::toQtEventType(uint32_t state)
|
||||
return state != 0 ? QEvent::KeyPress : QEvent::KeyRelease;
|
||||
}
|
||||
|
||||
QString QWaylandXkb::textFromKeysym(uint32_t keysym, Qt::KeyboardModifiers modifiers)
|
||||
{
|
||||
uint utf32 = xkb_keysym_to_utf32(keysym);
|
||||
|
||||
// Map control + letter to proper text
|
||||
if (utf32 >= 'A' && utf32 <= '~' && (modifiers & Qt::ControlModifier)) {
|
||||
utf32 &= ~0x60;
|
||||
return QString::fromUcs4(&utf32, 1);
|
||||
}
|
||||
|
||||
if (utf32)
|
||||
return QString::fromUcs4(&utf32, 1);
|
||||
|
||||
return QString();
|
||||
}
|
||||
|
||||
QVector<xkb_keysym_t> QWaylandXkb::toKeysym(QKeyEvent *event)
|
||||
{
|
||||
QVector<xkb_keysym_t> keysyms;
|
||||
|
@ -47,6 +47,8 @@
|
||||
#include <QEvent>
|
||||
#include <xkbcommon/xkbcommon.h>
|
||||
|
||||
#include <utility>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
class QKeyEvent;
|
||||
@ -54,11 +56,10 @@ class QKeyEvent;
|
||||
class QWaylandXkb
|
||||
{
|
||||
public:
|
||||
static int keysymToQtKey(xkb_keysym_t keysym, Qt::KeyboardModifiers &modifiers, const QString &text);
|
||||
static std::pair<int, QString> keysymToQtKey(xkb_keysym_t keysym, Qt::KeyboardModifiers &modifiers);
|
||||
static Qt::KeyboardModifiers modifiers(struct xkb_state *state);
|
||||
|
||||
static QEvent::Type toQtEventType(uint32_t state);
|
||||
static QString textFromKeysym(uint32_t keysym, Qt::KeyboardModifiers modifiers);
|
||||
static QVector<xkb_keysym_t> toKeysym(QKeyEvent *event);
|
||||
};
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user